1 //***************************************************************************** 2 // 3 // uart.h - Defines and Macros for the UART. 4 // 5 // Copyright (c) 2005-2012 Texas Instruments Incorporated. All rights reserved. 6 // Software License Agreement 7 // 8 // Redistribution and use in source and binary forms, with or without 9 // modification, are permitted provided that the following conditions 10 // are met: 11 // 12 // Redistributions of source code must retain the above copyright 13 // notice, this list of conditions and the following disclaimer. 14 // 15 // Redistributions in binary form must reproduce the above copyright 16 // notice, this list of conditions and the following disclaimer in the 17 // documentation and/or other materials provided with the 18 // distribution. 19 // 20 // Neither the name of Texas Instruments Incorporated nor the names of 21 // its contributors may be used to endorse or promote products derived 22 // from this software without specific prior written permission. 23 // 24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 // 36 // This is part of revision 9453 of the Stellaris Peripheral Driver Library. 37 // 38 //***************************************************************************** 39 40 #ifndef __UART_H__ 41 #define __UART_H__ 42 43 //***************************************************************************** 44 // 45 // If building with a C++ compiler, make all of the definitions in this header 46 // have a C binding. 47 // 48 //***************************************************************************** 49 #ifdef __cplusplus 50 extern "C" 51 { 52 #endif 53 54 //***************************************************************************** 55 // 56 // Values that can be passed to UARTIntEnable, UARTIntDisable, and UARTIntClear 57 // as the ulIntFlags parameter, and returned from UARTIntStatus. 58 // 59 //***************************************************************************** 60 #define UART_INT_9BIT 0x1000 // 9-bit address match interrupt 61 #define UART_INT_OE 0x400 // Overrun Error Interrupt Mask 62 #define UART_INT_BE 0x200 // Break Error Interrupt Mask 63 #define UART_INT_PE 0x100 // Parity Error Interrupt Mask 64 #define UART_INT_FE 0x080 // Framing Error Interrupt Mask 65 #define UART_INT_RT 0x040 // Receive Timeout Interrupt Mask 66 #define UART_INT_TX 0x020 // Transmit Interrupt Mask 67 #define UART_INT_RX 0x010 // Receive Interrupt Mask 68 #define UART_INT_DSR 0x008 // DSR Modem Interrupt Mask 69 #define UART_INT_DCD 0x004 // DCD Modem Interrupt Mask 70 #define UART_INT_CTS 0x002 // CTS Modem Interrupt Mask 71 #define UART_INT_RI 0x001 // RI Modem Interrupt Mask 72 73 //***************************************************************************** 74 // 75 // Values that can be passed to UARTConfigSetExpClk as the ulConfig parameter 76 // and returned by UARTConfigGetExpClk in the pulConfig parameter. 77 // Additionally, the UART_CONFIG_PAR_* subset can be passed to 78 // UARTParityModeSet as the ulParity parameter, and are returned by 79 // UARTParityModeGet. 80 // 81 //***************************************************************************** 82 #define UART_CONFIG_WLEN_MASK 0x00000060 // Mask for extracting word length 83 #define UART_CONFIG_WLEN_8 0x00000060 // 8 bit data 84 #define UART_CONFIG_WLEN_7 0x00000040 // 7 bit data 85 #define UART_CONFIG_WLEN_6 0x00000020 // 6 bit data 86 #define UART_CONFIG_WLEN_5 0x00000000 // 5 bit data 87 #define UART_CONFIG_STOP_MASK 0x00000008 // Mask for extracting stop bits 88 #define UART_CONFIG_STOP_ONE 0x00000000 // One stop bit 89 #define UART_CONFIG_STOP_TWO 0x00000008 // Two stop bits 90 #define UART_CONFIG_PAR_MASK 0x00000086 // Mask for extracting parity 91 #define UART_CONFIG_PAR_NONE 0x00000000 // No parity 92 #define UART_CONFIG_PAR_EVEN 0x00000006 // Even parity 93 #define UART_CONFIG_PAR_ODD 0x00000002 // Odd parity 94 #define UART_CONFIG_PAR_ONE 0x00000082 // Parity bit is one 95 #define UART_CONFIG_PAR_ZERO 0x00000086 // Parity bit is zero 96 97 //***************************************************************************** 98 // 99 // Values that can be passed to UARTFIFOLevelSet as the ulTxLevel parameter and 100 // returned by UARTFIFOLevelGet in the pulTxLevel. 101 // 102 //***************************************************************************** 103 #define UART_FIFO_TX1_8 0x00000000 // Transmit interrupt at 1/8 Full 104 #define UART_FIFO_TX2_8 0x00000001 // Transmit interrupt at 1/4 Full 105 #define UART_FIFO_TX4_8 0x00000002 // Transmit interrupt at 1/2 Full 106 #define UART_FIFO_TX6_8 0x00000003 // Transmit interrupt at 3/4 Full 107 #define UART_FIFO_TX7_8 0x00000004 // Transmit interrupt at 7/8 Full 108 109 //***************************************************************************** 110 // 111 // Values that can be passed to UARTFIFOLevelSet as the ulRxLevel parameter and 112 // returned by UARTFIFOLevelGet in the pulRxLevel. 113 // 114 //***************************************************************************** 115 #define UART_FIFO_RX1_8 0x00000000 // Receive interrupt at 1/8 Full 116 #define UART_FIFO_RX2_8 0x00000008 // Receive interrupt at 1/4 Full 117 #define UART_FIFO_RX4_8 0x00000010 // Receive interrupt at 1/2 Full 118 #define UART_FIFO_RX6_8 0x00000018 // Receive interrupt at 3/4 Full 119 #define UART_FIFO_RX7_8 0x00000020 // Receive interrupt at 7/8 Full 120 121 //***************************************************************************** 122 // 123 // Values that can be passed to UARTDMAEnable() and UARTDMADisable(). 124 // 125 //***************************************************************************** 126 #define UART_DMA_ERR_RXSTOP 0x00000004 // Stop DMA receive if UART error 127 #define UART_DMA_TX 0x00000002 // Enable DMA for transmit 128 #define UART_DMA_RX 0x00000001 // Enable DMA for receive 129 130 //***************************************************************************** 131 // 132 // Values returned from UARTRxErrorGet(). 133 // 134 //***************************************************************************** 135 #define UART_RXERROR_OVERRUN 0x00000008 136 #define UART_RXERROR_BREAK 0x00000004 137 #define UART_RXERROR_PARITY 0x00000002 138 #define UART_RXERROR_FRAMING 0x00000001 139 140 //***************************************************************************** 141 // 142 // Values that can be passed to UARTHandshakeOutputsSet() or returned from 143 // UARTHandshakeOutputGet(). 144 // 145 //***************************************************************************** 146 #define UART_OUTPUT_RTS 0x00000800 147 #define UART_OUTPUT_DTR 0x00000400 148 149 //***************************************************************************** 150 // 151 // Values that can be returned from UARTHandshakeInputsGet(). 152 // 153 //***************************************************************************** 154 #define UART_INPUT_RI 0x00000100 155 #define UART_INPUT_DCD 0x00000004 156 #define UART_INPUT_DSR 0x00000002 157 #define UART_INPUT_CTS 0x00000001 158 159 //***************************************************************************** 160 // 161 // Values that can be passed to UARTFlowControl() or returned from 162 // UARTFlowControlGet(). 163 // 164 //***************************************************************************** 165 #define UART_FLOWCONTROL_TX 0x00008000 166 #define UART_FLOWCONTROL_RX 0x00004000 167 #define UART_FLOWCONTROL_NONE 0x00000000 168 169 //***************************************************************************** 170 // 171 // Values that can be passed to UARTTxIntModeSet() or returned from 172 // UARTTxIntModeGet(). 173 // 174 //***************************************************************************** 175 #define UART_TXINT_MODE_FIFO 0x00000000 176 #define UART_TXINT_MODE_EOT 0x00000010 177 178 //***************************************************************************** 179 // 180 // Values that can be passed to UARTClockSourceSet() or returned from 181 // UARTClockSourceGet(). 182 // 183 //***************************************************************************** 184 #define UART_CLOCK_SYSTEM 0x00000000 185 #define UART_CLOCK_PIOSC 0x00000005 186 187 //***************************************************************************** 188 // 189 // API Function prototypes 190 // 191 //***************************************************************************** 192 extern void UARTParityModeSet(unsigned long ulBase, unsigned long ulParity); 193 extern unsigned long UARTParityModeGet(unsigned long ulBase); 194 extern void UARTFIFOLevelSet(unsigned long ulBase, unsigned long ulTxLevel, 195 unsigned long ulRxLevel); 196 extern void UARTFIFOLevelGet(unsigned long ulBase, unsigned long *pulTxLevel, 197 unsigned long *pulRxLevel); 198 extern void UARTConfigSetExpClk(unsigned long ulBase, unsigned long ulUARTClk, 199 unsigned long ulBaud, unsigned long ulConfig); 200 extern void UARTConfigGetExpClk(unsigned long ulBase, unsigned long ulUARTClk, 201 unsigned long *pulBaud, 202 unsigned long *pulConfig); 203 extern void UARTEnable(unsigned long ulBase); 204 extern void UARTDisable(unsigned long ulBase); 205 extern void UARTFIFOEnable(unsigned long ulBase); 206 extern void UARTFIFODisable(unsigned long ulBase); 207 extern void UARTEnableSIR(unsigned long ulBase, tBoolean bLowPower); 208 extern void UARTDisableSIR(unsigned long ulBase); 209 extern tBoolean UARTCharsAvail(unsigned long ulBase); 210 extern tBoolean UARTSpaceAvail(unsigned long ulBase); 211 extern long UARTCharGetNonBlocking(unsigned long ulBase); 212 extern long UARTCharGet(unsigned long ulBase); 213 extern tBoolean UARTCharPutNonBlocking(unsigned long ulBase, 214 unsigned char ucData); 215 extern void UARTCharPut(unsigned long ulBase, unsigned char ucData); 216 extern void UARTBreakCtl(unsigned long ulBase, tBoolean bBreakState); 217 extern tBoolean UARTBusy(unsigned long ulBase); 218 extern void UARTIntRegister(unsigned long ulBase, void(*pfnHandler)(void)); 219 extern void UARTIntUnregister(unsigned long ulBase); 220 extern void UARTIntEnable(unsigned long ulBase, unsigned long ulIntFlags); 221 extern void UARTIntDisable(unsigned long ulBase, unsigned long ulIntFlags); 222 extern unsigned long UARTIntStatus(unsigned long ulBase, tBoolean bMasked); 223 extern void UARTIntClear(unsigned long ulBase, unsigned long ulIntFlags); 224 extern void UARTDMAEnable(unsigned long ulBase, unsigned long ulDMAFlags); 225 extern void UARTDMADisable(unsigned long ulBase, unsigned long ulDMAFlags); 226 extern unsigned long UARTRxErrorGet(unsigned long ulBase); 227 extern void UARTRxErrorClear(unsigned long ulBase); 228 extern void UARTSmartCardEnable(unsigned long ulBase); 229 extern void UARTSmartCardDisable(unsigned long ulBase); 230 extern void UARTModemControlSet(unsigned long ulBase, 231 unsigned long ulControl); 232 extern void UARTModemControlClear(unsigned long ulBase, 233 unsigned long ulControl); 234 extern unsigned long UARTModemControlGet(unsigned long ulBase); 235 extern unsigned long UARTModemStatusGet(unsigned long ulBase); 236 extern void UARTFlowControlSet(unsigned long ulBase, unsigned long ulMode); 237 extern unsigned long UARTFlowControlGet(unsigned long ulBase); 238 extern void UARTTxIntModeSet(unsigned long ulBase, unsigned long ulMode); 239 extern unsigned long UARTTxIntModeGet(unsigned long ulBase); 240 extern void UARTClockSourceSet(unsigned long ulBase, unsigned long ulSource); 241 extern unsigned long UARTClockSourceGet(unsigned long ulBase); 242 extern void UART9BitEnable(unsigned long ulBase); 243 extern void UART9BitDisable(unsigned long ulBase); 244 extern void UART9BitAddrSet(unsigned long ulBase, unsigned char ucAddr, 245 unsigned char ucMask); 246 extern void UART9BitAddrSend(unsigned long ulBase, unsigned char ucAddr); 247 248 //***************************************************************************** 249 // 250 // Several UART APIs have been renamed, with the original function name being 251 // deprecated. These defines provide backward compatibility. 252 // 253 //***************************************************************************** 254 #ifndef DEPRECATED 255 #include "driverlib/sysctl.h" 256 #define UARTConfigSet(a, b, c) \ 257 UARTConfigSetExpClk(a, SysCtlClockGet(), b, c) 258 #define UARTConfigGet(a, b, c) \ 259 UARTConfigGetExpClk(a, SysCtlClockGet(), b, c) 260 #define UARTCharNonBlockingGet(a) \ 261 UARTCharGetNonBlocking(a) 262 #define UARTCharNonBlockingPut(a, b) \ 263 UARTCharPutNonBlocking(a, b) 264 #endif 265 266 //***************************************************************************** 267 // 268 // Mark the end of the C bindings section for C++ compilers. 269 // 270 //***************************************************************************** 271 #ifdef __cplusplus 272 } 273 #endif 274 275 #endif // __UART_H__ 276