blob: 442938813af760f6ec131c932c908a317f7bab7c [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
Isabella Gottardiee4920b2022-02-25 14:29:32 +00002 * Copyright (c) 2022 Arm Limited. All rights reserved.
alexander3c798932021-03-26 21:42:19 +00003 * 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
alexander31ae9f02022-02-10 16:15:54 +000020#include "platform_timer.h"
alexander3c798932021-03-26 21:42:19 +000021
22/** Struct for describing the capabilities available for
23 * the timer provided by HAL */
24typedef struct _platform_timer_capability {
25 uint32_t npu_cycles: 1;
26 uint32_t cpu_cycles: 1;
27 uint32_t duration_ms: 1;
28 uint32_t duration_us: 1;
29} timer_capability;
30
31/* Structure to hold a platform specific timer implementation */
32typedef struct _platform_timer {
33 int inited; /**< initialised or not */
34 timer_capability cap; /**< capability of this timer */
35
36 /* reset the timer */
37 void (* reset)(void);
38
39 /* Gets the current time counter. */
40 time_counter (* get_time_counter)(void);
41
42 /* Gets the duration in milliseconds. */
43 time_t (* get_duration_ms)(time_counter *start, time_counter *end);
44
45 /* Gets duration in microseconds. */
46 time_t (* get_duration_us)(time_counter *start, time_counter *end);
47
48 /* Gets difference in CPU cycle counts. */
Kshitij Sisodiaa3d87702021-05-14 17:34:09 +010049 uint64_t (* get_cpu_cycle_diff)(time_counter *start, time_counter *end);
alexander3c798932021-03-26 21:42:19 +000050
Isabella Gottardi8df12f32021-04-07 17:15:31 +010051 /* Gets the difference in terms of cycle counts for collected pmu counters. */
52 int (* get_npu_cycles_diff)(time_counter *start, time_counter *end,
53 uint64_t* pmu_counters_values, size_t size);
alexander3c798932021-03-26 21:42:19 +000054
55 /* Wraps get_time_counter function with additional profiling
56 * initialisation, if required. */
57 time_counter (* start_profiling)(void);
58
59 /* Wraps get_time_counter function along with additional instructions when
60 * profiling ends, if required. */
61 time_counter (* stop_profiling)(void);
62
63} platform_timer;
64
65/**
66 * @brief Initialise the timer available for the platform.
67 **/
68void init_timer(platform_timer *timer);
69
70#endif /* HAL_TIMER_H */