comparison chipsetsw/drivers/drv_app/uart/serialswitch.c @ 0:509db1a7b7b8

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