Loading...
Searching...
No Matches
stdio_base.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Kaspar Schleiser <kaspar@schleiser.de>
3 * SPDX-FileCopyrightText: 2018 Freie Universität Berlin
4 * SPDX-License-Identifier: LGPL-2.1-only
5 */
6
7#pragma once
8
19
20#include <unistd.h>
21
22#include "compiler_hints.h"
23#include "isrpipe.h"
24#include "modules.h"
25
26#if defined(MODULE_STDIO_DISPATCH)
27# include "xfa.h"
28#endif
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#ifndef STDIO_RX_BUFSIZE
38# define STDIO_RX_BUFSIZE (64)
39#endif
40
41enum {
54};
55
59typedef struct {
63 void (*open)(void);
67 void (*close)(void);
77 ssize_t (*write)(const void *src, size_t len);
79
84
88void stdio_init(void);
89
90#if IS_USED(MODULE_STDIO_AVAILABLE) || DOXYGEN
100#endif
101
110
120ACCESS(write_only, 1, 2)
121ssize_t stdio_read(void *buffer, size_t max_len);
122
138ACCESS(read_only, 1, 2)
139ssize_t stdio_write(const void *buffer, size_t len);
140
144void stdio_close(void);
145
146#if defined(MODULE_STDIO_DISPATCH) || DOXYGEN
155#define STDIO_PROVIDER(_type, _open, _close, _write) \
156 XFA_CONST(stdio_provider_t, stdio_provider_xfa, 0) stdio_ ##_type = { \
157 .open = _open, \
158 .close = _close, \
159 .write = _write, \
160 };
161#else
162#define STDIO_PROVIDER(_type, _open, _close, _write) \
163 void stdio_init(void) { \
164 void (*f)(void) = _open; \
165 if (f != NULL) { \
166 f(); \
167 } \
168 } \
169 void stdio_close(void) { \
170 void (*f)(void) = _close; \
171 if (f != NULL) { \
172 f(); \
173 } \
174 } \
175 ssize_t stdio_write(const void* buffer, size_t len) { \
176 return _write(buffer, len); \
177 }
178#endif
179
180#ifdef __cplusplus
181}
182#endif
Common macros and compiler attributes/pragmas configuration.
#define ACCESS(mode, ptr_idx, size_idx)
Emit an attribute (if supported by the compiler) that declares how a function will access its paramet...
void stdio_close(void)
Disable stdio and detach stdio providers.
isrpipe_t stdin_isrpipe
isrpipe for writing stdin input to
void stdio_init(void)
initialize the module
ssize_t stdio_read(void *buffer, size_t max_len)
Read len bytes from the STDIN into buffer.
int stdio_available(void)
Get the number of bytes available for reading from stdio.
ssize_t stdio_write(const void *buffer, size_t len)
Write len bytes from buffer into STDOUT.
void stdio_clear_stdin(void)
Clear the input buffer.
@ STDIO_ESP32_SERIAL_JTAG
stdio via ESP32 debug Serial/JTAG
Definition stdio_base.h:48
@ STDIO_USBUS_CDC_ACM
stdio via USB CDC ACM (usbus)
Definition stdio_base.h:46
@ STDIO_UART
stdio via UART
Definition stdio_base.h:43
@ STDIO_RTT
stdio via Segger RTT
Definition stdio_base.h:44
@ STDIO_TINYUSB_CDC_ACM
stdio via USB CDC ACM (TinyUSB)
Definition stdio_base.h:47
@ STDIO_TELNET
stdio via telnet
Definition stdio_base.h:51
@ STDIO_ETHOS
stdio via ethos (mutiplex)
Definition stdio_base.h:52
@ STDIO_NIMBLE
stdio via BLE (NimBLE)
Definition stdio_base.h:49
@ STDIO_SEMIHOSTING
stdio via Semihosting
Definition stdio_base.h:45
@ STDIO_SLIP
stdio via SLIP (mutiplex)
Definition stdio_base.h:53
@ STDIO_NULL
dummy stdio
Definition stdio_base.h:42
@ STDIO_UDP
stdio via UDP
Definition stdio_base.h:50
isrpipe Interface
Common macros and compiler attributes/pragmas configuration.
Context structure for isrpipe.
Definition isrpipe.h:36
stdio provider struct
Definition stdio_base.h:59
void(* open)(void)
Initialize and attach the stdio provider.
Definition stdio_base.h:63
void(* close)(void)
Detach the stdio provider.
Definition stdio_base.h:67
ssize_t(* write)(const void *src, size_t len)
Write len bytes from src into stdout.
Definition stdio_base.h:77
Cross File Arrays.