blob: 14d64e517a9bde785ef4537a86e47e3c4f29bcd7 [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 TIMER_MPS3_H
18#define TIMER_MPS3_H
19
20#include <stdint.h>
21#include <time.h>
22
23/* Container for timestamp up-counters. */
24typedef struct _mps3_time_counter {
25 uint32_t counter_1Hz;
26 uint32_t counter_100Hz;
27
28 /* Running at FPGA clock rate. See GetMPS3CoreClock(). */
29 uint32_t counter_fpga;
30
31 /* Running at processor core's internal clock rate, triggered by SysTick. */
32 uint64_t counter_systick;
33} mps3_time_counter;
34
35/**
36 * @brief Resets the counters.
37 */
38void timer_reset(void);
39
40/**
41 * @brief Gets the current counter values.
42 * @returns Mps3 timer counter.
43 **/
44mps3_time_counter get_time_counter(void);
45
46/**
47 * @brief Gets the duration elapsed between two counters in milliseconds.
48 * @param[in] start Pointer to mps3_time_counter value at start time.
49 * @param[in] end Pointer to mps3_time_counter value at end.
50 * @returns Difference in milliseconds between the two give counters
51 * expressed as an unsigned integer.
52 **/
53uint32_t get_duration_milliseconds(mps3_time_counter *start,
54 mps3_time_counter *end);
55
56/**
57 * @brief Gets the duration elapsed between two counters in microseconds.
58 * @param[in] start Pointer to mps3_time_counter value at start time.
59 * @param[in] end Pointer to mps3_time_counter value at end.
60 * @returns Difference in microseconds between the two give counters
61 * expressed as an unsigned integer.
62 **/
63uint32_t get_duration_microseconds(mps3_time_counter *start,
64 mps3_time_counter *end);
65
66/**
67 * @brief Gets the cycle counts elapsed between start and end.
68 * @param[in] start Pointer to mps3_time_counter value at start time.
69 * @param[in] end Pointer to mps3_time_counter value at end.
70 * @return Difference in counter values as 32 bit unsigned integer.
71 **/
72uint64_t get_cycle_count_diff(mps3_time_counter *start,
73 mps3_time_counter *end);
74
75/**
76 * @brief Enables or triggers cycle counting mechanism, if required
77 * by the platform.
78 **/
79void start_cycle_counter(void);
80
81/**
82 * @brief Stops cycle counting mechanism, if required by the platform.
83 **/
84void stop_cycle_counter(void);
85
86#endif /* TIMER_MPS3_H */