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 
48 #ifndef PERIPH_UART_H
49 #define PERIPH_UART_H
50 
51 #include <stddef.h>
52 #include <stdint.h>
53 #include <limits.h>
54 
55 #include "periph_cpu.h"
56 #include "periph_conf.h"
57 /* TODO: remove once all platforms are ported to this interface */
58 #include "periph/dev_enums.h"
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
67 #ifndef HAVE_UART_T
68 typedef unsigned int uart_t;
69 #endif
70 
74 #ifndef UART_UNDEF
75 #define UART_UNDEF (UINT_MAX)
76 #endif
77 
81 #ifndef UART_DEV
82 #define UART_DEV(x) (x)
83 #endif
84 
91 typedef void(*uart_rx_cb_t)(void *arg, uint8_t data);
92 
96 #ifndef HAVE_UART_ISR_CTX_T
97 typedef struct {
99  void *arg;
101 #endif
102 
106 enum {
107  UART_OK = 0,
108  UART_NODEV = -1,
109  UART_NOBAUD = -2,
110  UART_INTERR = -3,
112 };
113 
138 int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg);
139 
152 void uart_write(uart_t uart, const uint8_t *data, size_t len);
153 
159 void uart_poweron(uart_t uart);
160 
166 void uart_poweroff(uart_t uart);
167 
168 #ifdef __cplusplus
169 }
170 #endif
171 
172 #endif /* PERIPH_UART_H */
173 
Interrupt context for a UART device.
Definition: uart.h:97
void(* uart_rx_cb_t)(void *arg, uint8_t data)
Signature for receive interrupt callback.
Definition: uart.h:91
unsigned int uart_t
Define default UART type identifier.
Definition: uart.h:68
void uart_poweroff(uart_t uart)
Power off the given UART device.
given baudrate is not applicable
Definition: uart.h:109
everything in order
Definition: uart.h:107
invalid UART device given
Definition: uart.h:108
all other internal errors
Definition: uart.h:110
given mode is not applicable
Definition: uart.h:111
void uart_poweron(uart_t uart)
Power on the given UART device.
void * arg
argument to both callback routines
Definition: uart.h:99
Device enumerations for backward compatibility with existing peripheral driver implementations.
uart_rx_cb_t rx_cb
data received interrupt callback
Definition: uart.h:98
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.