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

📄 serialswitch_core.c

📁 手机GSM TI 平台 串口 uart 驱动 源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************* * * SERIALSWITCH_CORE.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 * ******************************************************************************//* * 17/12/03 * Duplication of serialswitch.c for L1 standalone only * ******************************************************************************/#define __SERIALSWITCH_CORE_C__#define __STANDARD_H__ /* Avoid to define UBYTE, SYS_UWORD16 and UINT32. */#include "l1sw.cfg"#include "chipset.cfg"#include "sys_types.h"#include "nucleus.h"#include "uart/traceswitch.h"#include "uart/serialswitch_core.h"#include "uart/uart.h"#include "memif/mem.h" #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    #if (((BOARD != 35) && (BOARD != 46)) || (GSM_IDLE_RAM == 0))      char ser_cfg_info[NUMBER_OF_TR_UART] = {DUMMY, DUMMY};    #else      char ser_cfg_info[NUMBER_OF_TR_UART] = {DUMMY};    #endif  #endifstatic SYS_UWORD16 serial_cfg = 0x0048; /* All dummies *//* * Types of flows supported. */typedef enum {    TRACE_FLOW#if (OP_L1_STANDALONE == 0)    , FAX_DATA_FLOW,    BLUETOOTH_HCI_FLOW#endif} 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;/* * 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);/* * 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/* * 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];/* * 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;#endifstatic const SYS_UWORD32 uart_base_address[NUMBER_OF_TR_UART] ={#if ((BOARD != 35) && (BOARD != 46)) || (GSM_IDLE_RAM == 0)    MEM_UART_IRDA,#endif    MEM_UART_MODEM    #if (CHIPSET == 12)      , MEM_UART_MODEM2    #endif};/******************************************************************************* * *                              dummy_tr_Init * * Purpose: No action. * * Parameters: See SER_tr_Init. * * Return: none * ******************************************************************************/ static voiddummy_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_UWORD32dummy_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_UWORD32dummy_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_UWORD32dummy_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_UWORD32dummy_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_UWORD32dummy_tr_WriteNBytes (T_tr_UartId device,                      SYS_UWORD8 *buffer,                      SYS_UWORD32 chars_to_write){    return (chars_to_write);}/******************************************************************************* * *                              dummy_tr_WriteChar *

⌨️ 快捷键说明

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