⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serialswitch.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 5 页
字号:
/*******************************************************************************
 *
 * 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
 *
 ******************************************************************************/

#define __SERIALSWITCH_C__

#define __STANDARD_H__ /* Avoid to define UBYTE, SYS_UWORD16 and UINT32. */

#include "sys_types.h"
#include "nucleus.h"

#include "traceswitch.h"
#include "faxdata.h"
#include "serialswitch.h"

#include "uart.h"
#include "uartfax.h"

#include "mem.h"

#include "rv.cfg"
#include "chipset.cfg"

#include <string.h> /* needed for memcmp & memset */

#if (defined BLUETOOTH && (CHIPSET != 12))
  #include "ffs.h"
  #include "rvf_api.h"
  #include "iq.h"
  #include "rvt_def_i.h" /* needed for Riviera/Layer1 Trace's callback function */
#endif

#ifdef BLUETOOTH
  #include "bluetooth.cfg"
  #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 (defined BLUETOOTH && (CHIPSET != 12))
  /*
   * 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 BLUETOOTH
  /*
   * 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) (UINT8 hciu_packet_type,
                                      void *uart_tx_buffer);

  } 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 BLUETOOTH
  /*
   * 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 (UINT8 hciu_packet_type,
                                            void *uart_tx_buffer);
#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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -