Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
uart.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 The Paparazzi Team
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi 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, or (at your option)
9  * any later version.
10  *
11  * paparazzi 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.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
28 #ifndef MCU_PERIPH_UART_H
29 #define MCU_PERIPH_UART_H
30 
31 #include "mcu_periph/uart_arch.h"
32 #include "std.h"
33 
34 #define UART_RX_BUFFER_SIZE 128
35 #define UART_TX_BUFFER_SIZE 128
36 #define UART_DEV_NAME_SIZE 16
37 
38 /*
39  * UART Baud rate defines in arch/x/mcu_periph/uart_arch.h
40  */
41 
42 #define UBITS_7 7
43 #define UBITS_8 8
44 
45 #define USTOP_1 1
46 #define USTOP_2 2
47 
48 #define UPARITY_NO 0
49 #define UPARITY_ODD 1
50 #define UPARITY_EVEN 2
51 
55 struct uart_periph {
66  void* reg_addr;
69  volatile uint16_t ore;
70  volatile uint16_t ne_err;
71  volatile uint16_t fe_err;
72 };
73 
74 
75 extern void uart_periph_init(struct uart_periph* p);
76 extern void uart_periph_set_baudrate(struct uart_periph* p, uint32_t baud);
77 extern void uart_periph_set_bits_stop_parity(struct uart_periph* p, uint8_t bits, uint8_t stop, uint8_t parity);
78 extern void uart_periph_set_mode(struct uart_periph* p, bool_t tx_enabled, bool_t rx_enabled, bool_t hw_flow_control);
79 extern void uart_transmit(struct uart_periph* p, uint8_t data);
80 extern bool_t uart_check_free_space(struct uart_periph* p, uint8_t len);
81 extern uint8_t uart_getch(struct uart_periph* p);
82 
87 static inline uint16_t uart_char_available(struct uart_periph* p) {
88  int16_t available = p->rx_insert_idx - p->rx_extract_idx;
89  if (available < 0)
90  available += UART_RX_BUFFER_SIZE;
91  return (uint16_t)available;
92 }
93 
94 
95 #if USE_UART0
96 extern struct uart_periph uart0;
97 extern void uart0_init(void);
98 
99 #define UART0Init() uart_periph_init(&uart0)
100 #define UART0CheckFreeSpace(_x) uart_check_free_space(&uart0, _x)
101 #define UART0Transmit(_x) uart_transmit(&uart0, _x)
102 #define UART0SendMessage() {}
103 #define UART0ChAvailable() uart_char_available(&uart0)
104 #define UART0Getch() uart_getch(&uart0)
105 #define UART0TxRunning uart0.tx_running
106 #define UART0SetBaudrate(_b) uart_periph_set_baudrate(&uart0, _b)
107 #define UART0SetBitsStopParity(_b, _s, _p) uart_periph_set_bits_stop_parity(&uart0, _b, _s, _p)
108 
109 #endif // USE_UART0
110 
111 #if USE_UART1
112 extern struct uart_periph uart1;
113 extern void uart1_init(void);
114 
115 #define UART1Init() uart_periph_init(&uart1)
116 #define UART1CheckFreeSpace(_x) uart_check_free_space(&uart1, _x)
117 #define UART1Transmit(_x) uart_transmit(&uart1, _x)
118 #define UART1SendMessage() {}
119 #define UART1ChAvailable() uart_char_available(&uart1)
120 #define UART1Getch() uart_getch(&uart1)
121 #define UART1TxRunning uart1.tx_running
122 #define UART1SetBaudrate(_b) uart_periph_set_baudrate(&uart1, _b)
123 #define UART1SetBitsStopParity(_b, _s, _p) uart_periph_set_bits_stop_parity(&uart1, _b, _s, _p)
124 
125 #endif // USE_UART1
126 
127 #if USE_UART2
128 extern struct uart_periph uart2;
129 extern void uart2_init(void);
130 
131 #define UART2Init() uart_periph_init(&uart2)
132 #define UART2CheckFreeSpace(_x) uart_check_free_space(&uart2, _x)
133 #define UART2Transmit(_x) uart_transmit(&uart2, _x)
134 #define UART2SendMessage() {}
135 #define UART2ChAvailable() uart_char_available(&uart2)
136 #define UART2Getch() uart_getch(&uart2)
137 #define UART2TxRunning uart2.tx_running
138 #define UART2SetBaudrate(_b) uart_periph_set_baudrate(&uart2, _b)
139 #define UART2SetBitsStopParity(_b, _s, _p) uart_periph_set_bits_stop_parity(&uart2, _b, _s, _p)
140 
141 #endif // USE_UART2
142 
143 #if USE_UART3
144 extern struct uart_periph uart3;
145 extern void uart3_init(void);
146 
147 #define UART3Init() uart_periph_init(&uart3)
148 #define UART3CheckFreeSpace(_x) uart_check_free_space(&uart3, _x)
149 #define UART3Transmit(_x) uart_transmit(&uart3, _x)
150 #define UART3SendMessage() {}
151 #define UART3ChAvailable() uart_char_available(&uart3)
152 #define UART3Getch() uart_getch(&uart3)
153 #define UART3TxRunning uart3.tx_running
154 #define UART3SetBaudrate(_b) uart_periph_set_baudrate(&uart3, _b)
155 #define UART3SetBitsStopParity(_b, _s, _p) uart_periph_set_bits_stop_parity(&uart3, _b, _s, _p)
156 
157 #endif // USE_UART3
158 
159 #if USE_UART4
160 extern struct uart_periph uart4;
161 extern void uart4_init(void);
162 
163 #define UART4Init() uart_periph_init(&uart4)
164 #define UART4CheckFreeSpace(_x) uart_check_free_space(&uart4, _x)
165 #define UART4Transmit(_x) uart_transmit(&uart4, _x)
166 #define UART4SendMessage() {}
167 #define UART4ChAvailable() uart_char_available(&uart4)
168 #define UART4Getch() uart_getch(&uart4)
169 #define UART4TxRunning uart4.tx_running
170 #define UART4SetBaudrate(_b) uart_periph_set_baudrate(&uart4, _b)
171 #define UART4SetBitsStopParity(_b, _s, _p) uart_periph_set_bits_stop_parity(&uart4, _b, _s, _p)
172 
173 #endif // USE_UART4
174 
175 #if USE_UART5
176 extern struct uart_periph uart5;
177 extern void uart5_init(void);
178 
179 #define UART5Init() uart_periph_init(&uart5)
180 #define UART5CheckFreeSpace(_x) uart_check_free_space(&uart5, _x)
181 #define UART5Transmit(_x) uart_transmit(&uart5, _x)
182 #define UART5SendMessage() {}
183 #define UART5ChAvailable() uart_char_available(&uart5)
184 #define UART5Getch() uart_getch(&uart5)
185 #define UART5TxRunning uart5.tx_running
186 #define UART5SetBaudrate(_b) uart_periph_set_baudrate(&uart5, _b)
187 #define UART5SetBitsStopParity(_b, _s, _p) uart_periph_set_bits_stop_parity(&uart5, _b, _s, _p)
188 
189 #endif // USE_UART5
190 
191 #if USE_UART6
192 extern struct uart_periph uart6;
193 extern void uart6_init(void);
194 
195 #define UART6Init() uart_periph_init(&uart6)
196 #define UART6CheckFreeSpace(_x) uart_check_free_space(&uart6, _x)
197 #define UART6Transmit(_x) uart_transmit(&uart6, _x)
198 #define UART6SendMessage() {}
199 #define UART6ChAvailable() uart_char_available(&uart6)
200 #define UART6Getch() uart_getch(&uart6)
201 #define UART6TxRunning uart6.tx_running
202 #define UART6SetBaudrate(_b) uart_periph_set_baudrate(&uart6, _b)
203 #define UART6SetBitsStopParity(_b, _s, _p) uart_periph_set_bits_stop_parity(&uart6, _b, _s, _p)
204 
205 #endif // USE_UART6
206 
207 #endif /* MCU_PERIPH_UART_H */
unsigned short uint16_t
Definition: types.h:16
#define UART_DEV_NAME_SIZE
Definition: uart.h:36
bool_t uart_check_free_space(struct uart_periph *p, uint8_t len)
Definition: uart.c:197
void uart_periph_set_bits_stop_parity(struct uart_periph *p, uint8_t bits, uint8_t stop, uint8_t parity)
Definition: uart_arch.c:71
char dev[UART_DEV_NAME_SIZE]
UART Dev (linux)
Definition: uart.h:68
static uint16_t uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
Definition: uart.h:87
volatile uint16_t ore
overrun error counter
Definition: uart.h:69
volatile uint16_t fe_err
framing error counter
Definition: uart.h:71
uint8_t tx_running
Definition: uart.h:64
volatile uint16_t ne_err
noise error counter
Definition: uart.h:70
void * reg_addr
UART Register.
Definition: uart.h:66
void uart_periph_set_baudrate(struct uart_periph *p, uint32_t baud)
Definition: uart_arch.c:65
uint16_t tx_extract_idx
Definition: uart.h:63
UART peripheral.
Definition: uart.h:55
#define UART_TX_BUFFER_SIZE
Definition: uart.h:35
unsigned long uint32_t
Definition: types.h:18
signed short int16_t
Definition: types.h:17
uint16_t rx_insert_idx
Definition: uart.h:58
void uart_transmit(struct uart_periph *p, uint8_t data)
Definition: uart_arch.c:75
uint8_t uart_getch(struct uart_periph *p)
Definition: uart.c:204
uint8_t tx_buf[UART_TX_BUFFER_SIZE]
Transmit buffer.
Definition: uart.h:61
unsigned char uint8_t
Definition: types.h:14
void uart_periph_init(struct uart_periph *p)
Definition: uart.c:181
uint16_t tx_insert_idx
Definition: uart.h:62
void uart_periph_set_mode(struct uart_periph *p, bool_t tx_enabled, bool_t rx_enabled, bool_t hw_flow_control)
Definition: uart_arch.c:88
uint8_t rx_buf[UART_RX_BUFFER_SIZE]
Receive buffer.
Definition: uart.h:57
static float p[2][2]
uint16_t rx_extract_idx
Definition: uart.h:59
#define UART_RX_BUFFER_SIZE
Definition: uart.h:34