Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
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 rates
40  * defines because the stupid c preprocessor can't handle enums
41 */
42 #define B1200 1200
43 #define B2400 2400
44 #define B4800 4800
45 #define B9600 9600
46 #define B19200 19200
47 #define B38400 38400
48 #define B57600 57600
49 #define B115200 115200
50 #define B230400 230400
51 #define B921600 921600
52 
56 struct uart_periph {
67  void* reg_addr;
70  volatile uint16_t ore;
71  volatile uint16_t ne_err;
72  volatile uint16_t fe_err;
73 };
74 
75 
76 extern void uart_periph_init(struct uart_periph* p);
77 extern void uart_periph_set_baudrate(struct uart_periph* p, uint32_t baud);
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 
83 static inline bool_t uart_char_available(struct uart_periph* p) {
84  return (p->rx_insert_idx != p->rx_extract_idx);
85 }
86 
87 
88 #ifdef USE_UART0
89 extern struct uart_periph uart0;
90 extern void uart0_init(void);
91 
92 #define UART0Init() uart_periph_init(&uart0)
93 #define UART0CheckFreeSpace(_x) uart_check_free_space(&uart0, _x)
94 #define UART0Transmit(_x) uart_transmit(&uart0, _x)
95 #define UART0SendMessage() {}
96 #define UART0ChAvailable() uart_char_available(&uart0)
97 #define UART0Getch() uart_getch(&uart0)
98 #define UART0TxRunning uart0.tx_running
99 #define UART0SetBaudrate(_b) uart_periph_set_baudrate(&uart0, _b)
100 
101 #endif // USE_UART0
102 
103 #ifdef USE_UART1
104 extern struct uart_periph uart1;
105 extern void uart1_init(void);
106 
107 #define UART1Init() uart_periph_init(&uart1)
108 #define UART1CheckFreeSpace(_x) uart_check_free_space(&uart1, _x)
109 #define UART1Transmit(_x) uart_transmit(&uart1, _x)
110 #define UART1SendMessage() {}
111 #define UART1ChAvailable() uart_char_available(&uart1)
112 #define UART1Getch() uart_getch(&uart1)
113 #define UART1TxRunning uart1.tx_running
114 #define UART1SetBaudrate(_b) uart_periph_set_baudrate(&uart1, _b)
115 
116 #endif // USE_UART1
117 
118 #ifdef USE_UART2
119 extern struct uart_periph uart2;
120 extern void uart2_init(void);
121 
122 #define UART2Init() uart_periph_init(&uart2)
123 #define UART2CheckFreeSpace(_x) uart_check_free_space(&uart2, _x)
124 #define UART2Transmit(_x) uart_transmit(&uart2, _x)
125 #define UART2SendMessage() {}
126 #define UART2ChAvailable() uart_char_available(&uart2)
127 #define UART2Getch() uart_getch(&uart2)
128 #define UART2TxRunning uart2.tx_running
129 #define UART2SetBaudrate(_b) uart_periph_set_baudrate(&uart2, _b)
130 
131 #endif // USE_UART2
132 
133 #ifdef USE_UART3
134 extern struct uart_periph uart3;
135 extern void uart3_init(void);
136 
137 #define UART3Init() uart_periph_init(&uart3)
138 #define UART3CheckFreeSpace(_x) uart_check_free_space(&uart3, _x)
139 #define UART3Transmit(_x) uart_transmit(&uart3, _x)
140 #define UART3SendMessage() {}
141 #define UART3ChAvailable() uart_char_available(&uart3)
142 #define UART3Getch() uart_getch(&uart3)
143 #define UART3TxRunning uart3.tx_running
144 #define UART3SetBaudrate(_b) uart_periph_set_baudrate(&uart3, _b)
145 
146 #endif // USE_UART3
147 
148 #ifdef USE_UART4
149 extern struct uart_periph uart4;
150 extern void uart4_init(void);
151 
152 #define UART4Init() uart_periph_init(&uart4)
153 #define UART4CheckFreeSpace(_x) uart_check_free_space(&uart4, _x)
154 #define UART4Transmit(_x) uart_transmit(&uart4, _x)
155 #define UART4SendMessage() {}
156 #define UART4ChAvailable() uart_char_available(&uart4)
157 #define UART4Getch() uart_getch(&uart4)
158 #define UART4TxRunning uart4.tx_running
159 #define UART4SetBaudrate(_b) uart_periph_set_baudrate(&uart4, _b)
160 
161 #endif // USE_UART4
162 
163 #ifdef USE_UART5
164 extern struct uart_periph uart5;
165 extern void uart5_init(void);
166 
167 #define UART5Init() uart_periph_init(&uart5)
168 #define UART5CheckFreeSpace(_x) uart_check_free_space(&uart5, _x)
169 #define UART5Transmit(_x) uart_transmit(&uart5, _x)
170 #define UART5SendMessage() {}
171 #define UART5ChAvailable() uart_char_available(&uart5)
172 #define UART5Getch() uart_getch(&uart5)
173 #define UART5TxRunning uart5.tx_running
174 #define UART5SetBaudrate(_b) uart_periph_set_baudrate(&uart5, _b)
175 
176 #endif // USE_UART5
177 
178 #ifdef USE_UART6
179 extern struct uart_periph uart6;
180 extern void uart6_init(void);
181 
182 #define UART6Init() uart_periph_init(&uart6)
183 #define UART6CheckFreeSpace(_x) uart_check_free_space(&uart6, _x)
184 #define UART6Transmit(_x) uart_transmit(&uart6, _x)
185 #define UART6SendMessage() {}
186 #define UART6ChAvailable() uart_char_available(&uart6)
187 #define UART6Getch() uart_getch(&uart6)
188 #define UART6TxRunning uart6.tx_running
189 #define UART6SetBaudrate(_b) uart_periph_set_baudrate(&uart6, _b)
190 
191 #endif // USE_UART6
192 
193 #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:64
char dev[UART_DEV_NAME_SIZE]
UART Dev (linux)
Definition: uart.h:69
static bool_t uart_char_available(struct uart_periph *p)
Definition: uart.h:83
volatile uint16_t ore
overrun error counter
Definition: uart.h:70
volatile uint16_t fe_err
framing error counter
Definition: uart.h:72
uint8_t tx_running
Definition: uart.h:65
volatile uint16_t ne_err
noise error counter
Definition: uart.h:71
void * reg_addr
UART Register.
Definition: uart.h:67
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:64
UART peripheral.
Definition: uart.h:56
#define UART_TX_BUFFER_SIZE
Definition: uart.h:35
unsigned long uint32_t
Definition: types.h:18
uint16_t rx_insert_idx
Definition: uart.h:59
void uart_transmit(struct uart_periph *p, uint8_t data)
Definition: uart_arch.c:71
uint8_t uart_getch(struct uart_periph *p)
Definition: uart.c:71
uint8_t tx_buf[UART_TX_BUFFER_SIZE]
Transmit buffer.
Definition: uart.h:62
unsigned char uint8_t
Definition: types.h:14
void uart_periph_init(struct uart_periph *p)
Definition: uart.c:53
uint16_t tx_insert_idx
Definition: uart.h:63
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:64
uint8_t rx_buf[UART_RX_BUFFER_SIZE]
Receive buffer.
Definition: uart.h:58
static float p[2][2]
uint16_t rx_extract_idx
Definition: uart.h:60
#define UART_RX_BUFFER_SIZE
Definition: uart.h:34