stdio_base.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
3  * 2018 Freie Universität Berlin
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
24 #ifndef STDIO_BASE_H
25 #define STDIO_BASE_H
26 
27 #include <unistd.h>
28 
29 #include "modules.h"
30 #include "isrpipe.h"
31 #include "xfa.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #ifndef STDIO_RX_BUFSIZE
41 #define STDIO_RX_BUFSIZE (64)
42 #endif
43 
44 enum {
56  STDIO_SLIP, /*<< stdio via SLIP (mutiplex) */
57 };
58 
62 typedef struct {
66  void (*open)(void);
70  void (*close)(void);
80  ssize_t (*write)(const void *src, size_t len);
82 
87 
91 void stdio_init(void);
92 
93 #if IS_USED(MODULE_STDIO_AVAILABLE) || DOXYGEN
102 int stdio_available(void);
103 #endif
104 
112 void stdio_clear_stdin(void);
113 
123 ssize_t stdio_read(void* buffer, size_t max_len);
124 
138 ssize_t stdio_write(const void* buffer, size_t len);
139 
143 void stdio_close(void);
144 
145 #if defined(MODULE_STDIO_DISPATCH) || DOXYGEN
154 #define STDIO_PROVIDER(_type, _open, _close, _write) \
155  XFA_CONST(stdio_provider_t, stdio_provider_xfa, 0) stdio_ ##_type = { \
156  .open = _open, \
157  .close = _close, \
158  .write = _write, \
159  };
160 #else
161 #define STDIO_PROVIDER(_type, _open, _close, _write) \
162  void stdio_init(void) { \
163  void (*f)(void) = _open; \
164  if (f != NULL) { \
165  f(); \
166  } \
167  } \
168  void stdio_close(void) { \
169  void (*f)(void) = _close; \
170  if (f != NULL) { \
171  f(); \
172  } \
173  } \
174  ssize_t stdio_write(const void* buffer, size_t len) { \
175  return _write(buffer, len); \
176  }
177 #endif
178 
179 #ifdef __cplusplus
180 }
181 #endif
183 #endif /* STDIO_BASE_H */
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:51
@ STDIO_USBUS_CDC_ACM
stdio via USB CDC ACM (usbus)
Definition: stdio_base.h:49
@ STDIO_UART
stdio via UART
Definition: stdio_base.h:46
@ STDIO_RTT
stdio via Segger RTT
Definition: stdio_base.h:47
@ STDIO_TINYUSB_CDC_ACM
tdio via USB CDC ACM (TinyUSB)
Definition: stdio_base.h:50
@ STDIO_TELNET
stdio via telnet
Definition: stdio_base.h:54
@ STDIO_ETHOS
stdio via ethos (mutiplex)
Definition: stdio_base.h:55
@ STDIO_NIMBLE
stdio via BLE (NimBLE)
Definition: stdio_base.h:52
@ STDIO_SEMIHOSTING
stdio via Semihosting
Definition: stdio_base.h:48
@ STDIO_NULL
dummy stdio
Definition: stdio_base.h:45
@ STDIO_UDP
stdio via UDP
Definition: stdio_base.h:53
isrpipe Interface
Common macros and compiler attributes/pragmas configuration.
Context structure for isrpipe.
Definition: isrpipe.h:37
stdio provider struct
Definition: stdio_base.h:62
Cross File Arrays.