Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
uart.c
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
23#include "mcu_periph/uart.h"
24
25#if PERIODIC_TELEMETRY && (USE_UART0 || USE_UART1 || USE_UART2 || USE_UART3 || USE_UART4 || USE_UART5 || USE_UART6 || USE_UART7 || USE_UART8)
27
28static void send_uartx_err(struct transport_tx *trans, struct link_device *dev, struct uart_periph* uart)
29{
30 uint16_t ore = uart->ore;
31 uint16_t ne_err = uart->ne_err;
32 uint16_t fe_err = uart->fe_err;
33 uint8_t _bus0 = 0;
35 &ore, &ne_err, &fe_err, &_bus0);
36}
37#endif
38
39#if USE_UART0
40struct uart_periph uart0;
41#endif
42
43#if USE_UART1
44struct uart_periph uart1;
45#endif
46
47#if USE_UART2
48struct uart_periph uart2;
49#endif
50
51#if USE_UART3
52struct uart_periph uart3;
53#endif
54
55#if USE_UART4
56struct uart_periph uart4;
57#endif
58
59#if USE_UART5
60struct uart_periph uart5;
61#endif
62
63#if USE_UART6
64struct uart_periph uart6;
65#endif
66
67#if USE_UART7
68struct uart_periph uart7;
69#endif
70
71#if USE_UART8
72struct uart_periph uart8;
73#endif
74
75#if PERIODIC_TELEMETRY
76static void send_uart_err(struct transport_tx *trans __attribute__ ((unused)),
77 struct link_device *dev __attribute__ ((unused)))
78{
79 static uint8_t uart_nb_cnt = 0;
80 switch (uart_nb_cnt) {
81#if USE_UART0
82 case 0:
83 send_uartx_err(trans, dev, &uart0); break;
84#endif
85#if USE_UART1
86 case 1:
87 send_uartx_err(trans, dev, &uart1); break;
88#endif
89#if USE_UART2
90 case 2:
91 send_uartx_err(trans, dev, &uart2); break;
92#endif
93#if USE_UART3
94 case 3:
95 send_uartx_err(trans, dev, &uart3); break;
96#endif
97#if USE_UART4
98 case 4:
99 send_uartx_err(trans, dev, &uart4); break;
100#endif
101#if USE_UART5
102 case 5:
103 send_uartx_err(trans, dev, &uart5); break;
104#endif
105#if USE_UART6
106 case 6:
107 send_uartx_err(trans, dev, &uart6); break;
108#endif
109#if USE_UART7
110 case 7:
111 send_uartx_err(trans, dev, &uart7); break;
112#endif
113#if USE_UART8
114 case 8:
115 send_uartx_err(trans, dev, &uart8); break;
116#endif
117 default: break;
118 }
119 uart_nb_cnt++;
120 if (uart_nb_cnt == 9) {
121 uart_nb_cnt = 0;
122 }
123}
124#endif
125
127{
128 p->rx_insert_idx = 0;
129 p->rx_extract_idx = 0;
130 p->tx_insert_idx = 0;
131 p->tx_extract_idx = 0;
132 p->tx_running = false;
133 p->ore = 0;
134 p->ne_err = 0;
135 p->fe_err = 0;
136 p->device.periph = (void *)p;
137 p->device.check_free_space = (check_free_space_t) uart_check_free_space;
138 p->device.put_byte = (put_byte_t) uart_put_byte;
139 p->device.put_buffer = (put_buffer_t) uart_put_buffer;
140 p->device.send_message = (send_message_t) uart_send_message;
141 p->device.char_available = (char_available_t) uart_char_available;
142 p->device.get_byte = (get_byte_t) uart_getch;
143 p->device.set_baudrate = (set_baudrate_t) uart_periph_set_baudrate;
144
145#if PERIODIC_TELEMETRY
146 // the first to register do it for the others
148#endif
149}
150
152{
153 int space = p->tx_extract_idx - p->tx_insert_idx - 1;
154 if (space < 0) {
156 }
157 return space >= len ? space : 0;
158}
159
160// Weak implementation of put_buffer, byte by byte
161void WEAK uart_put_buffer(struct uart_periph *p, long fd, const uint8_t *data, uint16_t len)
162{
163 int i = 0;
164 for (i = 0; i < len; i++) {
165 uart_put_byte(p, fd, data[i]);
166 }
167}
168
169// Weak implementation of send_message, not needed for stream operation
170void WEAK uart_send_message(struct uart_periph *p __attribute__((unused)), long fd __attribute__((unused)))
171{
172}
173
175{
176 uint8_t ret = p->rx_buf[p->rx_extract_idx];
177 p->rx_extract_idx = (p->rx_extract_idx + 1) % UART_RX_BUFFER_SIZE;
178 return ret;
179}
180
182{
183 int available = p->rx_insert_idx - p->rx_extract_idx;
184 if (available < 0) {
185 available += UART_RX_BUFFER_SIZE;
186 }
187 return available;
188}
189
191{
192}
193
195{
196}
197
static float p[2][2]
void uart_put_byte(struct uart_periph *periph, long fd, uint8_t data)
Definition uart_arch.c:306
void uart_periph_set_baudrate(struct uart_periph *periph, uint32_t baud)
Definition uart_arch.c:280
#define UART_TX_BUFFER_SIZE
Definition uart_arch.h:34
#define UART_RX_BUFFER_SIZE
Definition uart_arch.h:31
uint16_t foo
Definition main_demo5.c:58
int fd
Definition serial.c:26
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66
int WEAK uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
Definition uart.c:181
static void send_uart_err(struct transport_tx *trans, struct link_device *dev)
Definition uart.c:76
void WEAK uart_send_message(struct uart_periph *p, long fd)
Definition uart.c:170
void uart_periph_init(struct uart_periph *p)
Definition uart.c:126
void WEAK uart_put_buffer(struct uart_periph *p, long fd, const uint8_t *data, uint16_t len)
Definition uart.c:161
void WEAK uart_periph_invert_data_logic(struct uart_periph *p, bool invert_rx, bool invert_tx)
Definition uart.c:194
int WEAK uart_check_free_space(struct uart_periph *p, long *fd, uint16_t len)
Definition uart.c:151
void WEAK uart_arch_init(void)
Definition uart.c:190
uint8_t WEAK uart_getch(struct uart_periph *p)
Definition uart.c:174
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
UART peripheral.
Definition uart.h:72
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.