Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces 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 "pprzlink/pprzlink_device.h"
33 #include "std.h"
34 
35 #ifndef UART_RX_BUFFER_SIZE
36 #if defined STM32F4 || defined STM32F7 //the F4 and F7 have enough memory
37 #define UART_RX_BUFFER_SIZE 256
38 #else
39 #define UART_RX_BUFFER_SIZE 128
40 #endif
41 #endif
42 
43 #ifndef UART_TX_BUFFER_SIZE
44 #if defined STM32F4 || defined STM32F7 //the F4 and F7 have enough memory, and the PX4 bootloader needs more then 128
45 #define UART_TX_BUFFER_SIZE 256
46 #else
47 #define UART_TX_BUFFER_SIZE 128
48 #endif
49 #endif
50 
51 #define UART_DEV_NAME_SIZE 16
52 
53 /*
54  * UART Baud rate defines in arch/x/mcu_periph/uart_arch.h
55  */
56 
57 #define UBITS_7 7
58 #define UBITS_8 8
59 
60 #define USTOP_1 1
61 #define USTOP_2 2
62 
63 #define UPARITY_NO 0
64 #define UPARITY_ODD 1
65 #define UPARITY_EVEN 2
66 
70 struct uart_periph {
79  volatile uint8_t tx_running;
81  void *reg_addr;
83  int baudrate;
85  void *init_struct;
88  volatile uint16_t ore;
89  volatile uint16_t ne_err;
90  volatile uint16_t fe_err;
91 
92  struct link_device device;
93 };
94 
95 
96 extern void uart_periph_init(struct uart_periph *p);
97 extern void uart_periph_set_baudrate(struct uart_periph *p, uint32_t baud);
98 extern void uart_periph_set_bits_stop_parity(struct uart_periph *p, uint8_t bits, uint8_t stop, uint8_t parity);
99 extern void uart_periph_set_mode(struct uart_periph *p, bool tx_enabled, bool rx_enabled, bool hw_flow_control);
100 extern void uart_periph_invert_data_logic(struct uart_periph *p, bool invert_rx, bool invert_tx);
101 extern void uart_put_byte(struct uart_periph *p, long fd, uint8_t data);
102 extern void uart_put_buffer(struct uart_periph *p, long fd, const uint8_t *data, uint16_t len);
103 extern bool uart_check_free_space(struct uart_periph *p, long *fd, uint16_t len);
104 extern void uart_send_message(struct uart_periph *p, long fd);
105 extern uint8_t uart_getch(struct uart_periph *p);
106 
111 extern uint16_t uart_char_available(struct uart_periph *p);
112 
113 
114 extern void uart_arch_init(void);
115 
116 #if USE_UART0
117 extern struct uart_periph uart0;
118 extern void uart0_init(void);
119 #endif // USE_UART0
120 
121 #if USE_UART1
122 extern struct uart_periph uart1;
123 extern void uart1_init(void);
124 #endif // USE_UART1
125 
126 #if USE_UART2
127 extern struct uart_periph uart2;
128 extern void uart2_init(void);
129 #endif // USE_UART2
130 
131 #if USE_UART3
132 extern struct uart_periph uart3;
133 extern void uart3_init(void);
134 #endif // USE_UART3
135 
136 #if USE_UART4
137 extern struct uart_periph uart4;
138 extern void uart4_init(void);
139 #endif // USE_UART4
140 
141 #if USE_UART5
142 extern struct uart_periph uart5;
143 extern void uart5_init(void);
144 #endif // USE_UART5
145 
146 #if USE_UART6
147 extern struct uart_periph uart6;
148 extern void uart6_init(void);
149 #endif // USE_UART6
150 
151 #if USE_UART7
152 extern struct uart_periph uart7;
153 extern void uart7_init(void);
154 #endif // USE_UART7
155 
156 #if USE_UART8
157 extern struct uart_periph uart8;
158 extern void uart8_init(void);
159 #endif // USE_UART8
160 
161 #endif /* MCU_PERIPH_UART_H */
uint8_t tx_buf[UART_TX_BUFFER_SIZE]
Transmit buffer.
Definition: uart.h:76
unsigned short uint16_t
Definition: types.h:16
#define UART_DEV_NAME_SIZE
Definition: uart.h:51
void uart_periph_set_bits_stop_parity(struct uart_periph *p, uint8_t bits, uint8_t stop, uint8_t parity)
Set parity and stop bits.
Definition: uart_arch.c:885
uint8_t rx_buf[UART_RX_BUFFER_SIZE]
Receive buffer.
Definition: uart.h:72
volatile uint8_t tx_running
Definition: uart.h:79
void uart_periph_invert_data_logic(struct uart_periph *p, bool invert_rx, bool invert_tx)
Definition: uart.c:299
void * init_struct
User init struct.
Definition: uart.h:85
void uart_periph_set_baudrate(struct uart_periph *p, uint32_t baud)
Set baudrate.
Definition: uart_arch.c:856
struct link_device device
Generic device interface.
Definition: uart.h:92
uint16_t uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
Definition: uart_arch.c:323
bool uart_check_free_space(struct uart_periph *p, long *fd, uint16_t len)
Definition: uart_arch.c:949
void * reg_addr
UART Register.
Definition: uart.h:81
uint16_t rx_insert_idx
Definition: uart.h:73
void uart_put_buffer(struct uart_periph *p, long fd, const uint8_t *data, uint16_t len)
Uart transmit buffer implementation.
Definition: uart_arch.c:995
#define UART_TX_BUFFER_SIZE
Definition: uart.h:47
UART peripheral.
Definition: uart.h:70
unsigned long uint32_t
Definition: types.h:18
void uart_periph_set_mode(struct uart_periph *p, bool tx_enabled, bool rx_enabled, bool hw_flow_control)
Set mode (not necessary, or can be set by SerialConfig)
Definition: uart_arch.c:871
uint16_t rx_extract_idx
Definition: uart.h:74
volatile uint16_t ne_err
noise error counter
Definition: uart.h:89
volatile uint16_t fe_err
framing error counter
Definition: uart.h:90
uint16_t tx_insert_idx
Definition: uart.h:77
uint8_t uart_getch(struct uart_periph *p)
Definition: uart_arch.c:840
void uart_send_message(struct uart_periph *p, long fd)
Definition: uart_arch.c:1025
void uart_put_byte(struct uart_periph *p, long fd, uint8_t data)
Uart transmit implementation.
Definition: uart_arch.c:967
unsigned char uint8_t
Definition: types.h:14
char dev[UART_DEV_NAME_SIZE]
UART Dev (linux)
Definition: uart.h:87
void uart_periph_init(struct uart_periph *p)
Definition: uart.c:231
int fd
Definition: serial.c:26
int baudrate
UART Baudrate.
Definition: uart.h:83
static float p[2][2]
void uart_arch_init(void)
Definition: uart_arch.c:54
volatile uint16_t ore
overrun error counter
Definition: uart.h:88
#define UART_RX_BUFFER_SIZE
Definition: uart.h:39
uint16_t tx_extract_idx
Definition: uart.h:78