blob: 426a42fdbd2e8a9358ba316e5ee466db4c73bfc4 [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"
21
22#if ((PLATFORM_HAL) == PLATFORM_CORTEX_M_BAREMETAL)
23#include "baremetal_timer.h"
24#elif ((PLATFORM_HAL) == PLATFORM_UNKNOWN_LINUX_OS)
25#include "native_timer.h"
26#else
27#error "Platform does not support a timer API"
28#endif /* PLATFORM_HAL */
29
30/** Struct for describing the capabilities available for
31 * the timer provided by HAL */
32typedef struct _platform_timer_capability {
33 uint32_t npu_cycles: 1;
34 uint32_t cpu_cycles: 1;
35 uint32_t duration_ms: 1;
36 uint32_t duration_us: 1;
37} timer_capability;
38
39/* Structure to hold a platform specific timer implementation */
40typedef struct _platform_timer {
41 int inited; /**< initialised or not */
42 timer_capability cap; /**< capability of this timer */
43
44 /* reset the timer */
45 void (* reset)(void);
46
47 /* Gets the current time counter. */
48 time_counter (* get_time_counter)(void);
49
50 /* Gets the duration in milliseconds. */
51 time_t (* get_duration_ms)(time_counter *start, time_counter *end);
52
53 /* Gets duration in microseconds. */
54 time_t (* get_duration_us)(time_counter *start, time_counter *end);
55
56 /* Gets difference in CPU cycle counts. */
Kshitij Sisodiaa3d87702021-05-14 17:34:09 +010057 uint64_t (* get_cpu_cycle_diff)(time_counter *start, time_counter *end);
alexander3c798932021-03-26 21:42:19 +000058
Isabella Gottardi8df12f32021-04-07 17:15:31 +010059 /* Gets the difference in terms of cycle counts for collected pmu counters. */
60 int (* get_npu_cycles_diff)(time_counter *start, time_counter *end,
61 uint64_t* pmu_counters_values, size_t size);
alexander3c798932021-03-26 21:42:19 +000062
63 /* Wraps get_time_counter function with additional profiling
64 * initialisation, if required. */
65 time_counter (* start_profiling)(void);
66
67 /* Wraps get_time_counter function along with additional instructions when
68 * profiling ends, if required. */
69 time_counter (* stop_profiling)(void);
70
71} platform_timer;
72
73/**
74 * @brief Initialise the timer available for the platform.
75 **/
76void init_timer(platform_timer *timer);
77
78#endif /* HAL_TIMER_H */