alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 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 | #ifndef HAL_TIMER_H |
| 18 | #define HAL_TIMER_H |
| 19 | |
| 20 | #include "hal_config.h" |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame^] | 21 | #include "platform_timer.h" |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 22 | |
| 23 | /** Struct for describing the capabilities available for |
| 24 | * the timer provided by HAL */ |
| 25 | typedef struct _platform_timer_capability { |
| 26 | uint32_t npu_cycles: 1; |
| 27 | uint32_t cpu_cycles: 1; |
| 28 | uint32_t duration_ms: 1; |
| 29 | uint32_t duration_us: 1; |
| 30 | } timer_capability; |
| 31 | |
| 32 | /* Structure to hold a platform specific timer implementation */ |
| 33 | typedef struct _platform_timer { |
| 34 | int inited; /**< initialised or not */ |
| 35 | timer_capability cap; /**< capability of this timer */ |
| 36 | |
| 37 | /* reset the timer */ |
| 38 | void (* reset)(void); |
| 39 | |
| 40 | /* Gets the current time counter. */ |
| 41 | time_counter (* get_time_counter)(void); |
| 42 | |
| 43 | /* Gets the duration in milliseconds. */ |
| 44 | time_t (* get_duration_ms)(time_counter *start, time_counter *end); |
| 45 | |
| 46 | /* Gets duration in microseconds. */ |
| 47 | time_t (* get_duration_us)(time_counter *start, time_counter *end); |
| 48 | |
| 49 | /* Gets difference in CPU cycle counts. */ |
Kshitij Sisodia | a3d8770 | 2021-05-14 17:34:09 +0100 | [diff] [blame] | 50 | uint64_t (* get_cpu_cycle_diff)(time_counter *start, time_counter *end); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 51 | |
Isabella Gottardi | 8df12f3 | 2021-04-07 17:15:31 +0100 | [diff] [blame] | 52 | /* Gets the difference in terms of cycle counts for collected pmu counters. */ |
| 53 | int (* get_npu_cycles_diff)(time_counter *start, time_counter *end, |
| 54 | uint64_t* pmu_counters_values, size_t size); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 55 | |
| 56 | /* Wraps get_time_counter function with additional profiling |
| 57 | * initialisation, if required. */ |
| 58 | time_counter (* start_profiling)(void); |
| 59 | |
| 60 | /* Wraps get_time_counter function along with additional instructions when |
| 61 | * profiling ends, if required. */ |
| 62 | time_counter (* stop_profiling)(void); |
| 63 | |
| 64 | } platform_timer; |
| 65 | |
| 66 | /** |
| 67 | * @brief Initialise the timer available for the platform. |
| 68 | **/ |
| 69 | void init_timer(platform_timer *timer); |
| 70 | |
| 71 | #endif /* HAL_TIMER_H */ |