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 
64 #ifndef HAVE_UART_T
65 typedef unsigned int uart_t;
66 #endif
67 
71 #ifndef UART_UNDEF
72 #define UART_UNDEF (UINT_MAX)
73 #endif
74 
78 #ifndef UART_DEV
79 #define UART_DEV(x) (x)
80 #endif
81 
88 typedef void(*uart_rx_cb_t)(void *arg, uint8_t data);
89 
93 #ifndef HAVE_UART_ISR_CTX_T
94 typedef struct {
96  void *arg;
98 #endif
99 
103 enum {
104  UART_OK = 0,
105  UART_NODEV = -1,
106  UART_NOBAUD = -2,
107  UART_INTERR = -3,
109 };
110 
135 int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg);
136 
149 void uart_write(uart_t uart, const uint8_t *data, size_t len);
150 
156 void uart_poweron(uart_t uart);
157 
163 void uart_poweroff(uart_t uart);
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif /* PERIPH_UART_H */
170 
Interrupt context for a UART device.
Definition: uart.h:94
everything in order
Definition: uart.h:104
invalid UART device given
Definition: uart.h:105
void(* uart_rx_cb_t)(void *arg, uint8_t data)
Signature for receive interrupt callback.
Definition: uart.h:88
unsigned int uart_t
Define default UART type identifier.
Definition: uart.h:65
void uart_poweroff(uart_t uart)
Power off the given UART device.
all other internal errors
Definition: uart.h:107
void uart_poweron(uart_t uart)
Power on the given UART device.
void * arg
argument to both callback routines
Definition: uart.h:96
Device enumerations for backward compatibility with existing peripheral driver implementations.
uart_rx_cb_t rx_cb
data received interrupt callback
Definition: uart.h:95
given mode is not applicable
Definition: uart.h:108
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.
given baudrate is not applicable
Definition: uart.h:106