diff --git a/src/posix/platform/debug_uart.c b/src/posix/platform/debug_uart.c deleted file mode 100644 index d34a54718..000000000 --- a/src/posix/platform/debug_uart.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2017, The OpenThread Authors. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include -#include -#include - -#include -#include -#include - -/* - * Implementation note: - * These are all "weak" so that a platform may if it chooses override the instance. - */ - -OT_TOOL_WEAK -void otPlatDebugUart_printf(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - otPlatDebugUart_vprintf(fmt, ap); - va_end(ap); -} - -OT_TOOL_WEAK -void otPlatDebugUart_vprintf(const char *fmt, va_list ap) -{ - char buf[128]; - /* by standard ... - * vsnprintf() always null terminates - */ - vsnprintf(buf, sizeof(buf), fmt, ap); - /* however ... some platforms have bugs */ - buf[sizeof(buf) - 1] = 0; - otPlatDebugUart_puts_no_nl(buf); -} - -OT_TOOL_WEAK -void otPlatDebugUart_write_bytes(const uint8_t *pBytes, int nBytes) -{ - while (nBytes > 0) - { - otPlatDebugUart_putchar((int)(*pBytes)); - pBytes++; - nBytes--; - } -} - -OT_TOOL_WEAK -void otPlatDebugUart_puts_no_nl(const char *s) -{ - while (*s) - { - otPlatDebugUart_putchar(*s); - s++; - } -} - -OT_TOOL_WEAK -void otPlatDebugUart_puts(const char *s) -{ - otPlatDebugUart_puts_no_nl(s); - otPlatDebugUart_putchar('\n'); -} - -OT_TOOL_WEAK -void otPlatDebugUart_putchar(int c) -{ - /* map lf to crlf as needed */ - if (c == '\n') - { - otPlatDebugUart_putchar_raw('\r'); - } - - otPlatDebugUart_putchar_raw(c); -} - -/* provide WEAK stubs for platforms that do not implement all functions */ -OT_TOOL_WEAK -void otPlatDebugUart_putchar_raw(int c) -{ - OT_UNUSED_VARIABLE(c); -} - -OT_TOOL_WEAK -int otPlatDebugUart_kbhit(void) -{ - return 0; /* nothing */ -} - -OT_TOOL_WEAK -int otPlatDebugUart_getc(void) -{ - return -1; /* nothing */ -} - -OT_TOOL_WEAK -otError otPlatDebugUart_logfile(const char *filename) -{ - OT_UNUSED_VARIABLE(filename); - return OT_ERROR_FAILED; -} - -#if (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_DEBUG_UART) -/* this should not be a WEAK function */ -void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) -{ - va_list ap; - uint32_t now; - - OT_UNUSED_VARIABLE(aLogLevel); - OT_UNUSED_VARIABLE(aLogRegion); - - now = otPlatAlarmMilliGetNow(); - otPlatDebugUart_printf("%3d.%03d | ", (int)(now / 1000), (int)(now % 1000)); - va_start(ap, aFormat); - otPlatDebugUart_vprintf(aFormat, ap); - va_end(ap); - - otPlatDebugUart_putchar('\n'); -} -#endif diff --git a/src/posix/platform/uart.c b/src/posix/platform/uart.c index dcc7b5ffb..69ba8ebb8 100644 --- a/src/posix/platform/uart.c +++ b/src/posix/platform/uart.c @@ -40,7 +40,6 @@ #include #include -#include #include #include "code_utils.h" @@ -274,48 +273,3 @@ void platformUartProcess(const fd_set *aReadFdSet, const fd_set *aWriteFdSet, co } } } - -#if OPENTHREAD_CONFIG_ENABLE_DEBUG_UART && (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_DEBUG_UART) - -static FILE *posix_logfile; - -otError otPlatDebugUart_logfile(const char *filename) -{ - posix_logfile = fopen(filename, "wt"); - - return posix_logfile ? OT_ERROR_NONE : OT_ERROR_FAILED; -} - -void otPlatDebugUart_putchar_raw(int c) -{ - FILE *fp; - - /* note: log file will have a mix of cr/lf and - * in some/many cases duplicate cr because in - * some cases the log function {ie: Mbed} already - * includes the CR or LF... but other log functions - * do not include cr/lf and expect it appened - */ - fp = posix_logfile; - - if (fp != NULL) - { - /* log is lost ... until a file is setup */ - fputc(c, fp); - /* we could "fflush" but will not */ - } -} - -int otPlatDebugUart_kbhit(void) -{ - /* not supported */ - return 0; -} - -int otPlatDebugUart_getc(void) -{ - /* not supported */ - return -1; -} - -#endif