Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# uartintr.h

    00001 /*! \file uartintr.h \brief UART driver for ARM LPC2000 16550 with interrupts. */
    00002 //*****************************************************************************
    00003 //
    00004 // File Name    : 'uartintr.h'
    00005 // Title        : UART driver for ARM LPC2000 16550 with interrupts
    00006 // Author       : Pascal Stang - Copyright (C) 2004-2006
    00007 // Created      : 4/3/2004
    00008 // Revised      : 4/11/2006
    00009 // Version      : 0.1
    00010 // Target MCU   : Philips ARM LPC2000 Series
    00011 // Editor Tabs  : 4
    00012 //
    00013 // This code is distributed under the GNU Public License
    00014 //      which can be found at http://www.gnu.org/licenses/gpl.txt
    00015 //
    00016 //*****************************************************************************
    00017
    00018 #ifndef UARTINTR_H
    00019 #define UARTINTR_H
    00020
    00021 #include "global.h"
    00022 #include "buffer.h"
    00023 #include "LPC2000.h"
    00024
    00025 // defines
    00026
    00027 // UART_BAUD calculates a division rate given a baud rate
    00028 // for use with uart0Init() and uart1Init()
    00029 // example: uart0Init(UART_BAUD(115200), UART_8N1, UART_FIFO_8);
    00030 //
    00031 // BEWARE: additional code will be generated if 'baud' is not a contant
    00032 #define UART_BAUD(baud) (uint16_t)((PCLK+baud*8L)/(baud*16))
    00033
    00034 // Definitions for UART mode settings (databits, parity, stopbits)
    00035 #define UART_8N1      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_NO   + ULCR_STOP_1)
    00036 #define UART_7N1      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_NO   + ULCR_STOP_1)
    00037 #define UART_8N2      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_NO   + ULCR_STOP_2)
    00038 #define UART_7N2      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_NO   + ULCR_STOP_2)
    00039 #define UART_8E1      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_EVEN + ULCR_STOP_1)
    00040 #define UART_7E1      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_EVEN + ULCR_STOP_1)
    00041 #define UART_8E2      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_EVEN + ULCR_STOP_2)
    00042 #define UART_7E2      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_EVEN + ULCR_STOP_2)
    00043 #define UART_8O1      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_ODD  + ULCR_STOP_1)
    00044 #define UART_7O1      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_ODD  + ULCR_STOP_1)
    00045 #define UART_8O2      (uint8_t)(ULCR_CHAR_8 + ULCR_PAR_ODD  + ULCR_STOP_2)
    00046 #define UART_7O2      (uint8_t)(ULCR_CHAR_7 + ULCR_PAR_ODD  + ULCR_STOP_2)
    00047
    00048 // Definitions for UART fifo mode settings
    00049 #define UART_FIFO_OFF (0x00)
    00050 #define UART_FIFO_1   (uint8_t)(UFCR_FIFO_ENABLE + UFCR_FIFO_TRIG1)
    00051 #define UART_FIFO_4   (uint8_t)(UFCR_FIFO_ENABLE + UFCR_FIFO_TRIG4)
    00052 #define UART_FIFO_8   (uint8_t)(UFCR_FIFO_ENABLE + UFCR_FIFO_TRIG8)
    00053 #define UART_FIFO_14  (uint8_t)(UFCR_FIFO_ENABLE + UFCR_FIFO_TRIG14)
    00054
    00055 // buffer memory allocation defines
    00056 // buffer sizes
    00057 #ifndef UART0_TX_BUFFER_SIZE
    00058 #define UART0_TX_BUFFER_SIZE        0x0010  ///< number of bytes for uart0 transmit buffer
    00059 #endif
    00060 #ifndef UART0_RX_BUFFER_SIZE
    00061 #define UART0_RX_BUFFER_SIZE        0x0080  ///< number of bytes for uart0 receive buffer
    00062 #endif
    00063 #ifndef UART1_TX_BUFFER_SIZE
    00064 #define UART1_TX_BUFFER_SIZE        0x0010  ///< number of bytes for uart1 transmit buffer
    00065 #endif
    00066 #ifndef UART1_RX_BUFFER_SIZE
    00067 #define UART1_RX_BUFFER_SIZE        0x0080  ///< number of bytes for uart1 receive buffer
    00068 #endif
    00069
    00070
    00071 // functions
    00072
    00073 //! initializes uart
    00074 void uart0Init(uint16_t baud, uint8_t mode, uint8_t fifomode);
    00075 void uart1Init(uint16_t baud, uint8_t mode, uint8_t fifomode);
    00076
    00077 //! initializes transmit and receive buffers
    00078 // called from uartInit()
    00079 void uart0InitBuffers(void);
    00080 void uart1InitBuffers(void);
    00081
    00082 cBuffer* uart0GetRxBuffer(void);
    00083 cBuffer* uart1GetRxBuffer(void);
    00084
    00085 //! sends a single byte over the uart
    00086 int uart0SendByte(int data);
    00087 int uart1SendByte(int data);
    00088
    00089 //! gets a single byte from the uart receive buffer
    00090 int uart0GetByte(void);
    00091 int uart1GetByte(void);
    00092
    00093 //! interrupt service handlers
    00094 void uart0Service(void) __attribute__((interrupt));
    00095 void uart1Service(void) __attribute__((interrupt));
    00096
    00097 #endif