From c0402643cca95a8a1118f16ebce2aaab48403317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Sat, 23 Mar 2019 20:43:27 +0100 Subject: [PATCH] isrpipe: split isrpipe_read_timeout to isolate xtimer dependency This defines a new 'isrpipe_read_timeout' that should be used when using the timeout based function of isrpipe. This fix the implicit dependency to 'xtimer' that is only needed for the '_timeout' functions. It prevents 'stdio_uart' that uses 'isrpipe' to need to depend on xtimer. This was silently solved at link time for most platforms but not for the 'esp32' for example. 'drivers/at' needed to be updated at the same time to follow the api change. --- Makefile.dep | 5 +++ drivers/Makefile.dep | 1 + drivers/at/at.c | 1 + sys/Makefile | 3 ++ sys/include/isrpipe.h | 34 --------------- sys/include/isrpipe/read_timeout.h | 69 ++++++++++++++++++++++++++++++ sys/isrpipe/isrpipe.c | 4 ++ sys/isrpipe/read_timeout/Makefile | 3 ++ 8 files changed, 86 insertions(+), 34 deletions(-) create mode 100644 sys/include/isrpipe/read_timeout.h create mode 100644 sys/isrpipe/read_timeout/Makefile diff --git a/Makefile.dep b/Makefile.dep index 5e5872a9e7635..50b222968af23 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -405,6 +405,11 @@ ifneq (,$(filter isrpipe,$(USEMODULE))) USEMODULE += tsrb endif +ifneq (,$(filter isrpipe_read_timeout,$(USEMODULE))) + USEMODULE += isrpipe + USEMODULE += xtimer +endif + ifneq (,$(filter shell_commands,$(USEMODULE))) ifneq (,$(filter fib,$(USEMODULE))) USEMODULE += posix_inet diff --git a/drivers/Makefile.dep b/drivers/Makefile.dep index cdf6366c37605..050617707e515 100644 --- a/drivers/Makefile.dep +++ b/drivers/Makefile.dep @@ -34,6 +34,7 @@ ifneq (,$(filter at,$(USEMODULE))) USEMODULE += fmt USEMODULE += xtimer USEMODULE += isrpipe + USEMODULE += isrpipe_read_timeout endif ifneq (,$(filter at30tse75x,$(USEMODULE))) diff --git a/drivers/at/at.c b/drivers/at/at.c index 52646de19f317..e784ef20020ae 100644 --- a/drivers/at/at.c +++ b/drivers/at/at.c @@ -12,6 +12,7 @@ #include "at.h" #include "fmt.h" #include "isrpipe.h" +#include "isrpipe/read_timeout.h" #include "periph/uart.h" #include "xtimer.h" diff --git a/sys/Makefile b/sys/Makefile index 5a7f2c340b250..8fb54c382f911 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -4,6 +4,9 @@ endif ifneq (,$(filter eepreg,$(USEMODULE))) DIRS += eepreg endif +ifneq (,$(filter isrpipe_read_timeout,$(USEMODULE))) + DIRS += isrpipe/read_timeout +endif ifneq (,$(filter posix_inet,$(USEMODULE))) DIRS += posix/inet endif diff --git a/sys/include/isrpipe.h b/sys/include/isrpipe.h index 056b98cc09665..356eef82cc914 100644 --- a/sys/include/isrpipe.h +++ b/sys/include/isrpipe.h @@ -75,40 +75,6 @@ int isrpipe_write_one(isrpipe_t *isrpipe, char c); */ int isrpipe_read(isrpipe_t *isrpipe, char *buf, size_t count); -/** - * @brief Read data from isrpipe (with timeout, blocking) - * - * Currently, the timeout parameter is applied on every underlying read, which - * might be *per single byte*. - * - * @note This function might return less than @p count bytes - * - * @param[in] isrpipe isrpipe object to operate on - * @param[in] buf buffer to write to - * @param[in] count number of bytes to read - * @param[in] timeout timeout in microseconds - * - * @returns number of bytes read - * @returns -ETIMEDOUT on timeout - */ -int isrpipe_read_timeout(isrpipe_t *isrpipe, char *buf, size_t count, uint32_t timeout); - -/** - * @brief Read data from isrpipe (with timeout, blocking, wait until all read) - * - * This function is like @ref isrpipe_read_timeout, but will only return on - * timeout or when @p count bytes have been received. - * - * @param[in] isrpipe isrpipe object to operate on - * @param[in] buf buffer to write to - * @param[in] count number of bytes to read - * @param[in] timeout timeout in microseconds - * - * @returns number of bytes read - * @returns -ETIMEDOUT on timeout - */ -int isrpipe_read_all_timeout(isrpipe_t *isrpipe, char *buf, size_t count, uint32_t timeout); - #ifdef __cplusplus } #endif diff --git a/sys/include/isrpipe/read_timeout.h b/sys/include/isrpipe/read_timeout.h new file mode 100644 index 0000000000000..4d6bbb43bffa9 --- /dev/null +++ b/sys/include/isrpipe/read_timeout.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2016 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. + */ + +/** + * @defgroup isr_pipe ISR Pipe + * @ingroup sys + * @brief ISR -> userspace pipe with timeout + * + * @{ + * @file + * @brief isrpipe read timeout Interface + * + * @author Kaspar Schleiser + * + */ + +#ifndef ISRPIPE_READ_TIMEOUT_H +#define ISRPIPE_READ_TIMEOUT_H + +#include "isrpipe.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Read data from isrpipe (with timeout, blocking) + * + * Currently, the timeout parameter is applied on every underlying read, which + * might be *per single byte*. + * + * @note This function might return less than @p count bytes + * + * @param[in] isrpipe isrpipe object to operate on + * @param[in] buf buffer to write to + * @param[in] count number of bytes to read + * @param[in] timeout timeout in microseconds + * + * @returns number of bytes read + * @returns -ETIMEDOUT on timeout + */ +int isrpipe_read_timeout(isrpipe_t *isrpipe, char *buf, size_t count, uint32_t timeout); + +/** + * @brief Read data from isrpipe (with timeout, blocking, wait until all read) + * + * This function is like @ref isrpipe_read_timeout, but will only return on + * timeout or when @p count bytes have been received. + * + * @param[in] isrpipe isrpipe object to operate on + * @param[in] buf buffer to write to + * @param[in] count number of bytes to read + * @param[in] timeout timeout in microseconds + * + * @returns number of bytes read + * @returns -ETIMEDOUT on timeout + */ +int isrpipe_read_all_timeout(isrpipe_t *isrpipe, char *buf, size_t count, uint32_t timeout); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif /* ISRPIPE_READ_TIMEOUT_H_ */ diff --git a/sys/isrpipe/isrpipe.c b/sys/isrpipe/isrpipe.c index c9f6e1926acbc..0730fe7dc80ee 100644 --- a/sys/isrpipe/isrpipe.c +++ b/sys/isrpipe/isrpipe.c @@ -20,7 +20,9 @@ #include #include "isrpipe.h" +#ifdef MODULE_ISRPIPE_READ_TIMEOUT #include "xtimer.h" +#endif void isrpipe_init(isrpipe_t *isrpipe, char *buf, size_t bufsize) { @@ -50,6 +52,7 @@ int isrpipe_read(isrpipe_t *isrpipe, char *buffer, size_t count) return res; } +#ifdef MODULE_ISRPIPE_READ_TIMEOUT typedef struct { mutex_t *mutex; int flag; @@ -102,3 +105,4 @@ int isrpipe_read_all_timeout(isrpipe_t *isrpipe, char *buffer, size_t count, uin return pos - buffer; } +#endif diff --git a/sys/isrpipe/read_timeout/Makefile b/sys/isrpipe/read_timeout/Makefile new file mode 100644 index 0000000000000..92dff564d3dd3 --- /dev/null +++ b/sys/isrpipe/read_timeout/Makefile @@ -0,0 +1,3 @@ +MODULE = isrpipe_read_timeout + +include $(RIOTBASE)/Makefile.base