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 
20 #include <unistd.h>
21 
22 #include "modules.h"
23 #include "isrpipe.h"
24 #include "xfa.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #ifndef STDIO_RX_BUFSIZE
34 #define STDIO_RX_BUFSIZE (64)
35 #endif
36 
37 enum {
50 };
51 
55 typedef struct {
59  void (*open)(void);
63  void (*close)(void);
73  ssize_t (*write)(const void *src, size_t len);
75 
80 
84 void stdio_init(void);
85 
86 #if IS_USED(MODULE_STDIO_AVAILABLE) || DOXYGEN
95 int stdio_available(void);
96 #endif
97 
105 void stdio_clear_stdin(void);
106 
116 ssize_t stdio_read(void* buffer, size_t max_len);
117 
131 ssize_t stdio_write(const void* buffer, size_t len);
132 
136 void stdio_close(void);
137 
138 #if defined(MODULE_STDIO_DISPATCH) || DOXYGEN
147 #define STDIO_PROVIDER(_type, _open, _close, _write) \
148  XFA_CONST(stdio_provider_t, stdio_provider_xfa, 0) stdio_ ##_type = { \
149  .open = _open, \
150  .close = _close, \
151  .write = _write, \
152  };
153 #else
154 #define STDIO_PROVIDER(_type, _open, _close, _write) \
155  void stdio_init(void) { \
156  void (*f)(void) = _open; \
157  if (f != NULL) { \
158  f(); \
159  } \
160  } \
161  void stdio_close(void) { \
162  void (*f)(void) = _close; \
163  if (f != NULL) { \
164  f(); \
165  } \
166  } \
167  ssize_t stdio_write(const void* buffer, size_t len) { \
168  return _write(buffer, len); \
169  }
170 #endif
171 
172 #ifdef __cplusplus
173 }
174 #endif
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 stdio uart 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:44
@ STDIO_USBUS_CDC_ACM
stdio via USB CDC ACM (usbus)
Definition: stdio_base.h:42
@ STDIO_UART
stdio via UART
Definition: stdio_base.h:39
@ STDIO_RTT
stdio via Segger RTT
Definition: stdio_base.h:40
@ STDIO_TINYUSB_CDC_ACM
tdio via USB CDC ACM (TinyUSB)
Definition: stdio_base.h:43
@ STDIO_TELNET
stdio via telnet
Definition: stdio_base.h:47
@ STDIO_ETHOS
stdio via ethos (mutiplex)
Definition: stdio_base.h:48
@ STDIO_NIMBLE
stdio via BLE (NimBLE)
Definition: stdio_base.h:45
@ STDIO_SEMIHOSTING
stdio via Semihosting
Definition: stdio_base.h:41
@ STDIO_SLIP
stdio via SLIP (mutiplex)
Definition: stdio_base.h:49
@ STDIO_NULL
dummy stdio
Definition: stdio_base.h:38
@ STDIO_UDP
stdio via UDP
Definition: stdio_base.h:46
isrpipe Interface
Common macros and compiler attributes/pragmas configuration.
Context structure for isrpipe.
Definition: isrpipe.h:33
stdio provider struct
Definition: stdio_base.h:55
Cross File Arrays.