blob: 56aad5bfc77bb18e0ee1ba283f34e6611e92a80d [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
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"
alexander31ae9f02022-02-10 16:15:54 +000021#include "platform_timer.h"
alexander3c798932021-03-26 21:42:19 +000022
23/** Struct for describing the capabilities available for
24 * the timer provided by HAL */
25typedef 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 */
33typedef 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 Sisodiaa3d87702021-05-14 17:34:09 +010050 uint64_t (* get_cpu_cycle_diff)(time_counter *start, time_counter *end);
alexander3c798932021-03-26 21:42:19 +000051
Isabella Gottardi8df12f32021-04-07 17:15:31 +010052 /* 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);
alexander3c798932021-03-26 21:42:19 +000055
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 **/
69void init_timer(platform_timer *timer);
70
71#endif /* HAL_TIMER_H */