1# CMake integration for Simplicity SDK
2#
3# Copyright (c) 2017, Christian Taedcke
4# Copyright (c) 2021, Safran Passenger Innovations Germany GmbH
5# Copyright (c) 2022, Antmicro <www.antmicro.com>
6# Copyright (c) 2024, Silicon Laboratories Inc.
7#
8# SPDX-License-Identifier: Apache-2.0
9
10set(EMLIB_DIR      ${ZEPHYR_HAL_SILABS_MODULE_DIR}/simplicity_sdk/platform/emlib)
11set(COMMON_DIR     ${ZEPHYR_HAL_SILABS_MODULE_DIR}/simplicity_sdk/platform/common)
12set(DEVICE_DIR     ${ZEPHYR_HAL_SILABS_MODULE_DIR}/simplicity_sdk/platform/Device)
13set(RADIO_DIR      ${ZEPHYR_HAL_SILABS_MODULE_DIR}/simplicity_sdk/platform/radio)
14set(SECURITY_DIR   ${ZEPHYR_HAL_SILABS_MODULE_DIR}/simplicity_sdk/platform/security)
15set(SERVICE_DIR    ${ZEPHYR_HAL_SILABS_MODULE_DIR}/simplicity_sdk/platform/service)
16set(PERIPHERAL_DIR ${ZEPHYR_HAL_SILABS_MODULE_DIR}/simplicity_sdk/platform/peripheral)
17set(BLUETOOTH_DIR  ${ZEPHYR_HAL_SILABS_MODULE_DIR}/simplicity_sdk/protocol/bluetooth)
18set(BLOBS_DIR      ${ZEPHYR_HAL_SILABS_MODULE_DIR}/zephyr/blobs/simplicity_sdk)
19
20# Translate the SoC name and part number into the gecko device and cpu name
21# respectively.
22string(TOUPPER ${CONFIG_SOC_SERIES} SILABS_DEVICE_FAMILY)
23
24# Get SoC series number, i.e. translate e.g. efr32bg22 -> 22
25string(SUBSTRING ${CONFIG_SOC_SERIES} 7 2 SILABS_DEVICE_FAMILY_NUMBER)
26
27set(SILABS_DEVICE_PART_NUMBER ${CONFIG_SOC_PART_NUMBER})
28
29function(add_prebuilt_library lib_name prebuilt_path)
30  if(NOT CONFIG_BUILD_ONLY_NO_BLOBS)
31    add_library(${lib_name} STATIC IMPORTED GLOBAL)
32    set_target_properties(${lib_name} PROPERTIES
33      IMPORTED_LOCATION ${BLOBS_DIR}/${prebuilt_path}
34    )
35    zephyr_link_libraries(${lib_name})
36  endif()
37endfunction()
38
39if(CONFIG_SOC_GECKO_HAS_RADIO)
40  zephyr_include_directories_ifdef(CONFIG_SOC_FAMILY_SILABS_S2
41    ${RADIO_DIR}/rail_lib/plugin/pa-conversions/efr32xg${SILABS_DEVICE_FAMILY_NUMBER}/config
42    ${RADIO_DIR}/rail_lib/chip/efr32/efr32xg2x
43  )
44
45  zephyr_include_directories(
46    ${RADIO_DIR}/rail_lib/common
47    ${RADIO_DIR}/rail_lib/plugin/pa-conversions
48    ${BLUETOOTH_DIR}/bgstack/ll/inc
49  )
50
51  # sl_protocol_crypto
52  zephyr_library_sources_ifdef(CONFIG_BT_SILABS_EFR32
53    ${SECURITY_DIR}/sl_component/sl_protocol_crypto/src/sli_radioaes_management.c
54    ${SECURITY_DIR}/sl_component/sl_protocol_crypto/src/sli_protocol_crypto_radioaes.c
55  )
56
57  if(CONFIG_BT_SILABS_EFR32)
58    # prebuilt libs
59    add_prebuilt_library(liblinklayer protocol/bluetooth/bgstack/ll/lib/libbluetooth_controller_efr32xg${SILABS_DEVICE_FAMILY_NUMBER}_gcc_release.a)
60    add_prebuilt_library(libbgcommon  protocol/bluetooth/bgcommon/lib/build/gcc/cortex-m33/bgcommon/release/libbgcommon.a)
61
62    # link mbedTLS
63    if(CONFIG_MBEDTLS)
64      zephyr_link_libraries(mbedTLS)
65    endif()
66  endif()
67
68  if(CONFIG_SOC_GECKO_USE_RAIL)
69    # rail
70    zephyr_library_sources(${RADIO_DIR}/rail_lib/plugin/pa-conversions/pa_curves_efr32.c)
71    zephyr_library_sources(${RADIO_DIR}/rail_lib/plugin/pa-conversions/pa_conversions_efr32.c)
72
73    # prebuilt libs
74    add_prebuilt_library(librail platform/radio/rail_lib/autogen/librail_release/librail_efr32xg${SILABS_DEVICE_FAMILY_NUMBER}_gcc_release.a)
75
76    zephyr_include_directories_ifdef(CONFIG_SOC_GECKO_CUSTOM_RADIO_PHY
77      ${RADIO_DIR}/rail_lib/protocol/ble
78      ${RADIO_DIR}/rail_lib/protocol/ieee802154
79      ${RADIO_DIR}/rail_lib/protocol/zwave
80      ${RADIO_DIR}/rail_lib/protocol/sidewalk
81      ${RADIO_DIR}/rail_lib/plugin/rail_util_protocol
82      ${RADIO_DIR}/rail_lib/plugin/rail_util_protocol/config/efr32xg${SILABS_DEVICE_FAMILY_NUMBER}
83    )
84    zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_CUSTOM_RADIO_PHY
85      ${RADIO_DIR}/rail_lib/plugin/rail_util_protocol/sl_rail_util_protocol.c
86    )
87  endif()
88endif()
89
90zephyr_include_directories(
91  config
92  ${DEVICE_DIR}/SiliconLabs/${SILABS_DEVICE_FAMILY}/Include
93  ${COMMON_DIR}/config
94  ${COMMON_DIR}/inc
95  ${EMLIB_DIR}/inc
96  ${PERIPHERAL_DIR}/inc
97  ${SERVICE_DIR}/clock_manager/inc
98  ${SERVICE_DIR}/device_init/inc
99  ${SERVICE_DIR}/device_manager/inc
100  ${SERVICE_DIR}/hfxo_manager/config
101  ${SERVICE_DIR}/hfxo_manager/inc
102  ${SERVICE_DIR}/hfxo_manager/src
103  ${SERVICE_DIR}/memory_manager/inc
104  ${SERVICE_DIR}/memory_manager/profiler/inc
105  ${SERVICE_DIR}/power_manager/config
106  ${SERVICE_DIR}/power_manager/inc
107  ${SERVICE_DIR}/power_manager/src
108  ${SERVICE_DIR}/sleeptimer/config
109  ${SERVICE_DIR}/sleeptimer/inc
110  ${SERVICE_DIR}/sleeptimer/src
111  ${SECURITY_DIR}/sl_component/sl_protocol_crypto/src
112  ${BOARD_DIR}
113)
114
115zephyr_compile_definitions(
116  ${SILABS_DEVICE_PART_NUMBER}
117)
118
119zephyr_library_sources(
120  ${DEVICE_DIR}/SiliconLabs/${SILABS_DEVICE_FAMILY}/Source/system_${CONFIG_SOC_SERIES}.c
121  ${EMLIB_DIR}/src/em_system.c
122  ${SERVICE_DIR}/clock_manager/src/sl_clock_manager.c
123  ${SERVICE_DIR}/clock_manager/src/sl_clock_manager_hal_s2.c
124  ${SERVICE_DIR}/clock_manager/src/sl_clock_manager_init.c
125  ${SERVICE_DIR}/clock_manager/src/sl_clock_manager_init_hal_s2.c
126  ${SERVICE_DIR}/device_manager/devices/sl_device_peripheral_hal_efr32xg${SILABS_DEVICE_FAMILY_NUMBER}.c
127  ${SERVICE_DIR}/device_manager/gpios/sl_device_gpio_common.c
128  ${SERVICE_DIR}/device_manager/src/sl_device_clock.c
129  ${SERVICE_DIR}/device_manager/src/sl_device_gpio.c
130  ${SERVICE_DIR}/device_manager/src/sl_device_peripheral.c
131  ${SERVICE_DIR}/memory_manager/profiler/src/sli_memory_profiler_stubs.c
132)
133
134if(NOT SILABS_DEVICE_FAMILY_NUMBER EQUAL "21")
135  zephyr_library_sources(
136    ${SERVICE_DIR}/device_manager/clocks/sl_device_clock_efr32xg${SILABS_DEVICE_FAMILY_NUMBER}.c
137  )
138endif()
139
140# Sleeptimer
141if(CONFIG_SOC_SILABS_SLEEPTIMER)
142  zephyr_library_sources(
143    ${PERIPHERAL_DIR}/src/sl_hal_sysrtc.c
144    ${SERVICE_DIR}/sleeptimer/src/sl_sleeptimer_hal_rtcc.c
145    ${SERVICE_DIR}/sleeptimer/src/sl_sleeptimer_hal_sysrtc.c
146    ${SERVICE_DIR}/sleeptimer/src/sl_sleeptimer.c
147  )
148  zephyr_compile_definitions(
149    SL_CATALOG_SLEEPTIMER_PRESENT
150  )
151endif()
152
153zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_IADC         ${EMLIB_DIR}/src/em_iadc.c)
154zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_BURTC        ${EMLIB_DIR}/src/em_burtc.c)
155zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_CMU          ${EMLIB_DIR}/src/em_cmu.c)
156
157# Device Init
158if(CONFIG_SOC_GECKO_DEV_INIT)
159  zephyr_library_sources_ifdef(CONFIG_DT_HAS_SILABS_SERIES2_DCDC_ENABLED
160    ${SERVICE_DIR}/device_init/src/sl_device_init_dcdc_s2.c
161  )
162endif()
163
164# Power Manager
165if(CONFIG_SOC_GECKO_PM_BACKEND_PMGR)
166  zephyr_library_sources(
167    ${SERVICE_DIR}/power_manager/src/sl_power_manager.c
168    ${SERVICE_DIR}/power_manager/src/sl_power_manager_hal_s2.c
169  )
170  zephyr_compile_definitions(
171    SL_CATALOG_POWER_MANAGER_PRESENT
172  )
173  zephyr_compile_definitions_ifdef(CONFIG_SOC_GECKO_RTCC
174    SL_CATALOG_POWER_MANAGER_DEEPSLEEP_BLOCKING_HFXO_RESTORE_PRESENT
175  )
176endif()
177
178# HFXO Manager
179if(CONFIG_SOC_SILABS_HFXO_MANAGER)
180  zephyr_library_sources(
181    ${SERVICE_DIR}/hfxo_manager/src/sl_hfxo_manager.c
182    ${SERVICE_DIR}/hfxo_manager/src/sl_hfxo_manager_hal_s2.c
183  )
184  zephyr_compile_definitions(
185    SL_CATALOG_HFXO_MANAGER_PRESENT
186  )
187endif()
188
189zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_DEV_INIT     ${COMMON_DIR}/src/sl_slist.c)
190zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_CORE
191  ${EMLIB_DIR}/src/em_core.c
192  ${COMMON_DIR}/src/sl_core_cortexm.c
193)
194zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_CRYOTIMER    ${EMLIB_DIR}/src/em_cryotimer.c)
195zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_EMU          ${EMLIB_DIR}/src/em_emu.c)
196zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_GPIO         ${EMLIB_DIR}/src/em_gpio.c)
197zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_I2C          ${EMLIB_DIR}/src/em_i2c.c)
198zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_LETIMER      ${EMLIB_DIR}/src/em_letimer.c)
199zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_LEUART       ${EMLIB_DIR}/src/em_leuart.c)
200zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_MSC          ${EMLIB_DIR}/src/em_msc.c)
201zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_LDMA         ${EMLIB_DIR}/src/em_ldma.c)
202zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_PRS          ${EMLIB_DIR}/src/em_prs.c)
203zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_RMU          ${EMLIB_DIR}/src/em_rmu.c)
204zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_RTC          ${EMLIB_DIR}/src/em_rtc.c)
205zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_RTCC         ${EMLIB_DIR}/src/em_rtcc.c)
206zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_EUSART       ${EMLIB_DIR}/src/em_eusart.c)
207zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_TIMER        ${EMLIB_DIR}/src/em_timer.c)
208zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_USART        ${EMLIB_DIR}/src/em_usart.c)
209zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_WDOG         ${EMLIB_DIR}/src/em_wdog.c)
210
211zephyr_include_directories_ifdef(CONFIG_SOC_GECKO_SE
212  ${SECURITY_DIR}/sl_component/se_manager/src
213  ${SECURITY_DIR}/sl_component/se_manager/inc
214)
215
216zephyr_library_sources_ifdef(CONFIG_SOC_GECKO_SE
217  ${EMLIB_DIR}/src/em_se.c
218  ${SECURITY_DIR}/sl_component/se_manager/src/sl_se_manager.c
219  ${SECURITY_DIR}/sl_component/se_manager/src/sl_se_manager_util.c
220  ${SECURITY_DIR}/sl_component/se_manager/src/sli_se_manager_mailbox.c
221)
222
223zephyr_library_sources_ifdef(CONFIG_ENTROPY_GECKO_SE
224  ${SECURITY_DIR}/sl_component/se_manager/src/sl_se_manager_entropy.c
225)
226
227zephyr_library_sources(src/sl_memory_manager_shim.c)
228
229zephyr_library_sources_ifdef(
230  CONFIG_BUILD_ONLY_NO_BLOBS
231  src/blob_stubs.c
232)
233