comparison serial/debug-chases/serialswitch.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 * SERIALSWITCH.C
4 *
5 * This module allows managing the use of the serial ports of TI GSM Evaluation
6 * Boards.
7 * An application may have to send several serial data flows. The board on which
8 * the application is running may have one or several devices. The purpose of
9 * this module is to establish connections between the serial data flows and the
10 * serial devices at runtime, when the application is started.
11 *
12 * (C) Texas Instruments 1999 - 2003
13 *
14 ******************************************************************************/
15
16 #define __SERIALSWITCH_C__
17
18 #define __STANDARD_H__ /* Avoid to define UBYTE, SYS_UWORD16 and UINT32. */
19
20 #include "../include/config.h"
21 #include "../include/sys_types.h"
22 #include "../riviera/rv/rv_general.h"
23 #include "../riviera/rvf/rvf_api.h"
24 #include "../nucleus/nucleus.h"
25
26 #include "serialswitch.h"
27
28 #include "uart.h"
29 #include "uartfax.h"
30
31 #include "../bsp/mem.h"
32
33 #include <string.h> /* needed for memcmp & memset */
34
35 #if SERIAL_DYNAMIC_SWITCH
36 #include "ffs/ffs.h"
37 #include "rvf/rvf_api.h"
38 #include "inth/iq.h"
39 #include "rvt/rvt_def_i.h" /* needed for Riviera/Layer1 Trace's callback function */
40 #endif
41
42 #if defined(BTEMOBILE)
43 #include "hci_ser.h"
44 #endif
45
46 #define DUMMY_DEVICE (0)
47
48 #define IIR (0x02) /* UART interrupt ident. register - Read only */
49 #define SCR (0x10) /* UART suppl. control register - Read/Write */
50 #define SSR (0x11) /* UART suppl. status register - Read only */
51
52 /*
53 * Interrupt identification register.
54 * Bit 0 is set to 0 if an IT is pending.
55 * Bits 1 and 2 are used to identify the IT.
56 */
57
58 #define IIR_BITS_USED (0x07)
59 #define IT_NOT_PENDING (0x01)
60
61 /*
62 * Supplementary Control Register
63 */
64
65 #define RX_CTS_WAKE_UP_ENABLE_BIT (4)
66
67 /*
68 * Supplementary Status Register
69 */
70
71 #define RX_CTS_WAKE_UP_STS (0x02) /* Wake-up interrupt occurred */
72
73 /*
74 * This macro allows to read an UART register.
75 */
76
77 #define READ_UART_REGISTER(UART,REG) \
78 *((volatile SYS_UWORD8 *) ((UART)->base_address + (REG)))
79
80
81 /*
82 * This macro allows to disable the UART's wake-up interrupt.
83 */
84
85 #define DISABLE_WAKE_UP_INTERRUPT(UART) \
86 *((volatile SYS_UWORD8 *) ((UART)->base_address + SCR)) &= \
87 ~(1 << (RX_CTS_WAKE_UP_ENABLE_BIT));
88
89 /*
90 * Wake-up time duration in seconds and in number of TDMAs.
91 * 1 TDMA = (6 / 1300) s = 0.004615 s (= 4.615 ms).
92 */
93
94 #define WAKE_UP_TIME_DURATION (10) /* 10 seconds */
95 #define WAKE_UP_TIME_IN_TDMA (WAKE_UP_TIME_DURATION * 1300 / 6)
96
97
98 /*
99 * Global uartswitch variable as read from FFS.
100 * It is supposed that NUMBER_OF_TR_UART, NUMBER_OF_FD_UART
101 * and NUMBER_OF_BT_UART have the same values.
102 */
103
104 #define DUMMY ('0')
105 #define G23_PANEL ('G')
106 #define RIVIERA_TRACE_MUX ('R')
107 #define FD_AT_COMMAND ('D')
108 #define BLUETOOTH_HCI ('B')
109
110 #if (CHIPSET == 12)
111 char ser_cfg_info[NUMBER_OF_TR_UART] = {DUMMY, DUMMY, DUMMY};
112 #else
113 char ser_cfg_info[NUMBER_OF_TR_UART] = {DUMMY, DUMMY};
114 #endif
115 static SYS_UWORD16 serial_cfg = 0x0048; /* All dummies */
116
117 #if SERIAL_DYNAMIC_SWITCH
118 /*
119 * Global variables used for Dynamic Switch.
120 */
121
122 static char ser_new_cfg[NUMBER_OF_TR_UART] = {DUMMY, DUMMY};
123 const static char uart_config_file[] = "/sys/uartswitch";
124 static SYS_BOOL dynamic_switch = 0;
125
126 /* Import Serial Info structure. */
127 extern T_AppliSerialInfo appli_ser_cfg_info;
128 #endif
129
130 /*
131 * Types of flows supported.
132 */
133
134 typedef enum {
135 TRACE_FLOW,
136 FAX_DATA_FLOW,
137 BLUETOOTH_HCI_FLOW
138 } t_flow_type;
139
140 /*
141 * For each serial data flow, a set of function pointers allows calling the
142 * functions associated to a serial device.
143 */
144
145 typedef struct s_tr_functions {
146
147 T_tr_UartId device;
148
149 void (*tr_Init) (T_tr_UartId device,
150 T_tr_Baudrate baudrate,
151 void (callback_function (void)));
152
153 SYS_UWORD32 (*tr_ReadNChars) (T_tr_UartId device,
154 char *buffer,
155 SYS_UWORD32 chars_to_read);
156
157 SYS_UWORD32 (*tr_ReadNBytes) (T_tr_UartId device,
158 char *buffer,
159 SYS_UWORD32 chars_to_read,
160 SYS_BOOL *eof_detected);
161
162 SYS_UWORD32 (*tr_WriteNChars) (T_tr_UartId device,
163 char *buffer,
164 SYS_UWORD32 chars_to_write);
165
166 SYS_UWORD32 (*tr_EncapsulateNChars) (T_tr_UartId device,
167 char *buffer,
168 SYS_UWORD32 chars_to_write);
169
170 SYS_UWORD32 (*tr_WriteNBytes) (T_tr_UartId device,
171 SYS_UWORD8 *buffer,
172 SYS_UWORD32 chars_to_write);
173
174 void (*tr_WriteChar) (T_tr_UartId device,
175 char character);
176
177 void (*tr_WriteString) (T_tr_UartId device,
178 char *buffer);
179
180 SYS_BOOL (*tr_EnterSleep) (T_tr_UartId device);
181
182 void (*tr_WakeUp) (T_tr_UartId device);
183
184 } t_tr_functions;
185
186 /*
187 * Set of function pointers for fax & data functions.
188 */
189
190 typedef struct s_fd_functions {
191
192 T_fd_UartId device;
193
194 T_FDRET (*fd_Initialize) (T_fd_UartId device);
195
196 T_FDRET (*fd_Enable) (T_fd_UartId device,
197 SYS_BOOL enable);
198
199 T_FDRET (*fd_SetComPar) (T_fd_UartId device,
200 T_baudrate baudrate,
201 T_bitsPerCharacter bpc,
202 T_stopBits sb,
203 T_parity parity);
204
205 T_FDRET (*fd_SetBuffer) (T_fd_UartId device,
206 SYS_UWORD16 bufSize,
207 SYS_UWORD16 rxThreshold,
208 SYS_UWORD16 txThreshold);
209
210 T_FDRET (*fd_SetFlowCtrl) (T_fd_UartId device,
211 T_flowCtrlMode fcMode,
212 SYS_UWORD8 XON,
213 SYS_UWORD8 XOFF);
214
215 T_FDRET (*fd_SetEscape) (T_fd_UartId device,
216 SYS_UWORD8 escChar,
217 SYS_UWORD16 guardPeriod);
218
219 T_FDRET (*fd_InpAvail) (T_fd_UartId device);
220
221 T_FDRET (*fd_OutpAvail) (T_fd_UartId device);
222
223 T_FDRET (*fd_EnterSleep) (T_fd_UartId device);
224
225 T_FDRET (*fd_WakeUp) (T_fd_UartId device);
226
227 T_FDRET (*fd_ReadData) (T_fd_UartId device,
228 T_suspendMode suspend,
229 void (readOutFunc (SYS_BOOL cldFromIrq,
230 T_reInstMode *reInstall,
231 SYS_UWORD8 nsource,
232 SYS_UWORD8 *source[],
233 SYS_UWORD16 size[],
234 SYS_UWORD32 state)));
235
236 T_FDRET (*fd_WriteData) (T_fd_UartId device,
237 T_suspendMode suspend,
238 void (writeInFunc (SYS_BOOL cldFromIrq,
239 T_reInstMode *reInstall,
240 SYS_UWORD8 ndest,
241 SYS_UWORD8 *dest[],
242 SYS_UWORD16 size[])));
243
244 T_FDRET (*fd_StopRec) (T_fd_UartId device);
245
246 T_FDRET (*fd_StartRec) (T_fd_UartId device);
247
248 T_FDRET (*fd_GetLineState) (T_fd_UartId device,
249 SYS_UWORD32 *state);
250
251 T_FDRET (*fd_SetLineState) (T_fd_UartId device,
252 SYS_UWORD32 state,
253 SYS_UWORD32 mask);
254
255 T_FDRET (*fd_CheckXEmpty) (T_fd_UartId device);
256
257 } t_fd_functions;
258
259 #ifdef BTEMOBILE
260 /*
261 * Set of function pointers for Bluetooth HCI functions.
262 */
263
264 typedef struct s_bt_functions {
265
266 T_bt_UartId device;
267
268 T_HCI_RET (*bt_Init) (T_bt_UartId uart_device);
269
270 T_HCI_RET (*bt_Start) (void);
271
272 T_HCI_RET (*bt_Stop) (void);
273
274 T_HCI_RET (*bt_Kill) (void);
275
276 T_HCI_RET (*bt_SetBaudrate) (UINT8 baudrate);
277
278 T_HCI_RET (*bt_TransmitPacket) (void *uart_tx_buffer);
279
280 SYS_BOOL (*bt_EnterSleep) (void);
281
282 void (*bt_WakeUp) (void);
283
284 } t_bt_functions;
285 #endif
286
287 /*
288 * Prototypes of dummy functions.
289 * Dummy functions for Trace.
290 */
291
292 static void dummy_tr_Init (T_tr_UartId device,
293 T_tr_Baudrate baudrate,
294 void (callback_function (void)));
295
296 static SYS_UWORD32 dummy_tr_ReadNChars (T_tr_UartId device,
297 char *buffer,
298 SYS_UWORD32 chars_to_read);
299
300 static SYS_UWORD32 dummy_tr_ReadNBytes (T_tr_UartId device,
301 char *buffer,
302 SYS_UWORD32 chars_to_read,
303 SYS_BOOL *eof_detected);
304
305 static SYS_UWORD32 dummy_tr_WriteNChars (T_tr_UartId device,
306 char *buffer,
307 SYS_UWORD32 chars_to_write);
308
309 static SYS_UWORD32 dummy_tr_EncapsulateNChars (T_tr_UartId device,
310 char *buffer,
311 SYS_UWORD32 chars_to_write);
312
313 static SYS_UWORD32 dummy_tr_WriteNBytes (T_tr_UartId device,
314 SYS_UWORD8 *buffer,
315 SYS_UWORD32 chars_to_write);
316
317 static void dummy_tr_WriteChar (T_tr_UartId device,
318 char character);
319
320 static void dummy_tr_WriteString (T_tr_UartId device,
321 char *buffer);
322
323 static SYS_BOOL dummy_tr_EnterSleep (T_tr_UartId device);
324
325 static void dummy_tr_WakeUp (T_tr_UartId device);
326
327 /*
328 * Dummy functions for Fax & Data.
329 */
330
331 static T_FDRET dummy_fd_Init (T_fd_UartId device);
332
333 static T_FDRET dummy_fd_Enable (T_fd_UartId device,
334 SYS_BOOL enable);
335
336 static T_FDRET dummy_fd_SetComPar (T_fd_UartId device,
337 T_baudrate baudrate,
338 T_bitsPerCharacter bpc,
339 T_stopBits sb,
340 T_parity parity);
341
342 static T_FDRET dummy_fd_SetBuffer (T_fd_UartId device,
343 SYS_UWORD16 bufSize,
344 SYS_UWORD16 rxThreshold,
345 SYS_UWORD16 txThreshold);
346
347 static T_FDRET dummy_fd_SetFlowCtrl (T_fd_UartId device,
348 T_flowCtrlMode fcMode,
349 SYS_UWORD8 XON,
350 SYS_UWORD8 XOFF);
351
352 static T_FDRET dummy_fd_SetEscape (T_fd_UartId device,
353 SYS_UWORD8 escChar,
354 SYS_UWORD16 guardPeriod);
355
356 static T_FDRET dummy_fd_InpAvail (T_fd_UartId device);
357
358 static T_FDRET dummy_fd_OutpAvail (T_fd_UartId device);
359
360 static T_FDRET dummy_fd_EnterSleep (T_fd_UartId device);
361
362 static T_FDRET dummy_fd_WakeUp (T_fd_UartId device);
363
364 static T_FDRET dummy_fd_ReadData (T_fd_UartId device,
365 T_suspendMode suspend,
366 void (readOutFunc (SYS_BOOL cldFromIrq,
367 T_reInstMode *reInstall,
368 SYS_UWORD8 nsource,
369 SYS_UWORD8 *source[],
370 SYS_UWORD16 size[],
371 SYS_UWORD32 state)));
372
373 static T_FDRET dummy_fd_WriteData (T_fd_UartId device,
374 T_suspendMode suspend,
375 void (writeInFunc (SYS_BOOL cldFromIrq,
376 T_reInstMode *reInstall,
377 SYS_UWORD8 ndest,
378 SYS_UWORD8 *dest[],
379 SYS_UWORD16 size[])));
380
381 static T_FDRET dummy_fd_StopRec (T_fd_UartId device);
382
383 static T_FDRET dummy_fd_StartRec (T_fd_UartId device);
384
385 static T_FDRET dummy_fd_GetLineState (T_fd_UartId device,
386 SYS_UWORD32 *state);
387
388 static T_FDRET dummy_fd_SetLineState (T_fd_UartId device,
389 SYS_UWORD32 state,
390 SYS_UWORD32 mask);
391
392 static T_FDRET dummy_fd_CheckXEmpty (T_fd_UartId device);
393
394 #ifdef BTEMOBILE
395 /*
396 * Dummy functions for Bluetooth HCI.
397 */
398
399 static T_HCI_RET dummy_bt_Init (T_bt_UartId uart_device);
400
401 static T_HCI_RET dummy_bt_Start (void);
402
403 static T_HCI_RET dummy_bt_Stop (void);
404
405 static T_HCI_RET dummy_bt_Kill (void);
406
407 static T_HCI_RET dummy_bt_SetBaudrate (UINT8 baudrate);
408
409 static T_HCI_RET dummy_bt_TransmitPacket (void *uart_tx_buffer);
410
411 static SYS_BOOL dummy_bt_EnterSleep (void);
412
413 static void dummy_bt_WakeUp (void);
414
415 #endif
416
417 /*
418 * Constants tables representing the various possible configurations
419 * for Trace, Fax & Data and Bluetooth HCI according to the different devices.
420 * Constant table for Trace using no device.
421 */
422
423 static const t_tr_functions dummy_trace = {
424
425 DUMMY_DEVICE,
426 dummy_tr_Init,
427 dummy_tr_ReadNChars,
428 dummy_tr_ReadNBytes,
429 dummy_tr_WriteNChars,
430 dummy_tr_EncapsulateNChars,
431 dummy_tr_WriteNBytes,
432 dummy_tr_WriteChar,
433 dummy_tr_WriteString,
434 dummy_tr_EnterSleep,
435 dummy_tr_WakeUp
436 };
437
438 /*
439 * Constant table for Trace using UART IrDA.
440 */
441
442 static const t_tr_functions uart_irda_trace = {
443
444 UA_UART_0,
445 UA_Init,
446 UA_ReadNChars,
447 UA_ReadNBytes,
448 UA_WriteNChars,
449 UA_EncapsulateNChars,
450 UA_WriteNBytes,
451 UA_WriteChar,
452 UA_WriteString,
453 UA_EnterSleep,
454 UA_WakeUp
455 };
456
457 /*
458 * Constant table for Trace using UART Modem.
459 */
460
461 static const t_tr_functions uart_modem_trace = {
462
463 UA_UART_1,
464 UA_Init,
465 UA_ReadNChars,
466 UA_ReadNBytes,
467 UA_WriteNChars,
468 UA_EncapsulateNChars,
469 UA_WriteNBytes,
470 UA_WriteChar,
471 UA_WriteString,
472 UA_EnterSleep,
473 UA_WakeUp
474 };
475
476 #if (CHIPSET == 12)
477 /*
478 * Constant table for Trace using UART Modem2.
479 */
480
481 static const t_tr_functions uart_modem2_trace = {
482
483 UA_UART_2,
484 UA_Init,
485 UA_ReadNChars,
486 UA_ReadNBytes,
487 UA_WriteNChars,
488 UA_EncapsulateNChars,
489 UA_WriteNBytes,
490 UA_WriteChar,
491 UA_WriteString,
492 UA_EnterSleep,
493 UA_WakeUp
494 };
495 #endif
496
497 /*
498 * Constant table for Fax & Data using no device.
499 */
500
501 static const t_fd_functions dummy_fax_data = {
502
503 DUMMY_DEVICE,
504 dummy_fd_Init,
505 dummy_fd_Enable,
506 dummy_fd_SetComPar,
507 dummy_fd_SetBuffer,
508 dummy_fd_SetFlowCtrl,
509 dummy_fd_SetEscape,
510 dummy_fd_InpAvail,
511 dummy_fd_OutpAvail,
512 dummy_fd_EnterSleep,
513 dummy_fd_WakeUp,
514 dummy_fd_ReadData,
515 dummy_fd_WriteData,
516 dummy_fd_StopRec,
517 dummy_fd_StartRec,
518 dummy_fd_GetLineState,
519 dummy_fd_SetLineState,
520 dummy_fd_CheckXEmpty
521 };
522
523 /*
524 * Constant table for Fax & Data using UART Modem.
525 */
526
527 #if CONFIG_FDMODEM
528 static const t_fd_functions uart_modem_fax_data = {
529
530 UAF_UART_1,
531 UAF_Init,
532 UAF_Enable,
533 UAF_SetComPar,
534 UAF_SetBuffer,
535 UAF_SetFlowCtrl,
536 UAF_SetEscape,
537 UAF_InpAvail,
538 UAF_OutpAvail,
539 UAF_EnterSleep,
540 UAF_WakeUp,
541 UAF_ReadData,
542 UAF_WriteData,
543 UAF_StopRec,
544 UAF_StartRec,
545 UAF_GetLineState,
546 UAF_SetLineState,
547 UAF_CheckXEmpty
548 };
549 #endif
550
551 #ifdef BTEMOBILE
552 /*
553 * Constant table for BT HCI using no device.
554 */
555
556 static const t_bt_functions dummy_bt_hci = {
557
558 DUMMY_DEVICE,
559 dummy_bt_Init,
560 dummy_bt_Start,
561 dummy_bt_Stop,
562 dummy_bt_Kill,
563 dummy_bt_SetBaudrate,
564 dummy_bt_TransmitPacket,
565 dummy_bt_EnterSleep,
566 dummy_bt_WakeUp
567 };
568
569 /*
570 * Constant table for BT HCI using UART IrDA.
571 */
572
573 static const t_bt_functions uart_irda_bt_hci = {
574
575 UABT_UART_0,
576 hciu_init,
577 hciu_start,
578 hciu_stop,
579 hciu_kill,
580 hciu_set_baudrate,
581 hciu_transmit_packet,
582 hciu_enter_sleep,
583 hciu_wakeup
584 };
585
586 /*
587 * Constant table for BT HCI using UART Modem.
588 */
589
590 static const t_bt_functions uart_modem_bt_hci = {
591
592 UABT_UART_1,
593 hciu_init,
594 hciu_start,
595 hciu_stop,
596 hciu_kill,
597 hciu_set_baudrate,
598 hciu_transmit_packet,
599 hciu_enter_sleep,
600 hciu_wakeup
601 };
602
603 #if (CHIPSET == 12)
604 /*
605 * Constant table for BT HCI using UART Modem2.
606 */
607
608 static const t_bt_functions uart_modem2_bt_hci = {
609
610 UABT_UART_2,
611 hciu_init,
612 hciu_start,
613 hciu_stop,
614 hciu_kill,
615 hciu_set_baudrate,
616 hciu_transmit_packet,
617 hciu_go_to_sleep,
618 hciu_wakeup
619 };
620 #endif
621 #endif
622
623 #if SERIAL_DYNAMIC_SWITCH
624 /*
625 * Structure used to store initialization parameters related to the AT-Cmd/F&D flow.
626 * Numbers of paramaters (in case of multiple calls) have been figured out from
627 * Condat AT-Command/F&D flow initialization.
628 */
629
630 typedef struct s_data_flow {
631
632 /*
633 * Parameters related to SER_fd_SetComPar (2 calls)
634 */
635 T_baudrate baudrate[2];
636 T_bitsPerCharacter bpc[2];
637 T_stopBits sb[2];
638 T_parity parity[2];
639
640 /*
641 * Parameters related to SER_fd_SetBuffer
642 */
643 SYS_WORD16 bufSize;
644 SYS_WORD16 rxThreshold;
645 SYS_WORD16 txThreshold;
646
647 /*
648 * Parameters related to SER_fd_SetFlowCtrl (2 calls)
649 */
650 T_flowCtrlMode fcMode[2];
651 SYS_UWORD8 XON[2];
652 SYS_UWORD8 XOFF[2];
653
654 /*
655 * Parameters related to SER_fd_SetEscape (2 calls)
656 */
657 SYS_UWORD8 escChar[2];
658 SYS_UWORD16 guardPeriod[2];
659
660 /*
661 * Parameters related to SER_fd_SetLineState (4 calls)
662 */
663 SYS_UWORD32 state[4];
664 SYS_UWORD32 mask[4];
665
666 /*
667 * Parameters related to SER_fd_ReadData
668 */
669 T_suspendMode suspend_rd;
670 void (*readOutFunc) (SYS_BOOL cldFromIrq,
671 T_reInstMode *reInstall,
672 SYS_UWORD8 nsource,
673 SYS_UWORD8 *source[],
674 SYS_UWORD16 size[],
675 SYS_UWORD32 state);
676 /*
677 * Parameters related to SER_fd_WriteData
678 */
679 T_suspendMode suspend_wr;
680 void (*writeInFunc) (SYS_BOOL cldFromIrq,
681 T_reInstMode *reInstall,
682 SYS_UWORD8 ndest,
683 SYS_UWORD8 *dest[],
684 SYS_UWORD16 size[]);
685
686 } t_data_flow;
687 #endif /* (defined BTEMOBILE && (CHIPSET != 12)) */
688
689 /*
690 * UART structure used for UARTs.
691 */
692
693 typedef struct s_uart {
694
695 SYS_UWORD32 base_address;
696 SYS_BOOL device_used;
697 SYS_BOOL deep_sleep_set_up;
698 t_flow_type flow_type;
699 SYS_WORD16 flow_id;
700 void (*interrupt_handler) (int uart_id,
701 SYS_UWORD8 interrupt_status);
702
703 } t_uart;
704
705 static const t_tr_functions *tr_functions[SER_MAX_NUMBER_OF_FLOWS];
706 static const t_fd_functions *fd_functions;
707
708 #ifdef BTEMOBILE
709 static const t_bt_functions *bt_functions;
710 #endif
711
712 #if SERIAL_DYNAMIC_SWITCH
713 static SYS_BOOL uart_fd_initialized = 0;
714 #endif
715
716 static SYS_UWORD8 fd_buffer[FD_MAX_BUFFER_SIZE];
717 static SYS_BOOL fd_driver_enabled;
718
719 #if SERIAL_DYNAMIC_SWITCH
720 static t_data_flow data_flow_parameters;
721 #else
722 static SYS_WORD16 bufSize;
723 #endif
724
725 #if SERIAL_DYNAMIC_SWITCH
726 /*
727 * Variables used to count calls to SER_fd_XXX functions.
728 */
729
730 static SYS_UWORD8 fd_UAF_SetBuffer = 0;
731 static SYS_UWORD8 fd_UAF_SetEscape = 0;
732 static SYS_UWORD8 fd_UAF_SetComPar = 0;
733 static SYS_UWORD8 fd_UAF_SetFlowCtrl = 0;
734 static SYS_UWORD8 fd_UAF_ReadData = 0;
735 static SYS_UWORD8 fd_UAF_SetLineState = 0;
736 static SYS_UWORD8 fd_UAF_WriteData = 0;
737 #endif
738
739 /*
740 * Timer used for duration control when UARTs are waked up by an interrupt or
741 * each time any new incoming characters are received; This timer prevents the
742 * system to enter deep sleep mode.
743 */
744
745 static NU_TIMER uart_sleep_timer;
746 SYS_BOOL uart_sleep_timer_enabled;
747
748 /*
749 * HISR used to reset and restart the sleep timer from an UART use by a Trace
750 * flow in case of incoming characters.
751 */
752
753 #define TIMER_HISR_PRIORITY (2)
754 #define TIMER_HISR_STACK_SIZE (512) /* Bytes. */
755
756 static NU_HISR timer_hisr_ctrl_block;
757 static char timer_hisr_stack[TIMER_HISR_STACK_SIZE];
758
759 /*
760 * For next arrays, it is supposed that NUMBER_OF_TR_UART, NUMBER_OF_FD_UART
761 * and NUMBER_OF_BT_UART have the same values.
762 * An index on an internal uart for trace, fax & data or bluetooth hci reffers
763 * to the same uart device.
764 */
765
766 static t_uart int_uart[NUMBER_OF_TR_UART];
767
768 #if ((CHIPSET == 2) || (CHIPSET == 3))
769 static SYS_UWORD32 uart_spurious_interrupts;
770 #elif ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11) || (CHIPSET == 12))
771 static SYS_UWORD32 uart_modem_spurious_interrupts;
772 static SYS_UWORD32 uart_irda_spurious_interrupts;
773 #endif
774 #if (CHIPSET == 12)
775 static SYS_UWORD32 uart_modem2_spurious_interrupts;
776 #endif
777
778 static const SYS_UWORD32 uart_base_address[NUMBER_OF_TR_UART] =
779 {
780 MEM_UART_IRDA,
781 MEM_UART_MODEM
782 #if (CHIPSET == 12)
783 , MEM_UART_MODEM2
784 #endif
785 };
786
787
788 /*******************************************************************************
789 *
790 * dummy_tr_Init
791 *
792 * Purpose: No action.
793 *
794 * Parameters: See SER_tr_Init.
795 *
796 * Return: none
797 *
798 ******************************************************************************/
799
800 static void
801 dummy_tr_Init (T_tr_UartId device,
802 T_tr_Baudrate baudrate,
803 void (callback_function (void)))
804 {
805 /*
806 * No action.
807 */
808 }
809
810 /*******************************************************************************
811 *
812 * dummy_tr_ReadNChars
813 *
814 * Purpose: No action.
815 *
816 * Parameters: See SER_tr_ReadNChars.
817 *
818 * Return: 0
819 *
820 ******************************************************************************/
821
822 static SYS_UWORD32
823 dummy_tr_ReadNChars (T_tr_UartId device,
824 char *buffer,
825 SYS_UWORD32 chars_to_read)
826 {
827 return (0);
828 }
829
830 /*******************************************************************************
831 *
832 * dummy_tr_ReadNBytes
833 *
834 * Purpose: No action.
835 *
836 * Parameters: See SER_tr_ReadNBytes.
837 *
838 * Return: 0
839 *
840 ******************************************************************************/
841
842 static SYS_UWORD32
843 dummy_tr_ReadNBytes (T_tr_UartId device,
844 char *buffer,
845 SYS_UWORD32 chars_to_read,
846 SYS_BOOL *eof_detected)
847 {
848 return (0);
849 }
850
851 /*******************************************************************************
852 *
853 * dummy_tr_WriteNChars
854 *
855 * Purpose: No action.
856 *
857 * Parameters: See SER_tr_WriteNChars.
858 *
859 * Return: The number of character to write.
860 *
861 ******************************************************************************/
862
863 static SYS_UWORD32
864 dummy_tr_WriteNChars (T_tr_UartId device,
865 char *buffer,
866 SYS_UWORD32 chars_to_write)
867 {
868 return (chars_to_write);
869 }
870
871 /*******************************************************************************
872 *
873 * dummy_tr_EncapsulateNChars
874 *
875 * Purpose: No action.
876 *
877 * Parameters: See SER_tr_EncapsulateNChars.
878 *
879 * Return: The number of character to write.
880 *
881 ******************************************************************************/
882
883 static SYS_UWORD32
884 dummy_tr_EncapsulateNChars (T_tr_UartId device,
885 char *buffer,
886 SYS_UWORD32 chars_to_write)
887 {
888 return (chars_to_write);
889 }
890
891 /*******************************************************************************
892 *
893 * dummy_tr_WriteNBytes
894 *
895 * Purpose: No action.
896 *
897 * Parameters: See SER_tr_WriteNBytes.
898 *
899 * Return: The number of byte to write.
900 *
901 ******************************************************************************/
902
903 static SYS_UWORD32
904 dummy_tr_WriteNBytes (T_tr_UartId device,
905 SYS_UWORD8 *buffer,
906 SYS_UWORD32 chars_to_write)
907 {
908 return (chars_to_write);
909 }
910
911 /*******************************************************************************
912 *
913 * dummy_tr_WriteChar
914 *
915 * Purpose: No action.
916 *
917 * Parameters: See SER_tr_WriteChar.
918 *
919 * Return: none
920 *
921 ******************************************************************************/
922
923 static void
924 dummy_tr_WriteChar (T_tr_UartId device,
925 char character)
926 {
927 /*
928 * No action.
929 */
930 }
931
932 /*******************************************************************************
933 *
934 * dummy_tr_WriteString
935 *
936 * Purpose: No action.
937 *
938 * Parameters: See SER_tr_WriteString.
939 *
940 * Return: none
941 *
942 ******************************************************************************/
943
944 static void
945 dummy_tr_WriteString (T_tr_UartId device,
946 char *buffer)
947 {
948 /*
949 * No action.
950 */
951 }
952
953 /*******************************************************************************
954 *
955 * dummy_tr_EnterSleep
956 *
957 * Purpose: No action.
958 *
959 * Parameters: See SER_tr_EnterSleep.
960 *
961 * Return: 1
962 *
963 ******************************************************************************/
964
965 static SYS_BOOL
966 dummy_tr_EnterSleep (T_tr_UartId device)
967 {
968 return (1);
969 }
970
971 /*******************************************************************************
972 *
973 * dummy_tr_WakeUp
974 *
975 * Purpose: No action.
976 *
977 * Parameters: See SER_tr_WakeUp.
978 *
979 * Return: none
980 *
981 ******************************************************************************/
982
983 static void
984 dummy_tr_WakeUp (T_tr_UartId device)
985 {
986 /*
987 * No action.
988 */
989 }
990
991 /*******************************************************************************
992 *
993 * dummy_fd_Init
994 *
995 * Purpose: Sets the size of the circular buffer to the maximum value and the
996 * state of the driver to 'disabled'.
997 *
998 * Parameters: See SER_fd_Init.
999 *
1000 * Return: FD_OK: Successful operation.
1001 *
1002 ******************************************************************************/
1003
1004 static T_FDRET
1005 dummy_fd_Init (T_fd_UartId device)
1006 {
1007 #if SERIAL_DYNAMIC_SWITCH
1008 data_flow_parameters.bufSize = FD_MAX_BUFFER_SIZE;
1009 #else
1010 bufSize = FD_MAX_BUFFER_SIZE;
1011 #endif
1012 fd_driver_enabled = 0;
1013
1014 return (FD_OK);
1015 }
1016
1017 /*******************************************************************************
1018 *
1019 * dummy_fd_Enable
1020 *
1021 * Purpose: Stores the state of the driver.
1022 *
1023 * Parameters: See SER_fd_Enable.
1024 *
1025 * Return: FD_OK: Successful operation.
1026 *
1027 ******************************************************************************/
1028
1029 static T_FDRET
1030 dummy_fd_Enable (T_fd_UartId device,
1031 SYS_BOOL enable)
1032 {
1033 fd_driver_enabled = enable;
1034
1035 return (FD_OK);
1036 }
1037
1038 /*******************************************************************************
1039 *
1040 * dummy_fd_SetComPar
1041 *
1042 * Purpose: No action.
1043 *
1044 * Parameters: See SER_fd_SetComPar.
1045 *
1046 * Return: FD_OK: Successful operation.
1047 *
1048 ******************************************************************************/
1049
1050 static T_FDRET
1051 dummy_fd_SetComPar (T_fd_UartId device,
1052 T_baudrate baudrate,
1053 T_bitsPerCharacter bpc,
1054 T_stopBits sb,
1055 T_parity parity)
1056 {
1057 return (FD_OK);
1058 }
1059
1060 /*******************************************************************************
1061 *
1062 * dummy_fd_SetBuffer
1063 *
1064 * Purpose: No action.
1065 *
1066 * Parameters: See SER_fd_SetBuffer.
1067 *
1068 * Return: FD_OK: Successful operation.
1069 *
1070 ******************************************************************************/
1071
1072 static T_FDRET
1073 dummy_fd_SetBuffer (T_fd_UartId device,
1074 SYS_UWORD16 bufSize,
1075 SYS_UWORD16 rxThreshold,
1076 SYS_UWORD16 txThreshold)
1077 {
1078 return (FD_OK);
1079 }
1080
1081 /*******************************************************************************
1082 *
1083 * dummy_fd_SetFlowCtrl
1084 *
1085 * Purpose: No action.
1086 *
1087 * Parameters: See SER_fd_SetFlowCtrl.
1088 *
1089 * Return: FD_OK: Successful operation.
1090 *
1091 ******************************************************************************/
1092
1093 static T_FDRET
1094 dummy_fd_SetFlowCtrl (T_fd_UartId device,
1095 T_flowCtrlMode fcMode,
1096 SYS_UWORD8 XON,
1097 SYS_UWORD8 XOFF)
1098 {
1099 return (FD_OK);
1100 }
1101
1102 /*******************************************************************************
1103 *
1104 * dummy_fd_SetEscape
1105 *
1106 * Purpose: No action.
1107 *
1108 * Parameters: See SER_fd_SetEscape.
1109 *
1110 * Return: FD_OK: Successful operation.
1111 *
1112 ******************************************************************************/
1113
1114 static T_FDRET
1115 dummy_fd_SetEscape (T_fd_UartId device,
1116 SYS_UWORD8 escChar,
1117 SYS_UWORD16 guardPeriod)
1118 {
1119 return (FD_OK);
1120 }
1121
1122 /*******************************************************************************
1123 *
1124 * dummy_fd_InpAvail
1125 *
1126 * Purpose: No action.
1127 *
1128 * Parameters: See SER_fd_InpAvail.
1129 *
1130 * Return: The size of the circular buffer.
1131 *
1132 ******************************************************************************/
1133
1134 static T_FDRET
1135 dummy_fd_InpAvail (T_fd_UartId device)
1136 {
1137 #if SERIAL_DYNAMIC_SWITCH
1138 return (data_flow_parameters.bufSize);
1139 #else
1140 return (bufSize);
1141 #endif
1142 }
1143
1144 /*******************************************************************************
1145 *
1146 * dummy_fd_OutpAvail
1147 *
1148 * Purpose: No action.
1149 *
1150 * Parameters: See SER_fd_OutpAvail.
1151 *
1152 * Return: The size of the circular buffer.
1153 *
1154 ******************************************************************************/
1155
1156 static T_FDRET
1157 dummy_fd_OutpAvail (T_fd_UartId device)
1158 {
1159 #if SERIAL_DYNAMIC_SWITCH
1160 return (data_flow_parameters.bufSize);
1161 #else
1162 return (bufSize);
1163 #endif
1164 }
1165
1166 /*******************************************************************************
1167 *
1168 * dummy_fd_EnterSleep
1169 *
1170 * Purpose: No action.
1171 *
1172 * Parameters: See SER_tr_EnterSleep.
1173 *
1174 * Return: 1
1175 *
1176 ******************************************************************************/
1177
1178 static T_FDRET
1179 dummy_fd_EnterSleep (T_fd_UartId device)
1180 {
1181 return (1);
1182 }
1183
1184 /*******************************************************************************
1185 *
1186 * dummy_fd_WakeUp
1187 *
1188 * Purpose: No action.
1189 *
1190 * Parameters: See SER_tr_WakeUp.
1191 *
1192 * Return: FD_OK: Successful operation.
1193 *
1194 ******************************************************************************/
1195
1196 static T_FDRET
1197 dummy_fd_WakeUp (T_fd_UartId device)
1198 {
1199 return (FD_OK);
1200 }
1201
1202 /*******************************************************************************
1203 *
1204 * dummy_fd_ReadData
1205 *
1206 * Purpose: No action.
1207 *
1208 * Parameters: See SER_fd_ReadData.
1209 *
1210 * Return: 0 if the suspend parameter is set to 'sm_noSuspend'.
1211 * FD_SUSPENDED if the suspend parameter is set to 'sm_suspend'.
1212 *
1213 ******************************************************************************/
1214
1215 static T_FDRET
1216 dummy_fd_ReadData (T_fd_UartId device,
1217 T_suspendMode suspend,
1218 void (readOutFunc (SYS_BOOL cldFromIrq,
1219 T_reInstMode *reInstall,
1220 SYS_UWORD8 nsource,
1221 SYS_UWORD8 *source[],
1222 SYS_UWORD16 size[],
1223 SYS_UWORD32 state)))
1224 {
1225 T_FDRET result;
1226
1227 if (suspend == sm_noSuspend)
1228 result = 0;
1229 else
1230 result = FD_SUSPENDED;
1231
1232 return (result);
1233 }
1234
1235 /*******************************************************************************
1236 *
1237 * dummy_fd_WriteData
1238 *
1239 * Purpose: The user's function is called with:
1240 * - cldFromIrq = 0
1241 * - ndest = 1
1242 * - dest[0] is a SYS_UWORD8 pointer on the beginning address of a local
1243 * buffer
1244 * - size[0] is set to data_flow_parameters.bufSize.
1245 *
1246 * Parameters: See SER_fd_WriteData.
1247 *
1248 * Return: The number of bytes written in the local buffer.
1249 *
1250 ******************************************************************************/
1251
1252 static T_FDRET
1253 dummy_fd_WriteData (T_fd_UartId device,
1254 T_suspendMode suspend,
1255 void (writeInFunc (SYS_BOOL cldFromIrq,
1256 T_reInstMode *reInstall,
1257 SYS_UWORD8 ndest,
1258 SYS_UWORD8 *dest[],
1259 SYS_UWORD16 size[])))
1260 {
1261 T_reInstMode dummyInstall;
1262 SYS_UWORD8 *destination[2];
1263 SYS_UWORD16 buffer_size[2];
1264
1265 destination[0] = &(fd_buffer[0]);
1266 #if SERIAL_DYNAMIC_SWITCH
1267 buffer_size[0] = data_flow_parameters.bufSize;
1268 #else
1269 buffer_size[0] = bufSize;
1270 #endif
1271
1272 (*writeInFunc) (0, &dummyInstall, 1, &(destination[0]), &(buffer_size[0]));
1273
1274 #if SERIAL_DYNAMIC_SWITCH
1275 return ((T_FDRET) (data_flow_parameters.bufSize - buffer_size[0]));
1276 #else
1277 return ((T_FDRET) (bufSize - buffer_size[0]));
1278 #endif
1279 }
1280
1281 /*******************************************************************************
1282 *
1283 * dummy_fd_StopRec
1284 *
1285 * Purpose: No action.
1286 *
1287 * Parameters: See SER_fd_StopRec.
1288 *
1289 * Return: FD_OK: Successful operation.
1290 *
1291 ******************************************************************************/
1292
1293 static T_FDRET
1294 dummy_fd_StopRec (T_fd_UartId device)
1295 {
1296 return (FD_OK);
1297 }
1298
1299 /*******************************************************************************
1300 *
1301 * dummy_fd_StartRec
1302 *
1303 * Purpose: No action.
1304 *
1305 * Parameters: See SER_fd_StartRec.
1306 *
1307 * Return: FD_OK: Successful operation.
1308 *
1309 ******************************************************************************/
1310
1311 static T_FDRET
1312 dummy_fd_StartRec (T_fd_UartId device)
1313 {
1314 return (FD_OK);
1315 }
1316
1317 /*******************************************************************************
1318 *
1319 * dummy_fd_GetLineState
1320 *
1321 * Purpose: Sets the RXBLEV field to the bufSize value.
1322 *
1323 * Parameters: See SER_fd_GetLineState.
1324 *
1325 * Return: FD_OK: Successful operation.
1326 *
1327 ******************************************************************************/
1328
1329 static T_FDRET
1330 dummy_fd_GetLineState (T_fd_UartId device,
1331 SYS_UWORD32 *state)
1332 {
1333 #if SERIAL_DYNAMIC_SWITCH
1334 *state = data_flow_parameters.bufSize << RXBLEV;
1335 #else
1336 *state = bufSize << RXBLEV;
1337 #endif
1338
1339 return (FD_OK);
1340 }
1341
1342 /*******************************************************************************
1343 *
1344 * dummy_fd_SetLineState
1345 *
1346 * Purpose: No action.
1347 *
1348 * Parameters: See SER_fd_SetLineState.
1349 *
1350 * Return: FD_OK: Successful operation.
1351 *
1352 ******************************************************************************/
1353
1354 static T_FDRET
1355 dummy_fd_SetLineState (T_fd_UartId device,
1356 SYS_UWORD32 state,
1357 SYS_UWORD32 mask)
1358 {
1359 return (FD_OK);
1360 }
1361
1362 /*******************************************************************************
1363 *
1364 * dummy_fd_CheckXEmpty
1365 *
1366 * Purpose: No action.
1367 *
1368 * Parameters: See SER_fd_CheckXEmpty.
1369 *
1370 * Return: FD_OK: Successful operation.
1371 *
1372 ******************************************************************************/
1373
1374 static T_FDRET
1375 dummy_fd_CheckXEmpty (T_fd_UartId device)
1376 {
1377 return (FD_OK);
1378 }
1379
1380 #ifdef BTEMOBILE
1381 /*******************************************************************************
1382 *
1383 * dummy_bt_Init
1384 *
1385 * Purpose: No action.
1386 *
1387 * Parameters: See SER_bt_Init.
1388 *
1389 * Return: HCI_OK: Successful operation.
1390 *
1391 ******************************************************************************/
1392
1393 static T_HCI_RET
1394 dummy_bt_Init (T_bt_UartId uart_device)
1395 {
1396 return (HCI_OK);
1397 }
1398
1399 /*******************************************************************************
1400 *
1401 * dummy_bt_Start
1402 *
1403 * Purpose: No action.
1404 *
1405 * Parameters: See SER_bt_Start.
1406 *
1407 * Return: HCI_OK: Successful operation.
1408 *
1409 ******************************************************************************/
1410
1411 static T_HCI_RET
1412 dummy_bt_Start (void)
1413 {
1414 return (HCI_OK);
1415 }
1416
1417 /*******************************************************************************
1418 *
1419 * dummy_bt_Stop
1420 *
1421 * Purpose: No action.
1422 *
1423 * Parameters: See SER_bt_Stop.
1424 *
1425 * Return: HCI_OK: Successful operation.
1426 *
1427 ******************************************************************************/
1428
1429 static T_HCI_RET
1430 dummy_bt_Stop (void)
1431 {
1432 return (HCI_OK);
1433 }
1434
1435 /*******************************************************************************
1436 *
1437 * dummy_bt_Kill
1438 *
1439 * Purpose: No action.
1440 *
1441 * Parameters: See SER_bt_Kill.
1442 *
1443 * Return: HCI_OK: Successful operation.
1444 *
1445 ******************************************************************************/
1446
1447 static T_HCI_RET
1448 dummy_bt_Kill (void)
1449 {
1450 return (HCI_OK);
1451 }
1452
1453 /*******************************************************************************
1454 *
1455 * dummy_bt_SetBaudrate
1456 *
1457 * Purpose: No action.
1458 *
1459 * Parameters: See SER_bt_SetBaudrate.
1460 *
1461 * Return: HCI_OK: Successful operation.
1462 *
1463 ******************************************************************************/
1464
1465 static T_HCI_RET
1466 dummy_bt_SetBaudrate (UINT8 baudrate)
1467 {
1468 return (HCI_OK);
1469 }
1470
1471 /*******************************************************************************
1472 *
1473 * dummy_bt_TransmitPacket
1474 *
1475 * Purpose: No action.
1476 *
1477 * Parameters: See SER_bt_TransmitPacket.
1478 *
1479 * Return: HCI_OK: Successful operation.
1480 *
1481 ******************************************************************************/
1482
1483 static T_HCI_RET dummy_bt_TransmitPacket (void *uart_tx_buffer)
1484
1485 {
1486 return (HCI_OK);
1487 }
1488
1489 /*******************************************************************************
1490 *
1491 * dummy_bt_EnterSleep
1492 *
1493 * Purpose: No action.
1494 *
1495 * Parameters: See SER_bt_EnterSleep.
1496 *
1497 * Return: TRUE.
1498 *
1499 ******************************************************************************/
1500
1501 static SYS_BOOL
1502 dummy_bt_EnterSleep (void)
1503 {
1504 return (TRUE);
1505 }
1506
1507 /*******************************************************************************
1508 *
1509 * dummy_bt_WakeUp
1510 *
1511 * Purpose: No action.
1512 *
1513 * Parameters: See SER_bt_WakeUp
1514 *
1515 * Return: HCI_OK: none
1516 *
1517 ******************************************************************************/
1518
1519 static void
1520 dummy_bt_WakeUp (void)
1521 {
1522 /*
1523 * No action.
1524 */
1525 }
1526
1527 #endif /* BTEMOBILE */
1528
1529 /*******************************************************************************
1530 *
1531 * analyze_uart_sleep_timer_expiration
1532 *
1533 * Purpose : The timer has just expired. If requested, UARTs can again be set
1534 * up to enter Deep Sleep.
1535 *
1536 * Arguments: In : id: parameter not used.
1537 * Out: none
1538 *
1539 * Returns : none
1540 *
1541 ******************************************************************************/
1542
1543 static VOID
1544 analyze_uart_sleep_timer_expiration (UNSIGNED id)
1545 {
1546 /*
1547 * Timer has expired.
1548 * UARTs can again be set up for Deep Sleep.
1549 */
1550
1551 (void) NU_Control_Timer (&uart_sleep_timer,
1552 NU_DISABLE_TIMER);
1553
1554 uart_sleep_timer_enabled = 0;
1555 }
1556
1557 /*******************************************************************************
1558 *
1559 * start_uart_sleep_timer
1560 *
1561 * Purpose : Starts the sleep timer once UARTs have been waked-up by an
1562 * interrupt or if new incoming characters have been received.
1563 *
1564 * Arguments: In : none
1565 * Out: none
1566 *
1567 * Returns : none
1568 *
1569 ******************************************************************************/
1570
1571 static void
1572 start_uart_sleep_timer (void)
1573 {
1574 /*
1575 * UART sleep timer is started.
1576 * UARTs can't no more be set up for Deep Sleep until the timer expires.
1577 */
1578
1579 (void) NU_Reset_Timer (&uart_sleep_timer,
1580 &analyze_uart_sleep_timer_expiration,
1581 WAKE_UP_TIME_IN_TDMA,
1582 0, /* The timer expires once. */
1583 NU_DISABLE_TIMER);
1584
1585 (void) NU_Control_Timer (&uart_sleep_timer,
1586 NU_ENABLE_TIMER);
1587 }
1588
1589 /*******************************************************************************
1590 *
1591 * set_flow_functions
1592 *
1593 * Purpose: Initializes a serial data flow functions set with the set of
1594 * functions of the selected device.
1595 *
1596 * Parameters: In : flow : index of the serial data flow
1597 * serial_driver: allows knowing which set of functions must
1598 * be selected
1599 * Out: none
1600 *
1601 * Return: none
1602 *
1603 ******************************************************************************/
1604
1605 static void
1606 set_flow_functions (int flow,
1607 T_SerialDriver serial_driver)
1608 {
1609
1610 switch (serial_driver) {
1611
1612 case UART_MODEM_FAX_DATA:
1613
1614 #if CONFIG_FDMODEM
1615 fd_functions = &uart_modem_fax_data;
1616 int_uart[fd_functions->device].device_used = 1;
1617 int_uart[fd_functions->device].flow_type = FAX_DATA_FLOW;
1618 int_uart[fd_functions->device].flow_id = flow;
1619 int_uart[fd_functions->device].interrupt_handler =
1620 UAF_InterruptHandler;
1621 break;
1622 #endif
1623
1624 case DUMMY_FAX_DATA:
1625
1626 fd_functions = &dummy_fax_data;
1627 break;
1628
1629
1630 case UART_IRDA_TRACE:
1631 case UART_MODEM_TRACE:
1632 #if (CHIPSET == 12)
1633 case UART_MODEM2_TRACE:
1634 #endif
1635
1636 if (serial_driver == UART_IRDA_TRACE)
1637 tr_functions[flow] = &uart_irda_trace;
1638 else {
1639 #if (CHIPSET == 12)
1640 if (serial_driver == UART_MODEM2_TRACE)
1641 tr_functions[flow] = &uart_modem2_trace;
1642 else
1643 #endif
1644 tr_functions[flow] = &uart_modem_trace;
1645 }
1646
1647 int_uart[tr_functions[flow]->device].device_used = 1;
1648 int_uart[tr_functions[flow]->device].flow_type = TRACE_FLOW;
1649 int_uart[tr_functions[flow]->device].flow_id = flow;
1650 int_uart[tr_functions[flow]->device].interrupt_handler =
1651 UA_InterruptHandler;
1652 break;
1653
1654 case DUMMY_TRACE:
1655
1656 tr_functions[flow] = &dummy_trace;
1657 break;
1658
1659 case DUMMY_BT_HCI:
1660
1661 /*
1662 * if serial_driver = DUMMY_BT_HCI & if BTEMOBILE is not defined
1663 * no action is performed.
1664 */
1665
1666 #ifdef BTEMOBILE
1667 bt_functions = &dummy_bt_hci;
1668 break;
1669
1670 case UART_IRDA_BT_HCI:
1671 case UART_MODEM_BT_HCI:
1672 #if (CHIPSET == 12)
1673 case UART_MODEM2_BT_HCI:
1674 #endif
1675
1676 if (serial_driver == UART_IRDA_BT_HCI)
1677 bt_functions = &uart_irda_bt_hci;
1678 else {
1679 #if (CHIPSET == 12)
1680 if (serial_driver == UART_MODEM2_BT_HCI)
1681 bt_functions = &uart_modem2_bt_hci;
1682 else
1683 #endif
1684 bt_functions = &uart_modem_bt_hci;
1685 }
1686
1687 int_uart[bt_functions->device].device_used = 1;
1688 int_uart[bt_functions->device].flow_type = BLUETOOTH_HCI_FLOW;
1689 int_uart[bt_functions->device].flow_id = flow;
1690 int_uart[bt_functions->device].interrupt_handler =
1691 hciu_interrupt_handler;
1692 #endif /* BTEMOBILE */
1693 break;
1694 }
1695 }
1696
1697 /*******************************************************************************
1698 *
1699 * SER_InitSerialConfig
1700 *
1701 * Purpose: The parameter serial_info allows knowing all serial information
1702 * necessary to set up the serial configuration of an application.
1703 * From this information, the function is able to determine if the
1704 * current serial configuration read out from the flash memory is
1705 * valid. If it does not correspond to an allowed configuration, the
1706 * default configuration is selected. This function must be called at
1707 * the application's initialization, but never after.
1708 *
1709 * Parameters: In : serial_info: application serial information like the default
1710 * configuration and all allowed configurations.
1711 * Out: none
1712 *
1713 * Return: none
1714 *
1715 ******************************************************************************/
1716
1717 void
1718 SER_InitSerialConfig (const T_AppliSerialInfo *serial_info)
1719 {
1720 int uart_id;
1721 int flow;
1722 SYS_UWORD16 serial_driver;
1723 SYS_UWORD16 *allowed_config;
1724 SYS_UWORD8 nb_allowed_config;
1725 SYS_BOOL valid_config_selected;
1726 SYS_BOOL uart_used;
1727 SYS_BOOL uart_used_for_trace;
1728 SYS_UWORD16 current_config;
1729 SYS_UWORD16 *pt_current_config = &(current_config);
1730
1731 /*
1732 * Basic UARTs initializations.
1733 */
1734
1735 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) {
1736
1737 int_uart[uart_id].base_address = uart_base_address[uart_id];
1738 int_uart[uart_id].device_used = 0;
1739 int_uart[uart_id].deep_sleep_set_up = 0;
1740 }
1741
1742 #if ((CHIPSET == 2) || (CHIPSET == 3))
1743 uart_spurious_interrupts = 0;
1744 #elif ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11) || (CHIPSET == 12))
1745 uart_modem_spurious_interrupts = 0;
1746 uart_irda_spurious_interrupts = 0;
1747 #endif
1748 #if (CHIPSET == 12)
1749 uart_modem2_spurious_interrupts = 0;
1750 #endif
1751 uart_sleep_timer_enabled = 0;
1752
1753 /*
1754 * Compute the current serial configuration.
1755 */
1756
1757 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) {
1758
1759 switch (ser_cfg_info[uart_id]) {
1760
1761 case G23_PANEL:
1762 serial_cfg = serial_cfg +
1763 ((uart_id + 1) << (12 - (4 * SER_PROTOCOL_STACK)));
1764 break;
1765
1766 case RIVIERA_TRACE_MUX:
1767 serial_cfg = serial_cfg +
1768 ((uart_id + 1) << (12 - (4 * SER_LAYER_1)));
1769 break;
1770
1771 case FD_AT_COMMAND:
1772 serial_cfg = serial_cfg +
1773 ((uart_id + 1) << (12 - (4 * SER_FAX_DATA)));
1774 break;
1775
1776 case BLUETOOTH_HCI:
1777 serial_cfg = serial_cfg +
1778 ((uart_id + 1) << (12 - (4 * SER_BLUETOOTH_HCI)));
1779 break;
1780
1781 case DUMMY:
1782 break;
1783 }
1784 }
1785
1786 current_config = serial_cfg;
1787 valid_config_selected = 0;
1788 nb_allowed_config = serial_info->num_config;
1789
1790 /*
1791 * Checks if the current serial config is one of the allowed.
1792 */
1793
1794 while ((nb_allowed_config > 0) && !valid_config_selected) {
1795
1796 nb_allowed_config--;
1797 allowed_config = (SYS_UWORD16 *)
1798 &(serial_info->allowed_config[nb_allowed_config]);
1799
1800 if (*pt_current_config == *allowed_config)
1801 valid_config_selected = 1;
1802 }
1803
1804 /*
1805 * If not, the default configuration is selected.
1806 */
1807
1808 if (!valid_config_selected) {
1809
1810 pt_current_config = (SYS_UWORD16 *)&(serial_info->default_config);
1811
1812 #if SERIAL_DYNAMIC_SWITCH
1813 /*
1814 * Setup the global variable accordingly.
1815 * The following default value are identical to the ones defined at
1816 * the application initialization in init.c.
1817 */
1818
1819 #ifdef BT_UART_USED_MODEM
1820 memcpy (ser_cfg_info, "RB", NUMBER_OF_TR_UART);
1821 #else
1822 memcpy (ser_cfg_info, "BR", NUMBER_OF_TR_UART);
1823 #endif
1824 #endif
1825 }
1826
1827 /*
1828 * The serial data flow functions set is initialized.
1829 */
1830
1831 flow = 0;
1832 while (flow < SER_MAX_NUMBER_OF_FLOWS) {
1833
1834 serial_driver = (T_SerialDriver)
1835 (((*pt_current_config) >> (12 - flow * 4)) & 0x000F);
1836
1837 set_flow_functions (flow, serial_driver);
1838 flow++;
1839 }
1840
1841 /*
1842 * Checks if both UARTs are used.
1843 * If not, performs minimum initialization including Sleep Mode.
1844 * Checks also if at least one UART is used by a Trace flow.
1845 * If so, create a HISR in order to reset and restart the sleep timer
1846 * in case of incoming characters.
1847 */
1848
1849 uart_used = 0;
1850 uart_used_for_trace = 0;
1851 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) {
1852
1853 if (!(int_uart[uart_id].device_used))
1854 initialize_uart_sleep (uart_id);
1855
1856 else { /* if (int_uart[uart_id].device_used) */
1857
1858 uart_used = 1; /* At least one UART is used */
1859
1860 if (int_uart[uart_id].flow_type == TRACE_FLOW) {
1861
1862 /* At least one UART used by a Trace flow */
1863 uart_used_for_trace = 1;
1864 }
1865 }
1866 }
1867
1868 /*
1869 * If at least one uart is used, create a timer to figure out if the system
1870 * can enter deep sleep mode regarding the UARTs.
1871 */
1872
1873 if (uart_used) {
1874
1875 (void) NU_Create_Timer (
1876 &uart_sleep_timer,
1877 "Sleep",
1878 &analyze_uart_sleep_timer_expiration,
1879 0, /* Parameter supplied to the routine: not used. */
1880 WAKE_UP_TIME_IN_TDMA,
1881 0, /* The timer expires once. */
1882 NU_DISABLE_TIMER);
1883
1884 /*
1885 * If at least one uart is used by a Trace flow, create a HISR to reset
1886 * and restart the sleep timer.
1887 */
1888
1889 if (uart_used_for_trace) {
1890
1891 /*
1892 * The stack is entirely filled with the pattern 0xFE.
1893 */
1894
1895 memset (&(timer_hisr_stack[0]), 0xFE, TIMER_HISR_STACK_SIZE);
1896
1897 /*
1898 * The HISR entry function is the same function than the one called
1899 * by the Rx HISR of the UARTFAX, since the only aim is to reset
1900 * and restart the sleep timer in case of incoming characters on
1901 * the Trace UART.
1902 */
1903
1904 (void) NU_Create_HISR (
1905 &timer_hisr_ctrl_block,
1906 "Tim_HISR",
1907 SER_restart_uart_sleep_timer,
1908 TIMER_HISR_PRIORITY,
1909 &(timer_hisr_stack[0]),
1910 TIMER_HISR_STACK_SIZE);
1911 }
1912 }
1913 }
1914
1915
1916 /*******************************************************************************
1917 *
1918 * SER_WriteConfig
1919 *
1920 * Purpose: TBD
1921 *
1922 * Parameters: In : new_config: TBD
1923 * write_to_flash: TBD
1924 * Out: none
1925 *
1926 * Return: 0 (FALSE) : In case of error while trying to write file in FFS
1927 * >= 1 (TRUE) : Successful operation.
1928 *
1929 ******************************************************************************/
1930
1931 SYS_BOOL
1932 SER_WriteConfig (char *new_config,
1933 SYS_BOOL write_to_flash)
1934 {
1935 #if SERIAL_DYNAMIC_SWITCH
1936 int uart_id;
1937 SYS_BOOL status = 1;
1938
1939 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++)
1940 ser_new_cfg[uart_id] = *new_config++;
1941
1942 /*
1943 * Write in flash the new serial configuration if requested.
1944 */
1945
1946 if (write_to_flash) {
1947 if (ffs_fwrite (uart_config_file,
1948 ser_new_cfg,
1949 NUMBER_OF_TR_UART) < EFFS_OK) {
1950 status = 0;
1951 }
1952 }
1953
1954 return (status);
1955 #else
1956 /*
1957 * Real Dynamic Switch is only available with Bluetooth AND all chips but
1958 * Calypso+.
1959 */
1960
1961 return (1);
1962 #endif
1963 }
1964
1965 /*******************************************************************************
1966 *
1967 * SER_ImmediateSwitch
1968 *
1969 * Purpose: TBD
1970 *
1971 * Parameters: In : none
1972 * Out: none
1973 *
1974 * Return: 0 (FALSE) : In case of error.
1975 * >= 1 (TRUE) : Successful operation.
1976 *
1977 ******************************************************************************/
1978
1979 SYS_BOOL
1980 SER_ImmediateSwitch (void)
1981 {
1982 #if SERIAL_DYNAMIC_SWITCH
1983 int uart_id;
1984 SYS_BOOL valid_config = 0;
1985 T_AppliSerialInfo *serial_info = &appli_ser_cfg_info;
1986 SYS_UWORD8 nb_allowed_config = serial_info->num_config;
1987 SYS_UWORD16 *allowed_config;
1988 int flow;
1989 T_SerialDriver serial_flows[SER_MAX_NUMBER_OF_FLOWS];
1990 T_tr_UartId uart_nb;
1991
1992 /*
1993 * First check if the new serial configuration is actually different from
1994 * the previous one. A return is used to simplify the code.
1995 */
1996
1997 if (!memcmp (ser_new_cfg,
1998 ser_cfg_info,
1999 NUMBER_OF_TR_UART))
2000 return (1); /* new config and old config are identical => nothing to do */
2001
2002 /*
2003 * Then check if the new serial config is valid or not.
2004 * At that point, we assume that a serial config is valid if and only if the
2005 * Bluetooth HCI flow is still enabled and still uses the same UART.
2006 * Reset the current serial config, and compute the new one.
2007 */
2008
2009 serial_cfg = 0x0048; /* All dummies */
2010 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) {
2011
2012 switch (ser_new_cfg[uart_id]) {
2013
2014 case G23_PANEL:
2015 serial_cfg = serial_cfg +
2016 ((uart_id + 1) << (12 - (4 * SER_PROTOCOL_STACK)));
2017 break;
2018
2019 case RIVIERA_TRACE_MUX:
2020 serial_cfg = serial_cfg +
2021 ((uart_id + 1) << (12 - (4 * SER_LAYER_1)));
2022 break;
2023
2024 case FD_AT_COMMAND:
2025 serial_cfg = serial_cfg +
2026 ((uart_id + 1) << (12 - (4 * SER_FAX_DATA)));
2027 break;
2028
2029 case BLUETOOTH_HCI:
2030 serial_cfg = serial_cfg +
2031 ((uart_id + 1) << (12 - (4 * SER_BLUETOOTH_HCI)));
2032
2033 /*
2034 * Check if the Bluetooth HCI flow is enabled on the same UART.
2035 */
2036
2037 if (ser_cfg_info[uart_id] == BLUETOOTH_HCI)
2038 valid_config = 1;
2039
2040 break;
2041
2042 case DUMMY:
2043 break;
2044 }
2045 }
2046
2047 if (!valid_config)
2048 return (0); /* Bluetooth HCI flow not enabled in the new serial config,
2049 or enabled but using a different UART. */
2050
2051 /*
2052 * Finally check if the new serial config is allowed by the application.
2053 */
2054
2055 valid_config = 0;
2056 while ((nb_allowed_config > 0) && !valid_config) {
2057
2058 nb_allowed_config--;
2059 allowed_config = (SYS_UWORD16 *)
2060 &(serial_info->allowed_config[nb_allowed_config]);
2061
2062 if (serial_cfg == *allowed_config)
2063 valid_config = 1;
2064 }
2065
2066 if (!valid_config) /* the new config is not allowed by the application */
2067 return (0);
2068
2069 /*
2070 * From now on, Dynamic Switch is being processed.
2071 */
2072
2073 dynamic_switch = 1;
2074
2075 /*
2076 * Disable UART interrupts until new serial config setup is complete.
2077 */
2078
2079 #if ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11))
2080 IQ_Mask (IQ_UART_IRDA_IT);
2081 #endif
2082 IQ_Mask (IQ_UART_IT);
2083
2084 /*
2085 * Reset UARTs set-up.
2086 */
2087
2088 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) {
2089
2090 int_uart[uart_id].device_used = 0;
2091 int_uart[uart_id].deep_sleep_set_up = 0;
2092 int_uart[uart_id].interrupt_handler = NULL;
2093 }
2094
2095 /*
2096 * All function pointers are set to dummy functions.
2097 */
2098
2099 rvf_disable (21); /* beginning of the critical section */
2100
2101 for (flow = 0; flow < SER_MAX_NUMBER_OF_FLOWS; flow++)
2102 tr_functions[flow] = &dummy_trace;
2103
2104 fd_functions = &dummy_fax_data;
2105 bt_functions = &dummy_bt_hci;
2106
2107 rvf_enable (); /* end of the critical section */
2108
2109 /*
2110 * Calls the Exit function of the UARTFAX driver if it was previously used.
2111 */
2112
2113 if (uart_fd_initialized) {
2114
2115 /*
2116 * UART IrDA can't be used for F&D/AT-Cmd flow => UART Modem was used
2117 * by the F&D/AT-Cmd flow.
2118 */
2119
2120 if (UAF_Exit (UAF_UART_1) == FD_OK) {
2121 uart_fd_initialized = 0;
2122 }
2123 }
2124 else {
2125
2126 /*
2127 * AT that point, since the Bluetooth HCI flow already uses one UART,
2128 * and since the second UART was not used by the F&D/AT-Cmd flow, we
2129 * assume it was used by a Trace flow. Therefore, the HISR used to
2130 * reset and restart the sleep timer is deleted.
2131 */
2132
2133 (void) NU_Delete_HISR (&timer_hisr_ctrl_block);
2134 }
2135
2136 /*
2137 * Initialization of the new flows (Only AT-Cmd/F&D or Riviera/Layer1 Trace)
2138 * and their associated UARTs HW (Irda or Modem) & SW (Trace or Fax&Data).
2139 */
2140
2141 for (flow = 0; flow < SER_MAX_NUMBER_OF_FLOWS; flow++) {
2142
2143 serial_flows[flow] = (T_SerialDriver)
2144 ((serial_cfg >> (12 - flow * 4)) & 0x000F);
2145
2146 switch (serial_flows[flow]) {
2147
2148 /*
2149 * For Riviera/Layer1 Trace flow, default baudrate is 115200 bps
2150 * and callback function is defined in rvt_def_i.h.
2151 */
2152
2153 case UART_IRDA_TRACE:
2154 case UART_MODEM_TRACE:
2155
2156 if (serial_flows[flow] == UART_IRDA_TRACE)
2157 uart_nb = UA_UART_0;
2158 else /* if (serial_flows[flow] == UART_MODEM_TRACE) */
2159 uart_nb = UA_UART_1;
2160
2161 if (flow == SER_LAYER_1) {
2162
2163 UA_Init (uart_nb,
2164 TR_BAUD_CONFIG,
2165 rvt_activate_RX_HISR);
2166
2167 /*
2168 * Create the HISR used to reset and restart the sleep
2169 * timer in case of incoming characters on the Trace flow.
2170 * The stack is entirely filled with the pattern 0xFE.
2171 */
2172
2173 memset (&(timer_hisr_stack[0]),
2174 0xFE,
2175 TIMER_HISR_STACK_SIZE);
2176
2177 (void) NU_Create_HISR (
2178 &timer_hisr_ctrl_block,
2179 "Tim_HISR",
2180 SER_restart_uart_sleep_timer,
2181 TIMER_HISR_PRIORITY,
2182 &(timer_hisr_stack[0]),
2183 TIMER_HISR_STACK_SIZE);
2184 }
2185 else /* Other Trace flows are disabled */
2186 initialize_uart_sleep (uart_nb);
2187 break;
2188
2189 /*
2190 * For At-Cmd/F&D flow, functions are called in the appropriate
2191 * order with the saved parameters.
2192 * This has been figured out from the G23 initialization.
2193 */
2194
2195 case UART_MODEM_FAX_DATA:
2196
2197 /* Global Initialization */
2198 if (UAF_Init (UAF_UART_1) == FD_OK) {
2199 uart_fd_initialized = 1;
2200 }
2201
2202 /* Disable the driver */
2203 UAF_Enable (UAF_UART_1,
2204 0);
2205
2206 /* Set the SW Buffers parameters */
2207 UAF_SetBuffer (UAF_UART_1,
2208 data_flow_parameters.bufSize,
2209 data_flow_parameters.rxThreshold,
2210 data_flow_parameters.txThreshold);
2211
2212 /* Set the Escape Sequence parameters (1st call) */
2213 UAF_SetEscape (UAF_UART_1,
2214 data_flow_parameters.escChar[0],
2215 data_flow_parameters.guardPeriod[0]);
2216
2217 /* Set the Communication parameters (1st call) */
2218 UAF_SetComPar (UAF_UART_1,
2219 data_flow_parameters.baudrate[0],
2220 data_flow_parameters.bpc[0],
2221 data_flow_parameters.sb[0],
2222 data_flow_parameters.parity[0]);
2223
2224 /* Set the Flow Control parameters (1st call) */
2225 UAF_SetFlowCtrl (UAF_UART_1,
2226 data_flow_parameters.fcMode[0],
2227 data_flow_parameters.XON[0],
2228 data_flow_parameters.XOFF[0]);
2229
2230 /* Set the Communication parameters (2nd call) */
2231 UAF_SetComPar (UAF_UART_1,
2232 data_flow_parameters.baudrate[1],
2233 data_flow_parameters.bpc[1],
2234 data_flow_parameters.sb[1],
2235 data_flow_parameters.parity[1]);
2236
2237 /* Set the Flow Control parameters (2nd call) */
2238 UAF_SetFlowCtrl (UAF_UART_1,
2239 data_flow_parameters.fcMode[1],
2240 data_flow_parameters.XON[1],
2241 data_flow_parameters.XOFF[1]);
2242
2243 /* Set the Escape Sequence parameters (2nd call) */
2244 UAF_SetEscape (UAF_UART_1,
2245 data_flow_parameters.escChar[1],
2246 data_flow_parameters.guardPeriod[1]);
2247
2248 /* Enable the driver */
2249 UAF_Enable (UAF_UART_1,
2250 1);
2251
2252 /* Get the number of input bytes available */
2253 UAF_InpAvail (UAF_UART_1);
2254
2255 /* Set the readOutFunc and the suspend mode */
2256 UAF_ReadData (UAF_UART_1,
2257 data_flow_parameters.suspend_rd,
2258 data_flow_parameters.readOutFunc);
2259
2260 /* Get the number of output bytes available (1st call) */
2261 UAF_OutpAvail (UAF_UART_1);
2262
2263 /* Set the states of the V.24 status lines (1st call) */
2264 UAF_SetLineState (UAF_UART_1,
2265 data_flow_parameters.state[0],
2266 data_flow_parameters.mask[0]);
2267
2268 /* Set the states of the V.24 status lines (2nd call) */
2269 UAF_SetLineState (UAF_UART_1,
2270 data_flow_parameters.state[1],
2271 data_flow_parameters.mask[1]);
2272
2273 /* Set the states of the V.24 status lines (3rd call) */
2274 UAF_SetLineState (UAF_UART_1,
2275 data_flow_parameters.state[2],
2276 data_flow_parameters.mask[2]);
2277
2278 /* Set the states of the V.24 status lines (4th call) */
2279 UAF_SetLineState (UAF_UART_1,
2280 data_flow_parameters.state[3],
2281 data_flow_parameters.mask[3]);
2282
2283 /* Set the writeInFunc and the suspend mode */
2284 UAF_WriteData (UAF_UART_1,
2285 data_flow_parameters.suspend_wr,
2286 data_flow_parameters.writeInFunc);
2287
2288 /* Get the number of output bytes available (2nd call) */
2289 UAF_OutpAvail (UAF_UART_1);
2290
2291 break;
2292
2293 case UART_IRDA_BT_HCI:
2294 case UART_MODEM_BT_HCI:
2295 /*
2296 * Nothing to initialize for Bluetooth HCI flow since it does
2297 * use the same UART.
2298 */
2299
2300 case DUMMY_TRACE:
2301 case DUMMY_FAX_DATA:
2302 case DUMMY_BT_HCI:
2303 /*
2304 * Of course nothing to perform for Dummy flows.
2305 */
2306
2307 break;
2308 }
2309 }
2310
2311 /*
2312 * All function pointers are set to the appropriate functions set.
2313 */
2314
2315 for (flow = 0; flow < SER_MAX_NUMBER_OF_FLOWS; flow++){
2316
2317 /*
2318 * For Dummy flows, pointers to dummy functions are already set.
2319 */
2320
2321 if ((serial_flows[flow] != DUMMY_TRACE) &&
2322 (serial_flows[flow] != DUMMY_FAX_DATA) &&
2323 (serial_flows[flow] != DUMMY_BT_HCI)) {
2324
2325 rvf_disable (21); /* beginning of the critical section */
2326 set_flow_functions (flow, serial_flows[flow]);
2327 rvf_enable (); /* end of the critical section */
2328 }
2329 }
2330
2331 /*
2332 * Dynamic Switch has been processed.
2333 * The new serial config is actually stored.
2334 */
2335
2336 dynamic_switch = 0;
2337 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++)
2338 ser_cfg_info[uart_id] = ser_new_cfg[uart_id];
2339
2340 /*
2341 * Re-enable UART interrupts.
2342 */
2343
2344 #if ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11))
2345 IQ_Unmask (IQ_UART_IRDA_IT);
2346 #endif
2347 IQ_Unmask (IQ_UART_IT);
2348
2349 #endif
2350 /*
2351 * Real Dynamic Switch is only available with Bluetooth AND all chips but
2352 * Calypso+.
2353 */
2354
2355 return (1);
2356 }
2357
2358 /*******************************************************************************
2359 *
2360 * All functions SER_tr_xxx and SER_fd_xxx call a function of the UART trace
2361 * driver or the UART fax & data driver.
2362 * All functions SER_bt_xxx call a function of the UART Bluetooth HCI driver.
2363 * See the function call for parameters and return values.
2364 *
2365 ******************************************************************************/
2366
2367 void
2368 SER_tr_Init (int serial_data_flow,
2369 T_tr_Baudrate baudrate,
2370 void (callback_function (void)))
2371 {
2372 tr_functions[serial_data_flow]->tr_Init (
2373 tr_functions[serial_data_flow]->device, baudrate, callback_function);
2374 }
2375
2376 SYS_UWORD32
2377 SER_tr_ReadNChars (int serial_data_flow,
2378 char *buffer,
2379 SYS_UWORD32 chars_to_read)
2380 {
2381 return (tr_functions[serial_data_flow]->tr_ReadNChars (
2382 tr_functions[serial_data_flow]->device, buffer, chars_to_read));
2383 }
2384
2385 SYS_UWORD32
2386 SER_tr_ReadNBytes (int serial_data_flow,
2387 char *buffer,
2388 SYS_UWORD32 chars_to_read,
2389 SYS_BOOL *eof_detected)
2390 {
2391 return (tr_functions[serial_data_flow]->tr_ReadNBytes (
2392 tr_functions[serial_data_flow]->device, buffer, chars_to_read, eof_detected));
2393 }
2394
2395 SYS_UWORD32
2396 SER_tr_WriteNChars (int serial_data_flow,
2397 char *buffer,
2398 SYS_UWORD32 chars_to_write)
2399 {
2400 return (tr_functions[serial_data_flow]->tr_WriteNChars (
2401 tr_functions[serial_data_flow]->device, buffer, chars_to_write));
2402 }
2403
2404 SYS_UWORD32
2405 SER_tr_EncapsulateNChars (int serial_data_flow,
2406 char *buffer,
2407 SYS_UWORD32 chars_to_write)
2408 {
2409 return (tr_functions[serial_data_flow]->tr_EncapsulateNChars (
2410 tr_functions[serial_data_flow]->device, buffer, chars_to_write));
2411 }
2412
2413 SYS_UWORD32
2414 SER_tr_WriteNBytes (int serial_data_flow,
2415 SYS_UWORD8 *buffer,
2416 SYS_UWORD32 chars_to_write)
2417 {
2418 return (tr_functions[serial_data_flow]->tr_WriteNBytes (
2419 tr_functions[serial_data_flow]->device, buffer, chars_to_write));
2420 }
2421
2422 void
2423 SER_tr_WriteChar (int serial_data_flow,
2424 char character)
2425 {
2426 tr_functions[serial_data_flow]->tr_WriteChar (
2427 tr_functions[serial_data_flow]->device, character);
2428 }
2429
2430 void
2431 SER_tr_WriteString (int serial_data_flow,
2432 char *buffer)
2433 {
2434 tr_functions[serial_data_flow]->tr_WriteString (
2435 tr_functions[serial_data_flow]->device, buffer);
2436 }
2437
2438 SYS_BOOL
2439 SER_tr_EnterSleep (int serial_data_flow)
2440 {
2441 return (tr_functions[serial_data_flow]->tr_EnterSleep (
2442 tr_functions[serial_data_flow]->device));
2443 }
2444
2445 void
2446 SER_tr_WakeUp (int serial_data_flow)
2447 {
2448 tr_functions[serial_data_flow]->tr_WakeUp (
2449 tr_functions[serial_data_flow]->device);
2450 }
2451
2452 /* Dummy function for backward compatibility. */
2453 T_FDRET
2454 SER_fd_Init (void)
2455 {
2456 return (FD_OK);
2457 }
2458
2459 T_FDRET
2460 SER_fd_Initialize (void)
2461 {
2462 T_FDRET status;
2463
2464 #if SERIAL_DYNAMIC_SWITCH
2465 data_flow_parameters.bufSize = FD_MAX_BUFFER_SIZE;
2466 #else
2467 bufSize = FD_MAX_BUFFER_SIZE;
2468 #endif
2469 status = fd_functions->fd_Initialize (fd_functions->device);
2470
2471 #if SERIAL_DYNAMIC_SWITCH
2472 /*
2473 * Check if the UARTFAX driver has actually been initialized.
2474 */
2475
2476 if ((fd_functions->fd_Initialize == UAF_Init) &&
2477 (status = FD_OK)) {
2478
2479 uart_fd_initialized = 1;
2480 }
2481 #endif
2482
2483 return (status);
2484 }
2485
2486 static void
2487 fd_dbgtrace(char *msg, UINT32 val)
2488 {
2489 rvf_send_trace(msg, strlen(msg), val, RV_TRACE_LEVEL_DEBUG_HIGH, 0);
2490 }
2491
2492 T_FDRET
2493 SER_fd_Enable (SYS_BOOL enable)
2494 {
2495 T_FDRET rc;
2496
2497 fd_dbgtrace("SER_fd_Enable called", enable);
2498 rc = fd_functions->fd_Enable (fd_functions->device, enable);
2499 fd_dbgtrace("fd_Enable returned", rc);
2500 return rc;
2501 }
2502
2503 T_FDRET
2504 SER_fd_SetComPar (T_baudrate baudrate,
2505 T_bitsPerCharacter bpc,
2506 T_stopBits sb,
2507 T_parity parity)
2508 {
2509 T_FDRET rc;
2510 char trbuf[80];
2511
2512 sprintf(trbuf, "SER_fd_SetComPar(%d, %d, %d, %d)",
2513 baudrate, bpc, sb, parity);
2514 fd_dbgtrace(trbuf, NULL_PARAM);
2515 rc = (fd_functions->fd_SetComPar (
2516 fd_functions->device, baudrate, bpc, sb, parity));
2517 fd_dbgtrace("fd_SetComPar returned", rc);
2518 return rc;
2519 }
2520
2521 T_FDRET
2522 SER_fd_SetBuffer (SYS_UWORD16 bufSize,
2523 SYS_UWORD16 rxThreshold,
2524 SYS_UWORD16 txThreshold)
2525 {
2526 T_FDRET rc;
2527 char trbuf[80];
2528
2529 sprintf(trbuf, "SER_fd_SetBuffer(%u, %u, %u)",
2530 bufSize, rxThreshold, txThreshold);
2531 fd_dbgtrace(trbuf, NULL_PARAM);
2532 rc = (fd_functions->fd_SetBuffer (
2533 fd_functions->device, bufSize, rxThreshold, txThreshold));
2534 fd_dbgtrace("fd_SetBuffer returned", rc);
2535 return rc;
2536 }
2537
2538 T_FDRET
2539 SER_fd_SetFlowCtrl (T_flowCtrlMode fcMode,
2540 SYS_UWORD8 XON,
2541 SYS_UWORD8 XOFF)
2542 {
2543 T_FDRET rc;
2544 char trbuf[80];
2545
2546 sprintf(trbuf, "SER_fd_SetFlowCtrl(%d, %02x, %02x)", fcMode, XON, XOFF);
2547 fd_dbgtrace(trbuf, NULL_PARAM);
2548 rc = (fd_functions->fd_SetFlowCtrl (
2549 fd_functions->device, fcMode, XON, XOFF));
2550 fd_dbgtrace("fd_SetFlowCtrl returned", rc);
2551 return rc;
2552 }
2553
2554 T_FDRET
2555 SER_fd_SetEscape (char escChar,
2556 SYS_UWORD16 guardPeriod)
2557 {
2558 T_FDRET rc;
2559 char trbuf[80];
2560
2561 sprintf(trbuf, "SER_fd_SetEscape(%02x, %u)", escChar, guardPeriod);
2562 fd_dbgtrace(trbuf, NULL_PARAM);
2563 rc = (fd_functions->fd_SetEscape (
2564 fd_functions->device, escChar, guardPeriod));
2565 fd_dbgtrace("fd_SetEscape returned", rc);
2566 return rc;
2567 }
2568
2569 T_FDRET
2570 SER_fd_InpAvail (void)
2571 {
2572 T_FDRET rc;
2573
2574 fd_dbgtrace("SER_fd_InpAvail called", NULL_PARAM);
2575 rc = (fd_functions->fd_InpAvail (fd_functions->device));
2576 fd_dbgtrace("fd_InpAvail returned", rc);
2577 return rc;
2578 }
2579
2580 T_FDRET
2581 SER_fd_OutpAvail (void)
2582 {
2583 T_FDRET rc;
2584
2585 fd_dbgtrace("SER_fd_OutpAvail called", NULL_PARAM);
2586 rc = (fd_functions->fd_OutpAvail (fd_functions->device));
2587 fd_dbgtrace("fd_OutpAvail returned", rc);
2588 return rc;
2589 }
2590
2591 T_FDRET
2592 SER_fd_EnterSleep (void)
2593 {
2594 return (fd_functions->fd_EnterSleep (fd_functions->device));
2595 }
2596
2597 T_FDRET
2598 SER_fd_WakeUp (void)
2599 {
2600 return (fd_functions->fd_WakeUp (fd_functions->device));
2601 }
2602
2603 T_FDRET
2604 SER_fd_ReadData (T_suspendMode suspend,
2605 void (readOutFunc (SYS_BOOL cldFromIrq,
2606 T_reInstMode *reInstall,
2607 SYS_UWORD8 nsource,
2608 SYS_UWORD8 *source[],
2609 SYS_UWORD16 size[],
2610 SYS_UWORD32 state)))
2611 {
2612 T_FDRET rc;
2613
2614 fd_dbgtrace("SER_fd_ReadData called", suspend);
2615 rc = (fd_functions->fd_ReadData (
2616 fd_functions->device, suspend, readOutFunc));
2617 fd_dbgtrace("fd_ReadData returned", rc);
2618 return rc;
2619 }
2620
2621 T_FDRET
2622 SER_fd_WriteData (T_suspendMode suspend,
2623 void (writeInFunc (SYS_BOOL cldFromIrq,
2624 T_reInstMode *reInstall,
2625 SYS_UWORD8 ndest,
2626 SYS_UWORD8 *dest[],
2627 SYS_UWORD16 size[])))
2628 {
2629 T_FDRET rc;
2630
2631 fd_dbgtrace("SER_fd_WriteData called", suspend);
2632 rc = (fd_functions->fd_WriteData (
2633 fd_functions->device, suspend, writeInFunc));
2634 fd_dbgtrace("fd_WriteData returned", rc);
2635 return rc;
2636 }
2637
2638 T_FDRET
2639 SER_fd_StopRec (void)
2640 {
2641 T_FDRET rc;
2642
2643 fd_dbgtrace("SER_fd_StopRec called", NULL_PARAM);
2644 rc = (fd_functions->fd_StopRec (fd_functions->device));
2645 fd_dbgtrace("fd_StopRec returned", rc);
2646 return rc;
2647 }
2648
2649 T_FDRET
2650 SER_fd_StartRec (void)
2651 {
2652 T_FDRET rc;
2653
2654 fd_dbgtrace("SER_fd_StartRec called", NULL_PARAM);
2655 rc = (fd_functions->fd_StartRec (fd_functions->device));
2656 fd_dbgtrace("fd_StartRec returned", rc);
2657 return rc;
2658 }
2659
2660 T_FDRET
2661 SER_fd_GetLineState (SYS_UWORD32 *state)
2662 {
2663 T_FDRET rc;
2664 char trbuf[80];
2665
2666 fd_dbgtrace("SER_fd_GetLineState called", NULL_PARAM);
2667 rc = (fd_functions->fd_GetLineState (fd_functions->device, state));
2668 sprintf(trbuf, "fd_GetLineState returned %d, %x", rc, *state);
2669 fd_dbgtrace(trbuf, NULL_PARAM);
2670 return rc;
2671 }
2672
2673 T_FDRET
2674 SER_fd_SetLineState (SYS_UWORD32 state,
2675 SYS_UWORD32 mask)
2676 {
2677 T_FDRET rc;
2678 char trbuf[80];
2679
2680 sprintf(trbuf, "SER_fd_SetLineState(%x, %x)", state, mask);
2681 fd_dbgtrace(trbuf, NULL_PARAM);
2682 rc = (fd_functions->fd_SetLineState (fd_functions->device, state, mask));
2683 fd_dbgtrace("fd_SetLineState returned", rc);
2684 return rc;
2685 }
2686
2687 T_FDRET
2688 SER_fd_CheckXEmpty (void)
2689 {
2690 T_FDRET rc;
2691
2692 fd_dbgtrace("SER_fd_CheckXEmpty called", NULL_PARAM);
2693 rc = (fd_functions->fd_CheckXEmpty (fd_functions->device));
2694 fd_dbgtrace("fd_CheckXEmpty returned", rc);
2695 return rc;
2696 }
2697
2698 #ifdef BTEMOBILE
2699 T_HCI_RET
2700 SER_bt_Init (void)
2701 {
2702 return (bt_functions->bt_Init (bt_functions->device));
2703 }
2704
2705 T_HCI_RET
2706 SER_bt_Start (void)
2707 {
2708 return (bt_functions->bt_Start ());
2709 }
2710
2711 T_HCI_RET
2712 SER_bt_Stop (void)
2713 {
2714 return (bt_functions->bt_Stop ());
2715 }
2716
2717 T_HCI_RET
2718 SER_bt_Kill (void)
2719 {
2720 return (bt_functions->bt_Kill ());
2721 }
2722
2723 T_HCI_RET
2724 SER_bt_SetBaudrate (UINT8 baudrate)
2725 {
2726 return (bt_functions->bt_SetBaudrate (baudrate));
2727 }
2728
2729 T_HCI_RET SER_bt_TransmitPacket (void *uart_tx_buffer)
2730 {
2731 return (bt_functions->bt_TransmitPacket (uart_tx_buffer));
2732 }
2733
2734 SYS_BOOL SER_bt_EnterSleep (void)
2735 {
2736 return (bt_functions->bt_EnterSleep());
2737 }
2738
2739 void SER_bt_WakeUp (void)
2740 {
2741 bt_functions->bt_WakeUp();
2742 }
2743 #endif /* BTEMOBILE */
2744
2745 /*******************************************************************************
2746 *
2747 * SER_UartSleepStatus
2748 *
2749 * Purpose: This function checks if both UARTs are ready to enter Deep Sleep.
2750 *
2751 * Parameters: In : none
2752 * Out: none
2753 *
2754 * Return: 0 : Deep Sleep is not possible.
2755 * >= 1 : Deep Sleep is possible.
2756 *
2757 ******************************************************************************/
2758
2759 SYS_BOOL
2760 SER_UartSleepStatus (void)
2761 {
2762 t_uart *uart;
2763 int uart_id;
2764 SYS_BOOL status;
2765
2766 /*
2767 * Check first if the sleep timer is active or if a Dynamic Switch is
2768 * being processed. A return is used to simplify the code.
2769 */
2770
2771 #if SERIAL_DYNAMIC_SWITCH
2772 if (uart_sleep_timer_enabled || dynamic_switch)
2773 #else
2774 if (uart_sleep_timer_enabled)
2775 #endif
2776 return (0);
2777
2778 /*
2779 * Check if both UARTs are ready to enter Deep Sleep.
2780 */
2781
2782 status = 1;
2783 uart_id = 0;
2784 while ((uart_id < NUMBER_OF_TR_UART) &&
2785 (status)) {
2786
2787 uart = &(int_uart[uart_id]);
2788
2789 /*
2790 * Check if the specified UART is actually used.
2791 */
2792
2793 if (uart->device_used) {
2794
2795 /*
2796 * Check if the specified UART is used by a Trace or
2797 * by a Fax & Data flow.
2798 */
2799
2800 if (uart->flow_type == TRACE_FLOW)
2801 status = SER_tr_EnterSleep (uart->flow_id);
2802
2803 else
2804 if (uart->flow_type == FAX_DATA_FLOW)
2805 status = (SYS_BOOL) SER_fd_EnterSleep ();
2806 #ifdef BTEMOBILE
2807 else
2808 if (uart->flow_type == BLUETOOTH_HCI_FLOW)
2809 status = SER_bt_EnterSleep();
2810 #endif
2811 else
2812 status = 0;
2813
2814 if (status) {
2815
2816 /*
2817 * The specified UART is now set up for Deep Sleep.
2818 */
2819
2820 uart->deep_sleep_set_up = 1;
2821
2822 }
2823 }
2824
2825 uart_id++;
2826 }
2827
2828 /*
2829 * Check if Deep Sleep is finally possible.
2830 * If not revert eventual Deep Sleep settings.
2831 */
2832
2833 if (!status) {
2834
2835 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) {
2836
2837 uart = &(int_uart[uart_id]);
2838
2839 /*
2840 * If the specified used UART has already been set up for
2841 * Deep Sleep, revert these settings.
2842 */
2843
2844 if ((uart->device_used) &&
2845 (uart->deep_sleep_set_up)) {
2846
2847 /*
2848 * Check if the specified UART is used by a Trace or
2849 * by a Fax & Data flow.
2850 * Bluetooth HCI can not yet handled Deep Sleep Mode.
2851 */
2852
2853 if (uart->flow_type == TRACE_FLOW)
2854 SER_tr_WakeUp (uart->flow_id);
2855
2856 else
2857 if (uart->flow_type == FAX_DATA_FLOW)
2858 SER_fd_WakeUp ();
2859 #ifdef BTEMOBILE
2860 else
2861 if (uart->flow_type == BLUETOOTH_HCI_FLOW)
2862 SER_bt_WakeUp ();
2863 #endif
2864 uart->deep_sleep_set_up = 0;
2865
2866 }
2867 }
2868 }
2869
2870 return (status);
2871 }
2872
2873
2874 /*******************************************************************************
2875 *
2876 * SER_WakeUpUarts
2877 *
2878 * Purpose: This function wakes up used UARTs after Deep Sleep.
2879 *
2880 * Parameters: In : none
2881 * Out: none
2882 *
2883 * Return: none
2884 *
2885 ******************************************************************************/
2886
2887 void
2888 SER_WakeUpUarts (void)
2889 {
2890 t_uart *uart;
2891 int uart_id;
2892
2893 if (uart_sleep_timer_enabled)
2894 start_uart_sleep_timer ();
2895
2896 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) {
2897
2898 uart = &(int_uart[uart_id]);
2899
2900 /*
2901 * Check if the specified UART is actually used, and has not yet
2902 * been waked up.
2903 */
2904
2905 if ((uart->device_used) &&
2906 (uart->deep_sleep_set_up)) {
2907
2908 /*
2909 * Check if the specified UART is used by a Trace or
2910 * by a Fax & Data flow.
2911 * Bluetooth HCI can not yet handled Deep Sleep Mode.
2912 */
2913
2914 if (uart->flow_type == TRACE_FLOW)
2915 SER_tr_WakeUp (uart->flow_id);
2916
2917 else
2918 if (uart->flow_type == FAX_DATA_FLOW)
2919 SER_fd_WakeUp ();
2920 #ifdef BTEMOBILE
2921 else
2922 if (uart->flow_type == BLUETOOTH_HCI_FLOW)
2923 SER_bt_WakeUp ();
2924 #endif
2925 /*
2926 * The specified UART is no more set up for Deep Sleep.
2927 */
2928
2929 uart->deep_sleep_set_up = 0;
2930
2931 }
2932 }
2933 }
2934
2935
2936 /*******************************************************************************
2937 *
2938 * SER_restart_uart_sleep_timer
2939 *
2940 * Purpose : Resets and restarts the sleep timer each time some characters are
2941 * received.
2942 *
2943 * Arguments: In : none
2944 * Out: none
2945 *
2946 * Returns : none
2947 *
2948 ******************************************************************************/
2949
2950 void
2951 SER_restart_uart_sleep_timer (void)
2952 {
2953 /*
2954 * First disable the timer.
2955 */
2956
2957 (void) NU_Control_Timer (&uart_sleep_timer,
2958 NU_DISABLE_TIMER);
2959
2960 /*
2961 * Then start again this timer for a new period.
2962 */
2963
2964 start_uart_sleep_timer ();
2965 }
2966
2967
2968 /*******************************************************************************
2969 *
2970 * SER_activate_timer_hisr
2971 *
2972 * Purpose : Activates the timer HISR to reset and restart the sleep timer
2973 * each time some characters are received.
2974 *
2975 * Arguments: In : none
2976 * Out: none
2977 *
2978 * Returns : none
2979 *
2980 ******************************************************************************/
2981
2982 void
2983 SER_activate_timer_hisr (void)
2984 {
2985 (void) NU_Activate_HISR (&timer_hisr_ctrl_block);
2986 }
2987
2988
2989 #if ((CHIPSET == 2) || (CHIPSET == 3))
2990
2991 /*******************************************************************************
2992 *
2993 * SER_uart_handler
2994 *
2995 * Purpose : UART interrupt handler.
2996 *
2997 * Arguments: In : none
2998 * Out: none
2999 *
3000 * Returns : none
3001 *
3002 ******************************************************************************/
3003
3004 void
3005 SER_uart_handler (void)
3006 {
3007 SYS_UWORD8 interrupt_status;
3008 t_uart *uart;
3009 int uart_id;
3010 SYS_BOOL it_identified;
3011
3012 it_identified = 0;
3013
3014 /*
3015 * Check first for a wake-up interrupt.
3016 */
3017
3018 uart_id = 0;
3019 while ((uart_id < NUMBER_OF_TR_UART) &&
3020 (!it_identified)) {
3021
3022 uart = &(int_uart[uart_id]);
3023 interrupt_status = READ_UART_REGISTER (uart, SSR);
3024
3025 if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */
3026
3027 it_identified = 1;
3028 uart_sleep_timer_enabled = 1;
3029 DISABLE_WAKE_UP_INTERRUPT (uart);
3030 }
3031
3032 uart_id++;
3033 }
3034
3035 /*
3036 * If no wake-up interrupt has been detected, check then systematically
3037 * both UARTs for other interrupt causes.
3038 */
3039
3040 if (!it_identified) {
3041
3042 for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) {
3043
3044 uart = &(int_uart[uart_id]);
3045 interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED;
3046
3047 if (!(interrupt_status & IT_NOT_PENDING)) {
3048
3049 it_identified = 1;
3050 (*(uart->interrupt_handler)) (uart_id, interrupt_status);
3051
3052 } else {
3053
3054 if ((uart_id == UA_UART_1) && (!it_identified))
3055 uart_spurious_interrupts++;
3056 }
3057 }
3058 }
3059 }
3060
3061 #elif ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11) || (CHIPSET == 12))
3062
3063 /*******************************************************************************
3064 *
3065 * SER_uart_modem_handler
3066 *
3067 * Purpose : UART MODEM interrupt handler.
3068 *
3069 * Arguments: In : none
3070 * Out: none
3071 *
3072 * Returns : none
3073 *
3074 ******************************************************************************/
3075
3076 void
3077 SER_uart_modem_handler (void)
3078 {
3079 SYS_UWORD8 interrupt_status;
3080 t_uart *uart;
3081 SYS_BOOL it_wakeup_identified;
3082
3083 it_wakeup_identified = 0;
3084 uart = &(int_uart[UA_UART_1]);
3085
3086 /*
3087 * Check first for a wake-up interrupt.
3088 */
3089
3090 interrupt_status = READ_UART_REGISTER (uart, SSR);
3091
3092 if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */
3093
3094 it_wakeup_identified = 1;
3095 uart_sleep_timer_enabled = 1;
3096 #ifdef BTEMOBILE
3097 if (uart->flow_type == BLUETOOTH_HCI_FLOW)
3098 {
3099 interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED;
3100 (*(uart->interrupt_handler)) (UA_UART_1, interrupt_status);
3101 }
3102 #endif /* BTEMOBILE */
3103 DISABLE_WAKE_UP_INTERRUPT (uart);
3104 }
3105
3106 /*
3107 * If no wake-up interrupt has been detected, check UART for other
3108 * interrupt causes.
3109 */
3110
3111 if (!it_wakeup_identified) {
3112
3113 interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED;
3114
3115 if (!(interrupt_status & IT_NOT_PENDING))
3116 (*(uart->interrupt_handler)) (UA_UART_1, interrupt_status);
3117
3118 else
3119 uart_modem_spurious_interrupts++;
3120 }
3121 }
3122
3123
3124 /*******************************************************************************
3125 *
3126 * SER_uart_irda_handler
3127 *
3128 * Purpose : UART IrDA interrupt handler.
3129 *
3130 * Arguments: In : none
3131 * Out: none
3132 *
3133 * Returns : none
3134 *
3135 ******************************************************************************/
3136
3137 void
3138 SER_uart_irda_handler (void)
3139 {
3140 SYS_UWORD8 interrupt_status;
3141 t_uart *uart;
3142 SYS_BOOL it_wakeup_identified;
3143
3144 it_wakeup_identified = 0;
3145 uart = &(int_uart[UA_UART_0]);
3146
3147 /*
3148 * Check first for a wake-up interrupt.
3149 */
3150
3151 interrupt_status = READ_UART_REGISTER (uart, SSR);
3152
3153 if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */
3154
3155 it_wakeup_identified = 1;
3156 uart_sleep_timer_enabled = 1;
3157 #ifdef BTEMOBILE
3158 if (uart->flow_type == BLUETOOTH_HCI_FLOW)
3159 {
3160 interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED;
3161 (*(uart->interrupt_handler)) (UA_UART_0, interrupt_status);
3162 }
3163 #endif /* BTEMOBILE */
3164 DISABLE_WAKE_UP_INTERRUPT (uart);
3165 }
3166
3167 /*
3168 * If no wake-up interrupt has been detected, check UART for other
3169 * interrupt causes.
3170 */
3171
3172 if (!it_wakeup_identified) {
3173
3174 interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED;
3175
3176 if (!(interrupt_status & IT_NOT_PENDING))
3177 (*(uart->interrupt_handler)) (UA_UART_0, interrupt_status);
3178
3179 else
3180 uart_irda_spurious_interrupts++;
3181 }
3182 }
3183
3184 #endif
3185
3186 #if (CHIPSET == 12)
3187 /*******************************************************************************
3188 *
3189 * SER_uart_modem2_handler
3190 *
3191 * Purpose : UART IrDA interrupt handler.
3192 *
3193 * Arguments: In : none
3194 * Out: none
3195 *
3196 * Returns : none
3197 *
3198 ******************************************************************************/
3199
3200 void
3201 SER_uart_modem2_handler (void)
3202 {
3203 SYS_UWORD8 interrupt_status;
3204 t_uart *uart;
3205 SYS_BOOL it_wakeup_identified;
3206
3207 it_wakeup_identified = 0;
3208 uart = &(int_uart[UA_UART_2]);
3209
3210 /*
3211 * Check first for a wake-up interrupt.
3212 */
3213
3214 interrupt_status = READ_UART_REGISTER (uart, SSR);
3215
3216 if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */
3217
3218 it_wakeup_identified = 1;
3219 uart_sleep_timer_enabled = 1;
3220 #ifdef BTEMOBILE
3221 if (uart->flow_type == BLUETOOTH_HCI_FLOW)
3222 {
3223 interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED;
3224 (*(uart->interrupt_handler)) (UA_UART_2, interrupt_status);
3225 }
3226 #endif /* BTEMOBILE */
3227 DISABLE_WAKE_UP_INTERRUPT (uart);
3228 }
3229
3230 /*
3231 * If no wake-up interrupt has been detected, check UART for other
3232 * interrupt causes.
3233 */
3234
3235 if (!it_wakeup_identified) {
3236
3237 interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED;
3238
3239 if (!(interrupt_status & IT_NOT_PENDING))
3240 (*(uart->interrupt_handler)) (UA_UART_2, interrupt_status);
3241
3242 else
3243 uart_modem2_spurious_interrupts++;
3244 }
3245 }
3246
3247 #endif
3248
3249 /*
3250 * Temporary functions.
3251 *
3252 * FreeCalypso note: I'll put them back in if they are actually needed.
3253 */
3254
3255 #if 0
3256
3257 void
3258 UT_Init (int device_id,
3259 int baudrate,
3260 void (callback_function (void)))
3261 {
3262 SER_tr_Init (SER_PROTOCOL_STACK, baudrate, callback_function);
3263 }
3264
3265 SYS_UWORD32
3266 UT_ReadNChars (int device_id,
3267 char *buffer,
3268 SYS_UWORD32 chars_to_read)
3269 {
3270 return (SER_tr_ReadNChars (SER_PROTOCOL_STACK, buffer, chars_to_read));
3271 }
3272
3273 SYS_UWORD32
3274 UT_WriteNChars (int device_id,
3275 char *buffer,
3276 SYS_UWORD32 chars_to_write)
3277 {
3278 return (SER_tr_WriteNChars (SER_PROTOCOL_STACK, buffer, chars_to_write));
3279 }
3280
3281 void
3282 UT_WriteChar (int device_id,
3283 char character)
3284 {
3285 SER_tr_WriteChar (SER_PROTOCOL_STACK, character);
3286 }
3287
3288 void
3289 UT_WriteString (int device_id,
3290 char *buffer)
3291 {
3292 SER_tr_WriteString (SER_PROTOCOL_STACK, buffer);
3293 }
3294
3295 short
3296 UF_Init (SYS_UWORD8 deviceNo)
3297 {
3298 return (SER_fd_Init ());
3299 }
3300
3301 short
3302 UF_Enable (SYS_UWORD8 deviceNo,
3303 SYS_BOOL enable)
3304 {
3305 return (SER_fd_Enable (enable));
3306 }
3307
3308 short
3309 UF_SetComPar (SYS_UWORD8 deviceNo,
3310 T_baudrate baudrate,
3311 T_bitsPerCharacter bpc,
3312 T_stopBits sb,
3313 T_parity parity)
3314 {
3315 return (SER_fd_SetComPar (baudrate,
3316 bpc,
3317 sb,
3318 parity));
3319 }
3320
3321 short
3322 UF_SetBuffer (SYS_UWORD8 deviceNo,
3323 SYS_UWORD16 bufSize,
3324 SYS_UWORD16 rxThreshold,
3325 SYS_UWORD16 txThreshold)
3326 {
3327 return (SER_fd_SetBuffer (bufSize, rxThreshold, txThreshold));
3328 }
3329
3330 short
3331 UF_SetFlowCtrl (SYS_UWORD8 deviceNo,
3332 T_flowCtrlMode fcMode,
3333 SYS_UWORD8 XON,
3334 SYS_UWORD8 XOFF)
3335 {
3336 return (SER_fd_SetFlowCtrl (fcMode, XON, XOFF));
3337 }
3338
3339 short
3340 UF_SetEscape (SYS_UWORD8 deviceNo,
3341 SYS_UWORD8 escChar,
3342 SYS_UWORD16 guardPeriod)
3343 {
3344 return (SER_fd_SetEscape (escChar, guardPeriod));
3345 }
3346
3347 short
3348 UF_InpAvail (SYS_UWORD8 deviceNo)
3349 {
3350 return (SER_fd_InpAvail ());
3351 }
3352
3353 short
3354 UF_OutpAvail (SYS_UWORD8 deviceNo)
3355 {
3356 return (SER_fd_OutpAvail ());
3357 }
3358
3359 short
3360 UF_ReadData (SYS_UWORD8 deviceNo,
3361 T_suspendMode suspend,
3362 void (readOutFunc (SYS_BOOL cldFromIrq,
3363 T_reInstMode *reInstall,
3364 SYS_UWORD8 nsource,
3365 SYS_UWORD8 *source[],
3366 SYS_UWORD16 size[],
3367 SYS_UWORD32 state)))
3368 {
3369 return (SER_fd_ReadData (suspend, readOutFunc));
3370 }
3371
3372 short
3373 UF_WriteData (SYS_UWORD8 deviceNo,
3374 T_suspendMode suspend,
3375 void (writeInFunc (SYS_BOOL cldFromIrq,
3376 T_reInstMode *reInstall,
3377 SYS_UWORD8 ndest,
3378 SYS_UWORD8 *dest[],
3379 SYS_UWORD16 size[])))
3380 {
3381 return (SER_fd_WriteData (suspend, writeInFunc));
3382 }
3383
3384 short
3385 UF_StopRec (SYS_UWORD8 deviceNo)
3386 {
3387 return (SER_fd_StopRec ());
3388 }
3389
3390 short
3391 UF_StartRec (SYS_UWORD8 deviceNo)
3392 {
3393 return (SER_fd_StartRec ());
3394 }
3395
3396 short
3397 UF_GetLineState (SYS_UWORD8 deviceNo,
3398 SYS_UWORD32 *state)
3399 {
3400 return (SER_fd_GetLineState (state));
3401 }
3402
3403 short
3404 UF_SetLineState (SYS_UWORD8 deviceNo,
3405 SYS_UWORD32 state,
3406 SYS_UWORD32 mask)
3407 {
3408 return (SER_fd_SetLineState (state, mask));
3409 }
3410
3411 short
3412 UF_CheckXEmpty (SYS_UWORD8 deviceNo)
3413 {
3414 return (SER_fd_CheckXEmpty ());
3415 }
3416 #endif