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