libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
usart.h
Go to the documentation of this file.
1/*
2 * This file is part of the libopencm3 project.
3 *
4 * Copyright (C) 2015 Daniele Lacamera <root at danielinux dot net>
5 *
6 * This library is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This library 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 Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LM3S_USART_H
21#define LM3S_USART_H
22
24
25
26
27#define USART0_BASE 0x4000C000
28#define USART1_BASE 0x4000D000
29#define USART2_BASE 0x4000E000
30
31/* --- Universal Synchronous Asynchronous Receiver Transmitter (USART) */
32#define USART_DR(x) MMIO32((x) + 0x0000)
33#define USART_IR(x) MMIO32((x) + 0x0004)
34#define USART_FR(x) MMIO32((x) + 0x0018)
35#define USART_ILPR(x) MMIO32((x) + 0x0020)
36#define USART_IBRD(x) MMIO32((x) + 0x0024)
37#define USART_FBRD(x) MMIO32((x) + 0x0028)
38#define USART_LCRH(x) MMIO32((x) + 0x002c)
39#define USART_CTL(x) MMIO32((x) + 0x0030)
40#define USART_IFLS(x) MMIO32((x) + 0x0034)
41#define USART_IM(x) MMIO32((x) + 0x0038)
42#define USART_RIS(x) MMIO32((x) + 0x003c)
43#define USART_MIS(x) MMIO32((x) + 0x0040)
44#define USART_IC(x) MMIO32((x) + 0x0044)
45
46/* USART Data Register (USART_DR) */
47/* Bits [31:12] - Reserved */
48#define USART_DR_OE (0x01 << 11)
49#define USART_DR_BE (0x01 << 10)
50#define USART_DR_PE (0x01 << 9)
51#define USART_DR_FE (0x01 << 8)
52
53/* USART Flags Register (USART_FR) */
54/* Bits [31:8] - Reserved */
55#define USART_FR_TXFE (0x01 << 7)
56#define USART_FR_RXFF (0x01 << 6)
57#define USART_FR_TXFF (0x01 << 5)
58#define USART_FR_RXFE (0x01 << 4)
59#define USART_FR_BUSY (0x01 << 3)
60/* Bits [2:0] - Reserved */
61
62/* USART Interrupt Mask Register (USART_IM) */
63/* Bits [31:11] - Reserved */
64#define USART_IM_OE (0x01 << 10)
65#define USART_IM_BE (0x01 << 9)
66#define USART_IM_PE (0x01 << 8)
67#define USART_IM_FE (0x01 << 7)
68#define USART_IM_RT (0x01 << 6)
69#define USART_IM_TX (0x01 << 5)
70#define USART_IM_RX (0x01 << 4)
71/* Bits [3:0] - Reserved */
72
73/* USART Interrupt Clear Register (USART_IC) */
74/* Bits [31:11] - Reserved */
75#define USART_IC_OE (0x01 << 10)
76#define USART_IC_BE (0x01 << 9)
77#define USART_IC_PE (0x01 << 8)
78#define USART_IC_FE (0x01 << 7)
79#define USART_IC_RT (0x01 << 6)
80#define USART_IC_TX (0x01 << 5)
81#define USART_IC_RX (0x01 << 4)
82/* Bits [3:0] - Reserved */
83
88};
89
94};
95
101};
102
106};
107
108void usart_send(uint32_t usart, uint16_t data);
109uint16_t usart_recv(uint32_t usart);
110bool usart_is_send_ready(uint32_t usart);
111bool usart_is_recv_ready(uint32_t usart);
112void usart_send_blocking(uint32_t usart, uint16_t data);
113uint16_t usart_recv_blocking(uint32_t usart);
114void usart_enable_rx_interrupt(uint32_t usart);
115void usart_disable_rx_interrupt(uint32_t usart);
116void usart_clear_rx_interrupt(uint32_t usart);
117void usart_enable_tx_interrupt(uint32_t usart);
118void usart_disable_tx_interrupt(uint32_t usart);
119void usart_clear_tx_interrupt(uint32_t usart);
120bool usart_get_interrupt_source(uint32_t usart, uint32_t flag);
121
122#endif
123
uint16_t usart_recv(uint32_t usart)
Definition: usart.c:28
usart_mode
Definition: usart.h:96
@ USART_MODE_DISABLED
Definition: usart.h:97
@ USART_MODE_TX_RX
Definition: usart.h:100
@ USART_MODE_RX
Definition: usart.h:98
@ USART_MODE_TX
Definition: usart.h:99
void usart_send(uint32_t usart, uint16_t data)
Definition: usart.c:23
void usart_enable_tx_interrupt(uint32_t usart)
Definition: usart.c:60
void usart_clear_rx_interrupt(uint32_t usart)
Definition: usart.c:75
void usart_disable_rx_interrupt(uint32_t usart)
Definition: usart.c:65
bool usart_get_interrupt_source(uint32_t usart, uint32_t flag)
Definition: usart.c:85
bool usart_is_recv_ready(uint32_t usart)
Definition: usart.c:39
usart_parity
Definition: usart.h:90
@ USART_PARITY_ODD
Definition: usart.h:92
@ USART_PARITY_EVEN
Definition: usart.h:93
@ USART_PARITY_NONE
Definition: usart.h:91
uint16_t usart_recv_blocking(uint32_t usart)
Definition: usart.c:49
void usart_enable_rx_interrupt(uint32_t usart)
Definition: usart.c:55
usart_stopbits
Definition: usart.h:84
@ USART_STOPBITS_2
Definition: usart.h:87
@ USART_STOPBITS_1
Definition: usart.h:85
@ USART_STOPBITS_1_5
Definition: usart.h:86
void usart_clear_tx_interrupt(uint32_t usart)
Definition: usart.c:80
bool usart_is_send_ready(uint32_t usart)
Definition: usart.c:44
void usart_disable_tx_interrupt(uint32_t usart)
Definition: usart.c:70
void usart_send_blocking(uint32_t usart, uint16_t data)
Definition: usart.c:33
usart_flowcontrol
Definition: usart.h:103
@ USART_FLOWCONTROL_RTS_CTS
Definition: usart.h:105
@ USART_FLOWCONTROL_NONE
Definition: usart.h:104