blob: ea19de5da3acc3275d82e20a1672649c5a3058ba [file] [log] [blame]
alexander31ae9f02022-02-10 16:15:54 +00001#----------------------------------------------------------------------------
2# Copyright (c) 2022 Arm Limited. All rights reserved.
3# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#----------------------------------------------------------------------------
17
18#########################################################
19# HAL library #
20#########################################################
21
22cmake_minimum_required(VERSION 3.15.6)
23
24set(HAL_TARGET hal)
25
26project(${HAL_TARGET}
27 DESCRIPTION "HAL library"
28 LANGUAGES C CXX)
29
30# Create static library
31add_library(${HAL_TARGET} STATIC)
32
33# Select which profile needs to be used:
34if (${CMAKE_CROSSCOMPILING})
35 set(PLATFORM_PROFILE bare-metal)
36else()
37 set(PLATFORM_PROFILE native)
38endif()
39
40set(PLATFORM_PROFILE_DIR profiles/${PLATFORM_PROFILE})
41
42## Common include directories - public
43target_include_directories(${HAL_TARGET}
44 PUBLIC
45 include
46 ${PLATFORM_PROFILE_DIR}/timer/include
47 ${PLATFORM_PROFILE_DIR}/utils/include)
48
49## Common sources for all profiles
50target_sources(${HAL_TARGET}
51 PRIVATE
52 hal.c
53 ${PLATFORM_PROFILE_DIR}/data_presentation/data_psn.c
54 ${PLATFORM_PROFILE_DIR}/data_acquisition/data_acq.c
55 ${PLATFORM_PROFILE_DIR}/timer/platform_timer.c
56 ${PLATFORM_PROFILE_DIR}/utils/system_init.c)
57
58if (DEFINED VERIFY_TEST_OUTPUT)
59 message(STATUS "Test output verification flag is: ${VERIFY_TEST_OUTPUT}")
60 target_compile_definitions(${HAL_TARGET} PUBLIC
61 VERIFY_TEST_OUTPUT=${VERIFY_TEST_OUTPUT})
62endif ()
63
64############################ bare-metal profile #############################
65if (PLATFORM_PROFILE STREQUAL bare-metal)
66
67 if (NOT DEFINED PLATFORM_DRIVERS_DIR)
68 message(FATAL_ERROR "PLATFORM_DRIVERS_DIR need to be defined for this target")
69 endif()
70
71 ## Additional include directories - public
72 target_include_directories(${HAL_TARGET}
73 PUBLIC
74 ${PLATFORM_PROFILE_DIR}/bsp/include)
75
76 ## Additional include directories - private
77 target_include_directories(${HAL_TARGET}
78 PRIVATE
79 ${PLATFORM_PROFILE_DIR}/data_presentation/lcd/include)
80
81 ## Additional sources - public
82 target_sources(${HAL_TARGET}
83 PUBLIC
84 ${PLATFORM_PROFILE_DIR}/bsp/retarget.c)
85
86 ## Additional sources - private
87 target_sources(${HAL_TARGET}
88 PRIVATE
89 ${PLATFORM_PROFILE_DIR}/data_presentation/lcd/lcd_img.c)
90
91 ## Compile definition:
92 target_compile_definitions(${HAL_TARGET}
93 PUBLIC
94 PLATFORM_HAL=PLATFORM_CORTEX_M_BAREMETAL)
95
96 # Add dependencies for platform_driver first, in case they are needed by it.
97 add_subdirectory(cmsis_device ${CMAKE_BINARY_DIR}/cmsis_device)
98
99 # Add platform-drivers target
100 add_subdirectory(${PLATFORM_DRIVERS_DIR} ${CMAKE_BINARY_DIR}/platform_driver)
101
102 # Link time library targets:
103 target_link_libraries(${HAL_TARGET}
104 PUBLIC
105 log
106 platform-drivers)
107
108 # If Ethos-U is enabled, we need the driver library too
109 if (ETHOS_U_NPU_ENABLED)
110
111 if (NOT DEFINED ETHOS_U_NPU_DRIVER_SRC_PATH)
112 message(FATAL_ERROR "ETHOS_U_NPU_DRIVER_SRC_PATH should"
113 " be defined when ETHOS_U_NPU_ENABLED=${ETHOS_U_NPU_ENABLED}")
114 endif()
115
116 # Timing adapter, should, in theory be part of platform-drivers. For now
117 # limiting the scope of refactoring - but in future, TA should not be
118 # needed if not available on the target platform.
119 if (NOT DEFINED ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH)
120 message(FATAL_ERROR "ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH should"
121 " be defined when ETHOS_U_NPU_ENABLED=${ETHOS_U_NPU_ENABLED}")
122 endif()
123
124 target_compile_definitions(${HAL_TARGET}
125 PUBLIC
126 ARM_NPU)
127
128 # For the driver, we need to provide the CMSIS_PATH variable
129 set(CMSIS_PATH ${CMSIS_SRC_PATH} CACHE PATH "Path to CMSIS directory")
130 add_subdirectory(${ETHOS_U_NPU_DRIVER_SRC_PATH} ${CMAKE_BINARY_DIR}/ethos-u-driver)
131 add_subdirectory(${ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH} ${CMAKE_BINARY_DIR}/timing-adapter)
132
133 target_link_libraries(${HAL_TARGET}
134 PUBLIC
135 ethosu_core_driver
136 timing_adapter)
137
138 if (NOT DEFINED ETHOS_U_NPU_ID)
139 set(ETHOS_U_NPU_ID U55)
140 endif()
141
142 if (NOT DEFINED ETHOS_U_NPU_MEMORY_MODE)
143 set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
144 endif()
145
146 if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Sram_Only)
147 if (ETHOS_U_NPU_ID STREQUAL U55)
148 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEM_MODE_SRAM_ONLY")
149 else ()
150 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode and processor ${ETHOS_U_NPU_MEMORY_MODE} - ${ETHOS_U_NPU_ID}. `sram_only` can be used only for Ethos-U55.")
151 endif ()
152
153 elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Shared_Sram)
154 # Shared Sram can be used for Ethos-U55 and Ethos-U65
155 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM")
156
157 elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram)
158 # Dedicated Sram is used only for Ethos-U65
159 if (ETHOS_U_NPU_ID STREQUAL U65)
160 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_DEDICATED_SRAM")
161 else ()
162 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode and processor ${ETHOS_U_NPU_MEMORY_MODE} - ${ETHOS_U_NPU_ID}. `dedicated_sram` can be used only for Ethos-U65.")
163 endif ()
164 else ()
165 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}")
166 endif ()
167
168 target_compile_definitions(${HAL_TARGET}
169 PUBLIC
170 ${ETHOS_U_NPU_MEMORY_MODE_FLAG})
171 endif()
172
173############################ native profile #############################
174elseif (PLATFORM_PROFILE STREQUAL native)
175 ## Additional include directories - private
176 target_include_directories(${HAL_TARGET}
177 PRIVATE
178 ${PLATFORM_PROFILE_DIR}/data_presentation/log/include)
179
180 ## Additional sources - private
181 target_sources(${HAL_TARGET}
182 PRIVATE
183 ${PLATFORM_PROFILE_DIR}/data_presentation/log/log.c)
184
185 ## Compile definition:
186 target_compile_definitions(${HAL_TARGET}
187 PUBLIC
188 PLATFORM_HAL=PLATFORM_UNKNOWN_LINUX_OS
189 ACTIVATION_BUF_SRAM_SZ=0)
190
191 target_link_libraries(${HAL_TARGET}
192 PUBLIC
193 log)
194
195endif()
196
197# Display status:
198message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
199message(STATUS "*******************************************************")
200message(STATUS "Library : " ${HAL_TARGET})
201message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR})
202message(STATUS "*******************************************************")