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