STDIO redirection to USB virtual COM port disabled by default, can be enabled by defining the ENABLE_STDIO macro

This commit is contained in:
Silvano Seva 2022-03-05 09:42:44 +01:00
parent 3588f351a1
commit b97d1154d5
3 changed files with 32 additions and 3 deletions

View File

@ -9,7 +9,7 @@ project('OpenRTX', ['c', 'cpp'],
## Optional defines, common to all souces (e.g. to enable debugging) ## Optional defines, common to all souces (e.g. to enable debugging)
## ##
def = {'VCOM_ENABLED' : ''} def = {}
## ##
## ----------------- Platform-independent source files ------------------------- ## ----------------- Platform-independent source files -------------------------

View File

@ -1,5 +1,5 @@
/*************************************************************************** /***************************************************************************
* Copyright (C) 2020, 2021 by Silvano Seva IU2KWO * * Copyright (C) 2020 - 2022 by Silvano Seva IU2KWO *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
@ -32,10 +32,17 @@ extern "C" {
*/ */
int _write_r(struct _reent *ptr, int fd, const void *buf, size_t cnt) int _write_r(struct _reent *ptr, int fd, const void *buf, size_t cnt)
{ {
#ifdef ENABLE_STDIO
if(fd == STDOUT_FILENO || fd == STDERR_FILENO) if(fd == STDOUT_FILENO || fd == STDERR_FILENO)
{ {
return vcom_writeBlock(buf, cnt); return vcom_writeBlock(buf, cnt);
} }
#else
(void) ptr;
(void) fd;
(void) buf;
(void) cnt;
#endif
/* If fd is not stdout or stderr */ /* If fd is not stdout or stderr */
ptr->_errno = EBADF; ptr->_errno = EBADF;
@ -50,6 +57,7 @@ int _read_r(struct _reent *ptr, int fd, void *buf, size_t cnt)
{ {
int ret = -1; int ret = -1;
#ifdef ENABLE_STDIO
if(fd == STDIN_FILENO) if(fd == STDIN_FILENO)
{ {
for(;;) for(;;)
@ -68,6 +76,13 @@ int _read_r(struct _reent *ptr, int fd, void *buf, size_t cnt)
ptr->_errno = EBADF; ptr->_errno = EBADF;
ret = -1; ret = -1;
} }
#else
(void) ptr;
(void) fd;
(void) buf;
(void) cnt;
ptr->_errno = EBADF;
#endif
return ret; return ret;
} }

View File

@ -1,5 +1,5 @@
/*************************************************************************** /***************************************************************************
* Copyright (C) 2020, 2021 by Silvano Seva IU2KWO * * Copyright (C) 2020 - 2022 by Silvano Seva IU2KWO *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
@ -32,11 +32,18 @@ extern "C" {
*/ */
int _write_r(struct _reent *ptr, int fd, const void *buf, size_t cnt) int _write_r(struct _reent *ptr, int fd, const void *buf, size_t cnt)
{ {
#ifdef ENABLE_STDIO
if(fd == STDOUT_FILENO || fd == STDERR_FILENO) if(fd == STDOUT_FILENO || fd == STDERR_FILENO)
{ {
vcom_writeBlock(buf, cnt); vcom_writeBlock(buf, cnt);
return cnt; return cnt;
} }
#else
(void) ptr;
(void) fd;
(void) buf;
(void) cnt;
#endif
/* If fd is not stdout or stderr */ /* If fd is not stdout or stderr */
ptr->_errno = EBADF; ptr->_errno = EBADF;
@ -49,6 +56,7 @@ int _write_r(struct _reent *ptr, int fd, const void *buf, size_t cnt)
*/ */
int _read_r(struct _reent *ptr, int fd, void *buf, size_t cnt) int _read_r(struct _reent *ptr, int fd, void *buf, size_t cnt)
{ {
#ifdef ENABLE_STDIO
if(fd == STDIN_FILENO) if(fd == STDIN_FILENO)
{ {
for(;;) for(;;)
@ -57,6 +65,12 @@ int _read_r(struct _reent *ptr, int fd, void *buf, size_t cnt)
if((r < 0) || (r == (ssize_t)(cnt))) return r; if((r < 0) || (r == (ssize_t)(cnt))) return r;
} }
} }
#else
(void) ptr;
(void) fd;
(void) buf;
(void) cnt;
#endif
/* If fd is not stdin */ /* If fd is not stdin */
ptr->_errno = EBADF; ptr->_errno = EBADF;