1 /*
2  * Copyright (c) 2020 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <kernel.h>
8 
9 #define I2C_ENABLED(idx)  (IS_ENABLED(CONFIG_I2C) && \
10 			   DT_NODE_HAS_STATUS(DT_NODELABEL(i2c##idx), okay))
11 
12 #define SPI_ENABLED(idx)  (IS_ENABLED(CONFIG_SPI) && \
13 			   DT_NODE_HAS_STATUS(DT_NODELABEL(spi##idx), okay))
14 
15 #define UART_ENABLED(idx) (IS_ENABLED(CONFIG_SERIAL) && \
16 			   (IS_ENABLED(CONFIG_SOC_SERIES_NRF53X) || \
17 			    IS_ENABLED(CONFIG_SOC_SERIES_NRF91X)) && \
18 			   DT_NODE_HAS_STATUS(DT_NODELABEL(uart##idx), okay))
19 
20 /*
21  * In most Nordic SoCs, SPI and TWI peripherals with the same instance number
22  * share certain resources and therefore cannot be used at the same time (in
23  * nRF53 and nRF91 Series this limitation concerns UART peripherals as well).
24  *
25  * In some SoCs, like nRF52810, there are only single instances of
26  * these peripherals and they are arranged in a different way, so this
27  * limitation does not apply.
28  *
29  * The build assertions below check if conflicting peripheral instances are not
30  * enabled simultaneously.
31  */
32 
33 #define CHECK(idx) \
34 	!(I2C_ENABLED(idx) && SPI_ENABLED(idx)) && \
35 	!(I2C_ENABLED(idx) && UART_ENABLED(idx)) && \
36 	!(SPI_ENABLED(idx) && UART_ENABLED(idx))
37 
38 #define MSG(idx) \
39 	"Only one of the following peripherals can be enabled: " \
40 	"SPI"#idx", SPIM"#idx", SPIS"#idx", TWI"#idx", TWIM"#idx", TWIS"#idx \
41 	IF_ENABLED(CONFIG_SOC_SERIES_NRF53X, (", UARTE"#idx)) \
42 	IF_ENABLED(CONFIG_SOC_SERIES_NRF91X, (", UARTE"#idx)) \
43 	". Check nodes with status \"okay\" in zephyr.dts."
44 
45 #if (!IS_ENABLED(CONFIG_SOC_NRF52810) &&	\
46 	!IS_ENABLED(CONFIG_SOC_NRF52805) &&	\
47 	!IS_ENABLED(CONFIG_SOC_NRF52811))
48 BUILD_ASSERT(CHECK(0), MSG(0));
49 #endif
50 BUILD_ASSERT(CHECK(1), MSG(1));
51 BUILD_ASSERT(CHECK(2), MSG(2));
52 BUILD_ASSERT(CHECK(3), MSG(3));
53 
54 #if IS_ENABLED(CONFIG_SOC_NRF52811)
55 BUILD_ASSERT(!(SPI_ENABLED(1) && I2C_ENABLED(0)),
56 	     "Only one of the following peripherals can be enabled: "
57 	     "SPI1, SPIM1, SPIS1, TWI0, TWIM0, TWIS0. "
58 	     "Check nodes with status \"okay\" in zephyr.dts.");
59 #endif
60