1# Makefile - Gecko 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#
7# SPDX-License-Identifier: Apache-2.0
8#
9
10# Translate the SoC name and part number into the gecko device and cpu name
11# respectively.
12string(TOUPPER ${CONFIG_SOC_SERIES} SILABS_GECKO_DEVICE)
13
14# Get SoC series number, i.e. translate e.g. efr32bg22 -> 22
15string(SUBSTRING ${CONFIG_SOC_SERIES} 7 2 GECKO_SERIES_NUMBER)
16
17set(SILABS_GECKO_PART_NUMBER ${CONFIG_SOC_PART_NUMBER})
18
19if (${CONFIG_BOARD} STREQUAL "efr32_radio_brd4187c")
20  set(PRODUCT_NO "sdid215")
21endif()
22
23if (${CONFIG_BOARD} STREQUAL "efr32xg24_dk2601b")
24  set(SILABS_GECKO_BOARD "brd2601b")
25  set(PRODUCT_NO "sdid215")
26endif()
27
28if (${CONFIG_BOARD} STREQUAL "efr32bg22_brd4184a")
29  set(SILABS_GECKO_BOARD "brd4184a")
30  set(PRODUCT_NO "sdid205")
31endif()
32
33if (${CONFIG_BOARD} STREQUAL "efr32bg22_brd4184b")
34  set(SILABS_GECKO_BOARD "brd4184b")
35  set(PRODUCT_NO "sdid205")
36endif()
37
38if (${CONFIG_BOARD} STREQUAL "efr32bg27_brd2602a")
39  set(SILABS_GECKO_BOARD "brd2602a")
40  set(PRODUCT_NO "sdid230")
41endif()
42
43function(add_prebuilt_library lib_name prebuilt_path)
44  add_library(${lib_name} STATIC IMPORTED GLOBAL)
45  set_target_properties(${lib_name} PROPERTIES
46	  IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../zephyr/blobs/${prebuilt_path}
47  )
48  zephyr_link_libraries(${lib_name})
49endfunction()
50
51if(${CONFIG_SOC_GECKO_HAS_RADIO})
52  if(${CONFIG_SOC_GECKO_SERIES1})
53    zephyr_include_directories(
54      platform/radio/rail_lib/plugin/pa-conversions/efr32xg1x/config
55      platform/radio/rail_lib/chip/efr32/efr32xg1x
56    )
57  elseif(${CONFIG_SOC_GECKO_SERIES2})
58    zephyr_include_directories(
59      platform/radio/rail_lib/plugin/pa-conversions/efr32xg${GECKO_SERIES_NUMBER}/config
60      platform/radio/rail_lib/chip/efr32/efr32xg2x
61    )
62  endif()
63
64  zephyr_include_directories(
65    platform/radio/rail_lib/common
66    platform/radio/rail_lib/plugin/pa-conversions
67    protocol/bluetooth/bgstack/ll/inc
68    )
69
70  if(CONFIG_BT_SILABS_HCI)
71    # sl_protocol_crypto
72    zephyr_sources(util/third_party/crypto/sl_component/sl_protocol_crypto/src/sli_protocol_crypto_crypto.c)
73    zephyr_sources(util/third_party/crypto/sl_component/sl_protocol_crypto/src/sli_radioaes_management.c)
74    zephyr_sources(util/third_party/crypto/sl_component/sl_protocol_crypto/src/sli_protocol_crypto_radioaes.c)
75
76    # prebuilt libs
77    add_prebuilt_library(liblinklayer gecko/protocol/bluetooth/bgstack/ll/lib/libbluetooth_controller_efr32xg${GECKO_SERIES_NUMBER}_gcc_release.a)
78    add_prebuilt_library(libbgcommon  gecko/protocol/bluetooth/bgcommon/lib/libbgcommon_efr32xg${GECKO_SERIES_NUMBER}_gcc_release.a)
79
80    # link mbedTLS
81    if(CONFIG_MBEDTLS)
82      zephyr_link_libraries(mbedTLS)
83    endif()
84  endif()
85
86  if(CONFIG_SOC_GECKO_USE_RAIL)
87    # rail
88    zephyr_sources(platform/radio/rail_lib/plugin/pa-conversions/pa_conversions_efr32.c)
89    zephyr_sources(platform/radio/rail_lib/plugin/pa-conversions/pa_curves_efr32.c)
90
91    # prebuilt libs
92    add_prebuilt_library(librail      gecko/platform/radio/rail_lib/autogen/librail_release/librail_efr32xg${GECKO_SERIES_NUMBER}_gcc_release.a)
93
94    if(CONFIG_SOC_GECKO_CUSTOM_RADIO_PHY)
95      zephyr_include_directories(
96        platform/radio/rail_lib/plugin/rail_util_init/config/proprietary
97        platform/radio/rail_lib/plugin/rail_util_callbacks
98        platform/radio/rail_lib/plugin/rail_util_callbacks/config
99        platform/radio/rail_lib/plugin/rail_util_protocol
100        platform/radio/rail_lib/plugin/rail_util_protocol/config/efr32xg${GECKO_SERIES_NUMBER}/
101        platform/radio/rail_lib/protocol/ble
102        platform/radio/rail_lib/protocol/ieee802154
103        platform/radio/rail_lib/protocol/zwave
104      )
105      zephyr_sources(platform/radio/rail_lib/plugin/rail_util_protocol/sl_rail_util_protocol.c)
106    endif()
107
108  endif()
109endif()
110
111zephyr_include_directories(
112  Device/SiliconLabs/${SILABS_GECKO_DEVICE}/Include
113  board/config/${SILABS_GECKO_BOARD}
114  board/inc
115  common/inc
116  emlib/inc
117  service/device_init/config/s2
118  service/device_init/config/s2/${PRODUCT_NO}
119  service/device_init/inc
120  service/hfxo_manager/config
121  service/hfxo_manager/inc
122  service/hfxo_manager/src
123  service/power_manager/config
124  service/power_manager/inc
125  service/power_manager/src
126  service/sleeptimer/config
127  service/sleeptimer/inc
128  service/sleeptimer/src
129  util/third_party/crypto/sl_component/sl_protocol_crypto/src
130  ${BOARD_DIR}
131  )
132
133# The gecko SDK uses the cpu name to include the matching device header.
134# See Device/SiliconLabs/$(SILABS_GECKO_DEVICE)/Include/em_device.h for an example.
135zephyr_compile_definitions(
136  ${SILABS_GECKO_PART_NUMBER}
137  )
138
139add_subdirectory_ifdef(CONFIG_SOC_GECKO_SE se_manager)
140
141zephyr_sources(                                    emlib/src/em_system.c)
142zephyr_sources_ifdef(CONFIG_SOC_GECKO_ADC          emlib/src/em_adc.c)
143zephyr_sources_ifdef(CONFIG_SOC_GECKO_IADC         emlib/src/em_iadc.c)
144zephyr_sources_ifdef(CONFIG_SOC_GECKO_BURTC        emlib/src/em_burtc.c)
145zephyr_sources_ifdef(CONFIG_SOC_GECKO_CMU          emlib/src/em_cmu.c)
146
147zephyr_sources_ifdef(CONFIG_SOC_GECKO_DEV_INIT     service/device_init/src/sl_device_init_dcdc_s2.c)
148zephyr_sources_ifdef(CONFIG_SOC_GECKO_DEV_INIT     service/device_init/src/sl_device_init_dpll_s2.c)
149zephyr_sources_ifdef(CONFIG_SOC_GECKO_DEV_INIT     service/device_init/src/sl_device_init_emu_s2.c)
150zephyr_sources_ifdef(CONFIG_SOC_GECKO_DEV_INIT     service/device_init/src/sl_device_init_hfrco.c)
151zephyr_sources_ifdef(CONFIG_SOC_GECKO_DEV_INIT     service/device_init/src/sl_device_init_hfxo_s2.c)
152zephyr_sources_ifdef(CONFIG_SOC_GECKO_DEV_INIT     service/device_init/src/sl_device_init_nvic.c)
153zephyr_sources_ifdef(CONFIG_SOC_GECKO_DEV_INIT     service/power_manager/src/sl_power_manager.c)
154zephyr_sources_ifdef(CONFIG_SOC_GECKO_DEV_INIT     service/power_manager/src/sl_power_manager_hal_s2.c)
155zephyr_sources_ifdef(CONFIG_SOC_GECKO_DEV_INIT     service/hfxo_manager/src/sl_hfxo_manager.c)
156zephyr_sources_ifdef(CONFIG_SOC_GECKO_DEV_INIT     service/hfxo_manager/src/sl_hfxo_manager_hal_s2.c)
157
158zephyr_sources_ifdef(CONFIG_SOC_GECKO_DEV_INIT     common/src/sl_slist.c)
159zephyr_sources_ifdef(CONFIG_SOC_GECKO_CORE         emlib/src/em_core.c)
160zephyr_sources_ifdef(CONFIG_SOC_GECKO_CRYOTIMER    emlib/src/em_cryotimer.c)
161zephyr_sources_ifdef(CONFIG_SOC_GECKO_EMU          emlib/src/em_emu.c)
162zephyr_sources_ifdef(CONFIG_SOC_GECKO_GPIO         emlib/src/em_gpio.c)
163zephyr_sources_ifdef(CONFIG_SOC_GECKO_I2C          emlib/src/em_i2c.c)
164zephyr_sources_ifdef(CONFIG_SOC_GECKO_LETIMER      emlib/src/em_letimer.c)
165zephyr_sources_ifdef(CONFIG_SOC_GECKO_LEUART       emlib/src/em_leuart.c)
166zephyr_sources_ifdef(CONFIG_SOC_GECKO_MSC          emlib/src/em_msc.c)
167zephyr_sources_ifdef(CONFIG_SOC_GECKO_PRS          emlib/src/em_prs.c)
168zephyr_sources_ifdef(CONFIG_SOC_GECKO_RMU          emlib/src/em_rmu.c)
169zephyr_sources_ifdef(CONFIG_SOC_GECKO_RTC          emlib/src/em_rtc.c)
170zephyr_sources_ifdef(CONFIG_SOC_GECKO_RTCC         emlib/src/em_rtcc.c)
171zephyr_sources_ifdef(CONFIG_COUNTER_GECKO_STIMER   service/sleeptimer/src/peripheral_sysrtc.c)
172zephyr_sources_ifdef(CONFIG_COUNTER_GECKO_STIMER   service/sleeptimer/src/sl_sleeptimer_hal_rtcc.c)
173zephyr_sources_ifdef(CONFIG_COUNTER_GECKO_STIMER   service/sleeptimer/src/sl_sleeptimer_hal_sysrtc.c)
174zephyr_sources_ifdef(CONFIG_COUNTER_GECKO_STIMER   service/sleeptimer/src/sl_sleeptimer.c)
175zephyr_sources_ifdef(CONFIG_SOC_GECKO_SE           emlib/src/em_se.c)
176zephyr_sources_ifdef(CONFIG_SOC_GECKO_TIMER        emlib/src/em_timer.c)
177zephyr_sources_ifdef(CONFIG_SOC_GECKO_USART        emlib/src/em_usart.c)
178zephyr_sources_ifdef(CONFIG_SOC_GECKO_WDOG         emlib/src/em_wdog.c)
179zephyr_sources_ifdef(CONFIG_SOC_SERIES_EFM32WG     Device/SiliconLabs/EFM32WG/Source/system_efm32wg.c)
180zephyr_sources_ifdef(CONFIG_SOC_SERIES_EFR32BG13P  Device/SiliconLabs/EFR32BG13P/Source/system_efr32bg13p.c)
181zephyr_sources_ifdef(CONFIG_SOC_SERIES_EFR32BG22   Device/SiliconLabs/EFR32BG22/Source/system_efr32bg22.c)
182zephyr_sources_ifdef(CONFIG_SOC_SERIES_EFR32BG27   Device/SiliconLabs/EFR32BG27/Source/system_efr32bg27.c)
183zephyr_sources_ifdef(CONFIG_SOC_SERIES_EFR32FG1P   Device/SiliconLabs/EFR32FG1P/Source/system_efr32fg1p.c)
184zephyr_sources_ifdef(CONFIG_SOC_SERIES_EFR32FG13P  Device/SiliconLabs/EFR32FG13P/Source/system_efr32fg13p.c)
185zephyr_sources_ifdef(CONFIG_SOC_SERIES_EFM32HG     Device/SiliconLabs/EFM32HG/Source/system_efm32hg.c)
186zephyr_sources_ifdef(CONFIG_SOC_SERIES_EFR32MG12P  Device/SiliconLabs/EFR32MG12P/Source/system_efr32mg12p.c)
187zephyr_sources_ifdef(CONFIG_SOC_SERIES_EFM32PG12B  Device/SiliconLabs/EFM32PG12B/Source/system_efm32pg12b.c)
188zephyr_sources_ifdef(CONFIG_SOC_SERIES_EFM32GG11B  Device/SiliconLabs/EFM32GG11B/Source/system_efm32gg11b.c)
189zephyr_sources_ifdef(CONFIG_SOC_SERIES_EFM32GG12B  Device/SiliconLabs/EFM32GG12B/Source/system_efm32gg12b.c)
190zephyr_sources_ifdef(CONFIG_SOC_SERIES_EFM32JG12B  Device/SiliconLabs/EFM32JG12B/Source/system_efm32jg12b.c)
191zephyr_sources_ifdef(CONFIG_SOC_SERIES_EFR32MG21   Device/SiliconLabs/EFR32MG21/Source/system_efr32mg21.c)
192zephyr_sources_ifdef(CONFIG_SOC_SERIES_EFM32PG1B   Device/SiliconLabs/EFM32PG1B/Source/system_efm32pg1b.c)
193zephyr_sources_ifdef(CONFIG_SOC_SERIES_EFR32MG24   Device/SiliconLabs/EFR32MG24/Source/system_efr32mg24.c)
194