MAV'RIC
uart_int.h
1 /*******************************************************************************
2  * Copyright (c) 2009-2014, MAV'RIC Development Team
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  ******************************************************************************/
31 
32 /*******************************************************************************
33  * \file uart_int.h
34  *
35  * \author MAV'RIC Team
36  * \author Felix Schill
37  *
38  * \brief This file implements the UART communication protocol
39  *
40  ******************************************************************************/
41 
42 
43 #ifndef UART_INT_H_
44 #define UART_INT_H_
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 #include <stdint.h>
51 #include "usart.h"
52 #include "buffer.h"
53 #include "streams.h"
54 
58 typedef struct
59 {
60  avr32_usart_t *uart;
61  int32_t IRQ;
66 
70 typedef struct
71 {
72  uint8_t pin;
73  uint8_t function;
75 
76 
80 typedef struct
81 {
82  int32_t mode;
84  usart_options_t options;
88 
89 
93 enum UART_MODE
94 {
95  UART_OFF,
96  UART_IN,
97  UART_OUT,
98  UART_IN_OUT
99 };
100 
104 enum AVAILABLE_UARTS
105 {
106  UART0,
107  UART1,
108  UART2,
109  UART3,
110  UART4,
111  UART_COUNT
112 };
113 
120 void uart_int_set_usart_conf(int32_t UID, usart_config_t* usart_config);
121 
127 void uart_int_init(int32_t UID);
128 
136 usart_config_t *uart_int_get_uart_handle(int32_t UID);
137 
144 int8_t uart_int_get_byte(usart_config_t *usart_conf);
145 
153 int32_t uart_int_bytes_available(usart_config_t *usart_conf);
154 
163 void uart_int_send_byte(usart_config_t *usart_conf, uint8_t data);
164 
170 void uart_int_flush(usart_config_t *usart_conf );
171 
182 void uart_int_register_write_stream(usart_config_t *usart_conf, byte_stream_t *stream);
183 
192 void uart_int_register_write_stream_nonblocking(usart_config_t *usart_conf, byte_stream_t *stream);
193 
200 void uart_int_register_read_stream(usart_config_t *usart_conf, byte_stream_t *stream);
201 
202 #ifdef __cplusplus
203 }
204 #endif
205 
206 #endif /* UART_INT_H_ */
UART GPIO map structure.
Definition: uart_int.h:70
uint8_t pin
Module pin.
Definition: uart_int.h:72
avr32_usart_t * uart
Pointer to the AVR32 UART structure.
Definition: uart_int.h:60
UART interface structure.
Definition: uart_int.h:58
buffer_t transmit_buffer
Transmission buffer.
Definition: uart_int.h:62
uart_gpio_map_t rx_pin_map
Mapping of the Rx pin.
Definition: uart_int.h:85
Buffer structure.
Definition: buffer.h:61
byte_stream_t * receive_stream
Pointer to the reception stream.
Definition: uart_int.h:64
uart_interface_t uart_device
UART device to configure.
Definition: uart_int.h:83
buffer_t receive_buffer
Reception buffer.
Definition: uart_int.h:63
usart_options_t options
UART configuration options.
Definition: uart_int.h:84
int32_t mode
UART mode.
Definition: uart_int.h:82
Byte stream.
Definition: streams.h:62
int32_t IRQ
IRQ.
Definition: uart_int.h:61
uart_gpio_map_t tx_pin_map
Mapping of the Tx pin.
Definition: uart_int.h:86
UART configuration structure.
Definition: uart_int.h:80