Paparazzi UAS  v5.8.2_stable-0-g6260b7c
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 "mcu_periph/link_device.h"
33 #include "std.h"
34 
35 #ifndef UART_RX_BUFFER_SIZE
36 #define UART_RX_BUFFER_SIZE 128
37 #endif
38 #ifndef UART_TX_BUFFER_SIZE
39 #define UART_TX_BUFFER_SIZE 128
40 #endif
41 #define UART_DEV_NAME_SIZE 16
42 
43 /*
44  * UART Baud rate defines in arch/x/mcu_periph/uart_arch.h
45  */
46 
47 #define UBITS_7 7
48 #define UBITS_8 8
49 
50 #define USTOP_1 1
51 #define USTOP_2 2
52 
53 #define UPARITY_NO 0
54 #define UPARITY_ODD 1
55 #define UPARITY_EVEN 2
56 
60 struct uart_periph {
71  void *reg_addr;
73  int baudrate;
76  volatile uint16_t ore;
77  volatile uint16_t ne_err;
78  volatile uint16_t fe_err;
79 
81 };
82 
83 
84 extern void uart_periph_init(struct uart_periph *p);
85 extern void uart_periph_set_baudrate(struct uart_periph *p, uint32_t baud);
86 extern void uart_periph_set_bits_stop_parity(struct uart_periph *p, uint8_t bits, uint8_t stop, uint8_t parity);
87 extern void uart_periph_set_mode(struct uart_periph *p, bool_t tx_enabled, bool_t rx_enabled, bool_t hw_flow_control);
88 extern void uart_put_byte(struct uart_periph *p, uint8_t data);
89 extern bool_t uart_check_free_space(struct uart_periph *p, uint8_t len);
90 extern uint8_t uart_getch(struct uart_periph *p);
91 
97 
98 
99 extern void uart_arch_init(void);
100 
101 #if USE_UART0
102 extern struct uart_periph uart0;
103 extern void uart0_init(void);
104 #endif // USE_UART0
105 
106 #if USE_UART1
107 extern struct uart_periph uart1;
108 extern void uart1_init(void);
109 #endif // USE_UART1
110 
111 #if USE_UART2
112 extern struct uart_periph uart2;
113 extern void uart2_init(void);
114 #endif // USE_UART2
115 
116 #if USE_UART3
117 extern struct uart_periph uart3;
118 extern void uart3_init(void);
119 #endif // USE_UART3
120 
121 #if USE_UART4
122 extern struct uart_periph uart4;
123 extern void uart4_init(void);
124 #endif // USE_UART4
125 
126 #if USE_UART5
127 extern struct uart_periph uart5;
128 extern void uart5_init(void);
129 #endif // USE_UART5
130 
131 #if USE_UART6
132 extern struct uart_periph uart6;
133 extern void uart6_init(void);
134 #endif // USE_UART6
135 
136 #if USE_UART7
137 extern struct uart_periph uart7;
138 extern void uart7_init(void);
139 #endif // USE_UART7
140 
141 #if USE_UART8
142 extern struct uart_periph uart8;
143 extern void uart8_init(void);
144 #endif // USE_UART8
145 
146 #endif /* MCU_PERIPH_UART_H */
uint8_t tx_buf[UART_TX_BUFFER_SIZE]
Transmit buffer.
Definition: uart.h:66
unsigned short uint16_t
Definition: types.h:16
#define UART_DEV_NAME_SIZE
Definition: uart.h:41
bool_t uart_check_free_space(struct uart_periph *p, uint8_t len)
Definition: uart.c:256
void uart_periph_set_bits_stop_parity(struct uart_periph *p, uint8_t bits, uint8_t stop, uint8_t parity)
Definition: uart_arch.c:77
uint8_t tx_running
Definition: uart.h:69
uint8_t rx_buf[UART_RX_BUFFER_SIZE]
Receive buffer.
Definition: uart.h:62
void uart_put_byte(struct uart_periph *p, uint8_t data)
Definition: uart_arch.c:243
void uart_periph_set_baudrate(struct uart_periph *p, uint32_t baud)
Definition: uart_arch.c:216
struct link_device device
Generic device interface.
Definition: uart.h:80
uint16_t uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
Definition: uart_arch.c:296
void * reg_addr
UART Register.
Definition: uart.h:71
uint16_t rx_insert_idx
Definition: uart.h:63
#define UART_TX_BUFFER_SIZE
Definition: uart.h:39
UART peripheral.
Definition: uart.h:60
unsigned long uint32_t
Definition: types.h:18
uint16_t rx_extract_idx
Definition: uart.h:64
volatile uint16_t ne_err
noise error counter
Definition: uart.h:77
volatile uint16_t fe_err
framing error counter
Definition: uart.h:78
uint16_t tx_insert_idx
Definition: uart.h:67
uint8_t uart_getch(struct uart_periph *p)
Definition: uart_arch.c:287
unsigned char uint8_t
Definition: types.h:14
char dev[UART_DEV_NAME_SIZE]
UART Dev (linux)
Definition: uart.h:75
void uart_periph_init(struct uart_periph *p)
Definition: uart.c:233
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:92
int baudrate
UART Baudrate.
Definition: uart.h:73
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:76
#define UART_RX_BUFFER_SIZE
Definition: uart.h:36
uint16_t tx_extract_idx
Definition: uart.h:68