github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/common/include/platform/uart.h (about)

     1  /*
     2   * Copyright (c) 2013 Intel Corporation
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *     http://www.apache.org/licenses/LICENSE-2.0
     8   * Unless required by applicable law or agreed to in writing, software
     9   * distributed under the License is distributed on an "AS IS" BASIS,
    10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11   * See the License for the specific language governing permissions and
    12   * limitations under the License.
    13   */
    14  
    15  #ifndef _UART_H_
    16  #define _UART_H_
    17  
    18  // UART (Universal Asynchronous Receiver Transmitter) Serial Controller
    19  //
    20  // Hardware Definitions File
    21  // UART Programming Interface Type (Same as the PCI definition)
    22  
    23  typedef enum
    24  {
    25      UART_PROG_IF_GENERIC = 0,
    26      UART_PROG_IF_16450   = 1,
    27      UART_PROG_IF_16550   = 2,   // This is the default
    28      UART_PROG_IF_16650   = 3,
    29      UART_PROG_IF_16750   = 4,
    30      UART_PROG_IF_16850   = 5,
    31      UART_PROG_IF_16950   = 6,
    32      UART_PROG_IF_DEFAULT = 2
    33  } UART_PROG_IF_TYPE;
    34  
    35  // Serial Port Handshake Mode
    36  typedef enum
    37  {
    38      UART_HANDSHAKE_NONE     = 0,   // No handshake
    39      UART_HANDSHAKE_HW       = 1,   // RS-232 signals CTS/RTS and DTR/DSR
    40      UART_HANDSHAKE_XON_XOFF = 2,   // XON (ctrl-S) and XOFF (ctrl-Q)
    41      UART_HANDSHAKE_AUTO     = 3,   // Handshake mode is automatically detected
    42      UART_HANDSHAKE_DEFAULT  = 3
    43  } UART_HANDSHAKE_MODE;
    44  
    45  // (24000000/13)MHz input clock
    46  
    47  #define UART_INPUT_CLOCK 1843200
    48  
    49  
    50  // 115200 baud with rounding errors
    51  
    52  #define UART_MAX_BAUD_RATE           115400
    53  #define UART_MIN_BAUD_RATE           50
    54  
    55  #define UART_MAX_RECEIVE_FIFO_DEPTH  16
    56  #define UART_MIN_TIMEOUT             1         // 1 uS
    57  #define UART_MAX_TIMEOUT             100000000 // 100 seconds
    58  
    59  // UART Registers
    60  
    61  #define UART_REGISTER_THR 0   // WO   Transmit Holding Register
    62  #define UART_REGISTER_RBR 0   // RO   Receive Buffer Register
    63  #define UART_REGISTER_DLL 0   // R/W  Divisor Latch LSB
    64  #define UART_REGISTER_DLM 1   // R/W  Divisor Latch MSB
    65  #define UART_REGISTER_IER 1   // R/W  Interrupt Enable Register
    66  #define UART_REGISTER_IIR 2   // RO   Interrupt Identification Register
    67  #define UART_REGISTER_FCR 2   // WO   FIFO Cotrol Register
    68  #define UART_REGISTER_LCR 3   // R/W  Line Control Register
    69  #define UART_REGISTER_MCR 4   // R/W  Modem Control Register
    70  #define UART_REGISTER_LSR 5   // R/W  Line Status Register
    71  #define UART_REGISTER_MSR 6   // R/W  Modem Status Register
    72  #define UART_REGISTER_SCR 7   // R/W  Scratch Pad Register
    73  
    74  #pragma pack(1)
    75  
    76  //  Name:   UART_IER_BITS
    77  //  Purpose:  Define each bit in Interrupt Enable Register
    78  //  Context:
    79  //  Fields:
    80  //     RAVIE  Bit0: Receiver Data Available Interrupt Enable
    81  //     THEIE  Bit1: Transmistter Holding Register Empty Interrupt Enable
    82  //     RIE      Bit2: Receiver Interrupt Enable
    83  //     MIE      Bit3: Modem Interrupt Enable
    84  //     Reserved Bit4-Bit7: Reserved
    85  
    86  typedef struct
    87  {
    88      unsigned int RAVIE    : 1;
    89      unsigned int THEIE    : 1;
    90      unsigned int RIE      : 1;
    91      unsigned int MIE      : 1;
    92      unsigned int Reserved : 4;
    93  } PACKED UART_IER_BITS;
    94  
    95  
    96  //  Name:   UART_IER
    97  //  Purpose:
    98  //  Context:
    99  //  Fields:
   100  //      Bits    UART_IER_BITS:  Bits of the IER
   101  //      Data    UINT8: the value of the IER
   102  
   103  typedef union
   104  {
   105      UART_IER_BITS  bits;
   106      UINT8          data;
   107  } UART_IER;
   108  
   109  //  Name:   UART_IIR_BITS
   110  //  Purpose:  Define each bit in Interrupt Identification Register
   111  //  Context:
   112  //  Fields:
   113  //      IPS    Bit0: Interrupt Pending Status
   114  //      IIB    Bit1-Bit3: Interrupt ID Bits
   115  //      Reserved Bit4-Bit5: Reserved
   116  //      FIFOES   Bit6-Bit7: FIFO Mode Enable Status
   117  
   118  typedef struct
   119  {
   120      unsigned int IPS      : 1;
   121      unsigned int IIB      : 3;
   122      unsigned int Reserved : 2;
   123      unsigned int FIFOES   : 2;
   124  } PACKED UART_IIR_BITS;
   125  
   126  //  Name:   UART_IIR
   127  //  Purpose:
   128  //  Context:
   129  //  Fields:
   130  //      Bits    UART_IIR_BITS:  Bits of the IIR
   131  //      Data    UINT8: the value of the IIR
   132  
   133  typedef union
   134  {
   135      UART_IIR_BITS  bits;
   136      UINT8          data;
   137  } UART_IIR;
   138  
   139  //  Name:   UART_FCR_BITS
   140  //  Purpose:  Define each bit in FIFO Control Register
   141  //  Context:
   142  //  Fields:
   143  //      TRFIFOE    Bit0: Transmit and Receive FIFO Enable
   144  //      RESETRF    Bit1: Reset Reciever FIFO
   145  //      RESETTF    Bit2: Reset Transmistter FIFO
   146  //      DMS        Bit3: DMA Mode Select
   147  //      Reserved   Bit4-Bit5: Reserved
   148  //      RTB        Bit6-Bit7: Receive Trigger Bits
   149  
   150  typedef struct
   151  {
   152      unsigned int TRFIFOE  : 1;
   153      unsigned int RESETRF  : 1;
   154      unsigned int RESETTF  : 1;
   155      unsigned int DMS      : 1;
   156      unsigned int Reserved : 2;
   157      unsigned int RTB      : 2;
   158  } PACKED UART_FCR_BITS;
   159  
   160  //  Name:   UART_FCR
   161  //  Purpose:
   162  //  Context:
   163  //  Fields:
   164  //      Bits    UART_FCR_BITS:  Bits of the FCR
   165  //      Data    UINT8: the value of the FCR
   166  
   167  typedef union
   168  {
   169      UART_FCR_BITS  bits;
   170      UINT8          data;
   171  } UART_FCR;
   172  
   173  //  Name:   UART_LCR_BITS
   174  //  Purpose:  Define each bit in Line Control Register
   175  //  Context:
   176  //  Fields:
   177  //      SERIALDB  Bit0-Bit1: Number of Serial Data Bits
   178  //      STOPB   Bit2: Number of Stop Bits
   179  //      PAREN   Bit3: Parity Enable
   180  //      EVENPAR   Bit4: Even Parity Select
   181  //      STICPAR   Bit5: Sticky Parity
   182  //      BRCON   Bit6: Break Control
   183  //      DLAB    Bit7: Divisor Latch Access Bit
   184  
   185  typedef struct
   186  {
   187      unsigned int SERIALDB : 2;
   188      unsigned int STOPB    : 1;
   189      unsigned int PAREN    : 1;
   190      unsigned int EVENPAR  : 1;
   191      unsigned int STICPAR  : 1;
   192      unsigned int BRCON    : 1;
   193      unsigned int DLAB     : 1;
   194  } PACKED UART_LCR_BITS;
   195  
   196  //  Name:   UART_LCR
   197  //  Purpose:
   198  //  Context:
   199  //  Fields:
   200  //      Bits    UART_LCR_BITS:  Bits of the LCR
   201  //      Data    UINT8: the value of the LCR
   202  
   203  typedef union
   204  {
   205      UART_LCR_BITS  bits;
   206      UINT8          data;
   207  } UART_LCR;
   208  
   209  //  Name:   UART_MCR_BITS
   210  //  Purpose:  Define each bit in Modem Control Register
   211  //  Context:
   212  //  Fields:
   213  //      DTRC     Bit0: Data Terminal Ready Control
   214  //      RTS      Bit1: Request To Send Control
   215  //      OUT1     Bit2: Output1
   216  //      OUT2     Bit3: Output2, used to disable interrupt
   217  //      LME;     Bit4: Loopback Mode Enable
   218  //      Reserved Bit5-Bit7: Reserved
   219  
   220  typedef struct
   221  {
   222      unsigned int DTRC     : 1;
   223      unsigned int RTS      : 1;
   224      unsigned int OUT1     : 1;
   225      unsigned int OUT2     : 1;
   226      unsigned int LME      : 1;
   227      unsigned int Reserved : 3;
   228  } PACKED UART_MCR_BITS;
   229  
   230  //  Name:   UART_MCR
   231  //  Purpose:
   232  //  Context:
   233  //  Fields:
   234  //      Bits    UART_MCR_BITS:  Bits of the MCR
   235  //      Data    UINT8: the value of the MCR
   236  
   237  typedef union
   238  {
   239      UART_MCR_BITS  bits;
   240      UINT8          data;
   241  } UART_MCR;
   242  
   243  //  Name:   UART_LSR_BITS
   244  //  Purpose:  Define each bit in Line Status Register
   245  //  Context:
   246  //  Fields:
   247  //      DR    Bit0: Receiver Data Ready Status
   248  //      OE    Bit1: Overrun Error Status
   249  //      PE    Bit2: Parity Error Status
   250  //      FE    Bit3: Framing Error Status
   251  //      BI    Bit4: Break Interrupt Status
   252  //      THRE  Bit5: Transmistter Holding Register Status
   253  //      TEMT  Bit6: Transmitter Empty Status
   254  //      FIFOE Bit7: FIFO Error Status
   255  
   256  typedef struct
   257  {
   258      unsigned int DR    : 1;
   259      unsigned int OE    : 1;
   260      unsigned int PE    : 1;
   261      unsigned int FE    : 1;
   262      unsigned int BI    : 1;
   263      unsigned int THRE  : 1;
   264      unsigned int TEMT  : 1;
   265      unsigned int FIFOE : 1;
   266  } PACKED UART_LSR_BITS;
   267  
   268  //  Name:   UART_LSR
   269  //  Purpose:
   270  //  Context:
   271  //  Fields:
   272  //      Bits    UART_LSR_BITS:  Bits of the LSR
   273  //      Data    UINT8: the value of the LSR
   274  
   275  typedef union
   276  {
   277      UART_LSR_BITS  bits;
   278      UINT8          data;
   279  } UART_LSR;
   280  
   281  //  Name:   UART_MSR_BITS
   282  //  Purpose:  Define each bit in Modem Status Register
   283  //  Context:
   284  //  Fields:
   285  //      DeltaCTS      Bit0: Delta Clear To Send Status
   286  //      DeltaDSR        Bit1: Delta Data Set Ready Status
   287  //      TrailingEdgeRI  Bit2: Trailing Edge of Ring Indicator Status
   288  //      DeltaDCD        Bit3: Delta Data Carrier Detect Status
   289  //      CTS             Bit4: Clear To Send Status
   290  //      DSR             Bit5: Data Set Ready Status
   291  //      RI              Bit6: Ring Indicator Status
   292  //      DCD             Bit7: Data Carrier Detect Status
   293  
   294  typedef struct
   295  {
   296      unsigned int DeltaCTS       : 1;
   297      unsigned int DeltaDSR       : 1;
   298      unsigned int TrailingEdgeRI : 1;
   299      unsigned int DeltaDCD       : 1;
   300      unsigned int CTS            : 1;
   301      unsigned int DSR            : 1;
   302      unsigned int RI             : 1;
   303      unsigned int DCD            : 1;
   304  } PACKED UART_MSR_BITS;
   305  
   306  //  Name:   UART_MSR
   307  //  Purpose:
   308  //  Context:
   309  //  Fields:
   310  //      Bits    UART_MSR_BITS:  Bits of the MSR
   311  //      Data    UINT8: the value of the MSR
   312  
   313  typedef union
   314  {
   315      UART_MSR_BITS  bits;
   316      UINT8          data;
   317  } UART_MSR;
   318  
   319  #pragma pack()
   320  
   321  #endif