From 7e069290a0a554f877b0cc5320f940c3643be971 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 8 Sep 2020 01:16:45 +0200 Subject: [PATCH] sys/bus: add system buses --- makefiles/pseudomodules.inc.mk | 1 + sys/Makefile | 3 ++ sys/Makefile.dep | 5 +++ sys/auto_init/auto_init.c | 5 +++ sys/bus/Makefile | 3 ++ sys/bus/sys_bus_init.c | 29 +++++++++++++ sys/include/sys/bus.h | 77 ++++++++++++++++++++++++++++++++++ 7 files changed, 123 insertions(+) create mode 100644 sys/bus/Makefile create mode 100644 sys/bus/sys_bus_init.c create mode 100644 sys/include/sys/bus.h diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 4189235592..96bac8e3ec 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -127,6 +127,7 @@ PSEUDOMODULES += stm32_eth_auto PSEUDOMODULES += stm32_eth_link_up PSEUDOMODULES += suit_transport_% PSEUDOMODULES += suit_storage_% +PSEUDOMODULES += sys_bus_% PSEUDOMODULES += wakaama_objects_% PSEUDOMODULES += wifi_enterprise PSEUDOMODULES += xtimer_on_ztimer diff --git a/sys/Makefile b/sys/Makefile index e2216b74a1..f174755a58 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -158,6 +158,9 @@ endif ifneq (,$(filter suit%,$(USEMODULE))) DIRS += suit endif +ifneq (,$(filter sys_bus,$(USEMODULE))) + DIRS += bus +endif ifneq (,$(filter tcp,$(USEMODULE))) DIRS += net/transport_layer/tcp endif diff --git a/sys/Makefile.dep b/sys/Makefile.dep index a4551af11c..98c09d9f1a 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -44,6 +44,11 @@ ifneq (,$(filter crypto_%,$(USEMODULE))) USEMODULE += crypto endif +ifneq (,$(filter sys_bus_%,$(USEMODULE))) + USEMODULE += sys_bus + USEMODULE += core_msg_bus +endif + ifneq (,$(filter rtt_cmd,$(USEMODULE))) FEATURES_REQUIRED += periph_rtt endif diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index c24c0d4209..3479ff3602 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -58,6 +58,11 @@ void auto_init(void) extern void auto_init_event_thread(void); auto_init_event_thread(); } + if (IS_USED(MODULE_SYS_BUS)) { + LOG_DEBUG("Auto init system buses.\n"); + extern void auto_init_sys_bus(void); + auto_init_sys_bus(); + } if (IS_USED(MODULE_MCI)) { LOG_DEBUG("Auto init mci.\n"); extern void mci_initialize(void); diff --git a/sys/bus/Makefile b/sys/bus/Makefile new file mode 100644 index 0000000000..d66bde0cec --- /dev/null +++ b/sys/bus/Makefile @@ -0,0 +1,3 @@ +MODULE = sys_bus + +include $(RIOTBASE)/Makefile.base diff --git a/sys/bus/sys_bus_init.c b/sys/bus/sys_bus_init.c new file mode 100644 index 0000000000..eaba0d3e95 --- /dev/null +++ b/sys/bus/sys_bus_init.c @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2020 ML!PA Consulting GmbH + * + * 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 sys_bus + * @{ + * + * @file + * @brief System Buses + * + * @author Benjamin Valentin + * @} + */ + +#include "sys/bus.h" + +msg_bus_t _sys_bus[SYS_BUS_NUMOF]; + +void auto_init_sys_bus(void) +{ + for (unsigned i = 0; i < SYS_BUS_NUMOF; ++i) { + msg_bus_init(&_sys_bus[i]); + } +} diff --git a/sys/include/sys/bus.h b/sys/include/sys/bus.h new file mode 100644 index 0000000000..f6d29a1ff4 --- /dev/null +++ b/sys/include/sys/bus.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2020 ML!PA Consulting GmbH + * + * 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 sys + * @defgroup sys_bus System Buses for common events + * @{ + * + * @file + * @brief This provides System Buses for common events. + * + * @warning Bus Events will be lost if receiver message queue is full. + * + * @author Benjamin Valentin + */ + +#ifndef SYS_BUS_H +#define SYS_BUS_H + +#include +#include "msg_bus.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief System Bus types + */ +typedef enum { +#if MODULE_SYS_BUS_POWER + SYS_BUS_POWER, /**< Events related to system power */ +#endif + SYS_BUS_NUMOF /**< Number of enabled system buses */ +} sys_bus_t; + +/** + * @brief Power Bus Events + */ +typedef enum { + /** + * @brief Supply voltage fallen below threshold + */ + SYS_BUS_POWER_EVENT_LOW_VOLTAGE, + + /* add more if needed, but not more than 32 */ +} sys_bus_power_event_t; + +/** + * @brief The System Bus array - do not use directly + */ +extern msg_bus_t _sys_bus[SYS_BUS_NUMOF]; + +/** + * @brief Get a System Bus for a category of events. + * + * @param[in] bus The event category of the the user + * is interested in + * + * @return The message bus for those events + */ +static inline msg_bus_t *sys_bus_get(sys_bus_t bus) +{ + return &_sys_bus[bus]; +} + +#ifdef __cplusplus +} +#endif + +#endif /* SYS_BUS_H */ +/** @} */