Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
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 #ifdef STM32F4 //the F4 has 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 #ifdef STM32F4 //the F4 has 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_put_byte(struct uart_periph *p, long fd, uint8_t data);
101 extern void uart_put_buffer(struct uart_periph *p, long fd, const uint8_t *data, uint16_t len);
102 extern bool uart_check_free_space(struct uart_periph *p, long *fd, uint16_t len);
103 extern void uart_send_message(struct uart_periph *p, long fd);
104 extern uint8_t uart_getch(struct uart_periph *p);
105 
110 extern uint16_t uart_char_available(struct uart_periph *p);
111 
112 
113 extern void uart_arch_init(void);
114 
115 #if USE_UART0
116 extern struct uart_periph uart0;
117 extern void uart0_init(void);
118 #endif // USE_UART0
119 
120 #if USE_UART1
121 extern struct uart_periph uart1;
122 extern void uart1_init(void);
123 #endif // USE_UART1
124 
125 #if USE_UART2
126 extern struct uart_periph uart2;
127 extern void uart2_init(void);
128 #endif // USE_UART2
129 
130 #if USE_UART3
131 extern struct uart_periph uart3;
132 extern void uart3_init(void);
133 #endif // USE_UART3
134 
135 #if USE_UART4
136 extern struct uart_periph uart4;
137 extern void uart4_init(void);
138 #endif // USE_UART4
139 
140 #if USE_UART5
141 extern struct uart_periph uart5;
142 extern void uart5_init(void);
143 #endif // USE_UART5
144 
145 #if USE_UART6
146 extern struct uart_periph uart6;
147 extern void uart6_init(void);
148 #endif // USE_UART6
149 
150 #if USE_UART7
151 extern struct uart_periph uart7;
152 extern void uart7_init(void);
153 #endif // USE_UART7
154 
155 #if USE_UART8
156 extern struct uart_periph uart8;
157 extern void uart8_init(void);
158 #endif // USE_UART8
159 
160 #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:858
uint8_t rx_buf[UART_RX_BUFFER_SIZE]
Receive buffer.
Definition: uart.h:72
volatile uint8_t tx_running
Definition: uart.h:79
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:838
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:296
bool uart_check_free_space(struct uart_periph *p, long *fd, uint16_t len)
Definition: uart_arch.c:899
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:945
#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:852
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:822
void uart_send_message(struct uart_periph *p, long fd)
Definition: uart_arch.c:975
void uart_put_byte(struct uart_periph *p, long fd, uint8_t data)
Uart transmit implementation.
Definition: uart_arch.c:917
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