diff --git a/boards/chronos/stdio.c b/boards/chronos/stdio.c index d7e9ceb3cb5d610970fb0f59c4a6f8edafa3a474..a6def45cb979f7e46a9d64c96fa5e81a8bd9736e 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; +} diff --git a/cpu/atmega_common/include/sys/types.h b/cpu/atmega_common/include/sys/types.h index 75a30bcd15d44077d18a0aceff3e44baa2ffff00..74bf6c6ccf17231295840c2aae656855993f1c9f 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 <kaspar@schleiser.de> * * 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 } diff --git a/cpu/msp430-common/include/sys/types.h b/cpu/msp430-common/include/sys/types.h new file mode 100644 index 0000000000000000000000000000000000000000..d50105720c03a094e2736d918fc34c4624efa4a5 --- /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 17619dd1d5d30b41c567c0e2a9eea85859ad6259..31f783a669493c85aadf6a1a2bd5f4b20a4f85f6 100644 --- a/cpu/msp430fxyz/msp430_stdio.c +++ b/cpu/msp430fxyz/msp430_stdio.c @@ -18,6 +18,9 @@ * @} */ +#include <sys/types.h> +#include <unistd.h> + #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; + } } diff --git a/sys/fmt/fmt.c b/sys/fmt/fmt.c index 4ddc63f4b9940738926b391e61fa0c0da9f54f3d..803b1e0d639ead5f6fee50e45813486d6dfda013 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) diff --git a/tests/fmt_print/Makefile b/tests/fmt_print/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..810f36de745c9bd5078c1177be38360a4df2e09c --- /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 0000000000000000000000000000000000000000..1b5ecfba274d1c9f0ad78d8b69000e2ba8a36386 --- /dev/null +++ b/tests/fmt_print/main.c @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de> + * + * 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 <kaspar@schleiser.de> + * + * @} + */ + +#include "fmt.h" + +int main(void) +{ + print_str("If you can read this:\n"); + print_str("Test successful.\n"); + + return 0; +}