Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 1 | # |
| 2 | # Copyright (c) 2019-2020 Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the License); you may |
| 7 | # not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | |
| 19 | cmake_minimum_required(VERSION 3.15.6) |
| 20 | |
| 21 | project(ethosu_core_driver VERSION 0.0.1) |
| 22 | |
| 23 | # |
| 24 | # Build options |
| 25 | # |
| 26 | |
Kristofer Jonsson | 537c71c | 2020-05-05 14:17:22 +0200 | [diff] [blame^] | 27 | option(DRIVER_PMU_AUTOINIT "Enable PMU boot auto-initialization" OFF) |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 28 | option(LOG_SUPPORT "Enable logging." ON) |
| 29 | |
Kristofer Jonsson | 537c71c | 2020-05-05 14:17:22 +0200 | [diff] [blame^] | 30 | set(CMSIS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmsis" CACHE PATH "Path to CMSIS.") |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 31 | |
| 32 | # |
| 33 | # Global settings |
| 34 | # |
| 35 | |
| 36 | if(CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m0") |
| 37 | add_compile_definitions(CPU_CORTEX_M0) |
| 38 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m3") |
| 39 | add_compile_definitions(CPU_CORTEX_M3) |
| 40 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m33") |
| 41 | add_compile_definitions(CPU_CORTEX_M33) |
| 42 | add_compile_definitions(__DSP_PRESENT=1) |
| 43 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m4") |
| 44 | add_compile_definitions(CPU_CORTEX_M4) |
| 45 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m55") |
| 46 | add_compile_definitions(CPU_CORTEX_M55) |
| 47 | add_compile_definitions(__DSP_PRESENT=1) |
| 48 | add_compile_definitions(__FPU_PRESENT=1) |
| 49 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "cortex-m7") |
| 50 | add_compile_definitions(CPU_CORTEX_M7) |
| 51 | else() |
| 52 | message(FATAL_ERROR "Unsupported compiler ${CMAKE_SYSTEM_PROCESSOR}.") |
| 53 | endif() |
| 54 | |
| 55 | # Enable logging support |
| 56 | if (LOG_SUPPORT) |
| 57 | add_compile_definitions(LOG_ENABLED) |
| 58 | endif() |
| 59 | |
| 60 | # Make include directories available for current- and sub projects |
| 61 | include_directories(include src) |
| 62 | include_directories(${CMSIS_PATH}/CMSIS/Core/Include) |
| 63 | |
| 64 | # |
| 65 | # Build libraries |
| 66 | # |
| 67 | |
| 68 | # Build driver library |
| 69 | add_library(ethosu_core_driver STATIC) |
Kristofer Jonsson | 537c71c | 2020-05-05 14:17:22 +0200 | [diff] [blame^] | 70 | target_include_directories(ethosu_core_driver PUBLIC include) |
| 71 | target_sources(ethosu_core_driver PRIVATE src/ethosu_driver.c src/ethosu_device.c src/ethosu_pmu.c) |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 72 | |
| 73 | # Build PMU |
Kristofer Jonsson | 537c71c | 2020-05-05 14:17:22 +0200 | [diff] [blame^] | 74 | if (DRIVER_PMU_AUTOINIT) |
| 75 | set(NPU_PMCR "0x0" CACHE STRING "Register control b0 = CNT_EN = Enable counters (RW), b1 = EVENT_CNT_RST = Reset event counters (WO), b2 = CYCLE_CNT_RST = Reset cycle counter (WO), b[15:11] = Number of event counters (RO)") |
| 76 | set(NPU_PMCNTENSET "0x0" CACHE STRING "Bit k enables event counter k. k=31 enables the cycle counter. Read value is current status.") |
| 77 | set(NPU_PMCNTENCLR "0x0" CACHE STRING "Bit k disables event counter k. k=31 disables the cycle counter. Reda value is current status.") |
| 78 | set(NPU_PMOVSSET "0x0" CACHE STRING "Overflow detection set. Bit k is for counter k. k=31 is cycle counter.") |
| 79 | set(NPU_PMOVSCLR "0x0" CACHE STRING "Overflow detection clear. Bit k is for counter k. k=31 is cycle counter.") |
| 80 | set(NPU_PMINTSET "0x0" CACHE STRING "Interrupt set. Bit k is for counter k. k=31 is cycle counter.") |
| 81 | set(NPU_PMINTCLR "0x8003" CACHE STRING "Interrupt clear. Bit k is for counter k. k=31 is cycle counter.") |
| 82 | set(NPU_PMCCNTR "0x0" CACHE STRING "Cycle counter, 48 bits value") |
| 83 | set(NPU_PMCCNTR_CFG "0x0" CACHE STRING "b[9:0] Start Event – this event number starts the cycle counter b[25:16] Stop Event – this event number stops the cycle counter") |
| 84 | |
| 85 | target_compile_definitions(ethosu_core_driver PRIVATE |
| 86 | PMU_AUTOINIT |
| 87 | INIT_PMCR=${NPU_PMCR} |
| 88 | INIT_PMCNTENSET=${NPU_PMCNTENSET} |
| 89 | INIT_PMCNTENCLR=${NPU_PMCNTENCLR} |
| 90 | INIT_PMOVSSET=${NPU_PMOVSSET} |
| 91 | INIT_PMOVSCLR=${NPU_PMOVSCLR} |
| 92 | INIT_PMINTSET=${NPU_PMINTSET} |
| 93 | INIT_PMINTCLR=${NPU_PMINTCLR} |
| 94 | INIT_PMCCNTR=${NPU_PMCCNTR} |
| 95 | INIT_PMCCNTR_CFG=${NPU_PMCCNTR_CFG} |
| 96 | ) |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 97 | endif() |
| 98 | |
| 99 | # |
| 100 | # Print build status |
| 101 | # |
| 102 | |
| 103 | message(STATUS "*******************************************************") |
| 104 | message(STATUS "PROJECT_NAME : ${PROJECT_NAME}") |
| 105 | message(STATUS "CMAKE_SYSTEM_PROCESSOR : ${CMAKE_SYSTEM_PROCESSOR}") |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 106 | message(STATUS "LOG_SUPPORT : ${LOG_SUPPORT}") |
| 107 | message(STATUS "CMSIS_PATH : ${CMSIS_PATH}") |
Kristofer Jonsson | 49bdee8 | 2020-04-06 13:21:21 +0200 | [diff] [blame] | 108 | message(STATUS "*******************************************************") |