zephyr/soc/arm/nordic_nrf/validate_enabled_instances.c
Martí Bolívar 6e8775ff84 devicetree: remove DT_HAS_NODE_STATUS_OKAY
Several reviewers agreed that DT_HAS_NODE_STATUS_OKAY(...) was an
undesirable API for the following reasons:

- it's inconsistent with the rest of the DT_NODE_HAS_FOO names
- DT_NODE_HAS_FOO_BAR_BAZ(node) was agreed upon as a shorthand
  for macros which are equivalent to
  DT_NODE_HAS_FOO(node) && DT_NODE_HAS_BAR(node) &&
- DT_NODE_HAS_BAZ(node), and DT_HAS_NODE_STATUS_OKAY is an odd duck
- DT_NODE_HAS_STATUS(..., okay) was viewed as more readable anyway
- it is seen as a somewhat aesthetically challenged name

Replace all users with DT_NODE_HAS_STATUS(..., okay), which is
semantically equivalent.

This is mostly done with sed, but a few remaining cases were done by
hand, along with whitespace, docs, and comment changes. These special
cases include the Nordic SOC static assert files.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-13 18:24:42 +02:00

49 lines
1.7 KiB
C

/*
* Copyright (c) 2020 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#define I2C_ENABLED(idx) (IS_ENABLED(CONFIG_I2C) && \
DT_NODE_HAS_STATUS(DT_NODELABEL(i2c##idx), okay))
#define SPI_ENABLED(idx) (IS_ENABLED(CONFIG_SPI) && \
DT_NODE_HAS_STATUS(DT_NODELABEL(spi##idx), okay))
#define UART_ENABLED(idx) (IS_ENABLED(CONFIG_SERIAL) && \
(IS_ENABLED(CONFIG_SOC_SERIES_NRF53X) || \
IS_ENABLED(CONFIG_SOC_SERIES_NRF91X)) && \
DT_NODE_HAS_STATUS(DT_NODELABEL(uart##idx), okay))
/*
* In most Nordic SoCs, SPI and TWI peripherals with the same instance number
* share certain resources and therefore cannot be used at the same time (in
* nRF53 and nRF91 Series this limitation concerns UART peripherals as well).
* In nRF52810 though, there are only single instances of these peripherals
* and they are arranged in a different way, so this limitation does not apply.
*
* The build assertions below check if conflicting peripheral instances are not
* enabled simultaneously.
*/
#define CHECK(idx) \
!(I2C_ENABLED(idx) && SPI_ENABLED(idx)) && \
!(I2C_ENABLED(idx) && UART_ENABLED(idx)) && \
!(SPI_ENABLED(idx) && UART_ENABLED(idx))
#define MSG(idx) \
"Only one of the following peripherals can be enabled: " \
"SPI"#idx", SPIM"#idx", SPIS"#idx", TWI"#idx", TWIM"#idx", TWIS"#idx \
IF_ENABLED(CONFIG_SOC_SERIES_NRF53X, (", UARTE"#idx)) \
IF_ENABLED(CONFIG_SOC_SERIES_NRF91X, (", UARTE"#idx)) \
". Check nodes with status \"okay\" in zephyr.dts."
#if !IS_ENABLED(CONFIG_SOC_NRF52810)
BUILD_ASSERT(CHECK(0), MSG(0));
#endif
BUILD_ASSERT(CHECK(1), MSG(1));
BUILD_ASSERT(CHECK(2), MSG(2));
BUILD_ASSERT(CHECK(3), MSG(3));