FreeCalypso > hg > freecalypso-sw
changeset 116:22c8199e08af
started integrating TI's serial code
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 28 Oct 2013 06:49:44 +0000 |
parents | 1e41550feec5 |
children | e40d8661ecab |
files | nuc-fw/serial/Makefile nuc-fw/serial/faxdata.h nuc-fw/serial/serialswitch.c nuc-fw/serial/serialswitch.h nuc-fw/serial/traceswitch.h nuc-fw/serial/uart.c nuc-fw/serial/uart.h nuc-fw/serial/uartfax.h |
diffstat | 8 files changed, 6449 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nuc-fw/serial/Makefile Mon Oct 28 06:49:44 2013 +0000 @@ -0,0 +1,13 @@ +CC= arm-elf-gcc +CFLAGS= -O2 -fno-builtin -mthumb-interwork -mthumb + +OBJS= serialswitch.o uart.o + +HDRS= faxdata.h serialswitch.h traceswitch.h uart.h uartfax.h + +all: ${OBJS} + +${OBJS}: ${HDRS} + +clean: + rm -f *.[oa] *errs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nuc-fw/serial/faxdata.h Mon Oct 28 06:49:44 2013 +0000 @@ -0,0 +1,150 @@ +/******************************************************************************* + * + * FAXDATA.H + * + * This module defines constants used by UART and USART fax/data drivers. + * + * (C) Texas Instruments 1999 + * + ******************************************************************************/ + +#ifndef __FAXDATA_H__ +#define __FAXDATA_H__ + +/* + * Returned values. + */ + +#define FD_OK ( 0) +#define FD_SUSPENDED (-1) +#define FD_NOT_SUPPORTED (-2) +#define FD_NOT_READY (-3) +#define FD_INTERNAL_ERR (-9) + +/* + * Line status. + */ + +#define FD_LINE_ON (1) +#define FD_LINE_OFF (0) + +/* + * Signals used in UAF_xxx_GetLineState and UAF_xxx_SetLineState. + */ + +#define CTS ( 0) /* set */ +#define RTS ( 1) /* get */ +#define DSR ( 2) /* set */ +#define DTR ( 3) /* get */ +#define DCD ( 4) /* set */ +#define BRK ( 5) /* set/get */ +#define ESC ( 6) /* get */ +#define TXSTP ( 7) /* get */ +#define RXSTP ( 8) /* get */ +#define BRKLEN ( 9) /* set/get (8 bits) */ +#define RXBLEV (17) /* get (12 bits) */ +#define SA (29) /* set/get */ +#define SB (30) /* set/get */ +#define X (31) /* set/get */ + +#define RI (1) + +/* + * Size of the circular buffers used in the driver. + */ + +#define FD_MAX_BUFFER_SIZE (512) /* In bytes. */ + +/* + * Type of the returned value for each function. + */ + +typedef short T_FDRET; + +/* + * Baud rates. + */ + +typedef enum { + FD_BAUD_AUTO, + FD_BAUD_75, + FD_BAUD_150, + FD_BAUD_300, + FD_BAUD_600, + FD_BAUD_1200, + FD_BAUD_2400, + FD_BAUD_4800, + FD_BAUD_7200, + FD_BAUD_9600, + FD_BAUD_14400, + FD_BAUD_19200, + FD_BAUD_28800, + FD_BAUD_33900, + FD_BAUD_38400, + FD_BAUD_57600, + FD_BAUD_115200, + FD_BAUD_203125, + FD_BAUD_406250, + FD_BAUD_812500 +} T_baudrate; + +/* + * Bits per character. + */ + +typedef enum { + bpc_7, + bpc_8 +} T_bitsPerCharacter; + +/* + * Stop bits. + */ + +typedef enum { + sb_1, + sb_2 +} T_stopBits; + +/* + * Parity. + */ + +typedef enum { + pa_none, + pa_even, + pa_odd, + pa_space +} T_parity; + +/* + * Flow control mode. + */ + +typedef enum { + fc_none, + fc_rts, + fc_dtr, + fc_xoff +} T_flowCtrlMode; + +/* + * Suspend parameter used in UAF_xxx_ReadData and UAF_xxx_WriteData. + */ + +typedef enum { + sm_noSuspend, + sm_suspend +} T_suspendMode; + +/* + * Install mode parameter used in UAF_xxx_ReadData and UAF_xxx_WriteData. + */ + +typedef enum { + rm_notDefined, + rm_reInstall, + rm_noInstall +} T_reInstMode; + +#endif /* __FAXDATA_H__ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nuc-fw/serial/serialswitch.c Mon Oct 28 06:49:44 2013 +0000 @@ -0,0 +1,3461 @@ +/******************************************************************************* + * + * SERIALSWITCH.C + * + * This module allows managing the use of the serial ports of TI GSM Evaluation + * Boards. + * An application may have to send several serial data flows. The board on which + * the application is running may have one or several devices. The purpose of + * this module is to establish connections between the serial data flows and the + * serial devices at runtime, when the application is started. + * + * (C) Texas Instruments 1999 - 2003 + * + ******************************************************************************/ + +#define __SERIALSWITCH_C__ + +#define __STANDARD_H__ /* Avoid to define UBYTE, SYS_UWORD16 and UINT32. */ + +#include "../include/config.h" +#include "../include/sys_types.h" +#include "../nucleus/nucleus.h" + +#include "serialswitch.h" + +#include "uart.h" +#include "uartfax.h" + +#include "../bsp/mem.h" + +#include <string.h> /* needed for memcmp & memset */ + +#if SERIAL_DYNAMIC_SWITCH + #include "ffs/ffs.h" + #include "rvf/rvf_api.h" + #include "inth/iq.h" + #include "rvt/rvt_def_i.h" /* needed for Riviera/Layer1 Trace's callback function */ +#endif + +#if defined(BTEMOBILE) + #include "hci_ser.h" +#endif + +#define DUMMY_DEVICE (0) + +#define IIR (0x02) /* UART interrupt ident. register - Read only */ +#define SCR (0x10) /* UART suppl. control register - Read/Write */ +#define SSR (0x11) /* UART suppl. status register - Read only */ + +/* + * Interrupt identification register. + * Bit 0 is set to 0 if an IT is pending. + * Bits 1 and 2 are used to identify the IT. + */ + +#define IIR_BITS_USED (0x07) +#define IT_NOT_PENDING (0x01) + +/* + * Supplementary Control Register + */ + +#define RX_CTS_WAKE_UP_ENABLE_BIT (4) + +/* + * Supplementary Status Register + */ + +#define RX_CTS_WAKE_UP_STS (0x02) /* Wake-up interrupt occurred */ + +/* + * This macro allows to read an UART register. + */ + +#define READ_UART_REGISTER(UART,REG) \ + *((volatile SYS_UWORD8 *) ((UART)->base_address + (REG))) + + +/* + * This macro allows to disable the UART's wake-up interrupt. + */ + +#define DISABLE_WAKE_UP_INTERRUPT(UART) \ + *((volatile SYS_UWORD8 *) ((UART)->base_address + SCR)) &= \ + ~(1 << (RX_CTS_WAKE_UP_ENABLE_BIT)); + +/* + * Wake-up time duration in seconds and in number of TDMAs. + * 1 TDMA = (6 / 1300) s = 0.004615 s (= 4.615 ms). + */ + +#define WAKE_UP_TIME_DURATION (10) /* 10 seconds */ +#define WAKE_UP_TIME_IN_TDMA (WAKE_UP_TIME_DURATION * 1300 / 6) + + +/* + * Global uartswitch variable as read from FFS. + * It is supposed that NUMBER_OF_TR_UART, NUMBER_OF_FD_UART + * and NUMBER_OF_BT_UART have the same values. + */ + +#define DUMMY ('0') +#define G23_PANEL ('G') +#define RIVIERA_TRACE_MUX ('R') +#define FD_AT_COMMAND ('D') +#define BLUETOOTH_HCI ('B') + +#if (CHIPSET == 12) + char ser_cfg_info[NUMBER_OF_TR_UART] = {DUMMY, DUMMY, DUMMY}; +#else + char ser_cfg_info[NUMBER_OF_TR_UART] = {DUMMY, DUMMY}; +#endif +static SYS_UWORD16 serial_cfg = 0x0048; /* All dummies */ + +#if SERIAL_DYNAMIC_SWITCH + /* + * Global variables used for Dynamic Switch. + */ + + static char ser_new_cfg[NUMBER_OF_TR_UART] = {DUMMY, DUMMY}; + const static char uart_config_file[] = "/sys/uartswitch"; + static SYS_BOOL dynamic_switch = 0; + + /* Import Serial Info structure. */ + extern T_AppliSerialInfo appli_ser_cfg_info; +#endif + +/* + * Types of flows supported. + */ + +typedef enum { + TRACE_FLOW, + FAX_DATA_FLOW, + BLUETOOTH_HCI_FLOW +} t_flow_type; + +/* + * For each serial data flow, a set of function pointers allows calling the + * functions associated to a serial device. + */ + +typedef struct s_tr_functions { + + T_tr_UartId device; + + void (*tr_Init) (T_tr_UartId device, + T_tr_Baudrate baudrate, + void (callback_function (void))); + + SYS_UWORD32 (*tr_ReadNChars) (T_tr_UartId device, + char *buffer, + SYS_UWORD32 chars_to_read); + + SYS_UWORD32 (*tr_ReadNBytes) (T_tr_UartId device, + char *buffer, + SYS_UWORD32 chars_to_read, + SYS_BOOL *eof_detected); + + SYS_UWORD32 (*tr_WriteNChars) (T_tr_UartId device, + char *buffer, + SYS_UWORD32 chars_to_write); + + SYS_UWORD32 (*tr_EncapsulateNChars) (T_tr_UartId device, + char *buffer, + SYS_UWORD32 chars_to_write); + + SYS_UWORD32 (*tr_WriteNBytes) (T_tr_UartId device, + SYS_UWORD8 *buffer, + SYS_UWORD32 chars_to_write); + + void (*tr_WriteChar) (T_tr_UartId device, + char character); + + void (*tr_WriteString) (T_tr_UartId device, + char *buffer); + + SYS_BOOL (*tr_EnterSleep) (T_tr_UartId device); + + void (*tr_WakeUp) (T_tr_UartId device); + +} t_tr_functions; + +/* + * Set of function pointers for fax & data functions. + */ + +typedef struct s_fd_functions { + + T_fd_UartId device; + + T_FDRET (*fd_Initialize) (T_fd_UartId device); + + T_FDRET (*fd_Enable) (T_fd_UartId device, + SYS_BOOL enable); + + T_FDRET (*fd_SetComPar) (T_fd_UartId device, + T_baudrate baudrate, + T_bitsPerCharacter bpc, + T_stopBits sb, + T_parity parity); + + T_FDRET (*fd_SetBuffer) (T_fd_UartId device, + SYS_UWORD16 bufSize, + SYS_UWORD16 rxThreshold, + SYS_UWORD16 txThreshold); + + T_FDRET (*fd_SetFlowCtrl) (T_fd_UartId device, + T_flowCtrlMode fcMode, + SYS_UWORD8 XON, + SYS_UWORD8 XOFF); + + T_FDRET (*fd_SetEscape) (T_fd_UartId device, + SYS_UWORD8 escChar, + SYS_UWORD16 guardPeriod); + + T_FDRET (*fd_InpAvail) (T_fd_UartId device); + + T_FDRET (*fd_OutpAvail) (T_fd_UartId device); + + T_FDRET (*fd_EnterSleep) (T_fd_UartId device); + + T_FDRET (*fd_WakeUp) (T_fd_UartId device); + + T_FDRET (*fd_ReadData) (T_fd_UartId device, + T_suspendMode suspend, + void (readOutFunc (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 nsource, + SYS_UWORD8 *source[], + SYS_UWORD16 size[], + SYS_UWORD32 state))); + + T_FDRET (*fd_WriteData) (T_fd_UartId device, + T_suspendMode suspend, + void (writeInFunc (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 ndest, + SYS_UWORD8 *dest[], + SYS_UWORD16 size[]))); + + T_FDRET (*fd_StopRec) (T_fd_UartId device); + + T_FDRET (*fd_StartRec) (T_fd_UartId device); + + T_FDRET (*fd_GetLineState) (T_fd_UartId device, + SYS_UWORD32 *state); + + T_FDRET (*fd_SetLineState) (T_fd_UartId device, + SYS_UWORD32 state, + SYS_UWORD32 mask); + + T_FDRET (*fd_CheckXEmpty) (T_fd_UartId device); + +} t_fd_functions; + +#ifdef BTEMOBILE + /* + * Set of function pointers for Bluetooth HCI functions. + */ + + typedef struct s_bt_functions { + + T_bt_UartId device; + + T_HCI_RET (*bt_Init) (T_bt_UartId uart_device); + + T_HCI_RET (*bt_Start) (void); + + T_HCI_RET (*bt_Stop) (void); + + T_HCI_RET (*bt_Kill) (void); + + T_HCI_RET (*bt_SetBaudrate) (UINT8 baudrate); + + T_HCI_RET (*bt_TransmitPacket) (void *uart_tx_buffer); + + SYS_BOOL (*bt_EnterSleep) (void); + + void (*bt_WakeUp) (void); + + } t_bt_functions; +#endif + +/* + * Prototypes of dummy functions. + * Dummy functions for Trace. + */ + +static void dummy_tr_Init (T_tr_UartId device, + T_tr_Baudrate baudrate, + void (callback_function (void))); + +static SYS_UWORD32 dummy_tr_ReadNChars (T_tr_UartId device, + char *buffer, + SYS_UWORD32 chars_to_read); + +static SYS_UWORD32 dummy_tr_ReadNBytes (T_tr_UartId device, + char *buffer, + SYS_UWORD32 chars_to_read, + SYS_BOOL *eof_detected); + +static SYS_UWORD32 dummy_tr_WriteNChars (T_tr_UartId device, + char *buffer, + SYS_UWORD32 chars_to_write); + +static SYS_UWORD32 dummy_tr_EncapsulateNChars (T_tr_UartId device, + char *buffer, + SYS_UWORD32 chars_to_write); + +static SYS_UWORD32 dummy_tr_WriteNBytes (T_tr_UartId device, + SYS_UWORD8 *buffer, + SYS_UWORD32 chars_to_write); + +static void dummy_tr_WriteChar (T_tr_UartId device, + char character); + +static void dummy_tr_WriteString (T_tr_UartId device, + char *buffer); + +static SYS_BOOL dummy_tr_EnterSleep (T_tr_UartId device); + +static void dummy_tr_WakeUp (T_tr_UartId device); + +/* + * Dummy functions for Fax & Data. + */ + +static T_FDRET dummy_fd_Init (T_fd_UartId device); + +static T_FDRET dummy_fd_Enable (T_fd_UartId device, + SYS_BOOL enable); + +static T_FDRET dummy_fd_SetComPar (T_fd_UartId device, + T_baudrate baudrate, + T_bitsPerCharacter bpc, + T_stopBits sb, + T_parity parity); + +static T_FDRET dummy_fd_SetBuffer (T_fd_UartId device, + SYS_UWORD16 bufSize, + SYS_UWORD16 rxThreshold, + SYS_UWORD16 txThreshold); + +static T_FDRET dummy_fd_SetFlowCtrl (T_fd_UartId device, + T_flowCtrlMode fcMode, + SYS_UWORD8 XON, + SYS_UWORD8 XOFF); + +static T_FDRET dummy_fd_SetEscape (T_fd_UartId device, + SYS_UWORD8 escChar, + SYS_UWORD16 guardPeriod); + +static T_FDRET dummy_fd_InpAvail (T_fd_UartId device); + +static T_FDRET dummy_fd_OutpAvail (T_fd_UartId device); + +static T_FDRET dummy_fd_EnterSleep (T_fd_UartId device); + +static T_FDRET dummy_fd_WakeUp (T_fd_UartId device); + +static T_FDRET dummy_fd_ReadData (T_fd_UartId device, + T_suspendMode suspend, + void (readOutFunc (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 nsource, + SYS_UWORD8 *source[], + SYS_UWORD16 size[], + SYS_UWORD32 state))); + +static T_FDRET dummy_fd_WriteData (T_fd_UartId device, + T_suspendMode suspend, + void (writeInFunc (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 ndest, + SYS_UWORD8 *dest[], + SYS_UWORD16 size[]))); + +static T_FDRET dummy_fd_StopRec (T_fd_UartId device); + +static T_FDRET dummy_fd_StartRec (T_fd_UartId device); + +static T_FDRET dummy_fd_GetLineState (T_fd_UartId device, + SYS_UWORD32 *state); + +static T_FDRET dummy_fd_SetLineState (T_fd_UartId device, + SYS_UWORD32 state, + SYS_UWORD32 mask); + +static T_FDRET dummy_fd_CheckXEmpty (T_fd_UartId device); + +#ifdef BTEMOBILE + /* + * Dummy functions for Bluetooth HCI. + */ + + static T_HCI_RET dummy_bt_Init (T_bt_UartId uart_device); + + static T_HCI_RET dummy_bt_Start (void); + + static T_HCI_RET dummy_bt_Stop (void); + + static T_HCI_RET dummy_bt_Kill (void); + + static T_HCI_RET dummy_bt_SetBaudrate (UINT8 baudrate); + + static T_HCI_RET dummy_bt_TransmitPacket (void *uart_tx_buffer); + + static SYS_BOOL dummy_bt_EnterSleep (void); + + static void dummy_bt_WakeUp (void); + +#endif + +/* + * Constants tables representing the various possible configurations + * for Trace, Fax & Data and Bluetooth HCI according to the different devices. + * Constant table for Trace using no device. + */ + +static const t_tr_functions dummy_trace = { + + DUMMY_DEVICE, + dummy_tr_Init, + dummy_tr_ReadNChars, + dummy_tr_ReadNBytes, + dummy_tr_WriteNChars, + dummy_tr_EncapsulateNChars, + dummy_tr_WriteNBytes, + dummy_tr_WriteChar, + dummy_tr_WriteString, + dummy_tr_EnterSleep, + dummy_tr_WakeUp +}; + +/* + * Constant table for Trace using UART IrDA. + */ + +static const t_tr_functions uart_irda_trace = { + + UA_UART_0, + UA_Init, + UA_ReadNChars, + UA_ReadNBytes, + UA_WriteNChars, + UA_EncapsulateNChars, + UA_WriteNBytes, + UA_WriteChar, + UA_WriteString, + UA_EnterSleep, + UA_WakeUp +}; + +/* + * Constant table for Trace using UART Modem. + */ + +static const t_tr_functions uart_modem_trace = { + + UA_UART_1, + UA_Init, + UA_ReadNChars, + UA_ReadNBytes, + UA_WriteNChars, + UA_EncapsulateNChars, + UA_WriteNBytes, + UA_WriteChar, + UA_WriteString, + UA_EnterSleep, + UA_WakeUp +}; + +#if (CHIPSET == 12) + /* + * Constant table for Trace using UART Modem2. + */ + + static const t_tr_functions uart_modem2_trace = { + + UA_UART_2, + UA_Init, + UA_ReadNChars, + UA_ReadNBytes, + UA_WriteNChars, + UA_EncapsulateNChars, + UA_WriteNBytes, + UA_WriteChar, + UA_WriteString, + UA_EnterSleep, + UA_WakeUp + }; +#endif + +/* + * Constant table for Fax & Data using no device. + */ + +static const t_fd_functions dummy_fax_data = { + + DUMMY_DEVICE, + dummy_fd_Init, + dummy_fd_Enable, + dummy_fd_SetComPar, + dummy_fd_SetBuffer, + dummy_fd_SetFlowCtrl, + dummy_fd_SetEscape, + dummy_fd_InpAvail, + dummy_fd_OutpAvail, + dummy_fd_EnterSleep, + dummy_fd_WakeUp, + dummy_fd_ReadData, + dummy_fd_WriteData, + dummy_fd_StopRec, + dummy_fd_StartRec, + dummy_fd_GetLineState, + dummy_fd_SetLineState, + dummy_fd_CheckXEmpty +}; + +/* + * Constant table for Fax & Data using UART Modem. + */ + +#if CONFIG_FDMODEM +static const t_fd_functions uart_modem_fax_data = { + + UAF_UART_1, + UAF_Init, + UAF_Enable, + UAF_SetComPar, + UAF_SetBuffer, + UAF_SetFlowCtrl, + UAF_SetEscape, + UAF_InpAvail, + UAF_OutpAvail, + UAF_EnterSleep, + UAF_WakeUp, + UAF_ReadData, + UAF_WriteData, + UAF_StopRec, + UAF_StartRec, + UAF_GetLineState, + UAF_SetLineState, + UAF_CheckXEmpty +}; +#endif + +#ifdef BTEMOBILE + /* + * Constant table for BT HCI using no device. + */ + + static const t_bt_functions dummy_bt_hci = { + + DUMMY_DEVICE, + dummy_bt_Init, + dummy_bt_Start, + dummy_bt_Stop, + dummy_bt_Kill, + dummy_bt_SetBaudrate, + dummy_bt_TransmitPacket, + dummy_bt_EnterSleep, + dummy_bt_WakeUp + }; + + /* + * Constant table for BT HCI using UART IrDA. + */ + + static const t_bt_functions uart_irda_bt_hci = { + + UABT_UART_0, + hciu_init, + hciu_start, + hciu_stop, + hciu_kill, + hciu_set_baudrate, + hciu_transmit_packet, + hciu_enter_sleep, + hciu_wakeup + }; + + /* + * Constant table for BT HCI using UART Modem. + */ + + static const t_bt_functions uart_modem_bt_hci = { + + UABT_UART_1, + hciu_init, + hciu_start, + hciu_stop, + hciu_kill, + hciu_set_baudrate, + hciu_transmit_packet, + hciu_enter_sleep, + hciu_wakeup + }; + + #if (CHIPSET == 12) + /* + * Constant table for BT HCI using UART Modem2. + */ + + static const t_bt_functions uart_modem2_bt_hci = { + + UABT_UART_2, + hciu_init, + hciu_start, + hciu_stop, + hciu_kill, + hciu_set_baudrate, + hciu_transmit_packet, + hciu_go_to_sleep, + hciu_wakeup + }; + #endif +#endif + +#if SERIAL_DYNAMIC_SWITCH + /* + * Structure used to store initialization parameters related to the AT-Cmd/F&D flow. + * Numbers of paramaters (in case of multiple calls) have been figured out from + * Condat AT-Command/F&D flow initialization. + */ + + typedef struct s_data_flow { + + /* + * Parameters related to SER_fd_SetComPar (2 calls) + */ + T_baudrate baudrate[2]; + T_bitsPerCharacter bpc[2]; + T_stopBits sb[2]; + T_parity parity[2]; + + /* + * Parameters related to SER_fd_SetBuffer + */ + SYS_WORD16 bufSize; + SYS_WORD16 rxThreshold; + SYS_WORD16 txThreshold; + + /* + * Parameters related to SER_fd_SetFlowCtrl (2 calls) + */ + T_flowCtrlMode fcMode[2]; + SYS_UWORD8 XON[2]; + SYS_UWORD8 XOFF[2]; + + /* + * Parameters related to SER_fd_SetEscape (2 calls) + */ + SYS_UWORD8 escChar[2]; + SYS_UWORD16 guardPeriod[2]; + + /* + * Parameters related to SER_fd_SetLineState (4 calls) + */ + SYS_UWORD32 state[4]; + SYS_UWORD32 mask[4]; + + /* + * Parameters related to SER_fd_ReadData + */ + T_suspendMode suspend_rd; + void (*readOutFunc) (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 nsource, + SYS_UWORD8 *source[], + SYS_UWORD16 size[], + SYS_UWORD32 state); + /* + * Parameters related to SER_fd_WriteData + */ + T_suspendMode suspend_wr; + void (*writeInFunc) (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 ndest, + SYS_UWORD8 *dest[], + SYS_UWORD16 size[]); + + } t_data_flow; +#endif /* (defined BTEMOBILE && (CHIPSET != 12)) */ + +/* + * UART structure used for UARTs. + */ + +typedef struct s_uart { + + SYS_UWORD32 base_address; + SYS_BOOL device_used; + SYS_BOOL deep_sleep_set_up; + t_flow_type flow_type; + SYS_WORD16 flow_id; + void (*interrupt_handler) (int uart_id, + SYS_UWORD8 interrupt_status); + +} t_uart; + +static const t_tr_functions *tr_functions[SER_MAX_NUMBER_OF_FLOWS]; +static const t_fd_functions *fd_functions; + +#ifdef BTEMOBILE + static const t_bt_functions *bt_functions; +#endif + +#if SERIAL_DYNAMIC_SWITCH + static SYS_BOOL uart_fd_initialized = 0; +#endif + +static SYS_UWORD8 fd_buffer[FD_MAX_BUFFER_SIZE]; +static SYS_BOOL fd_driver_enabled; + +#if SERIAL_DYNAMIC_SWITCH + static t_data_flow data_flow_parameters; +#else + static SYS_WORD16 bufSize; +#endif + +#if SERIAL_DYNAMIC_SWITCH + /* + * Variables used to count calls to SER_fd_XXX functions. + */ + + static SYS_UWORD8 fd_UAF_SetBuffer = 0; + static SYS_UWORD8 fd_UAF_SetEscape = 0; + static SYS_UWORD8 fd_UAF_SetComPar = 0; + static SYS_UWORD8 fd_UAF_SetFlowCtrl = 0; + static SYS_UWORD8 fd_UAF_ReadData = 0; + static SYS_UWORD8 fd_UAF_SetLineState = 0; + static SYS_UWORD8 fd_UAF_WriteData = 0; +#endif + +/* + * Timer used for duration control when UARTs are waked up by an interrupt or + * each time any new incoming characters are received; This timer prevents the + * system to enter deep sleep mode. + */ + +static NU_TIMER uart_sleep_timer; + SYS_BOOL uart_sleep_timer_enabled; + +/* + * HISR used to reset and restart the sleep timer from an UART use by a Trace + * flow in case of incoming characters. + */ + +#define TIMER_HISR_PRIORITY (2) +#define TIMER_HISR_STACK_SIZE (512) /* Bytes. */ + +static NU_HISR timer_hisr_ctrl_block; +static char timer_hisr_stack[TIMER_HISR_STACK_SIZE]; + +/* + * For next arrays, it is supposed that NUMBER_OF_TR_UART, NUMBER_OF_FD_UART + * and NUMBER_OF_BT_UART have the same values. + * An index on an internal uart for trace, fax & data or bluetooth hci reffers + * to the same uart device. + */ + +static t_uart int_uart[NUMBER_OF_TR_UART]; + +#if ((CHIPSET == 2) || (CHIPSET == 3)) + static SYS_UWORD32 uart_spurious_interrupts; +#elif ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11) || (CHIPSET == 12)) + static SYS_UWORD32 uart_modem_spurious_interrupts; + static SYS_UWORD32 uart_irda_spurious_interrupts; +#endif +#if (CHIPSET == 12) + static SYS_UWORD32 uart_modem2_spurious_interrupts; +#endif + +static const SYS_UWORD32 uart_base_address[NUMBER_OF_TR_UART] = +{ + MEM_UART_IRDA, + MEM_UART_MODEM + #if (CHIPSET == 12) + , MEM_UART_MODEM2 + #endif +}; + + +/******************************************************************************* + * + * dummy_tr_Init + * + * Purpose: No action. + * + * Parameters: See SER_tr_Init. + * + * Return: none + * + ******************************************************************************/ + +static void +dummy_tr_Init (T_tr_UartId device, + T_tr_Baudrate baudrate, + void (callback_function (void))) +{ + /* + * No action. + */ +} + +/******************************************************************************* + * + * dummy_tr_ReadNChars + * + * Purpose: No action. + * + * Parameters: See SER_tr_ReadNChars. + * + * Return: 0 + * + ******************************************************************************/ + +static SYS_UWORD32 +dummy_tr_ReadNChars (T_tr_UartId device, + char *buffer, + SYS_UWORD32 chars_to_read) +{ + return (0); +} + +/******************************************************************************* + * + * dummy_tr_ReadNBytes + * + * Purpose: No action. + * + * Parameters: See SER_tr_ReadNBytes. + * + * Return: 0 + * + ******************************************************************************/ + +static SYS_UWORD32 +dummy_tr_ReadNBytes (T_tr_UartId device, + char *buffer, + SYS_UWORD32 chars_to_read, + SYS_BOOL *eof_detected) +{ + return (0); +} + +/******************************************************************************* + * + * dummy_tr_WriteNChars + * + * Purpose: No action. + * + * Parameters: See SER_tr_WriteNChars. + * + * Return: The number of character to write. + * + ******************************************************************************/ + +static SYS_UWORD32 +dummy_tr_WriteNChars (T_tr_UartId device, + char *buffer, + SYS_UWORD32 chars_to_write) +{ + return (chars_to_write); +} + +/******************************************************************************* + * + * dummy_tr_EncapsulateNChars + * + * Purpose: No action. + * + * Parameters: See SER_tr_EncapsulateNChars. + * + * Return: The number of character to write. + * + ******************************************************************************/ + +static SYS_UWORD32 +dummy_tr_EncapsulateNChars (T_tr_UartId device, + char *buffer, + SYS_UWORD32 chars_to_write) +{ + return (chars_to_write); +} + +/******************************************************************************* + * + * dummy_tr_WriteNBytes + * + * Purpose: No action. + * + * Parameters: See SER_tr_WriteNBytes. + * + * Return: The number of byte to write. + * + ******************************************************************************/ + +static SYS_UWORD32 +dummy_tr_WriteNBytes (T_tr_UartId device, + SYS_UWORD8 *buffer, + SYS_UWORD32 chars_to_write) +{ + return (chars_to_write); +} + +/******************************************************************************* + * + * dummy_tr_WriteChar + * + * Purpose: No action. + * + * Parameters: See SER_tr_WriteChar. + * + * Return: none + * + ******************************************************************************/ + +static void +dummy_tr_WriteChar (T_tr_UartId device, + char character) +{ + /* + * No action. + */ +} + +/******************************************************************************* + * + * dummy_tr_WriteString + * + * Purpose: No action. + * + * Parameters: See SER_tr_WriteString. + * + * Return: none + * + ******************************************************************************/ + +static void +dummy_tr_WriteString (T_tr_UartId device, + char *buffer) +{ + /* + * No action. + */ +} + +/******************************************************************************* + * + * dummy_tr_EnterSleep + * + * Purpose: No action. + * + * Parameters: See SER_tr_EnterSleep. + * + * Return: 1 + * + ******************************************************************************/ + +static SYS_BOOL +dummy_tr_EnterSleep (T_tr_UartId device) +{ + return (1); +} + +/******************************************************************************* + * + * dummy_tr_WakeUp + * + * Purpose: No action. + * + * Parameters: See SER_tr_WakeUp. + * + * Return: none + * + ******************************************************************************/ + +static void +dummy_tr_WakeUp (T_tr_UartId device) +{ + /* + * No action. + */ +} + +/******************************************************************************* + * + * dummy_fd_Init + * + * Purpose: Sets the size of the circular buffer to the maximum value and the + * state of the driver to 'disabled'. + * + * Parameters: See SER_fd_Init. + * + * Return: FD_OK: Successful operation. + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_Init (T_fd_UartId device) +{ + #if SERIAL_DYNAMIC_SWITCH + data_flow_parameters.bufSize = FD_MAX_BUFFER_SIZE; + #else + bufSize = FD_MAX_BUFFER_SIZE; + #endif + fd_driver_enabled = 0; + + return (FD_OK); +} + +/******************************************************************************* + * + * dummy_fd_Enable + * + * Purpose: Stores the state of the driver. + * + * Parameters: See SER_fd_Enable. + * + * Return: FD_OK: Successful operation. + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_Enable (T_fd_UartId device, + SYS_BOOL enable) +{ + fd_driver_enabled = enable; + + return (FD_OK); +} + +/******************************************************************************* + * + * dummy_fd_SetComPar + * + * Purpose: No action. + * + * Parameters: See SER_fd_SetComPar. + * + * Return: FD_OK: Successful operation. + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_SetComPar (T_fd_UartId device, + T_baudrate baudrate, + T_bitsPerCharacter bpc, + T_stopBits sb, + T_parity parity) +{ + return (FD_OK); +} + +/******************************************************************************* + * + * dummy_fd_SetBuffer + * + * Purpose: No action. + * + * Parameters: See SER_fd_SetBuffer. + * + * Return: FD_OK: Successful operation. + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_SetBuffer (T_fd_UartId device, + SYS_UWORD16 bufSize, + SYS_UWORD16 rxThreshold, + SYS_UWORD16 txThreshold) +{ + return (FD_OK); +} + +/******************************************************************************* + * + * dummy_fd_SetFlowCtrl + * + * Purpose: No action. + * + * Parameters: See SER_fd_SetFlowCtrl. + * + * Return: FD_OK: Successful operation. + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_SetFlowCtrl (T_fd_UartId device, + T_flowCtrlMode fcMode, + SYS_UWORD8 XON, + SYS_UWORD8 XOFF) +{ + return (FD_OK); +} + +/******************************************************************************* + * + * dummy_fd_SetEscape + * + * Purpose: No action. + * + * Parameters: See SER_fd_SetEscape. + * + * Return: FD_OK: Successful operation. + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_SetEscape (T_fd_UartId device, + SYS_UWORD8 escChar, + SYS_UWORD16 guardPeriod) +{ + return (FD_OK); +} + +/******************************************************************************* + * + * dummy_fd_InpAvail + * + * Purpose: No action. + * + * Parameters: See SER_fd_InpAvail. + * + * Return: The size of the circular buffer. + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_InpAvail (T_fd_UartId device) +{ + #if SERIAL_DYNAMIC_SWITCH + return (data_flow_parameters.bufSize); + #else + return (bufSize); + #endif +} + +/******************************************************************************* + * + * dummy_fd_OutpAvail + * + * Purpose: No action. + * + * Parameters: See SER_fd_OutpAvail. + * + * Return: The size of the circular buffer. + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_OutpAvail (T_fd_UartId device) +{ + #if SERIAL_DYNAMIC_SWITCH + return (data_flow_parameters.bufSize); + #else + return (bufSize); + #endif +} + +/******************************************************************************* + * + * dummy_fd_EnterSleep + * + * Purpose: No action. + * + * Parameters: See SER_tr_EnterSleep. + * + * Return: 1 + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_EnterSleep (T_fd_UartId device) +{ + return (1); +} + +/******************************************************************************* + * + * dummy_fd_WakeUp + * + * Purpose: No action. + * + * Parameters: See SER_tr_WakeUp. + * + * Return: FD_OK: Successful operation. + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_WakeUp (T_fd_UartId device) +{ + return (FD_OK); +} + +/******************************************************************************* + * + * dummy_fd_ReadData + * + * Purpose: No action. + * + * Parameters: See SER_fd_ReadData. + * + * Return: 0 if the suspend parameter is set to 'sm_noSuspend'. + * FD_SUSPENDED if the suspend parameter is set to 'sm_suspend'. + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_ReadData (T_fd_UartId device, + T_suspendMode suspend, + void (readOutFunc (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 nsource, + SYS_UWORD8 *source[], + SYS_UWORD16 size[], + SYS_UWORD32 state))) +{ + T_FDRET result; + + if (suspend == sm_noSuspend) + result = 0; + else + result = FD_SUSPENDED; + + return (result); +} + +/******************************************************************************* + * + * dummy_fd_WriteData + * + * Purpose: The user's function is called with: + * - cldFromIrq = 0 + * - ndest = 1 + * - dest[0] is a SYS_UWORD8 pointer on the beginning address of a local + * buffer + * - size[0] is set to data_flow_parameters.bufSize. + * + * Parameters: See SER_fd_WriteData. + * + * Return: The number of bytes written in the local buffer. + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_WriteData (T_fd_UartId device, + T_suspendMode suspend, + void (writeInFunc (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 ndest, + SYS_UWORD8 *dest[], + SYS_UWORD16 size[]))) +{ + T_reInstMode dummyInstall; + SYS_UWORD8 *destination[2]; + SYS_UWORD16 buffer_size[2]; + + destination[0] = &(fd_buffer[0]); + #if SERIAL_DYNAMIC_SWITCH + buffer_size[0] = data_flow_parameters.bufSize; + #else + buffer_size[0] = bufSize; + #endif + + (*writeInFunc) (0, &dummyInstall, 1, &(destination[0]), &(buffer_size[0])); + + #if SERIAL_DYNAMIC_SWITCH + return ((T_FDRET) (data_flow_parameters.bufSize - buffer_size[0])); + #else + return ((T_FDRET) (bufSize - buffer_size[0])); + #endif +} + +/******************************************************************************* + * + * dummy_fd_StopRec + * + * Purpose: No action. + * + * Parameters: See SER_fd_StopRec. + * + * Return: FD_OK: Successful operation. + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_StopRec (T_fd_UartId device) +{ + return (FD_OK); +} + +/******************************************************************************* + * + * dummy_fd_StartRec + * + * Purpose: No action. + * + * Parameters: See SER_fd_StartRec. + * + * Return: FD_OK: Successful operation. + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_StartRec (T_fd_UartId device) +{ + return (FD_OK); +} + +/******************************************************************************* + * + * dummy_fd_GetLineState + * + * Purpose: Sets the RXBLEV field to the bufSize value. + * + * Parameters: See SER_fd_GetLineState. + * + * Return: FD_OK: Successful operation. + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_GetLineState (T_fd_UartId device, + SYS_UWORD32 *state) +{ + #if SERIAL_DYNAMIC_SWITCH + *state = data_flow_parameters.bufSize << RXBLEV; + #else + *state = bufSize << RXBLEV; + #endif + + return (FD_OK); +} + +/******************************************************************************* + * + * dummy_fd_SetLineState + * + * Purpose: No action. + * + * Parameters: See SER_fd_SetLineState. + * + * Return: FD_OK: Successful operation. + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_SetLineState (T_fd_UartId device, + SYS_UWORD32 state, + SYS_UWORD32 mask) +{ + return (FD_OK); +} + +/******************************************************************************* + * + * dummy_fd_CheckXEmpty + * + * Purpose: No action. + * + * Parameters: See SER_fd_CheckXEmpty. + * + * Return: FD_OK: Successful operation. + * + ******************************************************************************/ + +static T_FDRET +dummy_fd_CheckXEmpty (T_fd_UartId device) +{ + return (FD_OK); +} + +#ifdef BTEMOBILE +/******************************************************************************* + * + * dummy_bt_Init + * + * Purpose: No action. + * + * Parameters: See SER_bt_Init. + * + * Return: HCI_OK: Successful operation. + * + ******************************************************************************/ + +static T_HCI_RET +dummy_bt_Init (T_bt_UartId uart_device) +{ + return (HCI_OK); +} + +/******************************************************************************* + * + * dummy_bt_Start + * + * Purpose: No action. + * + * Parameters: See SER_bt_Start. + * + * Return: HCI_OK: Successful operation. + * + ******************************************************************************/ + +static T_HCI_RET +dummy_bt_Start (void) +{ + return (HCI_OK); +} + +/******************************************************************************* + * + * dummy_bt_Stop + * + * Purpose: No action. + * + * Parameters: See SER_bt_Stop. + * + * Return: HCI_OK: Successful operation. + * + ******************************************************************************/ + +static T_HCI_RET +dummy_bt_Stop (void) +{ + return (HCI_OK); +} + +/******************************************************************************* + * + * dummy_bt_Kill + * + * Purpose: No action. + * + * Parameters: See SER_bt_Kill. + * + * Return: HCI_OK: Successful operation. + * + ******************************************************************************/ + +static T_HCI_RET +dummy_bt_Kill (void) +{ + return (HCI_OK); +} + +/******************************************************************************* + * + * dummy_bt_SetBaudrate + * + * Purpose: No action. + * + * Parameters: See SER_bt_SetBaudrate. + * + * Return: HCI_OK: Successful operation. + * + ******************************************************************************/ + +static T_HCI_RET +dummy_bt_SetBaudrate (UINT8 baudrate) +{ + return (HCI_OK); +} + +/******************************************************************************* + * + * dummy_bt_TransmitPacket + * + * Purpose: No action. + * + * Parameters: See SER_bt_TransmitPacket. + * + * Return: HCI_OK: Successful operation. + * + ******************************************************************************/ + +static T_HCI_RET dummy_bt_TransmitPacket (void *uart_tx_buffer) + +{ + return (HCI_OK); +} + +/******************************************************************************* + * + * dummy_bt_EnterSleep + * + * Purpose: No action. + * + * Parameters: See SER_bt_EnterSleep. + * + * Return: TRUE. + * + ******************************************************************************/ + +static SYS_BOOL +dummy_bt_EnterSleep (void) +{ + return (TRUE); +} + +/******************************************************************************* + * + * dummy_bt_WakeUp + * + * Purpose: No action. + * + * Parameters: See SER_bt_WakeUp + * + * Return: HCI_OK: none + * + ******************************************************************************/ + +static void +dummy_bt_WakeUp (void) +{ + /* + * No action. + */ +} + +#endif /* BTEMOBILE */ + +/******************************************************************************* + * + * analyze_uart_sleep_timer_expiration + * + * Purpose : The timer has just expired. If requested, UARTs can again be set + * up to enter Deep Sleep. + * + * Arguments: In : id: parameter not used. + * Out: none + * + * Returns : none + * + ******************************************************************************/ + +static VOID +analyze_uart_sleep_timer_expiration (UNSIGNED id) +{ + /* + * Timer has expired. + * UARTs can again be set up for Deep Sleep. + */ + + (void) NU_Control_Timer (&uart_sleep_timer, + NU_DISABLE_TIMER); + + uart_sleep_timer_enabled = 0; +} + +/******************************************************************************* + * + * start_uart_sleep_timer + * + * Purpose : Starts the sleep timer once UARTs have been waked-up by an + * interrupt or if new incoming characters have been received. + * + * Arguments: In : none + * Out: none + * + * Returns : none + * + ******************************************************************************/ + +static void +start_uart_sleep_timer (void) +{ + /* + * UART sleep timer is started. + * UARTs can't no more be set up for Deep Sleep until the timer expires. + */ + + (void) NU_Reset_Timer (&uart_sleep_timer, + &analyze_uart_sleep_timer_expiration, + WAKE_UP_TIME_IN_TDMA, + 0, /* The timer expires once. */ + NU_DISABLE_TIMER); + + (void) NU_Control_Timer (&uart_sleep_timer, + NU_ENABLE_TIMER); +} + +/******************************************************************************* + * + * set_flow_functions + * + * Purpose: Initializes a serial data flow functions set with the set of + * functions of the selected device. + * + * Parameters: In : flow : index of the serial data flow + * serial_driver: allows knowing which set of functions must + * be selected + * Out: none + * + * Return: none + * + ******************************************************************************/ + +static void +set_flow_functions (int flow, + T_SerialDriver serial_driver) +{ + + switch (serial_driver) { + + case UART_MODEM_FAX_DATA: + +#if CONFIG_FDMODEM + fd_functions = &uart_modem_fax_data; + int_uart[fd_functions->device].device_used = 1; + int_uart[fd_functions->device].flow_type = FAX_DATA_FLOW; + int_uart[fd_functions->device].flow_id = flow; + int_uart[fd_functions->device].interrupt_handler = + UAF_InterruptHandler; + break; +#endif + + case DUMMY_FAX_DATA: + + fd_functions = &dummy_fax_data; + break; + + + case UART_IRDA_TRACE: + case UART_MODEM_TRACE: + #if (CHIPSET == 12) + case UART_MODEM2_TRACE: + #endif + + if (serial_driver == UART_IRDA_TRACE) + tr_functions[flow] = &uart_irda_trace; + else { + #if (CHIPSET == 12) + if (serial_driver == UART_MODEM2_TRACE) + tr_functions[flow] = &uart_modem2_trace; + else + #endif + tr_functions[flow] = &uart_modem_trace; + } + + int_uart[tr_functions[flow]->device].device_used = 1; + int_uart[tr_functions[flow]->device].flow_type = TRACE_FLOW; + int_uart[tr_functions[flow]->device].flow_id = flow; + int_uart[tr_functions[flow]->device].interrupt_handler = + UA_InterruptHandler; + break; + + case DUMMY_TRACE: + + tr_functions[flow] = &dummy_trace; + break; + + case DUMMY_BT_HCI: + + /* + * if serial_driver = DUMMY_BT_HCI & if BTEMOBILE is not defined + * no action is performed. + */ + +#ifdef BTEMOBILE + bt_functions = &dummy_bt_hci; + break; + + case UART_IRDA_BT_HCI: + case UART_MODEM_BT_HCI: + #if (CHIPSET == 12) + case UART_MODEM2_BT_HCI: + #endif + + if (serial_driver == UART_IRDA_BT_HCI) + bt_functions = &uart_irda_bt_hci; + else { + #if (CHIPSET == 12) + if (serial_driver == UART_MODEM2_BT_HCI) + bt_functions = &uart_modem2_bt_hci; + else + #endif + bt_functions = &uart_modem_bt_hci; + } + + int_uart[bt_functions->device].device_used = 1; + int_uart[bt_functions->device].flow_type = BLUETOOTH_HCI_FLOW; + int_uart[bt_functions->device].flow_id = flow; + int_uart[bt_functions->device].interrupt_handler = + hciu_interrupt_handler; +#endif /* BTEMOBILE */ + break; + } +} + +/******************************************************************************* + * + * SER_InitSerialConfig + * + * Purpose: The parameter serial_info allows knowing all serial information + * necessary to set up the serial configuration of an application. + * From this information, the function is able to determine if the + * current serial configuration read out from the flash memory is + * valid. If it does not correspond to an allowed configuration, the + * default configuration is selected. This function must be called at + * the application's initialization, but never after. + * + * Parameters: In : serial_info: application serial information like the default + * configuration and all allowed configurations. + * Out: none + * + * Return: none + * + ******************************************************************************/ + +void +SER_InitSerialConfig (T_AppliSerialInfo *serial_info) +{ + int uart_id; + int flow; + SYS_UWORD16 serial_driver; + SYS_UWORD16 *allowed_config; + SYS_UWORD8 nb_allowed_config; + SYS_BOOL valid_config_selected; + SYS_BOOL uart_used; + SYS_BOOL uart_used_for_trace; + SYS_UWORD16 current_config; + SYS_UWORD16 *pt_current_config = &(current_config); + + /* + * Basic UARTs initializations. + */ + + for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { + + int_uart[uart_id].base_address = uart_base_address[uart_id]; + int_uart[uart_id].device_used = 0; + int_uart[uart_id].deep_sleep_set_up = 0; + } + +#if ((CHIPSET == 2) || (CHIPSET == 3)) + uart_spurious_interrupts = 0; +#elif ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11) || (CHIPSET == 12)) + uart_modem_spurious_interrupts = 0; + uart_irda_spurious_interrupts = 0; +#endif +#if (CHIPSET == 12) + uart_modem2_spurious_interrupts = 0; +#endif + uart_sleep_timer_enabled = 0; + + /* + * Compute the current serial configuration. + */ + + for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { + + switch (ser_cfg_info[uart_id]) { + + case G23_PANEL: + serial_cfg = serial_cfg + + ((uart_id + 1) << (12 - (4 * SER_PROTOCOL_STACK))); + break; + + case RIVIERA_TRACE_MUX: + serial_cfg = serial_cfg + + ((uart_id + 1) << (12 - (4 * SER_LAYER_1))); + break; + + case FD_AT_COMMAND: + serial_cfg = serial_cfg + + ((uart_id + 1) << (12 - (4 * SER_FAX_DATA))); + break; + + case BLUETOOTH_HCI: + serial_cfg = serial_cfg + + ((uart_id + 1) << (12 - (4 * SER_BLUETOOTH_HCI))); + break; + + case DUMMY: + break; + } + } + + current_config = serial_cfg; + valid_config_selected = 0; + nb_allowed_config = serial_info->num_config; + + /* + * Checks if the current serial config is one of the allowed. + */ + + while ((nb_allowed_config > 0) && !valid_config_selected) { + + nb_allowed_config--; + allowed_config = (SYS_UWORD16 *) + &(serial_info->allowed_config[nb_allowed_config]); + + if (*pt_current_config == *allowed_config) + valid_config_selected = 1; + } + + /* + * If not, the default configuration is selected. + */ + + if (!valid_config_selected) { + + pt_current_config = (SYS_UWORD16 *)&(serial_info->default_config); + + #if SERIAL_DYNAMIC_SWITCH + /* + * Setup the global variable accordingly. + * The following default value are identical to the ones defined at + * the application initialization in init.c. + */ + + #ifdef BT_UART_USED_MODEM + memcpy (ser_cfg_info, "RB", NUMBER_OF_TR_UART); + #else + memcpy (ser_cfg_info, "BR", NUMBER_OF_TR_UART); + #endif + #endif + } + + /* + * The serial data flow functions set is initialized. + */ + + flow = 0; + while (flow < SER_MAX_NUMBER_OF_FLOWS) { + + serial_driver = (T_SerialDriver) + (((*pt_current_config) >> (12 - flow * 4)) & 0x000F); + + set_flow_functions (flow, serial_driver); + flow++; + } + + /* + * Checks if both UARTs are used. + * If not, performs minimum initialization including Sleep Mode. + * Checks also if at least one UART is used by a Trace flow. + * If so, create a HISR in order to reset and restart the sleep timer + * in case of incoming characters. + */ + + uart_used = 0; + uart_used_for_trace = 0; + for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { + + if (!(int_uart[uart_id].device_used)) + initialize_uart_sleep (uart_id); + + else { /* if (int_uart[uart_id].device_used) */ + + uart_used = 1; /* At least one UART is used */ + + if (int_uart[uart_id].flow_type == TRACE_FLOW) { + + /* At least one UART used by a Trace flow */ + uart_used_for_trace = 1; + } + } + } + + /* + * If at least one uart is used, create a timer to figure out if the system + * can enter deep sleep mode regarding the UARTs. + */ + + if (uart_used) { + + (void) NU_Create_Timer ( + &uart_sleep_timer, + "Sleep", + &analyze_uart_sleep_timer_expiration, + 0, /* Parameter supplied to the routine: not used. */ + WAKE_UP_TIME_IN_TDMA, + 0, /* The timer expires once. */ + NU_DISABLE_TIMER); + + /* + * If at least one uart is used by a Trace flow, create a HISR to reset + * and restart the sleep timer. + */ + + if (uart_used_for_trace) { + + /* + * The stack is entirely filled with the pattern 0xFE. + */ + + memset (&(timer_hisr_stack[0]), 0xFE, TIMER_HISR_STACK_SIZE); + + /* + * The HISR entry function is the same function than the one called + * by the Rx HISR of the UARTFAX, since the only aim is to reset + * and restart the sleep timer in case of incoming characters on + * the Trace UART. + */ + + (void) NU_Create_HISR ( + &timer_hisr_ctrl_block, + "Tim_HISR", + SER_restart_uart_sleep_timer, + TIMER_HISR_PRIORITY, + &(timer_hisr_stack[0]), + TIMER_HISR_STACK_SIZE); + } + } +} + + +/******************************************************************************* + * + * SER_WriteConfig + * + * Purpose: TBD + * + * Parameters: In : new_config: TBD + * write_to_flash: TBD + * Out: none + * + * Return: 0 (FALSE) : In case of error while trying to write file in FFS + * >= 1 (TRUE) : Successful operation. + * + ******************************************************************************/ + +SYS_BOOL +SER_WriteConfig (char *new_config, + SYS_BOOL write_to_flash) +{ +#if SERIAL_DYNAMIC_SWITCH + int uart_id; + SYS_BOOL status = 1; + + for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) + ser_new_cfg[uart_id] = *new_config++; + + /* + * Write in flash the new serial configuration if requested. + */ + + if (write_to_flash) { + if (ffs_fwrite (uart_config_file, + ser_new_cfg, + NUMBER_OF_TR_UART) < EFFS_OK) { + status = 0; + } + } + + return (status); +#else + /* + * Real Dynamic Switch is only available with Bluetooth AND all chips but + * Calypso+. + */ + + return (1); +#endif +} + +/******************************************************************************* + * + * SER_ImmediateSwitch + * + * Purpose: TBD + * + * Parameters: In : none + * Out: none + * + * Return: 0 (FALSE) : In case of error. + * >= 1 (TRUE) : Successful operation. + * + ******************************************************************************/ + +SYS_BOOL +SER_ImmediateSwitch (void) +{ +#if SERIAL_DYNAMIC_SWITCH + int uart_id; + SYS_BOOL valid_config = 0; + T_AppliSerialInfo *serial_info = &appli_ser_cfg_info; + SYS_UWORD8 nb_allowed_config = serial_info->num_config; + SYS_UWORD16 *allowed_config; + int flow; + T_SerialDriver serial_flows[SER_MAX_NUMBER_OF_FLOWS]; + T_tr_UartId uart_nb; + + /* + * First check if the new serial configuration is actually different from + * the previous one. A return is used to simplify the code. + */ + + if (!memcmp (ser_new_cfg, + ser_cfg_info, + NUMBER_OF_TR_UART)) + return (1); /* new config and old config are identical => nothing to do */ + + /* + * Then check if the new serial config is valid or not. + * At that point, we assume that a serial config is valid if and only if the + * Bluetooth HCI flow is still enabled and still uses the same UART. + * Reset the current serial config, and compute the new one. + */ + + serial_cfg = 0x0048; /* All dummies */ + for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { + + switch (ser_new_cfg[uart_id]) { + + case G23_PANEL: + serial_cfg = serial_cfg + + ((uart_id + 1) << (12 - (4 * SER_PROTOCOL_STACK))); + break; + + case RIVIERA_TRACE_MUX: + serial_cfg = serial_cfg + + ((uart_id + 1) << (12 - (4 * SER_LAYER_1))); + break; + + case FD_AT_COMMAND: + serial_cfg = serial_cfg + + ((uart_id + 1) << (12 - (4 * SER_FAX_DATA))); + break; + + case BLUETOOTH_HCI: + serial_cfg = serial_cfg + + ((uart_id + 1) << (12 - (4 * SER_BLUETOOTH_HCI))); + + /* + * Check if the Bluetooth HCI flow is enabled on the same UART. + */ + + if (ser_cfg_info[uart_id] == BLUETOOTH_HCI) + valid_config = 1; + + break; + + case DUMMY: + break; + } + } + + if (!valid_config) + return (0); /* Bluetooth HCI flow not enabled in the new serial config, + or enabled but using a different UART. */ + + /* + * Finally check if the new serial config is allowed by the application. + */ + + valid_config = 0; + while ((nb_allowed_config > 0) && !valid_config) { + + nb_allowed_config--; + allowed_config = (SYS_UWORD16 *) + &(serial_info->allowed_config[nb_allowed_config]); + + if (serial_cfg == *allowed_config) + valid_config = 1; + } + + if (!valid_config) /* the new config is not allowed by the application */ + return (0); + + /* + * From now on, Dynamic Switch is being processed. + */ + + dynamic_switch = 1; + + /* + * Disable UART interrupts until new serial config setup is complete. + */ + + #if ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11)) + IQ_Mask (IQ_UART_IRDA_IT); + #endif + IQ_Mask (IQ_UART_IT); + + /* + * Reset UARTs set-up. + */ + + for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { + + int_uart[uart_id].device_used = 0; + int_uart[uart_id].deep_sleep_set_up = 0; + int_uart[uart_id].interrupt_handler = NULL; + } + + /* + * All function pointers are set to dummy functions. + */ + + rvf_disable (21); /* beginning of the critical section */ + + for (flow = 0; flow < SER_MAX_NUMBER_OF_FLOWS; flow++) + tr_functions[flow] = &dummy_trace; + + fd_functions = &dummy_fax_data; + bt_functions = &dummy_bt_hci; + + rvf_enable (); /* end of the critical section */ + + /* + * Calls the Exit function of the UARTFAX driver if it was previously used. + */ + + if (uart_fd_initialized) { + + /* + * UART IrDA can't be used for F&D/AT-Cmd flow => UART Modem was used + * by the F&D/AT-Cmd flow. + */ + + if (UAF_Exit (UAF_UART_1) == FD_OK) { + uart_fd_initialized = 0; + } + } + else { + + /* + * AT that point, since the Bluetooth HCI flow already uses one UART, + * and since the second UART was not used by the F&D/AT-Cmd flow, we + * assume it was used by a Trace flow. Therefore, the HISR used to + * reset and restart the sleep timer is deleted. + */ + + (void) NU_Delete_HISR (&timer_hisr_ctrl_block); + } + + /* + * Initialization of the new flows (Only AT-Cmd/F&D or Riviera/Layer1 Trace) + * and their associated UARTs HW (Irda or Modem) & SW (Trace or Fax&Data). + */ + + for (flow = 0; flow < SER_MAX_NUMBER_OF_FLOWS; flow++) { + + serial_flows[flow] = (T_SerialDriver) + ((serial_cfg >> (12 - flow * 4)) & 0x000F); + + switch (serial_flows[flow]) { + + /* + * For Riviera/Layer1 Trace flow, default baudrate is 115200 bps + * and callback function is defined in rvt_def_i.h. + */ + + case UART_IRDA_TRACE: + case UART_MODEM_TRACE: + + if (serial_flows[flow] == UART_IRDA_TRACE) + uart_nb = UA_UART_0; + else /* if (serial_flows[flow] == UART_MODEM_TRACE) */ + uart_nb = UA_UART_1; + + if (flow == SER_LAYER_1) { + + UA_Init (uart_nb, + TR_BAUD_CONFIG, + rvt_activate_RX_HISR); + + /* + * Create the HISR used to reset and restart the sleep + * timer in case of incoming characters on the Trace flow. + * The stack is entirely filled with the pattern 0xFE. + */ + + memset (&(timer_hisr_stack[0]), + 0xFE, + TIMER_HISR_STACK_SIZE); + + (void) NU_Create_HISR ( + &timer_hisr_ctrl_block, + "Tim_HISR", + SER_restart_uart_sleep_timer, + TIMER_HISR_PRIORITY, + &(timer_hisr_stack[0]), + TIMER_HISR_STACK_SIZE); + } + else /* Other Trace flows are disabled */ + initialize_uart_sleep (uart_nb); + break; + + /* + * For At-Cmd/F&D flow, functions are called in the appropriate + * order with the saved parameters. + * This has been figured out from the G23 initialization. + */ + + case UART_MODEM_FAX_DATA: + + /* Global Initialization */ + if (UAF_Init (UAF_UART_1) == FD_OK) { + uart_fd_initialized = 1; + } + + /* Disable the driver */ + UAF_Enable (UAF_UART_1, + 0); + + /* Set the SW Buffers parameters */ + UAF_SetBuffer (UAF_UART_1, + data_flow_parameters.bufSize, + data_flow_parameters.rxThreshold, + data_flow_parameters.txThreshold); + + /* Set the Escape Sequence parameters (1st call) */ + UAF_SetEscape (UAF_UART_1, + data_flow_parameters.escChar[0], + data_flow_parameters.guardPeriod[0]); + + /* Set the Communication parameters (1st call) */ + UAF_SetComPar (UAF_UART_1, + data_flow_parameters.baudrate[0], + data_flow_parameters.bpc[0], + data_flow_parameters.sb[0], + data_flow_parameters.parity[0]); + + /* Set the Flow Control parameters (1st call) */ + UAF_SetFlowCtrl (UAF_UART_1, + data_flow_parameters.fcMode[0], + data_flow_parameters.XON[0], + data_flow_parameters.XOFF[0]); + + /* Set the Communication parameters (2nd call) */ + UAF_SetComPar (UAF_UART_1, + data_flow_parameters.baudrate[1], + data_flow_parameters.bpc[1], + data_flow_parameters.sb[1], + data_flow_parameters.parity[1]); + + /* Set the Flow Control parameters (2nd call) */ + UAF_SetFlowCtrl (UAF_UART_1, + data_flow_parameters.fcMode[1], + data_flow_parameters.XON[1], + data_flow_parameters.XOFF[1]); + + /* Set the Escape Sequence parameters (2nd call) */ + UAF_SetEscape (UAF_UART_1, + data_flow_parameters.escChar[1], + data_flow_parameters.guardPeriod[1]); + + /* Enable the driver */ + UAF_Enable (UAF_UART_1, + 1); + + /* Get the number of input bytes available */ + UAF_InpAvail (UAF_UART_1); + + /* Set the readOutFunc and the suspend mode */ + UAF_ReadData (UAF_UART_1, + data_flow_parameters.suspend_rd, + data_flow_parameters.readOutFunc); + + /* Get the number of output bytes available (1st call) */ + UAF_OutpAvail (UAF_UART_1); + + /* Set the states of the V.24 status lines (1st call) */ + UAF_SetLineState (UAF_UART_1, + data_flow_parameters.state[0], + data_flow_parameters.mask[0]); + + /* Set the states of the V.24 status lines (2nd call) */ + UAF_SetLineState (UAF_UART_1, + data_flow_parameters.state[1], + data_flow_parameters.mask[1]); + + /* Set the states of the V.24 status lines (3rd call) */ + UAF_SetLineState (UAF_UART_1, + data_flow_parameters.state[2], + data_flow_parameters.mask[2]); + + /* Set the states of the V.24 status lines (4th call) */ + UAF_SetLineState (UAF_UART_1, + data_flow_parameters.state[3], + data_flow_parameters.mask[3]); + + /* Set the writeInFunc and the suspend mode */ + UAF_WriteData (UAF_UART_1, + data_flow_parameters.suspend_wr, + data_flow_parameters.writeInFunc); + + /* Get the number of output bytes available (2nd call) */ + UAF_OutpAvail (UAF_UART_1); + + break; + + case UART_IRDA_BT_HCI: + case UART_MODEM_BT_HCI: + /* + * Nothing to initialize for Bluetooth HCI flow since it does + * use the same UART. + */ + + case DUMMY_TRACE: + case DUMMY_FAX_DATA: + case DUMMY_BT_HCI: + /* + * Of course nothing to perform for Dummy flows. + */ + + break; + } + } + + /* + * All function pointers are set to the appropriate functions set. + */ + + for (flow = 0; flow < SER_MAX_NUMBER_OF_FLOWS; flow++){ + + /* + * For Dummy flows, pointers to dummy functions are already set. + */ + + if ((serial_flows[flow] != DUMMY_TRACE) && + (serial_flows[flow] != DUMMY_FAX_DATA) && + (serial_flows[flow] != DUMMY_BT_HCI)) { + + rvf_disable (21); /* beginning of the critical section */ + set_flow_functions (flow, serial_flows[flow]); + rvf_enable (); /* end of the critical section */ + } + } + + /* + * Dynamic Switch has been processed. + * The new serial config is actually stored. + */ + + dynamic_switch = 0; + for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) + ser_cfg_info[uart_id] = ser_new_cfg[uart_id]; + + /* + * Re-enable UART interrupts. + */ + + #if ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11)) + IQ_Unmask (IQ_UART_IRDA_IT); + #endif + IQ_Unmask (IQ_UART_IT); + +#endif + /* + * Real Dynamic Switch is only available with Bluetooth AND all chips but + * Calypso+. + */ + + return (1); +} + +/******************************************************************************* + * + * All functions SER_tr_xxx and SER_fd_xxx call a function of the UART trace + * driver or the UART fax & data driver. + * All functions SER_bt_xxx call a function of the UART Bluetooth HCI driver. + * See the function call for parameters and return values. + * + ******************************************************************************/ + +void +SER_tr_Init (int serial_data_flow, + T_tr_Baudrate baudrate, + void (callback_function (void))) +{ + tr_functions[serial_data_flow]->tr_Init ( + tr_functions[serial_data_flow]->device, baudrate, callback_function); +} + +SYS_UWORD32 +SER_tr_ReadNChars (int serial_data_flow, + char *buffer, + SYS_UWORD32 chars_to_read) +{ + return (tr_functions[serial_data_flow]->tr_ReadNChars ( + tr_functions[serial_data_flow]->device, buffer, chars_to_read)); +} + +SYS_UWORD32 +SER_tr_ReadNBytes (int serial_data_flow, + char *buffer, + SYS_UWORD32 chars_to_read, + SYS_BOOL *eof_detected) +{ + return (tr_functions[serial_data_flow]->tr_ReadNBytes ( + tr_functions[serial_data_flow]->device, buffer, chars_to_read, eof_detected)); +} + +SYS_UWORD32 +SER_tr_WriteNChars (int serial_data_flow, + char *buffer, + SYS_UWORD32 chars_to_write) +{ + return (tr_functions[serial_data_flow]->tr_WriteNChars ( + tr_functions[serial_data_flow]->device, buffer, chars_to_write)); +} + +SYS_UWORD32 +SER_tr_EncapsulateNChars (int serial_data_flow, + char *buffer, + SYS_UWORD32 chars_to_write) +{ + return (tr_functions[serial_data_flow]->tr_EncapsulateNChars ( + tr_functions[serial_data_flow]->device, buffer, chars_to_write)); +} + +SYS_UWORD32 +SER_tr_WriteNBytes (int serial_data_flow, + SYS_UWORD8 *buffer, + SYS_UWORD32 chars_to_write) +{ + return (tr_functions[serial_data_flow]->tr_WriteNBytes ( + tr_functions[serial_data_flow]->device, buffer, chars_to_write)); +} + +void +SER_tr_WriteChar (int serial_data_flow, + char character) +{ + tr_functions[serial_data_flow]->tr_WriteChar ( + tr_functions[serial_data_flow]->device, character); +} + +void +SER_tr_WriteString (int serial_data_flow, + char *buffer) +{ + tr_functions[serial_data_flow]->tr_WriteString ( + tr_functions[serial_data_flow]->device, buffer); +} + +SYS_BOOL +SER_tr_EnterSleep (int serial_data_flow) +{ + return (tr_functions[serial_data_flow]->tr_EnterSleep ( + tr_functions[serial_data_flow]->device)); +} + +void +SER_tr_WakeUp (int serial_data_flow) +{ + tr_functions[serial_data_flow]->tr_WakeUp ( + tr_functions[serial_data_flow]->device); +} + +/* Dummy function for backward compatibility. */ +T_FDRET +SER_fd_Init (void) +{ + return (FD_OK); +} + +T_FDRET +SER_fd_Initialize (void) +{ + T_FDRET status; + + #if SERIAL_DYNAMIC_SWITCH + data_flow_parameters.bufSize = FD_MAX_BUFFER_SIZE; + #else + bufSize = FD_MAX_BUFFER_SIZE; + #endif + status = fd_functions->fd_Initialize (fd_functions->device); + + #if SERIAL_DYNAMIC_SWITCH + /* + * Check if the UARTFAX driver has actually been initialized. + */ + + if ((fd_functions->fd_Initialize == UAF_Init) && + (status = FD_OK)) { + + uart_fd_initialized = 1; + } + #endif + + return (status); +} + +T_FDRET +SER_fd_Enable (SYS_BOOL enable) +{ + return (fd_functions->fd_Enable (fd_functions->device, enable)); +} + +T_FDRET +SER_fd_SetComPar (T_baudrate baudrate, + T_bitsPerCharacter bpc, + T_stopBits sb, + T_parity parity) +{ + #if SERIAL_DYNAMIC_SWITCH + if (fd_UAF_SetComPar < 2) { + + /* + * Stores the parameters in order to be able to retrieve them in case of + * Dynamic Sitch. + */ + + data_flow_parameters.baudrate[fd_UAF_SetComPar] = baudrate; + data_flow_parameters.bpc[fd_UAF_SetComPar] = bpc; + data_flow_parameters.sb[fd_UAF_SetComPar] = sb; + data_flow_parameters.parity[fd_UAF_SetComPar] = parity; + + /* + * Number of calls to SER_fd_SetComPar. + */ + + fd_UAF_SetComPar++; + } + #endif + + return (fd_functions->fd_SetComPar ( + fd_functions->device, baudrate, bpc, sb, parity)); +} + +T_FDRET +SER_fd_SetBuffer (SYS_UWORD16 bufSize, + SYS_UWORD16 rxThreshold, + SYS_UWORD16 txThreshold) +{ + #if SERIAL_DYNAMIC_SWITCH + if (fd_UAF_SetBuffer < 1) { + + /* + * Stores the parameters in order to be able to retrieve them in case of + * Dynamic Sitch. + */ + + data_flow_parameters.bufSize = bufSize; + data_flow_parameters.rxThreshold = rxThreshold; + data_flow_parameters.txThreshold = txThreshold; + + /* + * Number of calls to SER_fd_SetBuffer. + */ + + fd_UAF_SetBuffer++; + } + #endif + + return (fd_functions->fd_SetBuffer ( + fd_functions->device, bufSize, rxThreshold, txThreshold)); +} + +T_FDRET +SER_fd_SetFlowCtrl (T_flowCtrlMode fcMode, + SYS_UWORD8 XON, + SYS_UWORD8 XOFF) +{ + #if SERIAL_DYNAMIC_SWITCH + if (fd_UAF_SetFlowCtrl < 2) { + + /* + * Stores the parameters in order to be able to retrieve them in case of + * Dynamic Sitch. + */ + + data_flow_parameters.fcMode[fd_UAF_SetFlowCtrl] = fcMode; + data_flow_parameters.XON[fd_UAF_SetFlowCtrl] = XON; + data_flow_parameters.XOFF[fd_UAF_SetFlowCtrl] = XOFF; + + /* + * Number of calls to SER_fd_SetFlowCtrl. + */ + + fd_UAF_SetFlowCtrl++; + } + #endif + + return (fd_functions->fd_SetFlowCtrl ( + fd_functions->device, fcMode, XON, XOFF)); +} + +T_FDRET +SER_fd_SetEscape (char escChar, + SYS_UWORD16 guardPeriod) +{ + #if SERIAL_DYNAMIC_SWITCH + if (fd_UAF_SetEscape < 2) { + + /* + * Stores the parameters in order to be able to retrieve them in case of + * Dynamic Sitch. + */ + + data_flow_parameters.escChar[fd_UAF_SetEscape] = escChar; + data_flow_parameters.guardPeriod[fd_UAF_SetEscape] = guardPeriod; + + /* + * Number of calls to SER_fd_SetEscape. + */ + + fd_UAF_SetEscape++; + } + #endif + + return (fd_functions->fd_SetEscape ( + fd_functions->device, escChar, guardPeriod)); +} + +T_FDRET +SER_fd_InpAvail (void) +{ + return (fd_functions->fd_InpAvail (fd_functions->device)); +} + +T_FDRET +SER_fd_OutpAvail (void) +{ + return (fd_functions->fd_OutpAvail (fd_functions->device)); +} + +T_FDRET +SER_fd_EnterSleep (void) +{ + return (fd_functions->fd_EnterSleep (fd_functions->device)); +} + +T_FDRET +SER_fd_WakeUp (void) +{ + return (fd_functions->fd_WakeUp (fd_functions->device)); +} + +T_FDRET +SER_fd_ReadData (T_suspendMode suspend, + void (readOutFunc (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 nsource, + SYS_UWORD8 *source[], + SYS_UWORD16 size[], + SYS_UWORD32 state))) +{ + #if SERIAL_DYNAMIC_SWITCH + if (fd_UAF_ReadData < 1) { + + /* + * Stores the parameters in order to be able to retrieve them in case of + * Dynamic Sitch. + */ + + data_flow_parameters.suspend_rd = suspend; + data_flow_parameters.readOutFunc = readOutFunc; + + /* + * Number of calls to SER_fd_ReadData. + */ + + fd_UAF_ReadData++; + } + #endif + + return (fd_functions->fd_ReadData ( + fd_functions->device, suspend, readOutFunc)); +} + +T_FDRET +SER_fd_WriteData (T_suspendMode suspend, + void (writeInFunc (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 ndest, + SYS_UWORD8 *dest[], + SYS_UWORD16 size[]))) +{ + #if SERIAL_DYNAMIC_SWITCH + if (fd_UAF_WriteData < 1) { + + /* + * Stores the parameters in order to be able to retrieve them in case of + * Dynamic Sitch. + */ + + data_flow_parameters.suspend_wr = suspend; + data_flow_parameters.writeInFunc = writeInFunc; + + /* + * Number of calls to SER_fd_WriteData. + */ + + fd_UAF_WriteData++; + } + #endif + + return (fd_functions->fd_WriteData ( + fd_functions->device, suspend, writeInFunc)); +} + +T_FDRET +SER_fd_StopRec (void) +{ + return (fd_functions->fd_StopRec (fd_functions->device)); +} + +T_FDRET +SER_fd_StartRec (void) +{ + return (fd_functions->fd_StartRec (fd_functions->device)); +} + +T_FDRET +SER_fd_GetLineState (SYS_UWORD32 *state) +{ + return (fd_functions->fd_GetLineState (fd_functions->device, state)); +} + +T_FDRET +SER_fd_SetLineState (SYS_UWORD32 state, + SYS_UWORD32 mask) +{ + #if SERIAL_DYNAMIC_SWITCH + if (fd_UAF_SetLineState < 4) { + + /* + * Stores the parameters in order to be able to retrieve them in case of + * Dynamic Sitch. + */ + + data_flow_parameters.state[fd_UAF_SetLineState] = state; + data_flow_parameters.mask[fd_UAF_SetLineState] = mask; + + /* + * Number of calls to SER_fd_SetLineState. + */ + + fd_UAF_SetLineState++; + } + #endif + + return (fd_functions->fd_SetLineState (fd_functions->device, state, mask)); +} + +T_FDRET +SER_fd_CheckXEmpty (void) +{ + return (fd_functions->fd_CheckXEmpty (fd_functions->device)); +} + +#ifdef BTEMOBILE +T_HCI_RET +SER_bt_Init (void) +{ + return (bt_functions->bt_Init (bt_functions->device)); +} + +T_HCI_RET +SER_bt_Start (void) +{ + return (bt_functions->bt_Start ()); +} + +T_HCI_RET +SER_bt_Stop (void) +{ + return (bt_functions->bt_Stop ()); +} + +T_HCI_RET +SER_bt_Kill (void) +{ + return (bt_functions->bt_Kill ()); +} + +T_HCI_RET +SER_bt_SetBaudrate (UINT8 baudrate) +{ + return (bt_functions->bt_SetBaudrate (baudrate)); +} + +T_HCI_RET SER_bt_TransmitPacket (void *uart_tx_buffer) +{ + return (bt_functions->bt_TransmitPacket (uart_tx_buffer)); +} + +SYS_BOOL SER_bt_EnterSleep (void) +{ + return (bt_functions->bt_EnterSleep()); +} + +void SER_bt_WakeUp (void) +{ + bt_functions->bt_WakeUp(); +} +#endif /* BTEMOBILE */ + +/******************************************************************************* + * + * SER_UartSleepStatus + * + * Purpose: This function checks if both UARTs are ready to enter Deep Sleep. + * + * Parameters: In : none + * Out: none + * + * Return: 0 : Deep Sleep is not possible. + * >= 1 : Deep Sleep is possible. + * + ******************************************************************************/ + +SYS_BOOL +SER_UartSleepStatus (void) +{ + t_uart *uart; + int uart_id; + SYS_BOOL status; + + /* + * Check first if the sleep timer is active or if a Dynamic Switch is + * being processed. A return is used to simplify the code. + */ + +#if SERIAL_DYNAMIC_SWITCH + if (uart_sleep_timer_enabled || dynamic_switch) +#else + if (uart_sleep_timer_enabled) +#endif + return (0); + + /* + * Check if both UARTs are ready to enter Deep Sleep. + */ + + status = 1; + uart_id = 0; + while ((uart_id < NUMBER_OF_TR_UART) && + (status)) { + + uart = &(int_uart[uart_id]); + + /* + * Check if the specified UART is actually used. + */ + + if (uart->device_used) { + + /* + * Check if the specified UART is used by a Trace or + * by a Fax & Data flow. + */ + + if (uart->flow_type == TRACE_FLOW) + status = SER_tr_EnterSleep (uart->flow_id); + + else + if (uart->flow_type == FAX_DATA_FLOW) + status = (SYS_BOOL) SER_fd_EnterSleep (); +#ifdef BTEMOBILE + else + if (uart->flow_type == BLUETOOTH_HCI_FLOW) + status = SER_bt_EnterSleep(); +#endif + else + status = 0; + + if (status) { + + /* + * The specified UART is now set up for Deep Sleep. + */ + + uart->deep_sleep_set_up = 1; + + } + } + + uart_id++; + } + + /* + * Check if Deep Sleep is finally possible. + * If not revert eventual Deep Sleep settings. + */ + + if (!status) { + + for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { + + uart = &(int_uart[uart_id]); + + /* + * If the specified used UART has already been set up for + * Deep Sleep, revert these settings. + */ + + if ((uart->device_used) && + (uart->deep_sleep_set_up)) { + + /* + * Check if the specified UART is used by a Trace or + * by a Fax & Data flow. + * Bluetooth HCI can not yet handled Deep Sleep Mode. + */ + + if (uart->flow_type == TRACE_FLOW) + SER_tr_WakeUp (uart->flow_id); + + else + if (uart->flow_type == FAX_DATA_FLOW) + SER_fd_WakeUp (); +#ifdef BTEMOBILE + else + if (uart->flow_type == BLUETOOTH_HCI_FLOW) + SER_bt_WakeUp (); +#endif + uart->deep_sleep_set_up = 0; + + } + } + } + + return (status); +} + + +/******************************************************************************* + * + * SER_WakeUpUarts + * + * Purpose: This function wakes up used UARTs after Deep Sleep. + * + * Parameters: In : none + * Out: none + * + * Return: none + * + ******************************************************************************/ + +void +SER_WakeUpUarts (void) +{ + t_uart *uart; + int uart_id; + + if (uart_sleep_timer_enabled) + start_uart_sleep_timer (); + + for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { + + uart = &(int_uart[uart_id]); + + /* + * Check if the specified UART is actually used, and has not yet + * been waked up. + */ + + if ((uart->device_used) && + (uart->deep_sleep_set_up)) { + + /* + * Check if the specified UART is used by a Trace or + * by a Fax & Data flow. + * Bluetooth HCI can not yet handled Deep Sleep Mode. + */ + + if (uart->flow_type == TRACE_FLOW) + SER_tr_WakeUp (uart->flow_id); + + else + if (uart->flow_type == FAX_DATA_FLOW) + SER_fd_WakeUp (); +#ifdef BTEMOBILE + else + if (uart->flow_type == BLUETOOTH_HCI_FLOW) + SER_bt_WakeUp (); +#endif + /* + * The specified UART is no more set up for Deep Sleep. + */ + + uart->deep_sleep_set_up = 0; + + } + } +} + + +/******************************************************************************* + * + * SER_restart_uart_sleep_timer + * + * Purpose : Resets and restarts the sleep timer each time some characters are + * received. + * + * Arguments: In : none + * Out: none + * + * Returns : none + * + ******************************************************************************/ + +void +SER_restart_uart_sleep_timer (void) +{ + /* + * First disable the timer. + */ + + (void) NU_Control_Timer (&uart_sleep_timer, + NU_DISABLE_TIMER); + + /* + * Then start again this timer for a new period. + */ + + start_uart_sleep_timer (); +} + + +/******************************************************************************* + * + * SER_activate_timer_hisr + * + * Purpose : Activates the timer HISR to reset and restart the sleep timer + * each time some characters are received. + * + * Arguments: In : none + * Out: none + * + * Returns : none + * + ******************************************************************************/ + +void +SER_activate_timer_hisr (void) +{ + (void) NU_Activate_HISR (&timer_hisr_ctrl_block); +} + + +#if ((CHIPSET == 2) || (CHIPSET == 3)) + +/******************************************************************************* + * + * SER_uart_handler + * + * Purpose : UART interrupt handler. + * + * Arguments: In : none + * Out: none + * + * Returns : none + * + ******************************************************************************/ + +void +SER_uart_handler (void) +{ + SYS_UWORD8 interrupt_status; + t_uart *uart; + int uart_id; + SYS_BOOL it_identified; + + it_identified = 0; + + /* + * Check first for a wake-up interrupt. + */ + + uart_id = 0; + while ((uart_id < NUMBER_OF_TR_UART) && + (!it_identified)) { + + uart = &(int_uart[uart_id]); + interrupt_status = READ_UART_REGISTER (uart, SSR); + + if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */ + + it_identified = 1; + uart_sleep_timer_enabled = 1; + DISABLE_WAKE_UP_INTERRUPT (uart); + } + + uart_id++; + } + + /* + * If no wake-up interrupt has been detected, check then systematically + * both UARTs for other interrupt causes. + */ + + if (!it_identified) { + + for (uart_id = 0; uart_id < NUMBER_OF_TR_UART; uart_id++) { + + uart = &(int_uart[uart_id]); + interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; + + if (!(interrupt_status & IT_NOT_PENDING)) { + + it_identified = 1; + (*(uart->interrupt_handler)) (uart_id, interrupt_status); + + } else { + + if ((uart_id == UA_UART_1) && (!it_identified)) + uart_spurious_interrupts++; + } + } + } +} + +#elif ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11) || (CHIPSET == 12)) + +/******************************************************************************* + * + * SER_uart_modem_handler + * + * Purpose : UART MODEM interrupt handler. + * + * Arguments: In : none + * Out: none + * + * Returns : none + * + ******************************************************************************/ + +void +SER_uart_modem_handler (void) +{ + SYS_UWORD8 interrupt_status; + t_uart *uart; + SYS_BOOL it_wakeup_identified; + + it_wakeup_identified = 0; + uart = &(int_uart[UA_UART_1]); + + /* + * Check first for a wake-up interrupt. + */ + + interrupt_status = READ_UART_REGISTER (uart, SSR); + + if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */ + + it_wakeup_identified = 1; + uart_sleep_timer_enabled = 1; +#ifdef BTEMOBILE + if (uart->flow_type == BLUETOOTH_HCI_FLOW) + { + interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; + (*(uart->interrupt_handler)) (UA_UART_1, interrupt_status); + } +#endif /* BTEMOBILE */ + DISABLE_WAKE_UP_INTERRUPT (uart); + } + + /* + * If no wake-up interrupt has been detected, check UART for other + * interrupt causes. + */ + + if (!it_wakeup_identified) { + + interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; + + if (!(interrupt_status & IT_NOT_PENDING)) + (*(uart->interrupt_handler)) (UA_UART_1, interrupt_status); + + else + uart_modem_spurious_interrupts++; + } +} + + +/******************************************************************************* + * + * SER_uart_irda_handler + * + * Purpose : UART IrDA interrupt handler. + * + * Arguments: In : none + * Out: none + * + * Returns : none + * + ******************************************************************************/ + +void +SER_uart_irda_handler (void) +{ + SYS_UWORD8 interrupt_status; + t_uart *uart; + SYS_BOOL it_wakeup_identified; + + it_wakeup_identified = 0; + uart = &(int_uart[UA_UART_0]); + + /* + * Check first for a wake-up interrupt. + */ + + interrupt_status = READ_UART_REGISTER (uart, SSR); + + if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */ + + it_wakeup_identified = 1; + uart_sleep_timer_enabled = 1; +#ifdef BTEMOBILE + if (uart->flow_type == BLUETOOTH_HCI_FLOW) + { + interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; + (*(uart->interrupt_handler)) (UA_UART_0, interrupt_status); + } +#endif /* BTEMOBILE */ + DISABLE_WAKE_UP_INTERRUPT (uart); + } + + /* + * If no wake-up interrupt has been detected, check UART for other + * interrupt causes. + */ + + if (!it_wakeup_identified) { + + interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; + + if (!(interrupt_status & IT_NOT_PENDING)) + (*(uart->interrupt_handler)) (UA_UART_0, interrupt_status); + + else + uart_irda_spurious_interrupts++; + } +} + +#endif + +#if (CHIPSET == 12) + /******************************************************************************* + * + * SER_uart_modem2_handler + * + * Purpose : UART IrDA interrupt handler. + * + * Arguments: In : none + * Out: none + * + * Returns : none + * + ******************************************************************************/ + + void + SER_uart_modem2_handler (void) + { + SYS_UWORD8 interrupt_status; + t_uart *uart; + SYS_BOOL it_wakeup_identified; + + it_wakeup_identified = 0; + uart = &(int_uart[UA_UART_2]); + + /* + * Check first for a wake-up interrupt. + */ + + interrupt_status = READ_UART_REGISTER (uart, SSR); + + if (interrupt_status & RX_CTS_WAKE_UP_STS) { /* Wake-up IT has occurred */ + + it_wakeup_identified = 1; + uart_sleep_timer_enabled = 1; +#ifdef BTEMOBILE + if (uart->flow_type == BLUETOOTH_HCI_FLOW) + { + interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; + (*(uart->interrupt_handler)) (UA_UART_2, interrupt_status); + } +#endif /* BTEMOBILE */ + DISABLE_WAKE_UP_INTERRUPT (uart); + } + + /* + * If no wake-up interrupt has been detected, check UART for other + * interrupt causes. + */ + + if (!it_wakeup_identified) { + + interrupt_status = READ_UART_REGISTER (uart, IIR) & IIR_BITS_USED; + + if (!(interrupt_status & IT_NOT_PENDING)) + (*(uart->interrupt_handler)) (UA_UART_2, interrupt_status); + + else + uart_modem2_spurious_interrupts++; + } + } + +#endif + +/* + * Temporary functions. + * + * FreeCalypso note: I'll put them back in if they are actually needed. + */ + +#if 0 + +void +UT_Init (int device_id, + int baudrate, + void (callback_function (void))) +{ + SER_tr_Init (SER_PROTOCOL_STACK, baudrate, callback_function); +} + +SYS_UWORD32 +UT_ReadNChars (int device_id, + char *buffer, + SYS_UWORD32 chars_to_read) +{ + return (SER_tr_ReadNChars (SER_PROTOCOL_STACK, buffer, chars_to_read)); +} + +SYS_UWORD32 +UT_WriteNChars (int device_id, + char *buffer, + SYS_UWORD32 chars_to_write) +{ + return (SER_tr_WriteNChars (SER_PROTOCOL_STACK, buffer, chars_to_write)); +} + +void +UT_WriteChar (int device_id, + char character) +{ + SER_tr_WriteChar (SER_PROTOCOL_STACK, character); +} + +void +UT_WriteString (int device_id, + char *buffer) +{ + SER_tr_WriteString (SER_PROTOCOL_STACK, buffer); +} + +short +UF_Init (SYS_UWORD8 deviceNo) +{ + return (SER_fd_Init ()); +} + +short +UF_Enable (SYS_UWORD8 deviceNo, + SYS_BOOL enable) +{ + return (SER_fd_Enable (enable)); +} + +short +UF_SetComPar (SYS_UWORD8 deviceNo, + T_baudrate baudrate, + T_bitsPerCharacter bpc, + T_stopBits sb, + T_parity parity) +{ + return (SER_fd_SetComPar (baudrate, + bpc, + sb, + parity)); +} + +short +UF_SetBuffer (SYS_UWORD8 deviceNo, + SYS_UWORD16 bufSize, + SYS_UWORD16 rxThreshold, + SYS_UWORD16 txThreshold) +{ + return (SER_fd_SetBuffer (bufSize, rxThreshold, txThreshold)); +} + +short +UF_SetFlowCtrl (SYS_UWORD8 deviceNo, + T_flowCtrlMode fcMode, + SYS_UWORD8 XON, + SYS_UWORD8 XOFF) +{ + return (SER_fd_SetFlowCtrl (fcMode, XON, XOFF)); +} + +short +UF_SetEscape (SYS_UWORD8 deviceNo, + SYS_UWORD8 escChar, + SYS_UWORD16 guardPeriod) +{ + return (SER_fd_SetEscape (escChar, guardPeriod)); +} + +short +UF_InpAvail (SYS_UWORD8 deviceNo) +{ + return (SER_fd_InpAvail ()); +} + +short +UF_OutpAvail (SYS_UWORD8 deviceNo) +{ + return (SER_fd_OutpAvail ()); +} + +short +UF_ReadData (SYS_UWORD8 deviceNo, + T_suspendMode suspend, + void (readOutFunc (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 nsource, + SYS_UWORD8 *source[], + SYS_UWORD16 size[], + SYS_UWORD32 state))) +{ + return (SER_fd_ReadData (suspend, readOutFunc)); +} + +short +UF_WriteData (SYS_UWORD8 deviceNo, + T_suspendMode suspend, + void (writeInFunc (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 ndest, + SYS_UWORD8 *dest[], + SYS_UWORD16 size[]))) +{ + return (SER_fd_WriteData (suspend, writeInFunc)); +} + +short +UF_StopRec (SYS_UWORD8 deviceNo) +{ + return (SER_fd_StopRec ()); +} + +short +UF_StartRec (SYS_UWORD8 deviceNo) +{ + return (SER_fd_StartRec ()); +} + +short +UF_GetLineState (SYS_UWORD8 deviceNo, + SYS_UWORD32 *state) +{ + return (SER_fd_GetLineState (state)); +} + +short +UF_SetLineState (SYS_UWORD8 deviceNo, + SYS_UWORD32 state, + SYS_UWORD32 mask) +{ + return (SER_fd_SetLineState (state, mask)); +} + +short +UF_CheckXEmpty (SYS_UWORD8 deviceNo) +{ + return (SER_fd_CheckXEmpty ()); +} +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nuc-fw/serial/serialswitch.h Mon Oct 28 06:49:44 2013 +0000 @@ -0,0 +1,430 @@ +/******************************************************************************* + * + * SERIALSWITCH.H + * + * This module allows managing the use of the serial ports of TI GSM Evaluation + * Boards. + * An application may have to send several serial data flows. The board on which + * the application is running may have one or several devices. The purpose of + * this module is to establish connections between the serial data flows and the + * serial devices at runtime, when the application is started. + * + * (C) Texas Instruments 1999 - 2003 + * + ******************************************************************************/ + +#ifndef __SERIALSWITCH_H__ +#define __SERIALSWITCH_H__ + +#include "traceswitch.h" +#include "faxdata.h" + +#ifndef C_EXTERN + #if 1 //(OP_L1_STANDALONE) + #define C_EXTERN extern + #else + #define C_EXTERN + #endif +#endif + +/* + * Constants used to identify the serial data flows. + */ + +#define SER_FLOW_1 (0) +#define SER_FLOW_2 (1) +#define SER_FLOW_3 (2) +#define SER_FLOW_4 (3) + +#define SER_PROTOCOL_STACK (SER_FLOW_1) +#define SER_LAYER_1 (SER_FLOW_2) +#define SER_FAX_DATA (SER_FLOW_3) +#define SER_BLUETOOTH_HCI (SER_FLOW_4) + +#define SER_HWTEST (SER_FLOW_1) +#define SER_SERIAL_TEST_1 (SER_FLOW_3) + + +#define SER_MAX_NUMBER_OF_FLOWS (4) + +#define SER_MAX_NUMBER_OF_CFG (16) + +/* + * Type used to define the various drivers configuration + * available, according to the UART devices. + */ + +typedef enum { + /* Trace Flow */ + DUMMY_TRACE, /* = 0 */ + UART_IRDA_TRACE, /* = 1 */ + UART_MODEM_TRACE, /* = 2 */ + #if (CHIPSET == 12) + UART_MODEM2_TRACE, /* = 3 */ + #endif + /* AT-Commands/Fax & Data Flow */ + DUMMY_FAX_DATA = 4, /* = 4 */ + /* UART IrDA F&D Driver, not supported - should be = 5 */ + UART_MODEM_FAX_DATA = 6, /* = 6 */ + #if (CHIPSET == 12) + /* UART Modem2 F&D Driver, not supported - should be = 7 */ + #endif + /* Bluetooth HCI Flow */ + DUMMY_BT_HCI = 8, /* = 8 */ + UART_IRDA_BT_HCI, /* = 9 */ + UART_MODEM_BT_HCI /* = A */ + #if (CHIPSET == 12) + , UART_MODEM2_BT_HCI /* = B */ + #endif +} T_SerialDriver; + +/* + * Type used to describe a defined serial configuration; + * Each field is a 4 bits field representing one serial flow. + * + * T_DefinedSerialConfig : [ flow_1 | flow_2 | flow_3 | flow_4 ] + * 15 12 11 8 7 4 3 0 + */ + +typedef struct { + + unsigned int flow_4 :4; + unsigned int flow_3 :4; + unsigned int flow_2 :4; + unsigned int flow_1 :4; + +} T_DefinedSerialConfig; + + +/* + * Type used to describe all serial configuration informations + * of a defined application: + * - the default configuration to set up, if the current one is + * not valid, + * - the number of allowed serial configurations, + * - the entire allowed serial configurations. + */ + +typedef struct { + + T_DefinedSerialConfig default_config; + SYS_UWORD8 num_config; + T_DefinedSerialConfig allowed_config[SER_MAX_NUMBER_OF_CFG]; + +} T_AppliSerialInfo; + + +/* + * Functions prototypes. + */ + +#if (DP==1) + void SER_InitSerialConfig (int application_id); +#else + C_EXTERN void SER_InitSerialConfig (T_AppliSerialInfo *serial_info); +#endif //DP + +C_EXTERN SYS_BOOL SER_UartSleepStatus (void); + +C_EXTERN void SER_WakeUpUarts (void); + +void SER_restart_uart_sleep_timer (void); + +void SER_activate_timer_hisr (void); + +#if (DP==1) + void SER_tr_Init (int serial_data_flow, + int baudrate, + void (callback_function (void))); +#else + C_EXTERN void SER_tr_Init (int serial_data_flow, + T_tr_Baudrate baudrate, + void (callback_function (void))); +#endif //DP + +C_EXTERN SYS_UWORD32 SER_tr_ReadNChars (int serial_data_flow, + char *buffer, + SYS_UWORD32 chars_to_read); + +C_EXTERN SYS_UWORD32 SER_tr_ReadNBytes (int serial_data_flow, + char *buffer, + SYS_UWORD32 chars_to_read, + SYS_BOOL *eof_detected); + +C_EXTERN SYS_UWORD32 SER_tr_WriteNChars (int serial_data_flow, + char *buffer, + SYS_UWORD32 chars_to_write); + +C_EXTERN SYS_UWORD32 SER_tr_EncapsulateNChars (int serial_data_flow, + char *buffer, + SYS_UWORD32 chars_to_write); + +C_EXTERN SYS_UWORD32 SER_tr_WriteNBytes (int serial_data_flow, + SYS_UWORD8 *buffer, + SYS_UWORD32 chars_to_write); + +C_EXTERN void SER_tr_WriteChar (int serial_data_flow, + char character); + +C_EXTERN SYS_BOOL SER_tr_EnterSleep (int serial_data_flow); + +C_EXTERN void SER_tr_WakeUp (int serial_data_flow); + +C_EXTERN void SER_tr_WriteString (int serial_data_flow, + char *buffer); + +#define T_UFRET T_FDRET + +#define UF_DEVICE_0 (0) + +#define UF_OK FD_OK +#define UF_SUSPENDED FD_SUSPENDED +#define UF_NOT_SUPPORTED FD_NOT_SUPPORTED +#define UF_NOT_READY FD_NOT_READY +#define UF_INTERNAL_ERROR FD_INTERNAL_ERR + +#define UF_LINE_ON FD_LINE_ON +#define UF_LINE_OFF FD_LINE_OFF + +#define UF_MAX_BUFFER_SIZE FD_MAX_BUFFER_SIZE + +#define UF_BAUD_AUTO FD_BAUD_AUTO +#define UF_BAUD_75 FD_BAUD_75 +#define UF_BAUD_150 FD_BAUD_150 +#define UF_BAUD_300 FD_BAUD_300 +#define UF_BAUD_600 FD_BAUD_600 +#define UF_BAUD_1200 FD_BAUD_1200 +#define UF_BAUD_2400 FD_BAUD_2400 +#define UF_BAUD_4800 FD_BAUD_4800 +#define UF_BAUD_7200 FD_BAUD_7200 +#define UF_BAUD_9600 FD_BAUD_9600 +#define UF_BAUD_14400 FD_BAUD_14400 +#define UF_BAUD_19200 FD_BAUD_19200 +#define UF_BAUD_28800 FD_BAUD_28800 +#define UF_BAUD_33900 FD_BAUD_33900 +#define UF_BAUD_38400 FD_BAUD_38400 +#define UF_BAUD_57600 FD_BAUD_57600 +#define UF_BAUD_115200 FD_BAUD_115200 +#define UF_BAUD_203125 FD_BAUD_203125 +#define UF_BAUD_406250 FD_BAUD_406250 +#define UF_BAUD_812500 FD_BAUD_812500 + +C_EXTERN T_FDRET SER_fd_Init (void); + +#if (DP==0) + C_EXTERN T_FDRET SER_fd_Initialize (void); +#endif + +C_EXTERN T_FDRET SER_fd_Enable (SYS_BOOL enable); + +C_EXTERN T_FDRET SER_fd_SetComPar (T_baudrate baudrate, + T_bitsPerCharacter bpc, + T_stopBits sb, + T_parity parity); + +C_EXTERN T_FDRET SER_fd_SetBuffer (SYS_UWORD16 bufSize, + SYS_UWORD16 rxThreshold, + SYS_UWORD16 txThreshold); + +C_EXTERN T_FDRET SER_fd_SetFlowCtrl (T_flowCtrlMode fcMode, + SYS_UWORD8 XON, + SYS_UWORD8 XOFF); + +C_EXTERN T_FDRET SER_fd_SetEscape (char escChar, + SYS_UWORD16 guardPeriod); + +C_EXTERN T_FDRET SER_fd_InpAvail (void); + +C_EXTERN T_FDRET SER_fd_OutpAvail (void); + +C_EXTERN T_FDRET SER_fd_EnterSleep (void); + +C_EXTERN T_FDRET SER_fd_WakeUp (void); + +C_EXTERN T_FDRET SER_fd_ReadData (T_suspendMode suspend, + void (readOutFunc (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 nsource, + SYS_UWORD8 *source[], + SYS_UWORD16 size[], + SYS_UWORD32 state))); + +C_EXTERN T_FDRET SER_fd_WriteData (T_suspendMode suspend, + void (writeInFunc (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 ndest, + SYS_UWORD8 *dest[], + SYS_UWORD16 size[]))); + +C_EXTERN T_FDRET SER_fd_StopRec (void); + +C_EXTERN T_FDRET SER_fd_StartRec (void); + +C_EXTERN T_FDRET SER_fd_GetLineState (SYS_UWORD32 *state); + +C_EXTERN T_FDRET SER_fd_SetLineState (SYS_UWORD32 state, + SYS_UWORD32 mask); + +#if (DP==0) + C_EXTERN T_FDRET SER_fd_CheckXEmpty (void); +#endif + +#ifdef BTEMOBILE + C_EXTERN T_HCI_RET SER_bt_Init (void); + + C_EXTERN T_HCI_RET SER_bt_Start (void); + + C_EXTERN T_HCI_RET SER_bt_Stop (void); + + C_EXTERN T_HCI_RET SER_bt_Kill (void); + + C_EXTERN T_HCI_RET SER_bt_SetBaudrate (UINT8 baudrate); + + C_EXTERN T_HCI_RET SER_bt_TransmitPacket (void *uart_sco_tx_buffer); + + C_EXTERN SYS_BOOL SER_bt_EnterSleep (void); + + C_EXTERN void SER_bt_WakeUp (void); +#endif + +#if ((CHIPSET == 2) || (CHIPSET == 3)) + C_EXTERN void SER_uart_handler (void); +#elif ((CHIPSET == 4) || (CHIPSET == 5) || (CHIPSET == 6) || (CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 9) || (CHIPSET == 10) || (CHIPSET == 11) || (CHIPSET == 12)) + C_EXTERN void SER_uart_modem_handler (void); + C_EXTERN void SER_uart_irda_handler (void); +#endif +#if (CHIPSET == 12) + C_EXTERN void SER_uart_modem2_handler (void); +#endif + +#if (DP==1) + T_FDRET UF_Init (int serial_data_flow); + T_FDRET UF_Enable (int serial_data_flow, + SYS_BOOL enable); + T_FDRET UF_SetComPar (int serial_data_flow, + T_baudrate baudrate, + T_bitsPerCharacter bpc, + T_stopBits sb, + T_parity parity); + T_FDRET UF_SetBuffer (int serial_data_flow, + SYS_UWORD16 bufSize, + SYS_UWORD16 rxThreshold, + SYS_UWORD16 txThreshold); + T_FDRET UF_SetFlowCtrl (int serial_data_flow, + T_flowCtrlMode fcMode, + SYS_UWORD8 XON, + SYS_UWORD8 XOFF); + T_FDRET UF_SetEscape (int serial_data_flow, + char escChar, + SYS_UWORD16 guardPeriod); + T_FDRET UF_InpAvail (int serial_data_flow); + T_FDRET UF_OutpAvail (int serial_data_flow); + T_FDRET UF_ReadData (int serial_data_flow, + T_suspendMode suspend, + void (readOutFunc (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 nsource, + SYS_UWORD8 *source[], + SYS_UWORD16 size[], + SYS_UWORD32 state))); + T_FDRET UF_WriteData (int uartNo, + T_suspendMode suspend, + void (writeInFunc (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 ndest, + SYS_UWORD8 *dest[], + SYS_UWORD16 size[]))); + T_FDRET UF_StopRec (int serial_data_flow); + T_FDRET UF_StartRec (int serial_data_flow); + T_FDRET UF_GetLineState (int serial_data_flow, + SYS_UWORD32 *state); + T_FDRET UF_SetLineState (int serial_data_flow, + SYS_UWORD32 state, + SYS_UWORD32 mask); + T_FDRET UF_CheckXEmpty (int serial_data_flow); + T_FDRET UF_EnterSleep (int serial_data_flow); + T_FDRET UF_WakeUp (int serial_data_flow); +#endif //DP + +/* + * Functions used for Dynamic Switch. + */ + +SYS_BOOL SER_WriteConfig (char *new_config, + SYS_BOOL write_to_flash); + +SYS_BOOL SER_ImmediateSwitch (void); + +/* + * Constants and macros used by Condat. + * Condat uses a serial device for the protocol stack trace. + */ + +#ifndef __SERIALSWITCH_C__ + +#define UT_DEVICE_0 (0) + +#define UT_BAUD_406250 TR_BAUD_406250 +#define UT_BAUD_115200 TR_BAUD_115200 +#define UT_BAUD_57600 TR_BAUD_57600 +#define UT_BAUD_38400 TR_BAUD_38400 +#define UT_BAUD_33900 TR_BAUD_33900 +#define UT_BAUD_28800 TR_BAUD_28800 +#define UT_BAUD_19200 TR_BAUD_19200 +#define UT_BAUD_14400 TR_BAUD_14400 +#define UT_BAUD_9600 TR_BAUD_9600 +#define UT_BAUD_4800 TR_BAUD_4800 +#define UT_BAUD_2400 TR_BAUD_2400 +#define UT_BAUD_1200 TR_BAUD_1200 +#define UT_BAUD_600 TR_BAUD_600 +#define UT_BAUD_300 TR_BAUD_300 +#define UT_BAUD_150 TR_BAUD_150 +#define UT_BAUD_75 TR_BAUD_75 + +#define UT_Init(A,B,C) SER_tr_Init (SER_PROTOCOL_STACK, B, C) + +#define UT_ReadNChars(A,B,C) SER_tr_ReadNChars (SER_PROTOCOL_STACK, B, C) + +#define UT_WriteNChars(A,B,C) SER_tr_WriteNChars (SER_PROTOCOL_STACK, B, C) + +#define UT_WriteChar(A,B) SER_tr_WriteChar (SER_PROTOCOL_STACK, B) + +#define UT_WriteString(A,B) SER_tr_WriteString (SER_PROTOCOL_STACK, B) + +#if (DP==0) + #define UF_Init(A) SER_fd_Init () + + #define UF_Enable(A,B) SER_fd_Enable (B) + + #define UF_SetComPar(A,B,C,D,E) SER_fd_SetComPar (B, C, D, E) + + #define UF_SetBuffer(A,B,C,D) SER_fd_SetBuffer (B, C, D) + + #define UF_SetFlowCtrl(A,B,C,D) SER_fd_SetFlowCtrl (B, C, D) + + #define UF_SetEscape(A,B,C) SER_fd_SetEscape (B, C) + + #define UF_InpAvail(A) SER_fd_InpAvail () + + #define UF_OutpAvail(A) SER_fd_OutpAvail () + + #define UF_ReadData(A,B,C) SER_fd_ReadData (B, C) + + #define UF_WriteData(A,B,C) SER_fd_WriteData (B, C) + + #define UF_StopRec(A) SER_fd_StopRec() + + #define UF_StartRec(A) SER_fd_StartRec () + + #define UF_GetLineState(A,B) SER_fd_GetLineState (B) + + #define UF_SetLineState(A,B,C) SER_fd_SetLineState (B, C) + + #define UF_CheckXEmpty(A) SER_fd_CheckXEmpty () +#endif //DP + +#endif /* __SERIALSWITCH_C__ */ + +#undef C_EXTERN + +#endif /* __SERIALSWITCH_H__ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nuc-fw/serial/traceswitch.h Mon Oct 28 06:49:44 2013 +0000 @@ -0,0 +1,33 @@ +/******************************************************************************* + * + * TRACESWITCH.H + * + * This module defines constants used by UART and USART trace drivers. + * + * (C) Texas Instruments 1999 + * + ******************************************************************************/ + +#ifndef __TRACESWITCH_H__ +#define __TRACESWITCH_H__ + +typedef enum { + TR_BAUD_406250, + TR_BAUD_115200, + TR_BAUD_57600, + TR_BAUD_38400, + TR_BAUD_33900, + TR_BAUD_28800, + TR_BAUD_19200, + TR_BAUD_14400, + TR_BAUD_9600, + TR_BAUD_4800, + TR_BAUD_2400, + TR_BAUD_1200, + TR_BAUD_600, + TR_BAUD_300, + TR_BAUD_150, + TR_BAUD_75 +} T_tr_Baudrate; + +#endif /* __TRACESWITCH_H__ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nuc-fw/serial/uart.c Mon Oct 28 06:49:44 2013 +0000 @@ -0,0 +1,1488 @@ +/******************************************************************************* + * + * UART.C + * + * This module allows to use the UARTs of chipset 1.5 in interrupt mode for + * the Receive side and in polling mode for the Transmit side. + * The driver calls a user's function when characters are received. + * + * (C) Texas Instruments 1999 + * + ******************************************************************************/ + +#include "../include/config.h" +#include "../include/sys_types.h" + +#include "serialswitch.h" +#include "uart.h" + +#include <string.h> + +#include "../bsp/mem.h" + +#if (BOARD != 34) +/* + * Needed to reset and restart the sleep timer in case of incoming characters. + */ + +extern SYS_BOOL uart_sleep_timer_enabled; +#endif + +#define BUFFER_SIZE (512) /* In bytes. */ +#define FIFO_SIZE (64) /* In bytes. */ + +#define STX 0x02 +#define DLE 0x10 + +/* + * TLR is used to program the RX FIFO trigger levels. FCR[7:4] are not used. + */ + +#define RX_FIFO_TRIGGER_LEVEL (12 << 4) + + +/* + * 16750 addresses. Registers accessed when LCR[7] = 0. + */ + +#define RHR (0x00) /* Rx buffer register - Read access */ +#define THR (0x00) /* Tx holding register - Write access */ +#define IER (0x01) /* Interrupt enable register */ + +/* + * 16750 addresses. Registers accessed when LCR[7] = 1. + */ + +#define DLL (0x00) /* Divisor latch (LSB) */ +#define DLM (0x01) /* Divisor latch (MSB) */ + + +/* + * EFR is accessed when LCR[7:0] = 0xBF. + */ + +#define EFR (0x02) /* Enhanced feature register */ + + +/* + * 16750 addresses. Bit 5 of the FCR register is accessed when LCR[7] = 1. + */ + +#define IIR (0x02) /* Interrupt ident. register - Read only */ +#define FCR (0x02) /* FIFO control register - Write only */ +#define LCR (0x03) /* Line control register */ +#define MCR (0x04) /* Modem control register */ +#define LSR (0x05) /* Line status register */ +#define MSR (0x06) /* Modem status register */ +#define TCR (0x06) /* Transmission control register */ +#define TLR (0x07) /* Trigger level register */ +#define MDR1 (0x08) /* Mode definition register 1 */ +#define SCR (0x10) /* Supplementary Control register */ +#define SSR (0x11) /* Supplementary Status register */ + + +/* + * Supplementary control register. + */ + +#define TX_EMPTY_CTL_IT (0x08) +#define RX_CTS_WAKE_UP_ENABLE_BIT (4) /* Use RESET_BIT and SET_BIT macros. */ + +/* + * Enhanced feature register. + */ + +#define ENHANCED_FEATURE_BIT (4) /* Use RESET_BIT and SET_BIT macros. */ + +/* + * Mode definition register 1. + */ + +#define UART_MODE (0x00) +#define SIR_MODE (0x01) +#define UART_MODE_AUTOBAUDING (0x02) /* Reserved in UART/IrDA. */ +#define RESET_DEFAULT_STATE (0x07) +#define IR_SLEEP_DISABLED (0x00) +#define IR_SLEEP_ENABLED (0x08) +#define SIR_TX_WITHOUT_ACREG2 (0x00) /* Reserved in UART/modem. */ +#define SIR_TX_WITH_ACREG2 (0x20) /* Reserved in UART/modem. */ +#define FRAME_LENGTH_METHOD (0x00) /* Reserved in UART/modem. */ +#define EOT_BIT_METHOD (0x80) /* Reserved in UART/modem. */ + +/* + * Supplementary Status Register + */ + +#define TX_FIFO_FULL (0x01) + + +/* + * Interrupt enable register. + */ + +#define ERBI (0x01) /* Enable received data available interrupt */ +#define ETBEI (0x02) /* Enable transmitter holding register empty interrupt */ +#define ELSI (0x04) /* Enable receiver line status interrupt */ +#define EDSSI (0x08) /* Enable modem status interrupt */ +#define IER_SLEEP (0x10) /* Enable sleep mode */ + +/* + * Modem control register. + */ + +#define MDTR (0x01) /* Data terminal ready. */ +#define MRTS (0x02) /* Request to send. */ +#define TCR_TLR_BIT (6) + +/* + * Line status register. + */ + +#define DR (0x01) /* Data ready */ +#define OE (0x02) /* Overrun error */ +#define PE (0x04) /* Parity error */ +#define FE (0x08) /* Framing error */ +#define BI (0x10) /* Break interrupt */ +#define THRE (0x20) /* Transmitter holding register (FIFO empty) */ +#define TEMT (0x40) /* Transmitter empty (FIFO and TSR both empty) */ + +/* + * Interrupt identification register. + * Bit 0 is set to 0 if an IT is pending. + * Bits 1 and 2 are used to identify the IT. + */ + +#define IIR_BITS_USED (0x07) +#define IT_NOT_PENDING (0x01) +#define RX_DATA (0x04) +#define TX_EMPTY (0x02) +#define MODEM_STATUS (0x00) + +/* + * Line control register. + */ + +#define WLS_5 (0x00) /* Word length: 5 bits */ +#define WLS_6 (0x01) /* Word length: 6 bits */ +#define WLS_7 (0x02) /* Word length: 7 bits */ +#define WLS_8 (0x03) /* Word length: 8 bits */ +#define STB (0x04) /* Number of stop bits: 0: 1, 1: 1,5 or 2 */ +#define PEN (0x08) /* Parity enable */ +#define EPS (0x10) /* Even parity select */ +#define BREAK_CONTROL (0x40) /* Enable a break condition */ +#define DLAB (0x80) /* Divisor latch access bit */ +#define DIV_EN_BIT (7) + +/* + * FIFO control register. + */ + +#define FIFO_ENABLE (0x01) +#define RX_FIFO_RESET (0x02) +#define TX_FIFO_RESET (0x04) + +/* + * These macros allow to read and write a UART register. + */ + +#define READ_UART_REGISTER(UART,REG) \ + *((volatile SYS_UWORD8 *) ((UART)->base_address + (REG))) + +#define WRITE_UART_REGISTER(UART,REG,VALUE) \ + *((volatile SYS_UWORD8 *) ((UART)->base_address + (REG))) = (VALUE) + +#define RESET_BIT(UART,REG,BIT) \ + (WRITE_UART_REGISTER ( \ + UART, REG, READ_UART_REGISTER (UART, REG) & ~(1 << (BIT)))) + +#define SET_BIT(UART,REG,BIT) \ + (WRITE_UART_REGISTER ( \ + UART, REG, READ_UART_REGISTER (UART, REG) | (1 << (BIT)))) + +/* + * These macros allow to enable or disable the wake-up interrupt. + */ + +#define ENABLE_WAKEUP_INTERRUPT(UART) \ + SET_BIT(UART, SCR, RX_CTS_WAKE_UP_ENABLE_BIT); + +#define DISABLE_WAKEUP_INTERRUPT(UART) \ + RESET_BIT(UART, SCR, RX_CTS_WAKE_UP_ENABLE_BIT); + + +/* + * This macro allows to know if the RX buffer is full. It must be called only + * from the RX interrupt handler. If it is called from the application, the + * rx_in pointer may be updated if a RX interrupt occurs. + */ + +#define RX_BUFFER_FULL(UART) \ + (((UART)->rx_in == (UART)->rx_out - 1) || \ + ((UART)->rx_in == (UART)->rx_out + BUFFER_SIZE - 1)) + + +/* + * This allows monitor the last 32 inbound buffers gotten from the RX FIFO. + */ + +//#define UART_RX_BUFFER_DUMP + +#ifdef UART_RX_BUFFER_DUMP +struct { + char rx_buffer[(BUFFER_SIZE + 1) << 5]; + char *rx_in; + int errors_count; + int wrong_interrupt_status; +} uart_rx_buffer_dump = {0}; +#endif + + +typedef struct s_uart { + + SYS_UWORD32 base_address; + + /* + * Buffers management. + */ + + char rx_buffer[BUFFER_SIZE + 1]; + char *rx_in; + char *rx_out; + void (*callback_function) (void); + + /* + * Errors counters. + */ + + SYS_UWORD32 framing_error; + SYS_UWORD32 parity_error; + SYS_UWORD32 overrun_error; + + /* + * Framing flags. + */ + + SYS_BOOL dle_detected; + SYS_BOOL inframe; + SYS_BOOL encapsulation_flag; + unsigned char frame_length; + +} t_uart; + +static t_uart uart_parameter[NUMBER_OF_TR_UART]; + +static const SYS_UWORD32 base_address[NUMBER_OF_TR_UART] = +{ + MEM_UART_IRDA, + MEM_UART_MODEM + #if (CHIPSET == 12) + , MEM_UART_MODEM2 + #endif +}; + + +/* + * DLL (LSB) and DLH (MSB) registers values using the 13 MHz clock. + */ + +static const SYS_UWORD8 dll[] = +{ + 2, /* 406250 baud. */ + 7, /* 115200 baud. */ + 14, /* 57600 baud. */ + 21, /* 38400 baud. */ + 24, /* 33900 baud. */ + 28, /* 28800 baud. */ + 42, /* 19200 baud. */ + 56, /* 14400 baud. */ + 84, /* 9600 baud. */ + 169, /* 4800 baud. */ + 83, /* 2400 baud. */ + 165, /* 1200 baud. */ + 74, /* 600 baud. */ + 148, /* 300 baud. */ + 40, /* 150 baud. */ + 81 /* 75 baud. */ +}; + +static const SYS_UWORD8 dlh[] = +{ + 0, /* 406250 baud. */ + 0, /* 115200 baud. */ + 0, /* 57600 baud. */ + 0, /* 38400 baud. */ + 0, /* 33900 baud. */ + 0, /* 28800 baud. */ + 0, /* 19200 baud. */ + 0, /* 14400 baud. */ + 0, /* 9600 baud. */ + 0, /* 4800 baud. */ + 1, /* 2400 baud. */ + 2, /* 1200 baud. */ + 5, /* 600 baud. */ + 10, /* 300 baud. */ + 21, /* 150 baud. */ + 42 /* 75 baud. */ +}; + + +/******************************************************************************* + * + * read_rx_fifo + * + * Purpose : Check the bytes written into the RX FIFO. Characters are not + * written in the RX buffer if it is full. The HISR is called if + * enough characters are received. + * + * Arguments: In : uart: pointer on UART structure. + * Out: none + * + * Returns : none + * + ******************************************************************************/ + +static void +read_rx_fifo (t_uart *uart) +{ + volatile SYS_UWORD8 status; + int error_detected; + SYS_UWORD8 char_received; + +#if (BOARD != 34) + /* + * Since new characters have been received, the sleep timer is reset then + * restarted preventing the system to enter deep-sleep for a new period of + * time. + */ + + SER_activate_timer_hisr (); + uart_sleep_timer_enabled = 1; +#endif + + status = READ_UART_REGISTER (uart, LSR); + + while (status & DR) { /* While RX FIFO is not empty... */ + + error_detected = 0; + + char_received = READ_UART_REGISTER (uart, RHR); + + /* + * Check if an error (overrun, parity, framing or break) is associated with the + * received data. If there is an error the byte is not copied into the + * RX buffer. + */ + + if (status & (OE | PE | FE | BI)) { + + if (status & PE) + uart->parity_error++; + + if (status & FE) + uart->framing_error++; + + if (status & OE) + uart->overrun_error++; + + error_detected = 1; + } + + /* + * If there is no error the byte is copied into the RX + * buffer if it is not full. + */ + + if (!error_detected && !RX_BUFFER_FULL (uart)) { + + *(uart->rx_in++) = char_received; + + if (uart->rx_in == &(uart->rx_buffer[0]) + BUFFER_SIZE + 1) + uart->rx_in = &(uart->rx_buffer[0]); + +#ifdef UART_RX_BUFFER_DUMP + *(uart_rx_buffer_dump.rx_in)++ = char_received; + + if (uart_rx_buffer_dump.rx_in == uart_rx_buffer_dump.rx_buffer + sizeof (uart_rx_buffer_dump.rx_buffer)) + uart_rx_buffer_dump.rx_in = uart_rx_buffer_dump.rx_buffer; + } + else { + uart_rx_buffer_dump.errors_count++; +#endif + } + + status = READ_UART_REGISTER (uart, LSR); + } + + /* + * Call the user's function. + */ + + if (uart->callback_function != NULL) + (*(uart->callback_function)) (); +} + +/******************************************************************************* + * + * initialize_uart_sleep + * + * Purpose : Performs basic UART hardware initialization including sleep mode. + * + * Arguments: In : uart_id : UART id. + * Out: none + * + * Returns: none + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +void +initialize_uart_sleep (T_tr_UartId uart_id) +{ + t_uart *uart; + int index; + SYS_UWORD8 dummy; + + for (index = 0; index < NUMBER_OF_TR_UART; index++) + uart_parameter[index].base_address = base_address[index]; + + uart = &(uart_parameter[uart_id]); + + /* + * Mask all interrupts causes and disable sleep mode. + */ + + WRITE_UART_REGISTER (uart, IER, 0x00); + + /* + * Reset UART mode configuration. + */ + + WRITE_UART_REGISTER (uart, MDR1, RESET_DEFAULT_STATE); + + /* + * LCR[7:0] = 0xBF to allow to access EFR + * EFR[4] = 1 to allow to program IER[4]. + */ + + WRITE_UART_REGISTER (uart, LCR, 0xBF); + SET_BIT (uart, EFR, ENHANCED_FEATURE_BIT); + WRITE_UART_REGISTER (uart, LCR, 0x83); + + /* + * Enable FIFO and reset them. + */ + + WRITE_UART_REGISTER (uart, FCR, FIFO_ENABLE | + RX_FIFO_RESET | + TX_FIFO_RESET); + + /* + * Program the baud generator (dummy 115200). + */ + + WRITE_UART_REGISTER (uart, DLL, 0x07); + WRITE_UART_REGISTER (uart, DLM, 0x00); + + /* + * LCR[7] = 0 to allow to access IER and RHR - normal mode. + */ + + RESET_BIT (uart, LCR, DIV_EN_BIT); + + /* + * Select UART mode. + */ + + WRITE_UART_REGISTER (uart, MDR1, UART_MODE); + + /* + * Clear Interrupt and check that Rx FIFO is empty. + */ + + dummy = READ_UART_REGISTER (uart, IIR); + + while (READ_UART_REGISTER (uart, LSR) & DR) + dummy = READ_UART_REGISTER (uart, RHR); + +#if ((CHIPSET != 5) && (CHIPSET != 6)) + /* + * Enable sleep mode. + */ + + WRITE_UART_REGISTER (uart, IER, IER_SLEEP); +#endif +} + + +/******************************************************************************* + * + * UA_Init + * + * Purpose : Initializes the module and the UART. + * + * Arguments: In : uart_id : UART id. + * baudrate: baud rate selected. + * callback: user's function called characters are received. + * Out: none + * + * Returns: none + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +void +UA_Init (T_tr_UartId uart_id, + T_tr_Baudrate baudrate, + void (callback_function (void))) +{ + t_uart *uart; + int index; + +#ifdef UART_RX_BUFFER_DUMP + uart_rx_buffer_dump.rx_in = uart_rx_buffer_dump.rx_buffer; +#endif + + for (index = 0; index < NUMBER_OF_TR_UART; index++) + uart_parameter[index].base_address = base_address[index]; + + uart = &(uart_parameter[uart_id]); + + uart->rx_in = &(uart->rx_buffer[0]); + uart->rx_out = &(uart->rx_buffer[0]); + + uart->callback_function = callback_function; + + uart->framing_error = 0; + uart->parity_error = 0; + uart->overrun_error = 0; + + uart->dle_detected = 0; + uart->inframe = 0; + uart->encapsulation_flag = 0; + uart->frame_length = 0; + + /* + * Mask all interrupts causes and disable sleep mode. + */ + + WRITE_UART_REGISTER (uart, IER, 0x00); + + /* + * Reset UART mode configuration. + */ + + WRITE_UART_REGISTER (uart, MDR1, RESET_DEFAULT_STATE | + IR_SLEEP_DISABLED | + SIR_TX_WITHOUT_ACREG2 | + FRAME_LENGTH_METHOD); + + /* + * FIFO configuration. + * EFR[4] = 1 to allow to program FCR[5:4] and MCR[7:5]. + */ + + WRITE_UART_REGISTER (uart, LCR, 0xBF); + SET_BIT (uart, EFR, ENHANCED_FEATURE_BIT); + + /* + * Select the word length, the number of stop bits , the parity and set + * LCR[7] (DLAB) to allow to program FCR, DLL and DLM. + */ + + WRITE_UART_REGISTER (uart, LCR, WLS_8 | DLAB); + + /* + * Program the trigger levels. + * MCR[6] must be set to 1. + */ + + SET_BIT (uart, MCR, TCR_TLR_BIT); + WRITE_UART_REGISTER (uart, TCR, 0x0F); + WRITE_UART_REGISTER ( + uart, TLR, RX_FIFO_TRIGGER_LEVEL); + + /* + * Program the FIFO control register. Bit 0 must be set when other FCR bits + * are written to or they are not programmed. + * FCR is a write-only register. It will not be modified. + */ + + WRITE_UART_REGISTER (uart, FCR, FIFO_ENABLE | + RX_FIFO_RESET | /* self cleared */ + TX_FIFO_RESET); /* self cleared */ + + /* + * Program the baud generator. + */ + + WRITE_UART_REGISTER (uart, DLL, dll[baudrate]); + WRITE_UART_REGISTER (uart, DLM, dlh[baudrate]); + + + /* + * Reset LCR[7] (DLAB) to have access to the RBR, THR and IER registers. + */ + + WRITE_UART_REGISTER (uart, LCR, READ_UART_REGISTER (uart, LCR) & ~DLAB); + + + /* + * Select UART mode. + */ + + WRITE_UART_REGISTER (uart, MDR1, UART_MODE | + IR_SLEEP_DISABLED | + SIR_TX_WITHOUT_ACREG2 | + FRAME_LENGTH_METHOD); + +#if ((CHIPSET == 5) || (CHIPSET == 6)) + /* + * Unmask RX interrupt + */ + + WRITE_UART_REGISTER (uart, IER, ERBI); +#else + /* + * Unmask RX interrupt and allow sleep mode. + */ + + WRITE_UART_REGISTER (uart, IER, ERBI | IER_SLEEP); +#endif +} + +/******************************************************************************* + * + * UA_ReadNChars + * + * Purpose : Reads N characters from the RX buffer. + * + * Arguments: In : uart_id : UART id. + * buffer : buffer address where the characters are + * copied. + * chars_to_read: number of characters to read. + * Out: none + * + * Returns : The number of characters read. + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +SYS_UWORD32 +UA_ReadNChars (T_tr_UartId uart_id, + char *buffer, + SYS_UWORD32 chars_to_read) +{ + SYS_UWORD32 chars_in_rx_buffer; + SYS_UWORD32 chars_to_copy; + SYS_UWORD32 chars_written; + char *rx_in; + t_uart *uart; + + uart = &(uart_parameter[uart_id]); + + /* + * A copy of the rx_in pointer is used because it may be updated by + * the interrupt handler. + * Get the number of bytes available in the RX buffer. + */ + + rx_in = uart->rx_in; + + if (uart->rx_out <= rx_in) + chars_in_rx_buffer = (SYS_UWORD32) (rx_in - uart->rx_out); + else + chars_in_rx_buffer = (SYS_UWORD32) (rx_in - uart->rx_out + BUFFER_SIZE + 1); + + /* + * No more bytes than those received may be written in the output buffer. + */ + + if (chars_in_rx_buffer >= chars_to_read) + chars_to_copy = chars_to_read; + else + chars_to_copy = chars_in_rx_buffer; + + chars_written = chars_to_copy; + + /* + * Write the received bytes in the output buffer. + */ + + while (chars_to_copy) { + + *(buffer++) = *(uart->rx_out++); + chars_to_copy--; + + if (uart->rx_out == &(uart->rx_buffer[0]) + BUFFER_SIZE + 1) + uart->rx_out = &(uart->rx_buffer[0]); + } + + return (chars_written); +} + +/******************************************************************************* + * + * UA_ReadNBytes + * + * Purpose : Reads and destuff N bytes from the RX buffer. + * + * Arguments: In : uart_id : UART id. + * buffer : buffer address where the bytes are copied. + * chars_to_read: number of bytes to read. + * Out: eof_detected : indicates if an EOF has been detected. Possible + * values are: + * - 0: EOF not detected, + * - 1: EOF detected and no more bytes left, + * - 2: EOF not detected and more bytes left. + * Users must invoke this function one more + * time in order to get those remaining + * bytes, + * - 3: EOF detected and more bytes left. Users + * must invoke this function one more time + * in order to get those remaining bytes. + * + * Returns : The number of bytes read. + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +SYS_UWORD32 +UA_ReadNBytes (T_tr_UartId uart_id, + char *buffer_p, + SYS_UWORD32 bytes_to_read, + SYS_BOOL *eof_detected_p) +{ + SYS_UWORD32 bytes_written; + SYS_UWORD32 bytes_in_rx_buffer; + SYS_UWORD32 bytes_to_process; + t_uart *uart_p; + char *rx_in_p; + + bytes_written = 0; + uart_p = &(uart_parameter[uart_id]); + + /* + * A copy of the rx_in pointer is used because it may be updated by + * the interrupt handler. + * Get the number of bytes available in the RX buffer. + */ + + rx_in_p = uart_p->rx_in; + + if (uart_p->rx_out <= rx_in_p) + bytes_in_rx_buffer = (SYS_UWORD32) (rx_in_p - uart_p->rx_out); + else + bytes_in_rx_buffer = (SYS_UWORD32) (rx_in_p - uart_p->rx_out + BUFFER_SIZE + 1); + + /* + * No more bytes than those received may be processed and then written + * in the output buffer. + */ + + if (bytes_in_rx_buffer > bytes_to_read) { + bytes_to_process = bytes_to_read; + + /* + * More bytes left. Users must invoke this function one more time + * in order to get those remaining bytes. + */ + + *eof_detected_p = 2; + } + else { + bytes_to_process = bytes_in_rx_buffer; + + /* + * No more bytes left. + */ + + *eof_detected_p = 0; + } + + /* + * Perform the byte destuffing and then write the "valid" received bytes in + * the output buffer. + */ + + while ((bytes_to_process) && !(*eof_detected_p & 0x01)) { + + switch (*(uart_p->rx_out)) { + + /* + * Current byte is DLE. + */ + + case DLE: + + if (!uart_p->dle_detected) { + + /* + * No DLE previously detected => + * Skip the current byte and set the flag. + */ + + uart_p->dle_detected = 1; + uart_p->rx_out++; + } + + else { /* if (uart_p->dle_detected) */ + + if (uart_p->inframe) { + + /* + * DLE previously detected AND currently inside of a frame => + * Copy the current byte in the output buffer, reset the flag + * and increase the frame length. + */ + + uart_p->dle_detected = 0; + uart_p->frame_length++; + *(buffer_p++) = *(uart_p->rx_out++); + bytes_written++; + } + + else { /* if (!uart_p->inframe) */ + + /* + * DLE previously detected AND currently outside of a frame => + * Skip the current byte. + */ + + uart_p->rx_out++; + } + } + + break; /* case DLE */ + + /* + * Current byte is STX. + */ + + case STX: + + if ((!uart_p->dle_detected) && (uart_p->inframe)) { + + /* + * No DLE previously detected AND currently inside of a frame. + */ + + if (uart_p->frame_length) { + + /* + * Frame length is not zero (End of Frame) => + * Skip the current byte and set the flags (EOF). + */ + + uart_p->inframe = 0; + uart_p->frame_length = 0; + uart_p->rx_out++; + + /* + * More bytes left. + */ + + if ((*eof_detected_p == 0) && (bytes_to_process)) + *eof_detected_p = 2; + + /* + * EOF detected. + */ + + (*eof_detected_p)++; + } + + else { /* if (!uart_p->frame_length) */ + + /* + * Frame length is zero (STX followed by another STX = + * Synchro lost but start of a new frame) => + * Skip the current byte and keep the flag set. + */ + + uart_p->rx_out++; + } + } + + else if ((!uart_p->dle_detected) && (!uart_p->inframe)) { + + /* + * No DLE previously detected AND currently outside of a + * frame (Start of Frame) => + * Skip the current byte and set the flag. + */ + + uart_p->inframe = 1; + uart_p->rx_out++; + } + + else if ((uart_p->dle_detected) && (uart_p->inframe)) { + + /* + * DLE previously detected AND currently inside of a frame => + * Copy the current byte in the output buffer, reset the flag + * and increase the frame length. + */ + + uart_p->dle_detected = 0; + uart_p->frame_length++; + *(buffer_p++) = *(uart_p->rx_out++); + bytes_written++; + } + + else if ((uart_p->dle_detected) && (!uart_p->inframe)) { + + /* + * DLE previously detected AND currently outside of a frame => + * Skip the current byte and reset the flag. + */ + + uart_p->dle_detected = 0; + uart_p->rx_out++; + } + + break; /* case STX */ + + /* + * Current byte is neither DLE nor STX. + */ + + default: + + if (uart_p->inframe) { + + /* + * Currently inside of a frame => + * Copy the current byte in the output buffer and increase + * the frame length. + */ + + uart_p->frame_length++; + *(buffer_p++) = *(uart_p->rx_out++); + bytes_written++; + } + + else { /* if (!uart_p->inframe) */ + + /* + * Currently outside of a frame => + * Skip the current byte. + */ + + uart_p->rx_out++; + } + + break; /* default */ + } + + if (uart_p->rx_out == &(uart_p->rx_buffer[0]) + BUFFER_SIZE + 1) + uart_p->rx_out = &(uart_p->rx_buffer[0]); + + bytes_to_process--; + } + + return (bytes_written); +} + + +/******************************************************************************* + * + * UA_WriteNChars + * + * Purpose : Writes N characters in the TX FIFO. + * + * Arguments: In : uart_id : UART id. + * buffer : buffer address from which characters are + * written. + * bytes_to_write: number of bytes to write. + * Out: none + * + * Returns : Number of bytes written. + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +SYS_UWORD32 +UA_WriteNChars (T_tr_UartId uart_id, + char *buffer, + SYS_UWORD32 chars_to_write) +{ + SYS_UWORD32 chars_in_tx_fifo; + SYS_UWORD32 chars_written; + t_uart *uart; + + chars_written = 0; + uart = &(uart_parameter[uart_id]); + +#if ((CHIPSET != 5) && (CHIPSET != 6)) + /* + * Disable sleep mode. + */ + + WRITE_UART_REGISTER ( + uart, IER, READ_UART_REGISTER (uart, IER) & ~IER_SLEEP); +#endif + + /* + * Copy the input buffer to the TX FIFO. + * Ulyssse Bug #44: TX FIFO full status bit (SSR[1]) is corrupted during + * one period of Bclock => Workaround S/W. + * Write in TX FIFO only if FIFO is empty instead of writing in TX FIFO + * while FIFO is not full. + */ + + if (READ_UART_REGISTER (uart, LSR) & THRE) { + + chars_in_tx_fifo = 0; + + while ((chars_written < chars_to_write) && + (chars_in_tx_fifo < FIFO_SIZE)) { + + WRITE_UART_REGISTER (uart, THR, *(buffer++)); + chars_written++; + chars_in_tx_fifo++; + } + } + +#if ((CHIPSET != 5) && (CHIPSET != 6)) + /* + * Re-enable sleep mode. + */ + + WRITE_UART_REGISTER ( + uart, IER, READ_UART_REGISTER (uart, IER) | IER_SLEEP); +#endif + + return (chars_written); +} + + +/******************************************************************************* + * + * UA_EncapsulateNChars + * + * Purpose : Writes N characters in the TX FIFO in encapsulating them with 2 + * STX bytes (one at the beginning and one at the end). + * + * Arguments: In : uart_id : UART id. + * buffer : buffer address from which characters are + * written. + * chars_to_write: number of chars to write. + * Out: none + * + * Returns : Number of chars written. + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +SYS_UWORD32 +UA_EncapsulateNChars (T_tr_UartId uart_id, + char *buffer, + SYS_UWORD32 chars_to_write) +{ + SYS_UWORD32 chars_written; + SYS_UWORD32 chars_in_tx_fifo; + t_uart *uart; + + chars_written = 0; + uart = &(uart_parameter[uart_id]); + +#if ((CHIPSET != 5) && (CHIPSET != 6)) + /* + * Disable sleep mode. + */ + + WRITE_UART_REGISTER ( + uart, IER, READ_UART_REGISTER (uart, IER) & ~IER_SLEEP); +#endif + + /* + * Copy the input buffer to the TX FIFO. + * Ulyssse Bug #44: TX FIFO full status bit (SSR[1]) is corrupted during + * one period of Bclock => Workaround S/W. + * Write in TX FIFO only if FIFO is empty instead of writing in TX FIFO + * while FIFO is not full. + */ + + if (READ_UART_REGISTER (uart, LSR) & THRE) { + + chars_in_tx_fifo = 0; + + /* + * Check if the message has been already encapsulated. + */ + + if (!uart->encapsulation_flag) { + /* + * Write STX in the TX FIFO and set the flag. + */ + + WRITE_UART_REGISTER (uart, THR, STX); + chars_in_tx_fifo++; + uart->encapsulation_flag = 1; + } + + /* + * Keep one char margin in the TX FIFO for the last STX. + */ + + while ((chars_written < chars_to_write) && + (chars_in_tx_fifo < (FIFO_SIZE-1))) { + + WRITE_UART_REGISTER (uart, THR, *(buffer++)); + chars_written++; + chars_in_tx_fifo++; + } + + /* + * Append STX byte at the end if the frame is complete. + */ + + if (chars_written == chars_to_write) { + + /* + * Write STX in the TX FIFO and reset the flag. + */ + + WRITE_UART_REGISTER (uart, THR, STX); + uart->encapsulation_flag = 0; + } + } + +#if ((CHIPSET != 5) && (CHIPSET != 6)) + /* + * Re-enable sleep mode. + */ + + WRITE_UART_REGISTER ( + uart, IER, READ_UART_REGISTER (uart, IER) | IER_SLEEP); +#endif + + return (chars_written); +} + + +/******************************************************************************* + * + * UA_WriteNBytes + * + * Purpose : Writes N bytes in the TX FIFO in encapsulating with 2 STX bytes + * at the beginning and the end of the frame, and in making byte + * stuffing. + * + * Arguments: In : uart_id : UART id. + * buffer : buffer address from which bytes are + * written. + * bytes_to_write: number of bytes to write. + * Out: none + * + * Returns : Number of bytes written. + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +SYS_UWORD32 +UA_WriteNBytes (T_tr_UartId uart_id, + SYS_UWORD8 *buffer, + SYS_UWORD32 bytes_to_write) +{ + SYS_UWORD32 bytes_written; + SYS_UWORD32 bytes_in_tx_fifo; + t_uart *uart; + + bytes_written = 0; + uart = &(uart_parameter[uart_id]); + +#if ((CHIPSET != 5) && (CHIPSET != 6)) + /* + * Disable sleep mode. + */ + + WRITE_UART_REGISTER ( + uart, IER, READ_UART_REGISTER (uart, IER) & ~IER_SLEEP); +#endif + + /* + * Copy the input buffer to the TX FIFO. + * Ulyssse Bug #44: TX FIFO full status bit (SSR[1]) is corrupted during + * one period of Bclock => Workaround S/W. + * Write in TX FIFO only if FIFO is empty instead of writing in TX FIFO + * while FIFO is not full. + */ + + if (READ_UART_REGISTER (uart, LSR) & THRE) { + + bytes_in_tx_fifo = 0; + + /* + * Check if the message has been already encapsulated. + */ + + if (!uart->encapsulation_flag) { + + /* + * Write STX in the TX FIFO and set the flag. + */ + + WRITE_UART_REGISTER (uart, THR, STX); + bytes_in_tx_fifo++; + uart->encapsulation_flag = 1; + } + + /* + * Keep 2 chars margin in the FIFO, one for the stuffing (if necessary) + * and one for the last STX. + */ + + while ((bytes_written < bytes_to_write) && + (bytes_in_tx_fifo < (FIFO_SIZE-2))) { + + /* + * Check for STX or DLE in order to perform the stuffing. + */ + + if ((*(buffer) == STX) || (*(buffer) == DLE)) { + + /* + * Write DLE in the TX FIFO. + */ + + WRITE_UART_REGISTER (uart, THR, DLE); + bytes_in_tx_fifo++; + } + + WRITE_UART_REGISTER (uart, THR, *(buffer++)); + bytes_written++; + bytes_in_tx_fifo++; + } + + /* + * Append STX byte at the end if the frame is complete. + */ + + if (bytes_written == bytes_to_write) { + + /* + * Write STX in the TX FIFO and reset the flag. + */ + + WRITE_UART_REGISTER (uart, THR, STX); + uart->encapsulation_flag = 0; + } + } + +#if ((CHIPSET != 5) && (CHIPSET != 6)) + /* + * Re-enable sleep mode. + */ + + WRITE_UART_REGISTER ( + uart, IER, READ_UART_REGISTER (uart, IER) | IER_SLEEP); +#endif + + return (bytes_written); +} + + +/******************************************************************************* + * + * UA_WriteChar + * + * Purpose : Writes a character in the TX FIFO. + * + * Arguments: In : uart: UART id. + * character + * Out: none + * + * Returns : none + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +void +UA_WriteChar (T_tr_UartId uart_id, + char character) +{ + (void) UA_WriteNChars (uart_id, &character, 1); +} + +/******************************************************************************* + * + * UA_WriteString + * + * Purpose : Writes a null terminated string in the TX FIFO. + * + * Arguments: In : uart_id: UART id. + * buffer : buffer address from which characters are written. + * Out: none + * + * Returns : none + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +void +UA_WriteString (T_tr_UartId uart_id, + char *buffer) +{ + (void) UA_WriteNChars (uart_id, buffer, strlen (buffer)); +} + +/******************************************************************************* + * + * UA_EnterSleep + * + * Purpose : Checks if UART is ready to enter Deep Sleep. If ready, enables + * wake-up interrupt. + * + * Arguments: In : uart_id : UART id. + * Out: none + * + * Returns: 0 : Deep Sleep is not possible. + * >= 1 : Deep Sleep is possible. + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +SYS_BOOL +UA_EnterSleep (T_tr_UartId uart_id) +{ + t_uart *uart; + SYS_BOOL deep_sleep; + volatile SYS_UWORD8 status; + + uart = &(uart_parameter[uart_id]); + deep_sleep = 0; + + /* + * Check if RX & TX FIFOs are both empty + */ + + status = READ_UART_REGISTER (uart, LSR); + + if (!(status & DR) && + (status & TEMT)) { + +#if ((CHIPSET != 5) && (CHIPSET != 6)) + /* + * Disable sleep mode. + */ + + WRITE_UART_REGISTER ( + uart, IER, READ_UART_REGISTER (uart, IER) & ~IER_SLEEP); +#endif + + /* + * Mask RX interrupt. + */ + + WRITE_UART_REGISTER ( + uart, IER, READ_UART_REGISTER (uart, IER) & ~ERBI); + + /* + * Enable the wake-up interrupt. + */ + + ENABLE_WAKEUP_INTERRUPT (uart); + + deep_sleep = 1; + } + + return (deep_sleep); +} + +/******************************************************************************* + * + * UA_WakeUp + * + * Purpose : Wakes up UART after Deep Sleep. + * + * Arguments: In : uart_id : UART id. + * Out: none + * + * Returns: none + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +void +UA_WakeUp (T_tr_UartId uart_id) +{ + t_uart *uart; + + uart = &(uart_parameter[uart_id]); + + /* + * Disable the wake-up interrupt. + */ + + DISABLE_WAKEUP_INTERRUPT (uart); + + /* + * Unmask RX interrupts. + */ + + WRITE_UART_REGISTER ( + uart, IER, READ_UART_REGISTER (uart, IER) | ERBI); + +#if ((CHIPSET != 5) && (CHIPSET != 6)) + /* + * Allow sleep mode. + */ + + WRITE_UART_REGISTER ( + uart, IER, READ_UART_REGISTER (uart, IER) | IER_SLEEP); +#endif +} + +/******************************************************************************* + * + * UA_InterruptHandler + * + * Purpose : Interrupt handler. + * + * Arguments: In : uart_id : origin of interrupt + * interrupt_status: source of interrupt + * Out: none + * + * Returns : none + * + ******************************************************************************/ + +void +UA_InterruptHandler (T_tr_UartId uart_id, + SYS_UWORD8 interrupt_status) +{ + t_uart *uart; + + uart = &(uart_parameter[uart_id]); + + switch (interrupt_status) { + + case RX_DATA: + + read_rx_fifo (uart); + + break; + + default: + +#ifdef UART_RX_BUFFER_DUMP + uart_rx_buffer_dump.wrong_interrupt_status++; +#endif + + /* No Processing */ + + break; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nuc-fw/serial/uart.h Mon Oct 28 06:49:44 2013 +0000 @@ -0,0 +1,281 @@ +/******************************************************************************* + * + * UART.H + * + * This module allows to use the UARTs of chipset 1.5 in interrupt mode. + * The driver calls a user's function when characters are received. + * + * (C) Texas Instruments 1999 - 2003 + * + ******************************************************************************/ + +#ifndef __UART_H__ +#define __UART_H__ + +typedef enum { + UA_UART_0, /* IrDA */ + UA_UART_1 /* Modem */ + #if (CHIPSET == 12) + , UA_UART_2 /* Modem 2 */ + #endif +} T_tr_UartId; + +#if (CHIPSET == 12) + #define NUMBER_OF_TR_UART (3) +#else + #define NUMBER_OF_TR_UART (2) +#endif + +#ifndef C_EXTERN + #if 1 //(OP_L1_STANDALONE == 1) + #define C_EXTERN extern + #else + #define C_EXTERN + #endif +#endif + +/******************************************************************************* + * + * initialize_uart_sleep + * + * Purpose : Performs basic UART hardware initialization including sleep mode. + * + * Arguments: In : uart_id : UART id. + * Out: none + * + * Returns: none + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +C_EXTERN void initialize_uart_sleep (T_tr_UartId uart_id); + +/******************************************************************************* + * + * UA_Init + * + * Purpose : Initializes the module and the UART. + * + * Arguments: In : uart_id : UART id. + * baudrate: baud rate selected. + * callback: user's function called characters are received. + * Out: none + * + * Returns: none + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +C_EXTERN void UA_Init (T_tr_UartId uart_id, + T_tr_Baudrate baudrate, + void (callback_function (void))); + +/******************************************************************************* + * + * UA_ReadNChars + * + * Purpose : Reads N characters from the RX buffer. + * + * Arguments: In : uart_id : UART id. + * buffer : buffer address where the characters are + * copied. + * chars_to_read: number of characters to read. + * Out: none + * + * Returns : The number of characters read. + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +C_EXTERN SYS_UWORD32 UA_ReadNChars (T_tr_UartId uart_id, + char *buffer, + SYS_UWORD32 chars_to_read); + +/******************************************************************************* + * + * UA_ReadNBytes + * + * Purpose : Reads and destuff N bytes from the RX buffer. + * + * Arguments: In : uart_id : UART id. + * buffer : buffer address where the bytes are copied. + * chars_to_read: number of bytes to read. + * Out: eof_detected : indicates if an EOF has been detected. + * + * Returns : The number of bytes read. + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +C_EXTERN SYS_UWORD32 UA_ReadNBytes (T_tr_UartId uart_id, + char *buffer, + SYS_UWORD32 bytes_to_read, + SYS_BOOL *eof_detected); + +/******************************************************************************* + * + * UA_WriteNChars + * + * Purpose : Writes N characters in the TX FIFO. + * + * Arguments: In : uart_id : UART id. + * buffer : buffer address from which characters are + * written. + * bytes_to_write: number of bytes to write. + * Out: none + * + * Returns : Number of bytes written. + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +C_EXTERN SYS_UWORD32 UA_WriteNChars (T_tr_UartId uart_id, + char *buffer, + SYS_UWORD32 chars_to_write); + +/******************************************************************************* + * + * UA_EncapsulateNChars + * + * Purpose : Writes N characters in the TX FIFO in encapsulating them with 2 + * STX bytes (one at the beginning and one at the end). + * + * Arguments: In : uart_id : UART id. + * buffer : buffer address from which characters are + * written. + * chars_to_write: number of chars to write. + * Out: none + * + * Returns : Number of chars written. + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +C_EXTERN SYS_UWORD32 UA_EncapsulateNChars (T_tr_UartId uart_id, + char *buffer, + SYS_UWORD32 chars_to_write); + +/******************************************************************************* + * + * UA_WriteNBytes + * + * Purpose : Writes N bytes in the TX FIFO in encapsulating with 2 STX bytes + * at the beginning and the end of the frame, and in making byte + * stuffing. + * + * Arguments: In : uart_id : UART id. + * buffer : buffer address from which bytes are + * written. + * bytes_to_write: number of bytes to write. + * Out: none + * + * Returns : Number of bytes written. + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +C_EXTERN SYS_UWORD32 UA_WriteNBytes (T_tr_UartId uart_id, + SYS_UWORD8 *buffer, + SYS_UWORD32 bytes_to_write); + +/******************************************************************************* + * + * UA_WriteChar + * + * Purpose : Writes a character in the TX FIFO. + * + * Arguments: In : uart: UART id. + * character + * Out: none + * + * Returns : none + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +C_EXTERN void UA_WriteChar (T_tr_UartId uart_id, + char character); + +/******************************************************************************* + * + * UA_WriteString + * + * Purpose : Writes a null terminated string in the TX FIFO. + * + * Arguments: In : uart_id: UART id. + * buffer : buffer address from which characters are written. + * Out: none + * + * Returns : none + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +C_EXTERN void UA_WriteString (T_tr_UartId uart_id, + char *buffer); + +/******************************************************************************* + * + * UA_EnterSleep + * + * Purpose : Checks if UART is ready to enter Deep Sleep. If ready, enables + * wake-up interrupt. + * + * Arguments: In : uart_id : UART id. + * Out: none + * + * Returns: 0 : Deep Sleep is not possible. + * >= 1 : Deep Sleep is possible. + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +C_EXTERN SYS_BOOL UA_EnterSleep (T_tr_UartId uart_id); + +/******************************************************************************* + * + * UA_WakeUp + * + * Purpose : Wakes up UART after Deep Sleep. + * + * Arguments: In : uart_id : UART id. + * Out: none + * + * Returns: none + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +C_EXTERN void UA_WakeUp (T_tr_UartId uart_id); + +/******************************************************************************* + * + * UA_InterruptHandler + * + * Purpose : Interrupt handler. + * + * Arguments: In : uart_id : origin of interrupt + * interrupt_status: source of interrupt + * Out: none + * + * Returns : none + * + ******************************************************************************/ + +void UA_InterruptHandler (T_tr_UartId uart_id, + SYS_UWORD8 interrupt_status); + +#undef C_EXTERN + +#endif /* __UART_H__ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nuc-fw/serial/uartfax.h Mon Oct 28 06:49:44 2013 +0000 @@ -0,0 +1,593 @@ +/******************************************************************************* + * + * UARTFAX.H + * + * This driver allows to control the UARTs of chipset 1.5 for fax and data + * It performs flow control: RTS/CTS, XON/XOFF. + * + * (C) Texas Instruments 1999 - 2003 + * + ******************************************************************************/ + +#ifndef __UARTFAX_H__ +#define __UARTFAX_H__ + +#ifndef C_EXTERN + #if 1 //(OP_L1_STANDALONE == 1) + #define C_EXTERN extern + #else + #define C_EXTERN + #endif +#endif + +/* + * In UAF_Init, a constant is used to identify the UART. + */ + +typedef enum { + UAF_UART_0, /* IrDA */ + UAF_UART_1 /* Modem */ + #if (CHIPSET == 12) + , UAF_UART_2 /* Modem 2 */ + #endif +} T_fd_UartId; + +#if (CHIPSET == 12) + #define NUMBER_OF_FD_UART (3) +#else + #define NUMBER_OF_FD_UART (2) +#endif + +/******************************************************************************* + * + * UAF_Init + * + * Purpose : Initializes the UART hardware and installs interrupt handlers. + * The parameters are set to the default values: + * - 19200 baud, + * - 8 bits / character, + * - no parity, + * - 1 stop bit, + * - no flow control. + * All functionalities of the UART driver are disabled. + * + * Arguments: In : uartNo: Used UART. + * Out: none + * + * Returns : FD_OK : Successful operation. + * FD_NOT_SUPPORTED: Wrong UART number. + * FD_INTERNAL_ERR : Internal problem. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_Init (T_fd_UartId uartNo); + +/******************************************************************************* + * + * UAF_Enable + * + * Purpose : The functionalities of the UART driver are disabled or enabled. + * In the deactivated state, all information about the communication + * parameters should be stored and recalled if the driver is again + * enabled. When the driver is enabled the RX and TX buffers are + * cleared. + * + * Arguments: In : uartNo: Used UART. + * : enable: 1: enable the driver + * 0: disable the driver + * Out: none + * + * Returns : FD_OK : Successful operation. + * FD_NOT_SUPPORTED: Wrong UART number. + * FD_INTERNAL_ERR : Internal problem with the hardware. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_Enable (T_fd_UartId uartNo, + SYS_BOOL enable); + +/******************************************************************************* + * + * UAF_SetComPar + * + * Purpose : Sets up the communication parameters: baud rate, bits per + * character, number of stop bits, parity. + * + * Arguments: In : uartNo : Used UART. + * baudrate: Used baud rate. + * bpc : Used bits per character. + * sb : Used stop bits. + * parity : Used parity. + * Out: none + * + * Returns : FD_OK : Successful operation. + * FD_NOT_SUPPORTED: The specified parameters don't fit to the + * capabilities of the UART or wrong UART number. + * FD_INTERNAL_ERR : Internal problem with the hardware. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_SetComPar (T_fd_UartId uartNo, + T_baudrate baudrate, + T_bitsPerCharacter bpc, + T_stopBits sb, + T_parity parity); + +/******************************************************************************* + * + * UAF_SetBuffer + * + * Purpose : Sets up the size of the circular buffers to be used in the UART + * driver. This function may be called only if the UART is disabled + * with UAF_Enable. + * + * Arguments: In : uartNo : Used UART. + * bufSize : Specifies the size of the circular buffer. + * rxThreshold: Amount of received bytes that leads to a call + * to suspended read-out function which is passed + * to the function UAF_ReadData. + * txThreshold: Amount of bytes in the TX buffer to call the + * suspended write-in function which is passed to + * the function UAF_WriteData + * Out: none + * + * Returns : FD_OK : Successful operation. + * FD_NOT_SUPPORTED: bufSize exceeds the maximal possible + * capabilities of the driver or the threshold + * values don't correspond to the bufSize or + * wrong UART number. + * FD_INTERNAL_ERR : Internal problem with the hardware or the + * function has been called while the UART is + * enabled. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_SetBuffer (T_fd_UartId uartNo, + SYS_UWORD16 bufSize, + SYS_UWORD16 rxThreshold, + SYS_UWORD16 txThreshold); + +/******************************************************************************* + * + * UAF_SetFlowCtrl + * + * Purpose : Changes the flow control mode of the UART driver. + * If a flow control is activated, DTR is activated or XOFF is sent + * if the RX buffer is not able to store the received characters else + * DTR is deactivated or XON is sent. + * + * Arguments: In : uartNo: Used UART. + * fcMode: flow control mode (none, DTR/DSR, RTS/CTS, XON/XOFF). + * XON : ASCII code of the XON character. + * XOFF : ASCII code of the XOFF character. + * Out: none + * + * Returns : FD_OK : Successful operation. + * FD_NOT_SUPPORTED: The flow control mode is not supported or wrong + * UART number. + * FD_INTERNAL_ERR : Internal problem with the hardware. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_SetFlowCtrl (T_fd_UartId uartNo, + T_flowCtrlMode fcMode, + SYS_UWORD8 XON, + SYS_UWORD8 XOFF); + +/******************************************************************************* + * + * UAF_SetEscape + * + * Purpose : To return to the command mode at the ACI while a data connection + * is established, an escape sequence has to be detected. + * To distinguish between user data and the escape sequence a + * defined guard period is necessary before and after this sequence. + * + * Arguments: In: uartNo : Used UART. + * escChar : ASCII character which could appear three times + * as an escape sequence. + * guardPeriod: Denotes the minimal duration of the rest before + * the first and after the last character of the + * escape sequence, and the maximal receiving + * duration of the whole escape string. This value + * is expressed in ms. + * Out: none + * + * Returns : FD_OK : Successful operation. + * FD_NOT_SUPPORTED: Wrong UART number. + * FD_INTERNAL_ERR : Internal problem with the hardware. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_SetEscape (T_fd_UartId uartNo, + SYS_UWORD8 escChar, + SYS_UWORD16 guardPeriod); + +/******************************************************************************* + * + * UAF_InpAvail + * + * Purpose : Returns the number of characters available in the RX buffer of the + * driver. If the driver is disabled the function returns 0. + * + * Arguments: In : uartNo: Used UART. + * Out: none + * + * Returns : >= 0 : The returned value is the amount of data in the + * RX buffer. + * FD_NOT_SUPPORTED: Wrong UART number. + * FD_NOT_READY : The function is called while the callback of the + * readOutFunc function is activated and still not + * terminated. + * FD_INTERNAL_ERR : Internal problem with the hardware. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_InpAvail (T_fd_UartId uartNo); + +/******************************************************************************* + * + * UAF_OutpAvail + * + * Purpose : Returns the number of free characters in TX buffer of the driver. + * If the driver is disabled the function returns 0. + * + * Arguments: In : uartNo: Used UART. + * Out: none + * + * Returns : >= 0 : The returned value is the amount of data in the + * TX buffer. + * FD_NOT_SUPPORTED: Wrong UART number. + * FD_NOT_READY : The function is called while the callback of the + * writeInFunc function is activated and still not + * terminated. + * FD_INTERNAL_ERR : Internal problem with the hardware. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_OutpAvail (T_fd_UartId uartNo); + +/******************************************************************************* + * + * UAF_EnterSleep + * + * Purpose : Checks if UART is ready to enter Deep Sleep. If ready, enables + * wake-up interrupt. + * + * Arguments: In : uartNo: Used UART. + * Out: none + * + * Returns : 0 : Deep Sleep is not possible. + * >= 1 : Deep Sleep is possible. + * FD_NOT_SUPPORTED: Wrong UART number. + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_EnterSleep (T_fd_UartId uartNo); + +/******************************************************************************* + * + * UAF_WakeUp + * + * Purpose : Wakes up UART after Deep Sleep. + * + * Arguments: In : uartNo: Used UART. + * Out: none + * + * Returns : FD_OK : Successful operation. + * FD_NOT_SUPPORTED: Wrong UART number. + * + * Warning: Parameters are not verified. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_WakeUp (T_fd_UartId uartNo); + +/******************************************************************************* + * + * UAF_ReadData + * + * Purpose : To read the received characters out of the RX buffer the address + * of a function is passed. If characters are available, the driver + * calls this function and pass the address and the amount of + * readable characters. Because the RX buffer is circular, the + * callback function may be called with more than one address of + * buffer fragment. + * The readOutFunc function modifies the contents of the size array + * to return the driver the number of processed characters. Each + * array entry is decremented by the number of bytes read in the + * fragment. + * If the UAF_ReadData is called while the RX buffer is empty, it + * depends on the suspend parameter to suspend the call-back or to + * leave without any operation. In the case of suspension, the + * return value of UAF_ReadData is UAF_SUSPENDED. A delayed call-back + * will be performed if: + * - the RX buffer reachs the adjusted threshold (rxThreshold of + * UAF_SetBuffer), + * - the state of a V.24 input line has changed, + * - a break is detected, + * - an escape sequence is detected. + * If no suspension is necessary the function returns the number of + * processed bytes. + * + * Arguments: In : uartNo : Used UART. + * suspend : mode of suspension in case of RX buffer empty. + * readOutFunc: Callback function. + * cldFromIrq: The driver sets this parameter to 1 + * if the callback function is called + * from an interrupt service routine. + * reInstall : The call-back function sets this + * parameter to rm_reInstall if the + * driver must call again the callback + * function when the RX threshold level + * is reached. Else it will be set to + * rm_noInstall. Before to call the + * readOutFunc function this parameter + * is set to rm_notDefined. + * nsource : Informed the callback function about + * the number of fragments which are + * ready to copy from the circular RX + * buffer. + * source : Array which contains the addresses + * of the fragments. + * size : Array which contains the sizes of + * each fragments. + * state : The state parameter is the status + * of the V.24 lines and the break / + * escape detection. The state + * parameter is described in the + * specification of UAF_GetLineState. + * Out: none + * + * Returns : >= 0 : Succesful operation. Amount of processed bytes. + * FD_NOT_SUPPORTED: Wrong UART number. + * FD_SUSPENDED : The callback is suspended until the buffer or + * state condition changed. + * FD_NOT_READY : The function is called while the callback is + * activated and still not terminated. + * FD_INTERNAL_ERR : Internal problems with the hardware. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_ReadData (T_fd_UartId uartNo, + T_suspendMode suspend, + void (readOutFunc (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 nsource, + SYS_UWORD8 *source[], + SYS_UWORD16 size[], + SYS_UWORD32 state))); + +/******************************************************************************* + * + * UAF_WriteData + * + * Purpose : To write characters into the TX buffer the address of a function + * is passed. If free space is available in the buffer, the driver + * calls this function and passes the destination address and the + * amount of space. Because the TX buffer is circular, the callback + * function may be called with more than one address of buffer + * fragment. + * The writeInFunc function modifies the contents of the size array + * to return the driver the number of processed bytes. Each array + * entry is decremented by the number of bytes written in this + * fragment. + * If the UAF_WriteData function is called while the TX buffer is + * full, it depends on the suspend parameter to suspend the + * call-back or to leave this function without any operation. In the + * case of suspension the returned value of the UAF_WriteData is + * UAF_SUSPENDED. A delayed call-back will be performed if the TX + * buffer reaches the adjusted threshold (txThreshold of + * UAF_SetBuffer). If no suspension is necessary the function returns + * the number of processed bytes. + * + * Arguments: In : uartNo : Used UART. + * suspend : mode of suspension in case of TX buffer empty. + * writeInFunc: Callback function. + * cldFromIrq: The driver sets this parameter to 1 + * if the call-back function is called + * from an interrupt service routine. + * reInstall : The callback function sets this + * parameter to rm_reInstall if the + * driver must call again the callback + * function when the TX threshold level + * is reached. Else it will be set to + * rm_noInstall. Before to call the + * writeInFunc function this parameter + * is set to rm_notDefined. + * ndest : Informed the callback function about + * the number of fragments which are + * available in the TX buffer. + * dest : Array which contains the addresses + * of the fragments. + * size : Array which contains the sizes of + * each fragments. + * Out: none + * + * Returns : >= 0 : Succesful operation. Amount of processed bytes. + * FD_NOT_SUPPORTED: Wrong UART number. + * FD_SUSPENDED : The callback is suspended until the buffer + * condition changed. + * FD_NOT_READY : The function is called while the callback is + * activated and still not terminated. + * FD_INTERNAL_ERR : Internal problems with the hardware. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_WriteData (T_fd_UartId uartNo, + T_suspendMode suspend, + void (writeInFunc (SYS_BOOL cldFromIrq, + T_reInstMode *reInstall, + SYS_UWORD8 ndest, + SYS_UWORD8 *dest[], + SYS_UWORD16 size[]))); + +/******************************************************************************* + * + * UAF_StopRec + * + * Purpose : If a flow control mode is set, this function tells the terminal + * equipment that no more data can be received. + * XON/XOFF: XOFF is sent. + * DTR/DSR : DTR is desactivated. + * RTS/CTS : RTS is deactivated. + * + * Arguments: In : uartNo: Used UART. + * Out: none + * + * Returns : FD_OK : Successful operation. + * FD_NOT_SUPPORTED: Wrong UART number. + * FD_INTERNAL_ERR : Internal problem with the hardware. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_StopRec (T_fd_UartId uartNo); + +/******************************************************************************* + * + * UAF_StartRec + * + * Purpose : If a flow control mode is set, this function tells the terminal + * equipment that the receiver is again able to receive more data. + * If the buffer has already reached the high water mark the driver + * sends the signal only if the buffer drains to a low water mark. + * XON/XOFF: XON is sent. + * DTR/DSR : DTR is activated. + * RTS/CTS : RTS is activated. + * + * Arguments: In : uartNo: Used UART. + * Out: none + * + * Returns : FD_OK : Successful operation. + * FD_NOT_SUPPORTED: Wrong UART number. + * FD_INTERNAL_ERR : Internal problem with the hardware. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_StartRec (T_fd_UartId uartNo); + +/******************************************************************************* + * + * UAF_GetLineState + * + * Purpose : Returns the state of the V.24 lines, the flow control state and + * the result of the break/escape detection process as a bit field. + * + * Arguments: In : uartNo: Used UART. + * Out: state : State of the V.24 lines, the flow control state and + * the result of the break/escape sequence detection + * process as a bit field. + * + * Returns : FD_OK : Successful operation. + * FD_NOT_SUPPORTED: Wrong UART number. + * FD_NOT_READY : The function is called while the callback of + * the readOutFunc function is activated and still + * not terminated. + * FD_INTERNAL_ERR : Internal problem with the hardware. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_GetLineState (T_fd_UartId uartNo, + SYS_UWORD32 *state); + +/******************************************************************************* + * + * UAF_SetLineState + * + * Purpose : Sets the states of the V.24 status lines according to the bit + * field of the parameter state. + * + * Arguments: In : uartNo: Used UART. + * state : Bit field. Only the signals which are marked with + * the 'set' access can be used to change the state of + * the signal. + * mask : Bit field with the same structure as state. Each bit + * in state corresponds to a bit in mask. Settabled + * bits marked by a 1 are manipulated by the driver. + * Out: none + * + * Returns : FD_OK : Successful operation. + * FD_NOT_SUPPORTED: Wrong UART number. + * FD_INTERNAL_ERR : Internal problem with the hardware. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_SetLineState (T_fd_UartId uartNo, + SYS_UWORD32 state, + SYS_UWORD32 mask); + +/******************************************************************************* + * + * UAF_InterruptHandler + * + * Purpose : Interrupt handler. + * + * Arguments: In : uart_id : origin of interrupt + * interrupt_status: source of interrupt + * Out: none + * + * Returns : none + * + ******************************************************************************/ + +C_EXTERN void UAF_InterruptHandler (T_fd_UartId uart_id, + SYS_UWORD8 interrupt_status); + +/******************************************************************************* + * + * UAF_CheckXEmpty + * + * Purpose : Checks the empty condition of the Transmitter. + * + * Arguments: In : uartNo: Used UART. + * Out: none + * + * Returns : FD_OK : Empty condition OK. + * FD_NOT_SUPPORTED: Wrong UART number. + * FD_NOT_READY : Empty condition not OK. + * FD_INTERNAL_ERR : Internal problem with the hardware. + * + ******************************************************************************/ + +C_EXTERN T_FDRET UAF_CheckXEmpty (T_fd_UartId uartNo); + +/******************************************************************************* + * + * UAF_DTRInterruptHandler + * + * Purpose : This function is only used on C-Sample. On this platform, the DTR + * signal is controlled with an I/O. A change of state of this signal + * is detected with an interrupt. This function is called when this + * interrupt occurs. + * + * Arguments: In : none + * Out: none + * + * Returns : none + * + ******************************************************************************/ + +void UAF_DTRInterruptHandler (void); + +/******************************************************************************* + * + * UAF_Exit + * + * Purpose : + * + * Arguments: In : uartNo: Used UART. + * Out: none + * + * Returns : FD_OK : Successful operation. + * FD_NOT_SUPPORTED: Wrong UART number. + * FD_INTERNAL_ERR : Internal problem. + * + ******************************************************************************/ + +T_FDRET UAF_Exit (T_fd_UartId uartNo); + +#undef C_EXTERN + +#endif /* __UARTFAX_H__ */