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.c
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 
25 #include "mcu_periph/uart.h"
26 
27 #ifdef USE_UART0
28 struct uart_periph uart0;
29 #endif
30 
31 #ifdef USE_UART1
32 struct uart_periph uart1;
33 #endif
34 
35 #ifdef USE_UART2
36 struct uart_periph uart2;
37 #endif
38 
39 #ifdef USE_UART3
40 struct uart_periph uart3;
41 #endif
42 
43 #ifdef USE_UART5
44 struct uart_periph uart5;
45 #endif
46 
47 void uart_periph_init(struct uart_periph* p) {
48  p->rx_insert_idx = 0;
49  p->rx_extract_idx = 0;
50  p->tx_insert_idx = 0;
51  p->tx_extract_idx = 0;
52  p->tx_running = FALSE;
53 }
54 
55 bool_t uart_check_free_space(struct uart_periph* p, uint8_t len) {
56  int16_t space = p->tx_extract_idx - p->tx_insert_idx;
57  if (space <= 0)
58  space += UART_TX_BUFFER_SIZE;
59  return (uint16_t)(space - 1) >= len;
60 }
61 
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint8_t tx_running
Definition: uart.h:52
uint16_t tx_extract_idx
Definition: uart.h:51
#define FALSE
Definition: imu_chimu.h:141
UART peripheral.
Definition: uart.h:43
#define UART_TX_BUFFER_SIZE
Definition: uart.h:37
void uart_periph_init(struct uart_periph *p)
Definition: uart.c:47
signed short int16_t
Definition: types.h:17
uint16_t rx_insert_idx
Definition: uart.h:46
bool_t uart_check_free_space(struct uart_periph *p, uint8_t len)
Definition: uart.c:55
unsigned char uint8_t
Definition: types.h:14
uint16_t tx_insert_idx
Definition: uart.h:50
uint16_t rx_extract_idx
Definition: uart.h:47