4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
33 * \brief LM3S1968 UART interface driver.
35 * \author Andrea Righi <arighi@develer.com>
41 #include <cfg/cfg_debug.h>
42 #include <cpu/power.h> /* cpu_relax() */
43 #include <drv/clock_lm3s.h> /* lm3s_busyWait() */
46 /* Serial hardware numbers */
53 SER_CNT //< Number of serial ports
57 #define SERRF_RXFIFOOVERRUN BV(0) //< Rx FIFO buffer overrun
58 #define SERRF_RXTIMEOUT BV(1) //< Receive timeout
59 #define SERRF_TXTIMEOUT BV(2) //< Transmit timeout
64 #define SERRF_RXSROVERRUN 0 //< Input overrun
65 #define SERRF_FRAMEERROR 0 //< Stop bit missing
66 #define SERRF_PARITYERROR 0 //< Parity error
67 #define SERRF_NOISEERROR 0 //< Noise error
69 /* Serial error/status flags */
70 typedef uint32_t serstatus_t;
72 INLINE void lm3s_uartDisable(uint32_t base)
74 /* Disable the hardware FIFO */
75 HWREG(base + UART_O_LCRH) &= ~UART_LCRH_FEN;
77 /* Disable the UART */
78 HWREG(base + UART_O_CTL) &=
79 ~(UART_CTL_UARTEN | UART_CTL_TXE | UART_CTL_RXE);
83 INLINE void lm3s_uartEnable(uint32_t base)
85 /* Enable the hardware FIFO */
86 HWREG(base + UART_O_LCRH) |= UART_LCRH_FEN;
88 /* Enable RX, TX, and the UART */
89 HWREG(base + UART_O_CTL) |=
90 UART_CTL_UARTEN | UART_CTL_TXE | UART_CTL_RXE;
94 /* Clear the flags register */
95 INLINE void lm3s_uartClear(uint32_t base)
97 HWREG(base + UART_O_FR) = 0;
100 INLINE bool lm3s_uartTxDone(uint32_t base)
102 return HWREG(base + UART_O_FR) & UART_FR_TXFE ? true : false;
105 INLINE bool lm3s_uartTxReady(uint32_t base)
107 return HWREG(base + UART_O_FR) & UART_FR_TXFF ? false : true;
110 INLINE bool lm3s_uartRxReady(uint32_t base)
112 return HWREG(base + UART_O_FR) & UART_FR_RXFE ? false : true;
115 INLINE bool lm3s_uartReady(uint32_t base)
117 return HWREG(base + UART_O_FR) & UART_FR_BUSY ? false : true;
120 INLINE int lm3s_uartPutCharNonBlocking(uint32_t base, unsigned char c)
122 if (!lm3s_uartTxReady(base))
124 HWREG(base + UART_O_DR) = c;
128 INLINE int lm3s_uartPutChar(uint32_t base, unsigned char c)
130 while (!lm3s_uartTxReady(base))
132 HWREG(base + UART_O_DR) = c;
136 INLINE int lm3s_uartGetCharNonBlocking(uint32_t base)
138 if (!lm3s_uartRxReady(base))
140 return HWREG(base + UART_O_DR);
143 INLINE int lm3s_uartGetChar(uint32_t base)
145 while (!lm3s_uartRxReady(base))
147 return HWREG(base + UART_O_DR);
150 void lm3s_uartSetBaudRate(uint32_t base, unsigned long baud);
151 void lm3s_uartSetParity(uint32_t base, int parity);
152 void lm3s_uartInit(int port);
154 #endif /* SER_LM3S_H */