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 
45 #ifndef PERIPH_UART_H
46 #define PERIPH_UART_H
47 
48 #include <stddef.h>
49 #include <stdint.h>
50 #include <limits.h>
51 
52 #include "periph_cpu.h"
53 #include "periph_conf.h"
54 /* TODO: remove once all platforms are ported to this interface */
55 #include "periph/dev_enums.h"
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
65 #ifndef HAVE_UART_T
66 typedef unsigned int uart_t;
67 #endif
68 
74 #ifndef UART_UNDEF
75 #define UART_UNDEF (UINT_MAX)
76 #endif
77 
83 #ifndef UART_DEV
84 #define UART_DEV(x) (x)
85 #endif
86 
94 typedef void(*uart_rx_cb_t)(void *arg, uint8_t data);
95 
100 #ifndef HAVE_UART_ISR_CTX_T
101 typedef struct {
103  void *arg;
105 #endif
106 
111 enum {
112  UART_OK = 0,
113  UART_NODEV = -1,
114  UART_NOBAUD = -2,
115  UART_INTERR = -3,
117 };
118 
143 int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg);
144 
157 void uart_write(uart_t uart, const uint8_t *data, size_t len);
158 
164 void uart_poweron(uart_t uart);
165 
171 void uart_poweroff(uart_t uart);
172 
173 #ifdef __cplusplus
174 }
175 #endif
176 
177 #endif /* PERIPH_UART_H */
178 
Interrupt context for a UART device.
Definition: uart.h:101
void(* uart_rx_cb_t)(void *arg, uint8_t data)
Signature for receive interrupt callback.
Definition: uart.h:94
unsigned int uart_t
Define default UART type identifier.
Definition: uart.h:66
void uart_poweroff(uart_t uart)
Power off the given UART device.
given baudrate is not applicable
Definition: uart.h:114
everything in order
Definition: uart.h:112
invalid UART device given
Definition: uart.h:113
all other internal errors
Definition: uart.h:115
given mode is not applicable
Definition: uart.h:116
void uart_poweron(uart_t uart)
Power on the given UART device.
void * arg
argument to both callback routines
Definition: uart.h:103
Device enumerations for backward compatibility with existing peripheral driver implementations.
uart_rx_cb_t rx_cb
data received interrupt callback
Definition: uart.h:102
int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
Initialize a given UART device.
void uart_write(uart_t uart, const uint8_t *data, size_t len)
Write data from the given buffer to the specified UART device.