blob: 2955b7fd46fbb5f0837c2c2d8a058fd9ac054933 [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. */
57 uint32_t (* get_cpu_cycle_diff)(time_counter *start, time_counter *end);
58
59 /* Gets the difference in terms of total NPU cycle counts. */
60 uint64_t (* get_npu_total_cycle_diff)(time_counter *start, time_counter *end);
61
62 /* Gets the difference in terms of active NPU cycle counts. */
63 uint64_t (* get_npu_active_cycle_diff)(time_counter *start, time_counter *end);
64
65 /* Wraps get_time_counter function with additional profiling
66 * initialisation, if required. */
67 time_counter (* start_profiling)(void);
68
69 /* Wraps get_time_counter function along with additional instructions when
70 * profiling ends, if required. */
71 time_counter (* stop_profiling)(void);
72
73} platform_timer;
74
75/**
76 * @brief Initialise the timer available for the platform.
77 **/
78void init_timer(platform_timer *timer);
79
80#endif /* HAL_TIMER_H */