blob: 70d059c8469a790960991d61c721b2e0ef5a6389 [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;
alexander31ae9f02022-02-10 16:15:54 +000033} base_time_counter;
alexander3c798932021-03-26 21:42:19 +000034
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 **/
alexander31ae9f02022-02-10 16:15:54 +000044base_time_counter get_time_counter(void);
alexander3c798932021-03-26 21:42:19 +000045
46/**
47 * @brief Gets the duration elapsed between two counters in milliseconds.
alexander31ae9f02022-02-10 16:15:54 +000048 * @param[in] start Pointer to base_time_counter value at start time.
49 * @param[in] end Pointer to base_time_counter value at end.
alexander3c798932021-03-26 21:42:19 +000050 * @returns Difference in milliseconds between the two give counters
51 * expressed as an unsigned integer.
52 **/
alexander31ae9f02022-02-10 16:15:54 +000053uint32_t get_duration_milliseconds(base_time_counter *start,
54 base_time_counter *end);
alexander3c798932021-03-26 21:42:19 +000055
56/**
57 * @brief Gets the duration elapsed between two counters in microseconds.
alexander31ae9f02022-02-10 16:15:54 +000058 * @param[in] start Pointer to base_time_counter value at start time.
59 * @param[in] end Pointer to base_time_counter value at end.
alexander3c798932021-03-26 21:42:19 +000060 * @returns Difference in microseconds between the two give counters
61 * expressed as an unsigned integer.
62 **/
alexander31ae9f02022-02-10 16:15:54 +000063uint32_t get_duration_microseconds(base_time_counter *start,
64 base_time_counter *end);
alexander3c798932021-03-26 21:42:19 +000065
66/**
67 * @brief Gets the cycle counts elapsed between start and end.
alexander31ae9f02022-02-10 16:15:54 +000068 * @param[in] start Pointer to base_time_counter value at start time.
69 * @param[in] end Pointer to base_time_counter value at end.
alexander3c798932021-03-26 21:42:19 +000070 * @return Difference in counter values as 32 bit unsigned integer.
71 **/
alexander31ae9f02022-02-10 16:15:54 +000072uint64_t get_cycle_count_diff(base_time_counter *start,
73 base_time_counter *end);
alexander3c798932021-03-26 21:42:19 +000074
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 */