From 28d9eab42079d4c07e2f9b43e5ecdba71935bc7a Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 19 Nov 2015 12:53:03 +0100 Subject: [PATCH 1/5] cpu: atmega_common_ add off_t to sys/types.h --- cpu/atmega_common/include/sys/types.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cpu/atmega_common/include/sys/types.h b/cpu/atmega_common/include/sys/types.h index 75a30bcd15..74bf6c6ccf 100644 --- a/cpu/atmega_common/include/sys/types.h +++ b/cpu/atmega_common/include/sys/types.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen + * 2015 Kaspar Schleiser * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -18,6 +19,7 @@ extern "C" { typedef int16_t suseconds_t; typedef signed int ssize_t; +typedef unsigned int off_t; #ifdef __cplusplus } From 157f8c93ad6c9723c8f708d3c56e8f9fcf761773 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 19 Nov 2015 12:54:09 +0100 Subject: [PATCH 2/5] sys: fmt: add workaround for AVR libc's missing write() --- sys/fmt/fmt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sys/fmt/fmt.c b/sys/fmt/fmt.c index 4ddc63f4b9..803b1e0d63 100644 --- a/sys/fmt/fmt.c +++ b/sys/fmt/fmt.c @@ -137,6 +137,10 @@ uint32_t scn_u32_dec(const char *str, size_t n) void print(const char *s, size_t n) { +#ifdef __WITH_AVRLIBC__ + /* AVR's libc doesn't offer write(), so use fwrite() instead */ + fwrite(s, n, 1, stdout); +#else while (n > 0) { ssize_t written = write(STDOUT_FILENO, s, n); if (written < 0) { @@ -145,6 +149,7 @@ void print(const char *s, size_t n) n -= written; s += written; } +#endif /* __WITH_AVRLIBC__ */ } void print_u32_dec(uint32_t val) From 04bc408931583d29899b938a5d830f5254c92f60 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 19 Nov 2015 13:04:29 +0100 Subject: [PATCH 3/5] cpu: msp430: add write() + needed libc header fixes --- cpu/msp430-common/include/sys/types.h | 22 ++++++++++++++++++++++ cpu/msp430fxyz/msp430_stdio.c | 19 +++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 cpu/msp430-common/include/sys/types.h diff --git a/cpu/msp430-common/include/sys/types.h b/cpu/msp430-common/include/sys/types.h new file mode 100644 index 0000000000..d50105720c --- /dev/null +++ b/cpu/msp430-common/include/sys/types.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2014 INRIA + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +#ifndef SYS_TYPES_H_ +#define SYS_TYPES_H_ + +#include "msp430_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* SYS_TYPES_H_ */ diff --git a/cpu/msp430fxyz/msp430_stdio.c b/cpu/msp430fxyz/msp430_stdio.c index 17619dd1d5..31f783a669 100644 --- a/cpu/msp430fxyz/msp430_stdio.c +++ b/cpu/msp430fxyz/msp430_stdio.c @@ -18,6 +18,9 @@ * @} */ +#include +#include + #include "uart_stdio.h" /** @@ -37,6 +40,18 @@ int getchar(void) int putchar(int c) { char _c = c; - uart_stdio_write(&_c, 1); - return 1; + return uart_stdio_write(&_c, 1); +} + +/** + * @brief Write nbyte characters to the STDIO UART interface + */ +ssize_t write(int fildes, const void *buf, size_t nbyte) +{ + if (fildes == STDOUT_FILENO) { + return uart_stdio_write(buf, nbyte); + } + else { + return -1; + } } From 8d613ceb5371d65b4b65283fc80e95ca4daee5f5 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 19 Nov 2015 13:13:54 +0100 Subject: [PATCH 4/5] boards: chronos: add dummy write() implementation --- boards/chronos/stdio.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/boards/chronos/stdio.c b/boards/chronos/stdio.c index d7e9ceb3cb..a6def45cb9 100644 --- a/boards/chronos/stdio.c +++ b/boards/chronos/stdio.c @@ -40,3 +40,8 @@ int getchar(void) /* dummy implementation */ return EOF; } + +ssize_t write(int fildes, const void *buf, size_t nbyte) +{ + return -1; +} From dc1187ac6f65dbfe1d7e39af3f6f52a77e0e0765 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 19 Nov 2015 15:43:06 +0100 Subject: [PATCH 5/5] tests: fmt_print: initial commit --- tests/fmt_print/Makefile | 6 ++++++ tests/fmt_print/main.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/fmt_print/Makefile create mode 100644 tests/fmt_print/main.c diff --git a/tests/fmt_print/Makefile b/tests/fmt_print/Makefile new file mode 100644 index 0000000000..810f36de74 --- /dev/null +++ b/tests/fmt_print/Makefile @@ -0,0 +1,6 @@ +APPLICATION = fmt_print +include ../Makefile.tests_common + +USEMODULE += fmt + +include $(RIOTBASE)/Makefile.include diff --git a/tests/fmt_print/main.c b/tests/fmt_print/main.c new file mode 100644 index 0000000000..1b5ecfba27 --- /dev/null +++ b/tests/fmt_print/main.c @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015 Kaspar Schleiser + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief fmt print test application + * + * This test is supposed to check for "compilabilty" of the fmt print_* instructions. + * + * @author Kaspar Schleiser + * + * @} + */ + +#include "fmt.h" + +int main(void) +{ + print_str("If you can read this:\n"); + print_str("Test successful.\n"); + + return 0; +}