Loading...
Searching...
No Matches
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
9#pragma once
10
87
88#include <errno.h>
89#include <limits.h>
90#include <stddef.h>
91#include <stdint.h>
92
93#include "periph_cpu.h"
94#include "periph_conf.h"
95
96#ifdef __cplusplus
97extern "C" {
98#endif
99
104#ifndef CONFIG_UART_DMA_THRESHOLD_BYTES
105#define CONFIG_UART_DMA_THRESHOLD_BYTES 8
106#endif
107
111#ifndef HAVE_UART_T
112typedef uint_fast8_t uart_t;
113#endif
114
118#ifndef UART_UNDEF
119#define UART_UNDEF (UINT_FAST8_MAX)
120#endif
121
125#ifndef UART_DEV
126#define UART_DEV(x) (x)
127#endif
128
135typedef void(*uart_rx_cb_t)(void *arg, uint8_t data);
136
142typedef void(*uart_rxstart_cb_t)(void *arg);
143
147#ifndef HAVE_UART_ISR_CTX_T
148typedef struct {
150 void *arg;
151#ifdef MODULE_PERIPH_UART_RXSTART_IRQ
152 uart_rxstart_cb_t rxs_cb;
153 void *rxs_arg;
154#endif
156#endif
157
163enum {
169};
170
174#ifndef HAVE_UART_PARITY_T
182#endif
183
187#ifndef HAVE_UART_DATA_BITS_T
194#endif
195
199#ifndef HAVE_UART_STOP_BITS_T
204#endif
205
238int uart_init(uart_t uart, uint32_t baud, uart_rx_cb_t rx_cb, void *arg);
239
240#if defined(MODULE_PERIPH_UART_RECONFIGURE) || DOXYGEN
257
274
275#if DOXYGEN
286gpio_t uart_pin_rx(uart_t uart);
287
298gpio_t uart_pin_tx(uart_t uart);
299
300#endif /* DOXYGEN */
301
312gpio_t uart_pin_cts(uart_t uart);
313
324gpio_t uart_pin_rts(uart_t uart);
325
326#endif /* MODULE_PERIPH_UART_RECONFIGURE */
327
328#if defined(MODULE_PERIPH_UART_RXSTART_IRQ) || DOXYGEN
329
345
355
365#endif /* MODULE_PERIPH_UART_RXSTART_IRQ */
366
367#if defined(MODULE_PERIPH_UART_COLLISION) || DOXYGEN
393
407#endif /* MODULE_PERIPH_UART_COLLISION */
408
421int uart_mode(uart_t uart, uart_data_bits_t data_bits, uart_parity_t parity,
422 uart_stop_bits_t stop_bits);
423
436void uart_write(uart_t uart, const uint8_t *data, size_t len);
437
447
454
463
472
473#ifdef __cplusplus
474}
475#endif
476
#define EIO
I/O error.
Definition errno.h:97
#define ENOTSUP
Not supported (may be the same value as [EOPNOTSUPP]).
Definition errno.h:129
#define ENODEV
No such device.
Definition errno.h:112
void uart_enable_tx(uart_t uart)
Enable the TX line one the given UART.
void uart_poweroff(uart_t uart)
Power off and release the given UART device.
void uart_rxstart_irq_configure(uart_t uart, uart_rxstart_cb_t cb, void *arg)
Configure the function that will be called when a start condition is detected.
void uart_deinit_pins(uart_t uart)
Change the pins of the given UART back to plain GPIO functionality.
void(* uart_rxstart_cb_t)(void *arg)
Signature for receive start condition interrupt callback.
Definition uart.h:142
void uart_collision_detect_enable(uart_t uart)
Enables collision detection check of the UART.
int uart_init(uart_t uart, uint32_t baud, uart_rx_cb_t rx_cb, void *arg)
Initialize and acquire a given UART device.
void uart_disable_tx(uart_t uart)
Disable the TX line one the given UART.
void uart_rxstart_irq_disable(uart_t uart)
Disable the RX start interrupt.
uint_fast8_t uart_t
Define default UART type identifier.
Definition uart.h:112
void uart_poweron(uart_t uart)
Power on and acquire the given UART device.
bool uart_collision_detected(uart_t uart)
Disables collision detection check of the UART.
gpio_t uart_pin_tx(uart_t uart)
Get the TX pin of the given UART.
gpio_t uart_pin_cts(uart_t uart)
Get the CTS pin of the given UART.
void uart_init_pins(uart_t uart)
Initialize the used UART pins, i.e.
void(* uart_rx_cb_t)(void *arg, uint8_t data)
Signature for receive interrupt callback.
Definition uart.h:135
void uart_rxstart_irq_enable(uart_t uart)
Enable the RX start interrupt.
gpio_t uart_pin_rts(uart_t uart)
Get the RTS pin of the given UART.
gpio_t uart_pin_rx(uart_t uart)
Get the RX pin of the given UART.
void uart_write(uart_t uart, const uint8_t *data, size_t len)
Write data from the given buffer to the specified UART device.
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.
void uart_collision_detect_disable(uart_t uart)
Disables collision detection check of the UART.
@ UART_NOBAUD
given symbol rate is not applicable
Definition uart.h:166
@ UART_OK
everything in order
Definition uart.h:164
@ UART_NODEV
invalid UART device given
Definition uart.h:165
@ UART_INTERR
all other internal errors
Definition uart.h:168
@ UART_NOMODE
given mode is not applicable
Definition uart.h:167
uart_parity_t
Definition of possible parity modes.
Definition periph_cpu.h:498
@ UART_PARITY_SPACE
space parity
Definition periph_cpu.h:503
@ UART_PARITY_NONE
no parity
Definition periph_cpu.h:499
@ UART_PARITY_EVEN
even parity
Definition periph_cpu.h:500
@ UART_PARITY_ODD
odd parity
Definition periph_cpu.h:501
@ UART_PARITY_MARK
mark parity
Definition periph_cpu.h:502
uart_stop_bits_t
Definition of possible stop bits lengths.
Definition periph_cpu.h:530
@ UART_STOP_BITS_2
2 stop bits
Definition periph_cpu.h:532
@ UART_STOP_BITS_1
1 stop bit
Definition periph_cpu.h:531
uart_data_bits_t
Definition of possible data bits lengths in a UART frame.
Definition periph_cpu.h:514
@ UART_DATA_BITS_6
6 data bits
Definition periph_cpu.h:516
@ UART_DATA_BITS_5
5 data bits
Definition periph_cpu.h:515
@ UART_DATA_BITS_7
7 data bits
Definition periph_cpu.h:517
@ UART_DATA_BITS_8
8 data bits
Definition periph_cpu.h:518
Interrupt context for a UART device.
Definition uart.h:148
uart_rx_cb_t rx_cb
data received interrupt callback
Definition uart.h:149
void * arg
argument to data received callback
Definition uart.h:150