comparison src/cs/drivers/drv_app/uart/serialswitch_dp.c @ 0:b6a5e36de839

src/cs: initial import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 04:39:26 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:b6a5e36de839
1 /*******************************************************************************
2 *
3 * SERIALSWITCH.C
4 *
5 * Board-specific switch for Perseus
6 *
7 * (C) Texas Instruments 2000
8 *
9 ******************************************************************************/
10
11 #ifndef __SERIALSWITCH_C__
12 #define __SERIALSWITCH_C__
13
14 #include "main/sys_types.h"
15 #include "memif/mem.h"
16 #include "nucleus.h"
17 #include "csmi/csmi.h"
18 #include "uart/serialswitch.h"
19 #include "uart/uart.h"
20 #include "uart/uartfax.h"
21 #include "csmi/csmi_uart.h"
22 #include "csmi/csmi_uartfax.h"
23 #include "inth/iq.h"
24
25 static int serial_config;
26
27 #define NUMBER_OF_UART 2
28
29 // Constant used to avoid calling uart interrupt handler when using CSMI
30 #define DISABLE_UART_INTERRUPT_HANDLER 0x0
31
32 // Internal UART constants & macros - used by interrupt handler
33 #define IIR (0x02) /* UART interrupt ident. register - Read only */
34 #define SCR (0x10) /* UART suppl. control register - Read/Write */
35 #define SSR (0x11) /* UART suppl. status register - Read only */
36
37 #define IIR_BITS_USED (0x07)
38 #define IT_NOT_PENDING (0x01)
39
40 /*
41 * Supplementary Control Register
42 */
43
44 #define RX_CTS_WAKE_UP_ENABLE_BIT (4)
45
46 /*
47 * Supplementary Status Register
48 */
49
50 #define RX_CTS_WAKE_UP_STS (0x02) /* Wake-up interrupt occurred */
51
52 /*
53 * This macro allows to read an UART register.
54 */
55
56 #define READ_UART_REGISTER(UART,REG) \
57 *((volatile SYS_UWORD8 *) ((UART)->base_address + (REG)))
58
59 /*
60 * This macro allows to disable the UART's wake-up interrupt.
61 */
62
63 #define DISABLE_WAKE_UP_INTERRUPT(UART) \
64 *((volatile SYS_UWORD8 *) ((UART)->base_address + SCR)) &= \
65 ~(1 << (RX_CTS_WAKE_UP_ENABLE_BIT));
66
67 /*
68 * Wake-up time duration in seconds and in number of TDMAs.
69 * 1 TDMA = (6 / 1300) s = 0.004615 s (= 4.615 ms).
70 */
71
72 #define WAKE_UP_TIME_DURATION (10) /* 7200 seconds = 120 min. = 2 hours*/
73 #define WAKE_UP_TIME_IN_TDMA (WAKE_UP_TIME_DURATION * 1300 / 6)
74
75 char ser_cfg_info[NUMBER_OF_TR_UART] = {0, 0};
76
77 /*
78 * Types of flows supported.
79 */
80
81 typedef enum {
82 TRACE_FLOW,
83 FAX_DATA_FLOW
84 } t_flow_type;
85
86 static const unsigned long uart_base_address[NUMBER_OF_UART] =
87 {
88 MEM_UART_IRDA,
89 MEM_UART_MODEM
90 };
91
92 static NU_TIMER uart_wake_up_duration_timer;
93 static unsigned char uart_waked_up_by_interrupt;
94
95 #if ((CHIPSET == 2) || (CHIPSET == 3))
96 static unsigned long uart_spurious_interrupts;
97 #elif ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7))
98 static unsigned long uart_modem_spurious_interrupts;
99 static unsigned long uart_irda_spurious_interrupts;
100 #endif
101
102 // Structures representing the arrays
103 typedef struct
104 {
105 void (*tr_Init) (T_tr_UartId device, int baudrate, void (callback_function (void)));
106 unsigned long (*tr_ReadNChars) (T_tr_UartId device, char *buffer, unsigned long chars_to_read);
107 unsigned long (*tr_ReadNBytes) (T_tr_UartId device, char *buffer, unsigned long chars_to_read, unsigned char *eof_detected);
108 unsigned long (*tr_WriteNChars) (T_tr_UartId device, char *buffer, unsigned long chars_to_write);
109 unsigned long (*tr_EncapsulateNChars) (T_tr_UartId device, char *buffer, unsigned long chars_to_write);
110 unsigned long (*tr_WriteNBytes) (T_tr_UartId device, unsigned char *buffer, unsigned long chars_to_write);
111 void (*tr_WriteChar) (T_tr_UartId device, char character);
112 void (*tr_WriteString) (T_tr_UartId device, char *buffer);
113 unsigned char (*tr_EnterSleep) (T_tr_UartId device);
114 void (*tr_WakeUp) (T_tr_UartId device);
115 } TR_DRV;
116
117 /*
118 * Set of function pointers for fax & data functions.
119 */
120
121 typedef struct
122 {
123 T_FDRET (*fd_Init) (T_fd_UartId uartNo);
124 T_FDRET (*fd_Enable) (T_fd_UartId uartNo, unsigned char enable);
125 T_FDRET (*fd_SetComPar) (T_fd_UartId uartNo, T_baudrate baudrate, T_bitsPerCharacter bpc,
126 T_stopBits sb, T_parity parity);
127 T_FDRET (*fd_SetBuffer) (T_fd_UartId uartNo, unsigned short bufSize, unsigned short rxThreshold, unsigned short txThreshold);
128 T_FDRET (*fd_SetFlowCtrl) (T_fd_UartId uartNo, T_flowCtrlMode fcMode, unsigned char XON, unsigned char XOFF);
129 T_FDRET (*fd_SetEscape) (T_fd_UartId uartNo, unsigned char escChar, unsigned short guardPeriod);
130 T_FDRET (*fd_InpAvail) (T_fd_UartId uartNo);
131 T_FDRET (*fd_OutpAvail) (T_fd_UartId uartNo);
132 T_FDRET (*fd_EnterSleep) (T_fd_UartId uartNo);
133 T_FDRET (*fd_WakeUp) (T_fd_UartId uartNo);
134 T_FDRET (*fd_ReadData) (T_fd_UartId uartNo, T_suspendMode suspend, void (readOutFunc (unsigned char cldFromIrq,
135 T_reInstMode *reInstall, unsigned char nsource, unsigned char *source[],
136 unsigned short size[], unsigned long state)));
137 T_FDRET (*fd_WriteData) (T_fd_UartId uartNo, T_suspendMode suspend, void (writeInFunc (unsigned char cldFromIrq,
138 T_reInstMode *reInstall, unsigned char ndest, unsigned char *dest[],
139 unsigned short size[])));
140 T_FDRET (*fd_StopRec) (T_fd_UartId uartNo);
141 T_FDRET (*fd_StartRec) (T_fd_UartId uartNo);
142 T_FDRET (*fd_GetLineState) (T_fd_UartId uartNo, unsigned long *state);
143 T_FDRET (*fd_SetLineState) (T_fd_UartId uartNo, unsigned long state, unsigned long mask);
144 T_FDRET (*fd_CheckXEmpty) (T_fd_UartId uartNo);
145 } FD_DRV;
146
147 /*
148 * UART structure used for UARTs.
149 */
150
151 typedef struct
152 {
153 SYS_UWORD32 base_address;
154 SYS_BOOL device_used;
155 SYS_BOOL deep_sleep_set_up;
156 t_flow_type flow_type;
157 SYS_WORD16 flow_id;
158 void (*interrupt_handler) (int uart_id, SYS_UWORD8 interrupt_status);
159 } T_UART;
160
161 /*
162 * Internal variables and prototypes of stubs
163 */
164 static unsigned short fd_bufSize;
165 static unsigned char fd_buffer[FD_MAX_BUFFER_SIZE];
166 static unsigned char fd_driver_enabled;
167
168 static void dummy_tr_Init (int device, int baudrate, void (callback_function (void)));
169 static unsigned long dummy_tr_ReadNChars (int device, char *buffer, unsigned long chars_to_read);
170 static unsigned long dummy_tr_ReadNBytes (T_tr_UartId device, char *buffer, unsigned long chars_to_read, unsigned char *eof_detected);
171 static unsigned long dummy_tr_WriteNChars (int device, char *buffer, unsigned long chars_to_write);
172 static unsigned long dummy_tr_EncapsulateNChars (T_tr_UartId device, char *buffer, unsigned long chars_to_write);
173 static unsigned long dummy_tr_WriteNBytes (T_tr_UartId device, unsigned char *buffer, unsigned long chars_to_write);
174 static void dummy_tr_WriteChar (int device, char character);
175 static void dummy_tr_WriteString (int device, char *buffer);
176 static unsigned char dummy_tr_EnterSleep (T_tr_UartId device);
177 static void dummy_tr_WakeUp (T_tr_UartId device);
178
179 static T_FDRET dummy_fd_Init (T_fd_UartId uartNo);
180 static T_FDRET dummy_fd_Enable (T_fd_UartId uartNo, unsigned char enable);
181 static T_FDRET dummy_fd_SetComPar (T_fd_UartId uartNo, T_baudrate baudrate,
182 T_bitsPerCharacter bpc,
183 T_stopBits sb,
184 T_parity parity);
185 static T_FDRET dummy_fd_SetBuffer (T_fd_UartId uartNo, unsigned short bufSize, unsigned short rxThreshold, unsigned short txThreshold);
186 static T_FDRET dummy_fd_SetFlowCtrl (T_fd_UartId uartNo, T_flowCtrlMode fcMode, unsigned char XON, unsigned char XOFF);
187 static T_FDRET dummy_fd_SetEscape (T_fd_UartId uartNo, unsigned char escChar, unsigned short guardPeriod);
188 static T_FDRET dummy_fd_InpAvail (T_fd_UartId uartNo);
189 static T_FDRET dummy_fd_OutpAvail (T_fd_UartId uartNo);
190 static T_FDRET dummy_fd_EnterSleep (T_fd_UartId uartNo);
191 static T_FDRET dummy_fd_WakeUp (T_fd_UartId uartNo);
192 static T_FDRET dummy_fd_ReadData (T_fd_UartId uartNo,
193 T_suspendMode suspend,
194 void (readOutFunc (unsigned char cldFromIrq,
195 T_reInstMode *reInstall,
196 unsigned char nsource,
197 unsigned char *source[],
198 unsigned short size[],
199 unsigned long state)));
200 static T_FDRET dummy_fd_WriteData (T_fd_UartId uartNo,
201 T_suspendMode suspend,
202 void (writeInFunc (unsigned char cldFromIrq,
203 T_reInstMode *reInstall,
204 unsigned char ndest,
205 unsigned char *dest[],
206 unsigned short size[])));
207 static T_FDRET dummy_fd_StopRec (T_fd_UartId uartNo);
208 static T_FDRET dummy_fd_StartRec (T_fd_UartId uartNo);
209 static T_FDRET dummy_fd_GetLineState (T_fd_UartId uartNo, unsigned long *state);
210 static T_FDRET dummy_fd_SetLineState (T_fd_UartId uartNo, unsigned long state, unsigned long mask);
211 static T_FDRET dummy_fd_CheckXEmpty (T_fd_UartId uartNo);
212
213 // Arrays of pointers to functions
214 const TR_DRV TR_Uart =
215 {
216 UA_Init,
217 UA_ReadNChars,
218 UA_ReadNBytes,
219 UA_WriteNChars,
220 UA_EncapsulateNChars,
221 UA_WriteNBytes,
222 UA_WriteChar,
223 UA_WriteString,
224 UA_EnterSleep,
225 UA_WakeUp
226 };
227
228 const TR_DRV TR_Dummy =
229 {
230 dummy_tr_Init,
231 dummy_tr_ReadNChars,
232 dummy_tr_ReadNBytes,
233 dummy_tr_WriteNChars,
234 dummy_tr_EncapsulateNChars,
235 dummy_tr_WriteNBytes,
236 dummy_tr_WriteChar,
237 dummy_tr_WriteString,
238 dummy_tr_EnterSleep,
239 dummy_tr_WakeUp
240 };
241
242 const TR_DRV TR_Csmi =
243 {
244 CU_Init,
245 CU_ReadNChars,
246 CU_ReadNBytes,
247 CU_WriteNChars,
248 CU_EncapsulateNChars,
249 CU_WriteNBytes,
250 CU_WriteChar,
251 CU_WriteString,
252 CU_EnterSleep,
253 CU_WakeUp
254 };
255
256 const FD_DRV FD_Uart =
257 {
258 UAF_Init,
259 UAF_Enable,
260 UAF_SetComPar,
261 UAF_SetBuffer,
262 UAF_SetFlowCtrl,
263 UAF_SetEscape,
264 UAF_InpAvail,
265 UAF_OutpAvail,
266 UAF_EnterSleep,
267 UAF_WakeUp,
268 UAF_ReadData,
269 UAF_WriteData,
270 UAF_StopRec,
271 UAF_StartRec,
272 UAF_GetLineState,
273 UAF_SetLineState,
274 UAF_CheckXEmpty
275 };
276
277 const FD_DRV FD_Csmi =
278 {
279 CF_Init,
280 CF_Enable,
281 CF_SetComPar,
282 CF_SetBuffer,
283 CF_SetFlowCtrl,
284 CF_SetEscape,
285 CF_InpAvail,
286 CF_OutpAvail,
287 dummy_fd_EnterSleep,
288 dummy_fd_WakeUp,
289 CF_ReadData,
290 CF_WriteData,
291 CF_StopRec,
292 CF_StartRec,
293 CF_GetLineState,
294 CF_SetLineState,
295 dummy_fd_CheckXEmpty
296 };
297
298 const FD_DRV FD_Dummy =
299 {
300 dummy_fd_Init,
301 dummy_fd_Enable,
302 dummy_fd_SetComPar,
303 dummy_fd_SetBuffer,
304 dummy_fd_SetFlowCtrl,
305 dummy_fd_SetEscape,
306 dummy_fd_InpAvail,
307 dummy_fd_OutpAvail,
308 dummy_fd_EnterSleep,
309 dummy_fd_WakeUp,
310 dummy_fd_ReadData,
311 dummy_fd_WriteData,
312 dummy_fd_StopRec,
313 dummy_fd_StartRec,
314 dummy_fd_GetLineState,
315 dummy_fd_SetLineState,
316 dummy_fd_CheckXEmpty
317 };
318
319 #define MAX_TRACE_STREAMS 4
320 #define MAX_FD_STREAMS 2
321
322 /*
323 * The board's serial configuration includes :
324 * an array of trace drivers, each with its associated UART identifier
325 * a data driver, also with its UART identifier
326 *
327 */
328 typedef struct
329 {
330 const TR_DRV *trDrv;
331 int trId;
332 }
333 T_TRACE_CONFIG;
334
335 typedef struct
336 {
337 const FD_DRV *fdDrv;
338 int fdId;
339 }
340 T_DATA_CONFIG;
341
342
343 typedef struct
344 {
345 T_TRACE_CONFIG trCfg[MAX_TRACE_STREAMS];
346 T_DATA_CONFIG fdCfg[MAX_FD_STREAMS];
347 }
348 T_SERIAL_CONFIG;
349
350
351
352 /*
353 * All possible serial configurations are described in this table
354 */
355 const T_SERIAL_CONFIG serialConfigs[] =
356 {
357 // serial config 0 : TEST & DEBUG configuration
358 // - Riviera trace (1) on serial port 1 (gsm uart modem)
359 // - fax & data Dummy
360 {
361 {
362 { &TR_Dummy, -1 }, { &TR_Uart, 1 }, { &TR_Dummy, -1 }, { &TR_Dummy, -1 },
363 },
364 {
365 { &FD_Dummy, -1 }, { &FD_Dummy, -1 }
366 },
367 },
368
369 // serial config 1 : TEST & DEBUG configuration
370 // - trace (0) Dummy
371 // - fax & data on serial port 1 (gsm uart modem)
372 {
373 {
374 { &TR_Dummy, -1 }, { &TR_Dummy, -1 }, { &TR_Dummy, -1 }, { &TR_Dummy, -1 },
375 },
376 {
377 { &FD_Uart, 1 }, { &FD_Dummy, -1 }
378 },
379 },
380
381 // serial config 2 : PRODUCTION configuration
382 // - Riviera trace (Dummy for debug)
383 // - fax & data on CSMI port 5 (Fax Data #0)
384 {
385 {
386 { &TR_Dummy, -1 }, { &TR_Dummy, -1 }, { &TR_Dummy, -1 }, { &TR_Dummy, -1 },
387 },
388 {
389 { &FD_Csmi, 0 }, { &FD_Dummy, -1 }
390 },
391 },
392
393 // serial config 3 : PRODUCTION configuration (FaxData with dual port)
394 // - Riviera trace (Dummy for debug)
395 // - fax & data on CSMI port 5 and 6 (Fax Data #0 and #1)
396 {
397 {
398 { &TR_Dummy, -1 }, { &TR_Dummy, -1 }, { &TR_Dummy, -1 }, { &TR_Dummy, -1 },
399 },
400 {
401 { &FD_Csmi, 0 }, { &FD_Csmi, 1 }
402 },
403 },
404
405 // serial config 4 : TEST & DEBUG configuration (for ANITE dial up networking)
406 // - trace (0) dummy
407 // - fax & data on serial port 1 (gsm uart modem)
408 {
409 {
410 { &TR_Dummy, -1 }, { &TR_Dummy, -1 }, { &TR_Dummy, -1 }, { &TR_Dummy, -1 },
411 },
412 {
413 { &FD_Uart, 1 }, { &FD_Dummy, -1 }
414 },
415 },
416
417 // serial config 5 : TEST & DEBUG configuration
418 // - trace (1) dummy
419 // - fax & data on serial port 1 (gsm uart modem)
420 {
421 {
422 { &TR_Dummy, -1 }, { &TR_Dummy, -1 }, { &TR_Dummy, -1 }, { &TR_Dummy, -1 },
423 },
424 {
425 { &FD_Uart, 1 }, { &FD_Dummy, -1 }
426 },
427 },
428
429 // serial config 6 : TEST & DEBUG configuration (CSMI debug)
430 // - Riviera trace (1) on serial port 1 (gsm uart modem)
431 // - fax & data on CSMI
432 {
433 {
434 { &TR_Dummy, -1 }, { &TR_Uart, 1 }, { &TR_Dummy, -1 }, { &TR_Dummy, -1 },
435 },
436 {
437 { &FD_Csmi, 0 }, { &FD_Csmi, 1 }
438 },
439 },
440 // serial config 7 : TEST & DEBUG configuration (stand-alone)
441 // - Riviera trace (1) on csmi trace port
442 // - fax & data on CSMI
443 {
444 {
445 { &TR_Dummy, -1 }, { &TR_Csmi, 0 }, { &TR_Dummy, -1 }, { &TR_Dummy, -1 },
446 },
447 {
448 { &FD_Csmi, 0 }, { &FD_Csmi, 1 }
449 },
450 },
451
452 // serial config 8 : TEST & DEBUG configuration for PGT
453 // - trace (0) on serial port 1 (gsm uart modem)
454 // - fax & data Dummy
455 {
456 {
457 { &TR_Uart, 1 }, { &TR_Dummy, -1 }, { &TR_Dummy, -1 }, { &TR_Dummy, -1 },
458 },
459 {
460 { &FD_Dummy, -1 }, { &FD_Dummy, -1 }
461 },
462 }
463 };
464
465 const T_SERIAL_CONFIG *serialConfigP;
466
467
468 // Physical UART data structures
469 static T_UART int_uart[2];
470 static SYS_UWORD32 uart_spurious_interrupts;
471
472 /*******************************************************************************
473 *
474 * analyze_uart_wake_up_timer_expiration
475 *
476 * Purpose : The wake-up time duration has just expired. If requested, UARTs
477 * can again be set up to enter Deep Sleep.
478 *
479 * Arguments: In : id: parameter not used.
480 * Out: none
481 *
482 * Returns : none
483 *
484 ******************************************************************************/
485
486 void
487 analyze_uart_wake_up_timer_expiration (UNSIGNED id)
488 {
489 /*
490 * Wake-up time duration has expired.
491 * UARTs can again be set up for Deep Sleep.
492 */
493
494 (void) NU_Control_Timer (&uart_wake_up_duration_timer,
495 NU_DISABLE_TIMER);
496
497 uart_waked_up_by_interrupt = 0;
498 }
499
500 /*******************************************************************************
501 *
502 * start_uart_wake_up_timer
503 *
504 * Purpose : Starts the wake-up duration timer once UARTs have been waked-up
505 * by an interrupt.
506 *
507 * Arguments: In : none
508 * Out: none
509 *
510 * Returns : none
511 *
512 ******************************************************************************/
513
514 void
515 start_uart_wake_up_timer (void)
516 {
517 /*
518 * Wake-up duration timer is started.
519 * UARTs can't no more be set up for Deep Sleep until the timer expires.
520 */
521
522 (void) NU_Reset_Timer (&uart_wake_up_duration_timer,
523 &analyze_uart_wake_up_timer_expiration,
524 WAKE_UP_TIME_IN_TDMA,
525 0, /* The timer expires once. */
526 NU_DISABLE_TIMER);
527
528 (void) NU_Control_Timer (&uart_wake_up_duration_timer,
529 NU_ENABLE_TIMER);
530 }
531
532
533
534
535 /*******************************************************************************
536 *
537 * SER_WriteConfig
538 *
539 * Purpose: TBD
540 *
541 * Parameters: In : new_config: TBD
542 * write_to_flash: TBD
543 * Out: none
544 *
545 * Return: 0 (FALSE) : In case of error while trying to write file in FFS
546 * >= 1 (TRUE) : Successful operation.
547 *
548 ******************************************************************************/
549
550 SYS_BOOL SER_WriteConfig (char *new_config, SYS_BOOL write_to_flash)
551 {
552 // Dummy function to make the linker happy. (SER_WriteConfig is called by cst)
553 SYS_BOOL status = 0;
554 return (status);
555 }
556
557 /*******************************************************************************
558 *
559 * SER_ImmediateSwitch
560 *
561 * Purpose: TBD
562 *
563 * Parameters: In : none
564 * Out: none
565 *
566 * Return: 0 (FALSE) : In case of error.
567 * >= 1 (TRUE) : Successful operation.
568 *
569 ******************************************************************************/
570
571 SYS_BOOL SER_ImmediateSwitch (void)
572 {
573 // Dummy function to make the linker happy. (SER_ImmediateSwitch is called by cst)
574 SYS_BOOL status = 0;
575 return (status);
576 }
577
578 /*
579 * SER_InitSerialConfig
580 *
581 *
582 */
583 void
584 SER_InitSerialConfig (int cfg)
585 {
586 int uart_id;
587 SYS_BOOL uart_used;
588
589 /*
590 * Basic UARTs initializations.
591 */
592
593 for (uart_id = 0; uart_id < NUMBER_OF_UART; uart_id++)
594 {
595 int_uart[uart_id].base_address = uart_base_address[uart_id];
596 int_uart[uart_id].device_used = 0;
597 int_uart[uart_id].deep_sleep_set_up = 0;
598 }
599
600 uart_spurious_interrupts = 0;
601 uart_waked_up_by_interrupt = 0;
602
603 // Install the 2 interrupt handlers for each serial config
604 switch (cfg)
605 {
606 case 0:
607 int_uart[0].interrupt_handler = DISABLE_UART_INTERRUPT_HANDLER;
608 int_uart[1].interrupt_handler = UA_InterruptHandler;
609 break;
610
611 case 1:
612 int_uart[0].device_used = 0;
613 int_uart[0].interrupt_handler = DISABLE_UART_INTERRUPT_HANDLER;
614
615 int_uart[1].device_used = 1;
616 int_uart[1].flow_id = 1;
617 int_uart[1].flow_type = FAX_DATA_FLOW;
618 int_uart[1].interrupt_handler = UAF_InterruptHandler;
619 break;
620
621 case 2:
622 int_uart[0].interrupt_handler = DISABLE_UART_INTERRUPT_HANDLER;
623 int_uart[1].interrupt_handler = DISABLE_UART_INTERRUPT_HANDLER;
624 break;
625
626 case 3:
627 int_uart[0].interrupt_handler = DISABLE_UART_INTERRUPT_HANDLER;
628 int_uart[1].interrupt_handler = DISABLE_UART_INTERRUPT_HANDLER;
629 break;
630
631 case 4:
632 int_uart[0].interrupt_handler = DISABLE_UART_INTERRUPT_HANDLER;
633 int_uart[1].interrupt_handler = UAF_InterruptHandler;
634 break;
635
636 case 5:
637 int_uart[0].interrupt_handler = DISABLE_UART_INTERRUPT_HANDLER;
638 int_uart[1].interrupt_handler = UAF_InterruptHandler;
639 break;
640
641 case 6:
642 int_uart[0].device_used = 0;
643 int_uart[0].interrupt_handler = DISABLE_UART_INTERRUPT_HANDLER;
644
645 int_uart[1].device_used = 1;
646 int_uart[1].flow_id = 1;
647 int_uart[1].flow_type = TRACE_FLOW;
648 int_uart[1].interrupt_handler = UA_InterruptHandler;
649 break;
650
651 case 7:
652 int_uart[0].interrupt_handler = DISABLE_UART_INTERRUPT_HANDLER;
653 int_uart[1].interrupt_handler = DISABLE_UART_INTERRUPT_HANDLER;
654 break;
655
656 case 8:
657 int_uart[0].interrupt_handler = DISABLE_UART_INTERRUPT_HANDLER;
658 int_uart[1].interrupt_handler = UA_InterruptHandler;
659 break;
660
661 default :
662 cfg=0;
663 int_uart[0].interrupt_handler = DISABLE_UART_INTERRUPT_HANDLER;
664 int_uart[1].interrupt_handler = UA_InterruptHandler;
665 break;
666 }
667
668 serialConfigP = &serialConfigs[cfg];
669
670 /*
671 * Checks if both UARTs are used.
672 * If not, performs minimum initialization including Sleep Mode.
673 */
674
675 uart_used = 0;
676 for (uart_id = 0; uart_id < NUMBER_OF_UART; uart_id++) {
677
678 if (!(int_uart[uart_id].device_used))
679 initialize_uart_sleep (uart_id);
680
681 else /* if (int_uart[uart_id].device_used) */
682 uart_used = 1; /* At least one UART is used */
683 }
684
685 /*
686 * If at least one uart is used, create a timer to control the wake-up
687 * time duration.
688 */
689
690 if (uart_used)
691 (void) NU_Create_Timer (
692 &uart_wake_up_duration_timer,
693 "Wake Up",
694 &analyze_uart_wake_up_timer_expiration,
695 0, /* Parameter supplied to the routine: not used. */
696 WAKE_UP_TIME_IN_TDMA,
697 0, /* The timer expires once. */
698 NU_DISABLE_TIMER);
699
700 }
701
702
703 void SER_tr_Init (int id,
704 int baudrate,
705 void (callback_function (void)))
706 {
707 const TR_DRV *trDrv;
708 int trId;
709
710 trDrv = serialConfigP->trCfg[id].trDrv;
711 trId = serialConfigP->trCfg[id].trId;
712
713 (trDrv->tr_Init)(trId, baudrate, callback_function);
714 }
715
716 unsigned long SER_tr_ReadNChars (int id,
717 char *buffer,
718 unsigned long chars_to_read)
719 {
720 const TR_DRV *trDrv;
721 int trId;
722
723 trDrv = serialConfigP->trCfg[id].trDrv;
724 trId = serialConfigP->trCfg[id].trId;
725
726 return ((trDrv->tr_ReadNChars)(trId, buffer, chars_to_read));
727 }
728
729 unsigned long SER_tr_ReadNBytes (int id,
730 char *buffer,
731 unsigned long chars_to_read,
732 unsigned char *eof_detected)
733 {
734 const TR_DRV *trDrv;
735 int trId;
736
737 trDrv = serialConfigP->trCfg[id].trDrv;
738 trId = serialConfigP->trCfg[id].trId;
739
740 return ((trDrv->tr_ReadNBytes) (trId, buffer, chars_to_read, eof_detected));
741 }
742
743 unsigned long SER_tr_WriteNChars (int id,
744 char *buffer,
745 unsigned long chars_to_write)
746 {
747 const TR_DRV *trDrv;
748 int trId;
749
750 trDrv = serialConfigP->trCfg[id].trDrv;
751 trId = serialConfigP->trCfg[id].trId;
752
753 return ((trDrv->tr_WriteNChars)(trId, buffer, chars_to_write));
754 }
755
756 unsigned long SER_tr_EncapsulateNChars (int id,
757 char *buffer,
758 unsigned long chars_to_write)
759 {
760 const TR_DRV *trDrv;
761 int trId;
762
763 trDrv = serialConfigP->trCfg[id].trDrv;
764 trId = serialConfigP->trCfg[id].trId;
765
766 return ((trDrv->tr_EncapsulateNChars) (trId, buffer, chars_to_write));
767 }
768
769 unsigned long SER_tr_WriteNBytes (int id,
770 unsigned char *buffer,
771 unsigned long chars_to_write)
772 {
773 const TR_DRV *trDrv;
774 int trId;
775
776 trDrv = serialConfigP->trCfg[id].trDrv;
777 trId = serialConfigP->trCfg[id].trId;
778
779 return ((trDrv->tr_WriteNBytes) (trId, buffer, chars_to_write));
780 }
781
782 void SER_tr_WriteChar (int id, char character)
783 {
784 const TR_DRV *trDrv;
785 int trId;
786
787 trDrv = serialConfigP->trCfg[id].trDrv;
788 trId = serialConfigP->trCfg[id].trId;
789
790 (trDrv->tr_WriteChar)(trId, character);
791 }
792
793 void SER_tr_WriteString (int id, char *buffer)
794 {
795 const TR_DRV *trDrv;
796 int trId;
797
798 trDrv = serialConfigP->trCfg[id].trDrv;
799 trId = serialConfigP->trCfg[id].trId;
800
801 (trDrv->tr_WriteString)(trId, buffer);
802 }
803
804 unsigned char SER_tr_EnterSleep (int id)
805 {
806 const TR_DRV *trDrv;
807 int trId;
808
809 trDrv = serialConfigP->trCfg[id].trDrv;
810 trId = serialConfigP->trCfg[id].trId;
811
812 return ((trDrv->tr_EnterSleep) (trId));
813 }
814
815 void SER_tr_WakeUp (int id)
816 {
817 const TR_DRV *trDrv;
818 int trId;
819
820 trDrv = serialConfigP->trCfg[id].trDrv;
821 trId = serialConfigP->trCfg[id].trId;
822
823 (trDrv->tr_WakeUp) (trId);
824 }
825
826 /*
827 * SER_fd_xx : Fax/data functions
828 *
829 */
830 T_FDRET SER_fd_Init(void)
831 {
832 return UF_Init (0);
833 }
834
835
836 T_FDRET
837 SER_fd_Enable (unsigned char enable)
838 {
839 return UF_Enable (0, enable);
840 }
841
842 T_FDRET
843 SER_fd_SetComPar (T_baudrate baudrate,
844 T_bitsPerCharacter bpc,
845 T_stopBits sb,
846 T_parity parity)
847 {
848 return UF_SetComPar (0, baudrate, bpc, sb, parity);
849 }
850
851 T_FDRET
852 SER_fd_SetBuffer (unsigned short bufSize, unsigned short rxThreshold, unsigned short txThreshold)
853 {
854 return UF_SetBuffer (0, bufSize, rxThreshold, txThreshold);
855 }
856
857 T_FDRET
858 SER_fd_SetFlowCtrl (T_flowCtrlMode fcMode, unsigned char XON, unsigned char XOFF)
859 {
860 return UF_SetFlowCtrl (0, fcMode, XON, XOFF);
861 }
862
863 T_FDRET
864 SER_fd_SetEscape (char escChar, unsigned short guardPeriod)
865 {
866 return UF_SetEscape (0, escChar, guardPeriod);
867 }
868
869 T_FDRET
870 SER_fd_InpAvail (void)
871 {
872 return UF_InpAvail (0);
873 }
874
875 T_FDRET
876 SER_fd_OutpAvail (void)
877 {
878 return UF_OutpAvail (0);
879 }
880
881 T_FDRET
882 SER_fd_EnterSleep (void)
883 {
884 return UF_EnterSleep (0);
885 }
886
887 T_FDRET
888 SER_fd_WakeUp (void)
889 {
890 UF_WakeUp (0);
891 }
892
893 T_FDRET
894 SER_fd_ReadData (T_suspendMode suspend,
895 void (readOutFunc (unsigned char cldFromIrq,
896 T_reInstMode *reInstall,
897 unsigned char nsource,
898 unsigned char *source[],
899 unsigned short size[],
900 unsigned long state)))
901 {
902 return UF_ReadData (0, suspend, readOutFunc);
903 }
904
905 T_FDRET
906 SER_fd_WriteData (T_suspendMode suspend,
907 void (writeInFunc (unsigned char cldFromIrq,
908 T_reInstMode *reInstall,
909 unsigned char ndest,
910 unsigned char *dest[],
911 unsigned short size[])))
912 {
913 return UF_WriteData (0, suspend, writeInFunc);
914 }
915
916 T_FDRET
917 SER_fd_StopRec (void)
918 {
919 return UF_StopRec(0);
920 }
921
922 T_FDRET
923 SER_fd_StartRec (void)
924 {
925 return UF_StartRec(0);
926 }
927
928 T_FDRET
929 SER_fd_GetLineState (unsigned long *state)
930 {
931 return UF_GetLineState(0, state);
932 }
933
934 T_FDRET
935 SER_fd_SetLineState (unsigned long state, unsigned long mask)
936 {
937 return UF_SetLineState(0, state, mask);
938 }
939
940 T_FDRET
941 SER_fd_CheckXEmpty (void)
942 {
943 return UF_CheckXEmpty(0);
944 }
945
946 /*
947 *
948 * SER_int_uart_handlerx
949 *
950 * Internal UART interrupt handler.
951 *
952 * Perseus has 2 internal UARTs, each with its own interrupt vector
953 *
954 */
955
956 void
957 SER_uart_irda_handler (void)
958 {
959 SYS_UWORD8 interrupt_status;
960 T_UART *uart;
961 int uart_id;
962
963 uart_id = 0;
964 uart = &(int_uart[0]);
965
966 // clear UART interrupt
967 interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED;
968
969 // call interrupt handler if necessary
970 if(uart->interrupt_handler != DISABLE_UART_INTERRUPT_HANDLER)
971 (*(uart->interrupt_handler)) (uart_id, interrupt_status);
972
973 }
974
975 void
976 SER_uart_modem_handler (void)
977 {
978 SYS_UWORD8 interrupt_status;
979 T_UART *uart;
980 SYS_BOOL it_wakeup_identified;
981 int uart_id;
982
983 uart_id = 1;
984 it_wakeup_identified = 0;
985 uart = &(int_uart[1]);
986
987
988 /*
989 * Check first for a wake-up interrupt.
990 */
991 interrupt_status = READ_UART_REGISTER (uart, SSR);
992
993 if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */
994
995 it_wakeup_identified = 1;
996 uart_waked_up_by_interrupt = 1;
997 DISABLE_WAKE_UP_INTERRUPT (uart);
998 }
999
1000 /*
1001 * If no wake-up interrupt has been detected, check UART for other
1002 * interrupt causes.
1003 */
1004
1005 if (!it_wakeup_identified) {
1006
1007 // clear UART interrupt
1008 interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED;
1009
1010 if (!(interrupt_status & IT_NOT_PENDING))
1011 (*(uart->interrupt_handler)) (uart_id, interrupt_status);
1012 else
1013 uart_modem_spurious_interrupts++;
1014 }
1015
1016 }
1017
1018
1019 T_FDRET UF_Init (int uartNo)
1020 {
1021 const FD_DRV *fdDrv;
1022 int fdId;
1023
1024 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1025 fdId = serialConfigP->fdCfg[uartNo].fdId;
1026
1027 return ((fdDrv->fd_Init)(fdId));
1028 }
1029
1030
1031 T_FDRET UF_Enable (int uartNo, SYS_BOOL enable)
1032 {
1033 const FD_DRV *fdDrv;
1034 int fdId;
1035
1036 fdId = serialConfigP->fdCfg[uartNo].fdId;
1037 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1038
1039 return((fdDrv->fd_Enable)(fdId, enable));
1040 }
1041
1042 short
1043 UF_SetComPar (int uartNo,
1044 T_baudrate baudrate,
1045 T_bitsPerCharacter bpc,
1046 T_stopBits sb,
1047 T_parity parity)
1048 {
1049 const FD_DRV *fdDrv;
1050 int fdId;
1051
1052 fdId = serialConfigP->fdCfg[uartNo].fdId;
1053 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1054
1055 return((fdDrv->fd_SetComPar)(fdId, baudrate, bpc, sb, parity));
1056 }
1057
1058 short
1059 UF_SetBuffer (int uartNo,
1060 unsigned short bufSize,
1061 unsigned short rxThreshold,
1062 unsigned short txThreshold)
1063 {
1064 const FD_DRV *fdDrv;
1065 int fdId;
1066
1067 fdId = serialConfigP->fdCfg[uartNo].fdId;
1068 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1069
1070 return((fdDrv->fd_SetBuffer)(fdId, bufSize, rxThreshold, txThreshold));
1071 }
1072
1073 short
1074 UF_SetFlowCtrl (int uartNo,
1075 T_flowCtrlMode fcMode,
1076 unsigned char XON,
1077 unsigned char XOFF)
1078 {
1079 const FD_DRV *fdDrv;
1080 int fdId;
1081
1082 fdId = serialConfigP->fdCfg[uartNo].fdId;
1083 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1084
1085 return((fdDrv->fd_SetFlowCtrl)(fdId, fcMode, XON, XOFF));
1086 }
1087
1088 short
1089 UF_SetEscape (int uartNo, char escChar, unsigned short guardPeriod)
1090 {
1091 const FD_DRV *fdDrv;
1092 int fdId;
1093
1094 fdId = serialConfigP->fdCfg[uartNo].fdId;
1095 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1096
1097 return ((fdDrv->fd_SetEscape) (fdId, escChar, guardPeriod));
1098 }
1099
1100 T_FDRET UF_InpAvail (int uartNo)
1101 {
1102 const FD_DRV *fdDrv;
1103 int fdId;
1104
1105 fdId = serialConfigP->fdCfg[uartNo].fdId;
1106 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1107
1108 return ((fdDrv->fd_InpAvail) (fdId));
1109 }
1110
1111 T_FDRET UF_OutpAvail (int uartNo)
1112 {
1113 const FD_DRV *fdDrv;
1114 int fdId;
1115
1116 fdId = serialConfigP->fdCfg[uartNo].fdId;
1117 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1118
1119 return ((fdDrv->fd_OutpAvail) (fdId));
1120 }
1121
1122 short UF_EnterSleep (int uartNo)
1123 {
1124 const FD_DRV *fdDrv;
1125 int fdId;
1126
1127 fdId = serialConfigP->fdCfg[uartNo].fdId;
1128 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1129
1130 return ((fdDrv->fd_EnterSleep) (fdId));
1131 }
1132
1133 short UF_WakeUp (int uartNo)
1134 {
1135 const FD_DRV *fdDrv;
1136 int fdId;
1137
1138 fdId = serialConfigP->fdCfg[uartNo].fdId;
1139 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1140
1141 return ((fdDrv->fd_WakeUp) (fdId));
1142 }
1143
1144 short
1145 UF_ReadData (int uartNo,
1146 T_suspendMode suspend,
1147 void (readOutFunc (unsigned char cldFromIrq,
1148 T_reInstMode *reInstall,
1149 unsigned char nsource,
1150 unsigned char *source[],
1151 unsigned short size[],
1152 unsigned long state)))
1153 {
1154 const FD_DRV *fdDrv;
1155 int fdId;
1156
1157 fdId = serialConfigP->fdCfg[uartNo].fdId;
1158 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1159
1160 return ((fdDrv->fd_ReadData) (fdId, suspend, readOutFunc));
1161 }
1162
1163 short
1164 UF_WriteData (int uartNo,
1165 T_suspendMode suspend,
1166 void (writeInFunc (unsigned char cldFromIrq,
1167 T_reInstMode *reInstall,
1168 unsigned char ndest,
1169 unsigned char *dest[],
1170 unsigned short size[])))
1171 {
1172 const FD_DRV *fdDrv;
1173 int fdId;
1174
1175 fdId = serialConfigP->fdCfg[uartNo].fdId;
1176 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1177
1178 return ((fdDrv->fd_WriteData) (fdId, suspend, writeInFunc));
1179 }
1180
1181 short
1182 UF_StopRec (int uartNo)
1183 {
1184 const FD_DRV *fdDrv;
1185 int fdId;
1186
1187 fdId = serialConfigP->fdCfg[uartNo].fdId;
1188 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1189
1190 return ((fdDrv->fd_StopRec) (fdId));
1191 }
1192
1193 short
1194 UF_StartRec (int uartNo)
1195 {
1196 const FD_DRV *fdDrv;
1197 int fdId;
1198
1199 fdId = serialConfigP->fdCfg[uartNo].fdId;
1200 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1201
1202 return ((fdDrv->fd_StartRec) (fdId));
1203 }
1204
1205 short
1206 UF_GetLineState (int uartNo, unsigned long *state)
1207 {
1208 const FD_DRV *fdDrv;
1209 int fdId;
1210
1211 fdId = serialConfigP->fdCfg[uartNo].fdId;
1212 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1213
1214 return ((fdDrv->fd_GetLineState) (fdId, state));
1215 }
1216
1217 short
1218 UF_SetLineState (int uartNo, unsigned long state, unsigned long mask)
1219 {
1220 const FD_DRV *fdDrv;
1221 int fdId;
1222
1223 fdId = serialConfigP->fdCfg[uartNo].fdId;
1224 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1225
1226 return ((fdDrv->fd_SetLineState) (fdId, state, mask));
1227 }
1228
1229 short
1230 UF_CheckXEmpty (int uartNo)
1231 {
1232 const FD_DRV *fdDrv;
1233 int fdId;
1234
1235 fdId = serialConfigP->fdCfg[uartNo].fdId;
1236 fdDrv = serialConfigP->fdCfg[uartNo].fdDrv;
1237
1238 return ((fdDrv->fd_CheckXEmpty) (fdId));
1239 }
1240
1241
1242 /*******************************************************************************
1243 *
1244 * dummy_tr_Init
1245 *
1246 * Purpose: No action.
1247 *
1248 * Parameters: See SER_tr_Init.
1249 *
1250 * Return: none
1251 *
1252 ******************************************************************************/
1253
1254 static void
1255 dummy_tr_Init (int device, int baudrate, void (callback_function (void)))
1256 {
1257 /*
1258 * No action.
1259 */
1260 }
1261
1262 /*******************************************************************************
1263 *
1264 * dummy_tr_ReadNChars
1265 *
1266 * Purpose: No action.
1267 *
1268 * Parameters: See SER_tr_ReadNChars.
1269 *
1270 * Return: 0
1271 *
1272 ******************************************************************************/
1273
1274 static unsigned long
1275 dummy_tr_ReadNChars (int device, char *buffer, unsigned long chars_to_read)
1276 {
1277 return (0);
1278 }
1279
1280 /*******************************************************************************
1281 *
1282 * dummy_tr_ReadNBytes
1283 *
1284 * Purpose: No action.
1285 *
1286 * Parameters: See SER_tr_ReadNBytes.
1287 *
1288 * Return: 0
1289 *
1290 ******************************************************************************/
1291
1292 static unsigned long
1293 dummy_tr_ReadNBytes (T_tr_UartId device,
1294 char *buffer,
1295 unsigned long chars_to_read,
1296 unsigned char *eof_detected)
1297 {
1298 return (0);
1299 }
1300
1301 /*******************************************************************************
1302 *
1303 * dummy_tr_WriteNChars
1304 *
1305 * Purpose: No action.
1306 *
1307 * Parameters: See SER_tr_WriteNChars.
1308 *
1309 * Return: The number of character to write.
1310 *
1311 ******************************************************************************/
1312
1313 static unsigned long
1314 dummy_tr_WriteNChars (int device, char *buffer, unsigned long chars_to_write)
1315 {
1316 return (chars_to_write);
1317 }
1318
1319 /*******************************************************************************
1320 *
1321 * dummy_tr_EncapsulateNChars
1322 *
1323 * Purpose: No action.
1324 *
1325 * Parameters: See SER_tr_EncapsulateNChars.
1326 *
1327 * Return: The number of character to write.
1328 *
1329 ******************************************************************************/
1330
1331 static unsigned long
1332 dummy_tr_EncapsulateNChars (T_tr_UartId device,
1333 char *buffer,
1334 unsigned long chars_to_write)
1335 {
1336 return (chars_to_write);
1337 }
1338
1339 /*******************************************************************************
1340 *
1341 * dummy_tr_WriteNBytes
1342 *
1343 * Purpose: No action.
1344 *
1345 * Parameters: See SER_tr_WriteNBytes.
1346 *
1347 * Return: The number of byte to write.
1348 *
1349 ******************************************************************************/
1350
1351 static unsigned long
1352 dummy_tr_WriteNBytes (T_tr_UartId device,
1353 unsigned char *buffer,
1354 unsigned long chars_to_write)
1355 {
1356 return (chars_to_write);
1357 }
1358
1359 /*******************************************************************************
1360 *
1361 * dummy_tr_WriteChar
1362 *
1363 * Purpose: No action.
1364 *
1365 * Parameters: See SER_tr_WriteChar.
1366 *
1367 * Return: none
1368 *
1369 ******************************************************************************/
1370
1371 static void
1372 dummy_tr_WriteChar (int device, char character)
1373 {
1374 /*
1375 * No action.
1376 */
1377 }
1378
1379 /*******************************************************************************
1380 *
1381 * dummy_tr_WriteString
1382 *
1383 * Purpose: No action.
1384 *
1385 * Parameters: See SER_tr_WriteString.
1386 *
1387 * Return: none
1388 *
1389 ******************************************************************************/
1390
1391 static void
1392 dummy_tr_WriteString (int device, char *buffer)
1393 {
1394 /*
1395 * No action.
1396 */
1397 }
1398
1399 /*******************************************************************************
1400 *
1401 * dummy_tr_EnterSleep
1402 *
1403 * Purpose: No action.
1404 *
1405 * Parameters: See SER_tr_EnterSleep.
1406 *
1407 * Return: 1
1408 *
1409 ******************************************************************************/
1410
1411 static unsigned char
1412 dummy_tr_EnterSleep (T_tr_UartId device)
1413 {
1414 return (1);
1415 }
1416
1417 /*******************************************************************************
1418 *
1419 * dummy_tr_WakeUp
1420 *
1421 * Purpose: No action.
1422 *
1423 * Parameters: See SER_tr_WakeUp.
1424 *
1425 * Return: none
1426 *
1427 ******************************************************************************/
1428
1429 static void
1430 dummy_tr_WakeUp (T_tr_UartId device)
1431 {
1432 /*
1433 * No action.
1434 */
1435 }
1436
1437 /*******************************************************************************
1438 *
1439 * dummy_fd_Init
1440 *
1441 * Purpose: Sets the size of the circular buffer to the maximum value and the
1442 * state of the driver to 'disabled'.
1443 *
1444 * Parameters: See SER_fd_Init.
1445 *
1446 * Return: FD_OK: Successful operation.
1447 *
1448 ******************************************************************************/
1449
1450 static T_FDRET
1451 dummy_fd_Init (T_fd_UartId uartNo)
1452 {
1453 fd_bufSize = FD_MAX_BUFFER_SIZE;
1454 fd_driver_enabled = 0;
1455
1456 return (FD_OK);
1457 }
1458
1459 /*******************************************************************************
1460 *
1461 * dummy_fd_Enable
1462 *
1463 * Purpose: Stores the state of the driver.
1464 *
1465 * Parameters: See SER_fd_Enable.
1466 *
1467 * Return: FD_OK: Successful operation.
1468 *
1469 ******************************************************************************/
1470
1471 static T_FDRET
1472 dummy_fd_Enable (T_fd_UartId uartNo, unsigned char enable)
1473 {
1474 fd_driver_enabled = enable;
1475
1476 return (FD_OK);
1477 }
1478
1479 /*******************************************************************************
1480 *
1481 * dummy_fd_SetComPar
1482 *
1483 * Purpose: No action.
1484 *
1485 * Parameters: See SER_fd_SetComPar.
1486 *
1487 * Return: FD_OK: Successful operation.
1488 *
1489 ******************************************************************************/
1490
1491 static T_FDRET
1492 dummy_fd_SetComPar (T_fd_UartId uartNo,
1493 T_baudrate baudrate,
1494 T_bitsPerCharacter bpc,
1495 T_stopBits sb,
1496 T_parity parity)
1497 {
1498 return (FD_OK);
1499 }
1500
1501 /*******************************************************************************
1502 *
1503 * dummy_fd_SetBuffer
1504 *
1505 * Purpose: Stores the size of the circular buffer.
1506 *
1507 * Parameters: See SER_fd_SetBuffer.
1508 *
1509 * Return: FD_OK: Successful operation.
1510 *
1511 ******************************************************************************/
1512
1513 static T_FDRET
1514 dummy_fd_SetBuffer (T_fd_UartId uartNo, unsigned short bufSize, unsigned short rxThreshold, unsigned short txThreshold)
1515 {
1516 fd_bufSize = bufSize;
1517
1518 return (FD_OK);
1519 }
1520
1521 /*******************************************************************************
1522 *
1523 * dummy_fd_SetFlowCtrl
1524 *
1525 * Purpose: No action.
1526 *
1527 * Parameters: See SER_fd_SetFlowCtrl.
1528 *
1529 * Return: FD_OK: Successful operation.
1530 *
1531 ******************************************************************************/
1532
1533 static T_FDRET
1534 dummy_fd_SetFlowCtrl (T_fd_UartId uartNo, T_flowCtrlMode fcMode, unsigned char XON, unsigned char XOFF)
1535 {
1536 return (FD_OK);
1537 }
1538
1539 /*******************************************************************************
1540 *
1541 * dummy_fd_SetEscape
1542 *
1543 * Purpose: No action.
1544 *
1545 * Parameters: See SER_fd_SetEscape.
1546 *
1547 * Return: FD_OK: Successful operation.
1548 *
1549 ******************************************************************************/
1550
1551 static T_FDRET
1552 dummy_fd_SetEscape (T_fd_UartId uartNo, unsigned char escChar, unsigned short guardPeriod)
1553 {
1554 return (FD_OK);
1555 }
1556
1557 /*******************************************************************************
1558 *
1559 * dummy_fd_InpAvail
1560 *
1561 * Purpose: No action.
1562 *
1563 * Parameters: See SER_fd_InpAvail.
1564 *
1565 * Return: The size of the circular buffer.
1566 *
1567 ******************************************************************************/
1568
1569 static T_FDRET
1570 dummy_fd_InpAvail (T_fd_UartId uartNo)
1571 {
1572 return (fd_bufSize);
1573 }
1574
1575 /*******************************************************************************
1576 *
1577 * dummy_fd_OutpAvail
1578 *
1579 * Purpose: No action.
1580 *
1581 * Parameters: See SER_fd_OutpAvail.
1582 *
1583 * Return: The size of the circular buffer.
1584 *
1585 ******************************************************************************/
1586
1587 static T_FDRET
1588 dummy_fd_OutpAvail (T_fd_UartId uartNo)
1589 {
1590 return (fd_bufSize);
1591 }
1592
1593 /*******************************************************************************
1594 *
1595 * dummy_fd_EnterSleep
1596 *
1597 * Purpose: No action.
1598 *
1599 * Parameters: See SER_tr_EnterSleep.
1600 *
1601 * Return: 1
1602 *
1603 ******************************************************************************/
1604
1605 static T_FDRET
1606 dummy_fd_EnterSleep (T_fd_UartId uartNo)
1607 {
1608 return (1);
1609 }
1610
1611 /*******************************************************************************
1612 *
1613 * dummy_fd_WakeUp
1614 *
1615 * Purpose: No action.
1616 *
1617 * Parameters: See SER_tr_WakeUp.
1618 *
1619 * Return: FD_OK: Successful operation.
1620 *
1621 ******************************************************************************/
1622
1623 static T_FDRET
1624 dummy_fd_WakeUp (T_fd_UartId uartNo)
1625 {
1626 return (FD_OK);
1627 }
1628
1629 /*******************************************************************************
1630 *
1631 * dummy_fd_ReadData
1632 *
1633 * Purpose: No action.
1634 *
1635 * Parameters: See SER_fd_ReadData.
1636 *
1637 * Return: 0 if the suspend parameter is set to 'sm_noSuspend'.
1638 * FD_SUSPENDED if the suspend parameter is set to 'sm_suspend'.
1639 *
1640 ******************************************************************************/
1641
1642 static T_FDRET
1643 dummy_fd_ReadData (T_fd_UartId uartNo,
1644 T_suspendMode suspend,
1645 void (readOutFunc (unsigned char cldFromIrq,
1646 T_reInstMode *reInstall,
1647 unsigned char nsource,
1648 unsigned char *source[],
1649 unsigned short size[],
1650 unsigned long state)))
1651 {
1652 T_FDRET result;
1653
1654 if (suspend == sm_noSuspend)
1655 result = 0;
1656 else
1657 result = FD_SUSPENDED;
1658
1659 return (result);
1660 }
1661
1662 /*******************************************************************************
1663 *
1664 * dummy_fd_WriteData
1665 *
1666 * Purpose: The user's function is called with:
1667 * - cldFromIrq = 0
1668 * - ndest = 1
1669 * - dest[0] is a unsigned char pointer on the beginning address of a local
1670 * buffer
1671 * - size[0] is set to fd_bufSize.
1672 *
1673 * Parameters: See SER_fd_WriteData.
1674 *
1675 * Return: The number of bytes written in the local buffer.
1676 *
1677 ******************************************************************************/
1678
1679 static T_FDRET
1680 dummy_fd_WriteData (T_fd_UartId uartNo,
1681 T_suspendMode suspend,
1682 void (writeInFunc (unsigned char cldFromIrq,
1683 T_reInstMode *reInstall,
1684 unsigned char ndest,
1685 unsigned char *dest[],
1686 unsigned short size[])))
1687 {
1688 T_reInstMode dummyInstall;
1689 unsigned char *destination[2];
1690 unsigned short buffer_size[2];
1691
1692 destination[0] = &(fd_buffer[0]);
1693 buffer_size[0] = fd_bufSize;
1694
1695 (*writeInFunc) (0, &dummyInstall, 1, &(destination[0]), &(buffer_size[0]));
1696
1697 return ((T_FDRET) (fd_bufSize - buffer_size[0]));
1698 }
1699
1700 /*******************************************************************************
1701 *
1702 * dummy_fd_StopRec
1703 *
1704 * Purpose: No action.
1705 *
1706 * Parameters: See SER_fd_StopRec.
1707 *
1708 * Return: FD_OK: Successful operation.
1709 *
1710 ******************************************************************************/
1711
1712 static T_FDRET
1713 dummy_fd_StopRec (T_fd_UartId uartNo)
1714 {
1715 return (FD_OK);
1716 }
1717
1718 /*******************************************************************************
1719 *
1720 * dummy_fd_StartRec
1721 *
1722 * Purpose: No action.
1723 *
1724 * Parameters: See SER_fd_StartRec.
1725 *
1726 * Return: FD_OK: Successful operation.
1727 *
1728 ******************************************************************************/
1729
1730 static T_FDRET
1731 dummy_fd_StartRec (T_fd_UartId uartNo)
1732 {
1733 return (FD_OK);
1734 }
1735
1736 /*******************************************************************************
1737 *
1738 * dummy_fd_GetLineState
1739 *
1740 * Purpose: Sets the RXBLEV field to the bufSize value.
1741 *
1742 * Parameters: See SER_fd_GetLineState.
1743 *
1744 * Return: FD_OK: Successful operation.
1745 *
1746 ******************************************************************************/
1747
1748 static T_FDRET
1749 dummy_fd_GetLineState (T_fd_UartId uartNo, unsigned long *state)
1750 {
1751 *state = fd_bufSize << RXBLEV;
1752
1753 return (FD_OK);
1754 }
1755
1756 /*******************************************************************************
1757 *
1758 * dummy_fd_SetLineState
1759 *
1760 * Purpose: No action.
1761 *
1762 * Parameters: See SER_fd_SetLineState.
1763 *
1764 * Return: FD_OK: Successful operation.
1765 *
1766 ******************************************************************************/
1767
1768 static T_FDRET
1769 dummy_fd_SetLineState (T_fd_UartId uartNo, unsigned long state, unsigned long mask)
1770 {
1771 return (FD_OK);
1772 }
1773
1774 /*******************************************************************************
1775 *
1776 * dummy_fd_CheckXEmpty
1777 *
1778 * Purpose: No action.
1779 *
1780 * Parameters: See SER_fd_CheckXEmpty.
1781 *
1782 * Return: FD_OK: Successful operation.
1783 *
1784 ******************************************************************************/
1785
1786 static T_FDRET
1787 dummy_fd_CheckXEmpty (T_fd_UartId uartNo)
1788 {
1789 return (FD_OK);
1790 }
1791
1792 /*******************************************************************************
1793 *
1794 * SER_UartSleepStatus
1795 *
1796 * Purpose: This function checks if both UARTs are ready to enter Deep Sleep.
1797 *
1798 * Parameters: In : none
1799 * Out: none
1800 *
1801 * Return: 0 : Deep Sleep is not possible.
1802 * >= 1 : Deep Sleep is possible.
1803 *
1804 ******************************************************************************/
1805
1806 unsigned char
1807 SER_UartSleepStatus (void)
1808 {
1809 T_UART *uart;
1810 int uart_id;
1811 SYS_BOOL status;
1812
1813 /*
1814 * Check first if wake-up time duration is active.
1815 * A return is used to simplify the code.
1816 */
1817
1818 /* Wake-up duration timer has not yet expired. */
1819
1820 if (uart_waked_up_by_interrupt) return (0);
1821
1822 /*
1823 * Check if both UARTs are ready to enter Deep Sleep.
1824 */
1825
1826 status = 1;
1827 uart_id = 0;
1828 while ((uart_id < NUMBER_OF_UART) &&
1829 (status)) {
1830
1831 uart = &(int_uart[uart_id]);
1832
1833 /*
1834 * Check if the specified UART is actually used.
1835 */
1836
1837 if (uart->device_used) {
1838
1839 /*
1840 * Check if the specified UART is used by a Trace or
1841 * by a Fax & Data flow.
1842 */
1843 if (uart->flow_type == TRACE_FLOW)
1844 status = SER_tr_EnterSleep (uart->flow_id);
1845
1846 else
1847 if (uart->flow_type == FAX_DATA_FLOW)
1848 status = (SYS_BOOL) SER_fd_EnterSleep ();
1849 else
1850 status = 0;
1851
1852 if (status) {
1853
1854 /*
1855 * The specified UART is now set up for Deep Sleep.
1856 */
1857
1858 uart->deep_sleep_set_up = 1;
1859
1860 }
1861 }
1862
1863 uart_id++;
1864 }
1865
1866 /*
1867 * Check if Deep Sleep is finally possible.
1868 * If not revert eventual Deep Sleep settings.
1869 */
1870 if (!status) {
1871
1872 for (uart_id = 0; uart_id < NUMBER_OF_UART; uart_id++) {
1873
1874 uart = &(int_uart[uart_id]);
1875
1876 /*
1877 * If the specified used UART has already been set up for
1878 * Deep Sleep, revert these settings.
1879 */
1880
1881 if ((uart->device_used) &&
1882 (uart->deep_sleep_set_up)) {
1883
1884 /*
1885 * Check if the specified UART is used by a Trace or
1886 * by a Fax & Data flow.
1887 */
1888
1889 if (uart->flow_type == TRACE_FLOW)
1890 SER_tr_WakeUp (uart->flow_id);
1891
1892 else /* if (uart->flow_type == FAX_DATA_FLOW) */
1893 SER_fd_WakeUp ();
1894
1895 uart->deep_sleep_set_up = 0;
1896
1897 }
1898 }
1899 }
1900
1901 return (status);
1902 }
1903
1904
1905 /*******************************************************************************
1906 *
1907 * SER_WakeUpUarts
1908 *
1909 * Purpose: This function wakes up used UARTs after Deep Sleep.
1910 *
1911 * Parameters: In : none
1912 * Out: none
1913 *
1914 * Return: none
1915 *
1916 ******************************************************************************/
1917
1918 void
1919 SER_WakeUpUarts (void)
1920 {
1921 T_UART *uart;
1922 int uart_id;
1923
1924 if (uart_waked_up_by_interrupt)
1925 start_uart_wake_up_timer ();
1926
1927 for (uart_id = 0; uart_id < NUMBER_OF_UART; uart_id++) {
1928
1929 uart = &(int_uart[uart_id]);
1930
1931 /*
1932 * Check if the specified UART is actually used, and has not yet
1933 * been waked up.
1934 */
1935
1936 if ((uart->device_used) &&
1937 (uart->deep_sleep_set_up)) {
1938
1939 /*
1940 * Check if the specified UART is used by a Trace or
1941 * by a Fax & Data flow.
1942 * Bluetooth HCI can not yet handled Deep Sleep Mode.
1943 */
1944
1945 if (uart->flow_type == TRACE_FLOW)
1946 SER_tr_WakeUp (uart->flow_id);
1947
1948 else
1949 SER_fd_WakeUp ();
1950
1951 /*
1952 * The specified UART is no more set up for Deep Sleep.
1953 */
1954
1955 uart->deep_sleep_set_up = 0;
1956 }
1957 }
1958
1959 }
1960
1961 #endif // end __SERIALSWITCH_C__
1962