uart.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2015 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
58 #ifndef PERIPH_UART_H
59 #define PERIPH_UART_H
60 
61 #include <stddef.h>
62 #include <stdint.h>
63 #include <limits.h>
64 
65 #include "periph_cpu.h"
66 #include "periph_conf.h"
67 /* TODO: remove once all platforms are ported to this interface */
68 #include "periph/dev_enums.h"
69 
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 
77 #ifndef HAVE_UART_T
78 typedef unsigned int uart_t;
79 #endif
80 
84 #ifndef UART_UNDEF
85 #define UART_UNDEF (UINT_MAX)
86 #endif
87 
91 #ifndef UART_DEV
92 #define UART_DEV(x) (x)
93 #endif
94 
101 typedef void(*uart_rx_cb_t)(void *arg, uint8_t data);
102 
106 #ifndef HAVE_UART_ISR_CTX_T
107 typedef struct {
109  void *arg;
111 #endif
112 
116 enum {
117  UART_OK = 0,
118  UART_NODEV = -1,
119  UART_NOBAUD = -2,
120  UART_INTERR = -3,
122 };
123 
127 #ifndef HAVE_UART_PARITY_T
128 typedef enum {
134 } uart_parity_t;
135 #endif
136 
140 #ifndef HAVE_UART_DATA_BITS_T
141 typedef enum {
147 #endif
148 
152 #ifndef HAVE_UART_STOP_BITS_T
153 typedef enum {
157 #endif
158 
183 int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg);
184 
196 int uart_mode(uart_t uart, uart_data_bits_t data_bits, uart_parity_t parity,
197  uart_stop_bits_t stop_bits);
198 
211 void uart_write(uart_t uart, const uint8_t *data, size_t len);
212 
218 void uart_poweron(uart_t uart);
219 
225 void uart_poweroff(uart_t uart);
226 
227 #ifdef __cplusplus
228 }
229 #endif
230 
231 #endif /* PERIPH_UART_H */
232 
all other internal errors
Definition: uart.h:120
Interrupt context for a UART device.
Definition: uart.h:107
uart_data_bits_t
Definition of possible data bits lengths in a UART frame.
Definition: uart.h:141
odd parity
Definition: uart.h:131
void(* uart_rx_cb_t)(void *arg, uint8_t data)
Signature for receive interrupt callback.
Definition: uart.h:101
unsigned int uart_t
Define default UART type identifier.
Definition: uart.h:78
mark parity
Definition: uart.h:132
void uart_poweroff(uart_t uart)
Power off the given UART device.
uart_stop_bits_t
Definition of possible stop bits lengths in a UART frame.
Definition: uart.h:153
space parity
Definition: uart.h:133
given baudrate is not applicable
Definition: uart.h:119
no parity
Definition: uart.h:129
5 data bits
Definition: uart.h:142
void uart_poweron(uart_t uart)
Power on the given UART device.
void * arg
argument to both callback routines
Definition: uart.h:109
given mode is not applicable
Definition: uart.h:121
uart_parity_t
Definition of possible parity modes.
Definition: uart.h:128
1 stop bit
Definition: uart.h:154
Device enumerations for backward compatibility with existing peripheral driver implementations.
even parity
Definition: uart.h:130
uart_rx_cb_t rx_cb
data received interrupt callback
Definition: uart.h:108
7 data bits
Definition: uart.h:144
2 stop bits
Definition: uart.h:155
8 data bits
Definition: uart.h:145
6 data bits
Definition: uart.h:143
int uart_mode(uart_t uart, uart_data_bits_t data_bits, uart_parity_t parity, uart_stop_bits_t stop_bits)
Setup parity, data and stop bits for a given UART device.
int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
Initialize a given UART device.
everything in order
Definition: uart.h:117
void uart_write(uart_t uart, const uint8_t *data, size_t len)
Write data from the given buffer to the specified UART device.
invalid UART device given
Definition: uart.h:118