Loading...
Searching...
No Matches
uart_half_duplex.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2017 Inria
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
22
23#include <stdlib.h>
24
25#include "periph/uart.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#ifndef UART_HALF_DUPLEX_DEFAULT_TIMEOUT_US
32#define UART_HALF_DUPLEX_DEFAULT_TIMEOUT_US (20000LU)
33#endif
34
38typedef struct {
39 void (*init)(uart_t);
40 void (*enable_tx)(uart_t);
41 void (*disable_tx)(uart_t);
43
44#define UART_HALF_DUPLEX_DIR_NONE { NULL, NULL, NULL }
45
54
65
69enum {
76};
77
93int uart_half_duplex_init(uart_half_duplex_t *dev, uint8_t *buffer, size_t buffer_max_size, const uart_half_duplex_params_t *params);
94
101{
102 dev->size = dev->buffer_max_size;
103}
104
111{
112 dev->size = 0;
113}
114
123size_t uart_half_duplex_send(const uart_half_duplex_t *dev, size_t size);
124
133size_t uart_half_duplex_recv(const uart_half_duplex_t *dev, size_t size);
134
135#ifdef __cplusplus
136}
137#endif
138
uint_fast8_t uart_t
Define default UART type identifier.
Definition uart.h:112
@ 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
static void uart_half_duplex_set_tx(uart_half_duplex_t *dev)
Set the half-duplex UART bus in TX mode.
int uart_half_duplex_init(uart_half_duplex_t *dev, uint8_t *buffer, size_t buffer_max_size, const uart_half_duplex_params_t *params)
Initialize the half-duplex UART bus to communicate with devices.
size_t uart_half_duplex_recv(const uart_half_duplex_t *dev, size_t size)
Recv data an fill the driver's buffer.
size_t uart_half_duplex_send(const uart_half_duplex_t *dev, size_t size)
Send the data contained in the driver's buffer.
static void uart_half_duplex_set_rx(uart_half_duplex_t *dev)
Set the half-duplex UART bus in RX mode.
@ UART_HALF_DUPLEX_NOBAUD
given baudrate is not applicable
@ UART_HALF_DUPLEX_NOMODE
given mode is not applicable
@ UART_HALF_DUPLEX_NOBUFF
invalid buffer given
@ UART_HALF_DUPLEX_INTERR
all other internal errors
@ UART_HALF_DUPLEX_OK
everything in order
@ UART_HALF_DUPLEX_NODEV
invalid UART device given
half-duplex UART direction management method type
void(* init)(uart_t)
function initializing direction management method
void(* disable_tx)(uart_t)
function disabling TX
void(* enable_tx)(uart_t)
function enabling TX
Configuration for half-duplex UART.
uart_t uart
the half-duplex UART bus to use
uart_half_duplex_dir_t dir
the direction management method
uint32_t baudrate
the baudrate to use
Descriptor struct for half-duplex UART.
uint8_t * buffer
the buffer used for TX and RX
size_t size
the number of available elements for TX/RX
uart_half_duplex_params_t params
the half-duplex UART configuration
uint32_t timeout_us
the maximum duration (in microseconds) for waiting data
size_t buffer_max_size
the buffer size
Low-level UART peripheral driver interface definition.