From 2d582cdd2e4839d6ed438a9044c0939e0ce46ffc Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Tue, 15 Sep 2020 14:43:09 +0200 Subject: [PATCH] sys: initial import of dbgpin module --- makefiles/pseudomodules.inc.mk | 1 + sys/Makefile.dep | 5 ++ sys/include/dbgpin.h | 131 +++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 sys/include/dbgpin.h diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index c4e4673ebf..f310a128eb 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -20,6 +20,7 @@ PSEUDOMODULES += cortexm_fpu PSEUDOMODULES += cortexm_svc PSEUDOMODULES += cpu_check_address PSEUDOMODULES += crypto_% # crypto_aes or crypto_3des +PSEUDOMODULES += dbgpin PSEUDOMODULES += devfs_% PSEUDOMODULES += dhcpv6_% PSEUDOMODULES += ecc_% diff --git a/sys/Makefile.dep b/sys/Makefile.dep index 1af2827552..08b58517c5 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -1118,4 +1118,9 @@ ifneq (,$(filter ecc_%,$(USEMODULE))) USEMODULE += ecc endif +ifneq (,$(filter dbgpin,$(USEMODULE))) + FEATURES_REQUIRED += periph_gpio + FEATURES_REQUIRED += dbgpin +endif + include $(RIOTBASE)/sys/test_utils/Makefile.dep diff --git a/sys/include/dbgpin.h b/sys/include/dbgpin.h new file mode 100644 index 0000000000..1e85e69381 --- /dev/null +++ b/sys/include/dbgpin.h @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2020 Freie Universität Berlin + * + * 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 sys_dbgpin Direct pin control for debugging/profiling + * @ingroup sys + * + * @warning This module does not verify the given pin number, so make sure + * the pin numbers you use are actually configured! + * + * @{ + * @file + * @brief GPIO wrapper for debugging/profiling purposes + * + * @author Hauke Petersen + */ + +#ifndef DBGPIN_H +#define DBGPIN_H + +#include "kernel_defines.h" +#include "periph/gpio.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifndef DBGPIN_PINS +#error Please specify the pins to use with the dbgpin module (DBGPIN_PINS) +#endif + +// extern const gpio_t dbgpin_pins[]; + +/** + * @brief Set the given debug pin to HIGH + * + * @param[in] pin pin to set, pin number is offset to the list of defined + * debug pins in DBGPIN_PINS + */ +static inline void dbgpin_set(unsigned pin) +{ + static const gpio_t dbgpin_pins[] = { DBGPIN_PINS }; + gpio_set(dbgpin_pins[pin]); +} + +/** + * @brief Set the given debug pin to LOW + * + * @param[in] pin pin to set, pin number is offset to the list of defined + * debug pins in DBGPIN_PINS + */ +static inline void dbgpin_clear(unsigned pin) +{ + static const gpio_t dbgpin_pins[] = { DBGPIN_PINS }; + gpio_clear(dbgpin_pins[pin]); +} + +/** + * @brief Toggle the given debug pin + * + * @param[in] pin pin to set, pin number is offset to the list of defined + * debug pins in DBGPIN_PINS + */ +static inline void dbgpin_toggle(unsigned pin) +{ + static const gpio_t dbgpin_pins[] = { DBGPIN_PINS }; + gpio_toggle(dbgpin_pins[pin]); +} + +/** + * @brief Output a pulse on the given debug pin (toggles the pin twice) + * + * @param[in] pin pin to set, pin number is offset to the list of defined + * debug pins in DBGPIN_PINS + */ +static inline void dbgpin_pulse(unsigned pin) +{ + dbgpin_toggle(pin); + dbgpin_toggle(pin); +} + +/** + * @brief Output a specified number of pulses on the given debug pin + * + * @param[in] pin pin to set, pin number is offset to the list of defined + * debug pins in DBGPIN_PINS + * @param[in] num number of pulses to output + */ +static inline void dbgpin_signal(unsigned pin, unsigned num) +{ + for (unsigned i = 0; i < num; i++) { + dbgpin_pulse(pin); + } +} + +/** + * @brief Get the number of configured debug pins + * + * @return number of configured debug pins + */ +static inline size_t dbgpin_count(void) +{ + static const gpio_t dbgpin_pins[] = { DBGPIN_PINS }; + return ARRAY_SIZE(dbgpin_pins); +} + + +/** + * @brief Initialize the configured input pins + */ +static inline void dbgpin_init(void) +{ + static const gpio_t dbgpin_pins[] = { DBGPIN_PINS }; + for (unsigned i = 0; i < ARRAY_SIZE(dbgpin_pins); i++) { + gpio_init(dbgpin_pins[i], GPIO_OUT); + gpio_clear(dbgpin_pins[i]); + } +} + +#ifdef __cplusplus +} +#endif + +#endif /* DBGPIN_H */ +/** @} **/