Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
uart.h
Go to the documentation of this file.
1 /*
2  * Paparazzi $Id$
3  *
4  * Copyright (C) 2010 The Paparazzi Team
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  */
24 
30 #ifndef MCU_PERIPH_UART_H
31 #define MCU_PERIPH_UART_H
32 
33 #include "mcu_periph/uart_arch.h"
34 #include "std.h"
35 
36 #define UART_RX_BUFFER_SIZE 128
37 #define UART_TX_BUFFER_SIZE 128
38 #define UART_DEV_NAME_SIZE 16
39 
43 struct uart_periph {
44  /* Receive buffer */
48  /* Transmit buffer */
53  /* UART Register */
54  void* reg_addr;
55  /* UART Dev (linux) */
57 };
58 
59 extern void uart_periph_init(struct uart_periph* p);
60 extern void uart_periph_set_baudrate(struct uart_periph* p, uint32_t baud);
61 //extern void uart_periph_init_param(struct uart_periph* p, uint32_t baud, uint8_t mode, uint8_t fmode, char * dev);
62 extern void uart_transmit(struct uart_periph* p, uint8_t data);
63 extern bool_t uart_check_free_space(struct uart_periph* p, uint8_t len);
64 
65 #define UartChAvailable(_p) (_p.rx_insert_idx != _p.rx_extract_idx)
66 
67 #define UartGetch(_p) ({ \
68  uint8_t ret = _p.rx_buf[_p.rx_extract_idx]; \
69  _p.rx_extract_idx = (_p.rx_extract_idx + 1)%UART_RX_BUFFER_SIZE; \
70  ret; \
71 })
72 
73 
74 #ifdef USE_UART0
75 extern struct uart_periph uart0;
76 extern void uart0_init(void);
77 
78 #define Uart0Init() uart_periph_init(&uart0)
79 #define Uart0CheckFreeSpace(_x) uart_check_free_space(&uart0, _x)
80 #define Uart0Transmit(_x) uart_transmit(&uart0, _x)
81 #define Uart0SendMessage() {}
82 #define Uart0ChAvailable() UartChAvailable(uart0)
83 #define Uart0Getch() UartGetch(uart0)
84 #define Uart0TxRunning uart0.tx_running
85 #define Uart0SetBaudrate(_b) uart_periph_set_baudrate(&uart0, _b)
86 //#define Uart0InitParam(_b, _m, _fm) uart_periph_init_param(&uart0, _b, _m, _fm, "")
87 
88 #define UART0Init Uart0Init
89 #define UART0CheckFreeSpace Uart0CheckFreeSpace
90 #define UART0Transmit Uart0Transmit
91 #define UART0SendMessage Uart0SendMessage
92 #define UART0ChAvailable Uart0ChAvailable
93 #define UART0Getch Uart0Getch
94 #define UART0TxRunning Uart0TxRunning
95 #define UART0SetBaudrate Uart0SetBaudrate
96 
97 #endif // USE_UART0
98 
99 #ifdef USE_UART1
100 extern struct uart_periph uart1;
101 extern void uart1_init(void);
102 
103 #define Uart1Init() uart_periph_init(&uart1)
104 #define Uart1CheckFreeSpace(_x) uart_check_free_space(&uart1, _x)
105 #define Uart1Transmit(_x) uart_transmit(&uart1, _x)
106 #define Uart1SendMessage() {}
107 #define Uart1ChAvailable() UartChAvailable(uart1)
108 #define Uart1Getch() UartGetch(uart1)
109 #define Uart1TxRunning uart1.tx_running
110 #define Uart1SetBaudrate(_b) uart_periph_set_baudrate(&uart1, _b)
111 //#define Uart1InitParam(_b, _m, _fm) uart_periph_init_param(&uart1, _b, _m, _fm, "")
112 
113 #define UART1Init Uart1Init
114 #define UART1CheckFreeSpace Uart1CheckFreeSpace
115 #define UART1Transmit Uart1Transmit
116 #define UART1SendMessage Uart1SendMessage
117 #define UART1ChAvailable Uart1ChAvailable
118 #define UART1Getch Uart1Getch
119 #define UART1TxRunning Uart1TxRunning
120 #define UART1SetBaudrate Uart1SetBaudrate
121 
122 #endif // USE_UART1
123 
124 #ifdef USE_UART2
125 extern struct uart_periph uart2;
126 extern void uart2_init(void);
127 
128 #define Uart2Init() uart_periph_init(&uart2)
129 #define Uart2CheckFreeSpace(_x) uart_check_free_space(&uart2, _x)
130 #define Uart2Transmit(_x) uart_transmit(&uart2, _x)
131 #define Uart2SendMessage() {}
132 #define Uart2ChAvailable() UartChAvailable(uart2)
133 #define Uart2Getch() UartGetch(uart2)
134 #define Uart2TxRunning uart2.tx_running
135 #define Uart2SetBaudrate(_b) uart_periph_set_baudrate(&uart2, _b)
136 //#define Uart2InitParam(_b, _m, _fm) uart_periph_init_param(&uart2, _b, _m, _fm, "")
137 
138 #define UART2Init Uart2Init
139 #define UART2CheckFreeSpace Uart2CheckFreeSpace
140 #define UART2Transmit Uart2Transmit
141 #define UART2SendMessage Uart2SendMessage
142 #define UART2ChAvailable Uart2ChAvailable
143 #define UART2Getch Uart2Getch
144 #define UART2TxRunning Uart2TxRunning
145 #define UART2SetBaudrate Uart2SetBaudrate
146 
147 #endif // USE_UART2
148 
149 #ifdef USE_UART3
150 extern struct uart_periph uart3;
151 extern void uart3_init(void);
152 
153 #define Uart3Init() uart_periph_init(&uart3)
154 #define Uart3CheckFreeSpace(_x) uart_check_free_space(&uart3, _x)
155 #define Uart3Transmit(_x) uart_transmit(&uart3, _x)
156 #define Uart3SendMessage() {}
157 #define Uart3ChAvailable() UartChAvailable(uart3)
158 #define Uart3Getch() UartGetch(uart3)
159 #define Uart3TxRunning uart3.tx_running
160 #define Uart3SetBaudrate(_b) uart_periph_set_baudrate(&uart3, _b)
161 //#define Uart3InitParam(_b, _m, _fm) uart_periph_init_param(&uart3, _b, _m, _fm, "")
162 
163 #define UART3Init Uart3Init
164 #define UART3CheckFreeSpace Uart3CheckFreeSpace
165 #define UART3Transmit Uart3Transmit
166 #define UART3SendMessage Uart3SendMessage
167 #define UART3ChAvailable Uart3ChAvailable
168 #define UART3Getch Uart3Getch
169 #define UART3TxRunning Uart3TxRunning
170 #define UART3SetBaudrate Uart3SetBaudrate
171 
172 #endif // USE_UART3
173 
174 #ifdef USE_UART5
175 extern struct uart_periph uart5;
176 extern void uart5_init(void);
177 
178 #define Uart5Init() uart_periph_init(&uart5)
179 #define Uart5CheckFreeSpace(_x) uart_check_free_space(&uart5, _x)
180 #define Uart5Transmit(_x) uart_transmit(&uart5, _x)
181 #define Uart5SendMessage() {}
182 #define Uart5ChAvailable() UartChAvailable(uart5)
183 #define Uart5Getch() UartGetch(uart5)
184 #define Uart5TxRunning uart5.tx_running
185 #define Uart5SetBaudrate(_b) uart_periph_set_baudrate(&uart5, _b)
186 //#define Uart5InitParam(_b, _m, _fm) uart_periph_init_param(&uart5, _b, _m, _fm, "")
187 
188 #define UART5Init Uart5Init
189 #define UART5CheckFreeSpace Uart5CheckFreeSpace
190 #define UART5Transmit Uart5Transmit
191 #define UART5SendMessage Uart5SendMessage
192 #define UART5ChAvailable Uart5ChAvailable
193 #define UART5Getch Uart5Getch
194 #define UART5TxRunning Uart5TxRunning
195 #define UART5SetBaudrate Uart5SetBaudrate
196 
197 #endif // USE_UART5
198 
199 #endif /* MCU_PERIPH_UART_H */
unsigned short uint16_t
Definition: types.h:16
#define UART_DEV_NAME_SIZE
Definition: uart.h:38
bool_t uart_check_free_space(struct uart_periph *p, uint8_t len)
Definition: uart.c:55
char dev[UART_DEV_NAME_SIZE]
Definition: uart.h:56
uint8_t tx_running
Definition: uart.h:52
void * reg_addr
Definition: uart.h:54
void uart_periph_set_baudrate(struct uart_periph *p, uint32_t baud)
Definition: uart_arch.c:59
uint16_t tx_extract_idx
Definition: uart.h:51
UART peripheral.
Definition: uart.h:43
#define UART_TX_BUFFER_SIZE
Definition: uart.h:37
unsigned long uint32_t
Definition: types.h:18
uint16_t rx_insert_idx
Definition: uart.h:46
void uart_transmit(struct uart_periph *p, uint8_t data)
Definition: uart_arch.c:65
uint8_t tx_buf[UART_TX_BUFFER_SIZE]
Definition: uart.h:49
unsigned char uint8_t
Definition: types.h:14
void uart_periph_init(struct uart_periph *p)
Definition: uart.c:47
uint16_t tx_insert_idx
Definition: uart.h:50
uint8_t rx_buf[UART_RX_BUFFER_SIZE]
Definition: uart.h:45
uint16_t rx_extract_idx
Definition: uart.h:47
#define UART_RX_BUFFER_SIZE
Definition: uart.h:36