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
90
105#if IS_USED(MODULE_STDIO_NOTIFY) || DOXYGEN
106int stdio_rx_write_one(uint8_t c);
107#else
108static inline int stdio_rx_write_one(uint8_t c)
109{
111}
112#endif
113
129#if IS_USED(MODULE_STDIO_NOTIFY) || DOXYGEN
130int stdio_rx_write(const uint8_t *buf, size_t len);
131#else
132static inline int stdio_rx_write(const uint8_t *buf, size_t len)
133{
134 return isrpipe_write(&stdin_isrpipe, buf, len);
135}
136#endif
137
138#if IS_USED(MODULE_STDIO_NOTIFY) || DOXYGEN
148typedef void (*stdio_notify_cb_t)(void *arg);
149
166#endif
167
171void stdio_init(void);
172
173#if IS_USED(MODULE_STDIO_AVAILABLE) || DOXYGEN
183#endif
184
193
203ACCESS(write_only, 1, 2)
204ssize_t stdio_read(void *buffer, size_t max_len);
205
221ACCESS(read_only, 1, 2)
222ssize_t stdio_write(const void *buffer, size_t len);
223
227void stdio_close(void);
228
229#if defined(MODULE_STDIO_DISPATCH) || DOXYGEN
238#define STDIO_PROVIDER(_type, _open, _close, _write) \
239 XFA_CONST(stdio_provider_t, stdio_provider_xfa, 0) stdio_ ##_type = { \
240 .open = _open, \
241 .close = _close, \
242 .write = _write, \
243 };
244#else
245#define STDIO_PROVIDER(_type, _open, _close, _write) \
246 void stdio_init(void) { \
247 void (*f)(void) = _open; \
248 if (f != NULL) { \
249 f(); \
250 } \
251 } \
252 void stdio_close(void) { \
253 void (*f)(void) = _close; \
254 if (f != NULL) { \
255 f(); \
256 } \
257 } \
258 ssize_t stdio_write(const void* buffer, size_t len) { \
259 return _write(buffer, len); \
260 }
261#endif
262
263#ifdef __cplusplus
264}
265#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...
int isrpipe_write_one(isrpipe_t *isrpipe, uint8_t c)
Put one byte into the isrpipe's buffer.
int isrpipe_write(isrpipe_t *isrpipe, const uint8_t *buf, size_t n)
Put number of bytes into the isrpipe's buffer.
void stdio_close(void)
Disable stdio and detach stdio providers.
int stdio_rx_write(const uint8_t *buf, size_t len)
Push received bytes into stdin.
isrpipe_t stdin_isrpipe
isrpipe for writing stdin input to
void stdio_set_notify(stdio_notify_cb_t cb, void *arg)
Register a callback fired when data is available on stdin.
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_rx_write_one(uint8_t c)
Push a single received byte into stdin.
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_notify_cb_t)(void *arg)
Definition of a stdio notify callback.
Definition stdio_base.h:148
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:33
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.