blob: b5db7226b42177ebc18c1e7f10fc91d22d4865fc [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +00002 * Copyright (c) 2021-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 TIMER_MPS3_H
18#define TIMER_MPS3_H
19
20#include <stdint.h>
alexander3c798932021-03-26 21:42:19 +000021
22/* Container for timestamp up-counters. */
23typedef struct _mps3_time_counter {
24 uint32_t counter_1Hz;
25 uint32_t counter_100Hz;
26
27 /* Running at FPGA clock rate. See GetMPS3CoreClock(). */
28 uint32_t counter_fpga;
29
30 /* Running at processor core's internal clock rate, triggered by SysTick. */
31 uint64_t counter_systick;
alexander31ae9f02022-02-10 16:15:54 +000032} base_time_counter;
alexander3c798932021-03-26 21:42:19 +000033
34/**
35 * @brief Resets the counters.
36 */
37void timer_reset(void);
38
39/**
40 * @brief Gets the current counter values.
41 * @returns Mps3 timer counter.
42 **/
alexander31ae9f02022-02-10 16:15:54 +000043base_time_counter get_time_counter(void);
alexander3c798932021-03-26 21:42:19 +000044
45/**
46 * @brief Gets the duration elapsed between two counters in milliseconds.
alexander31ae9f02022-02-10 16:15:54 +000047 * @param[in] start Pointer to base_time_counter value at start time.
48 * @param[in] end Pointer to base_time_counter value at end.
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000049 * @returns Difference in milliseconds between the two give counters
alexander3c798932021-03-26 21:42:19 +000050 * expressed as an unsigned integer.
51 **/
alexander31ae9f02022-02-10 16:15:54 +000052uint32_t get_duration_milliseconds(base_time_counter *start,
53 base_time_counter *end);
alexander3c798932021-03-26 21:42:19 +000054
55/**
56 * @brief Gets the duration elapsed between two counters in microseconds.
alexander31ae9f02022-02-10 16:15:54 +000057 * @param[in] start Pointer to base_time_counter value at start time.
58 * @param[in] end Pointer to base_time_counter value at end.
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000059 * @returns Difference in microseconds between the two give counters
alexander3c798932021-03-26 21:42:19 +000060 * expressed as an unsigned integer.
61 **/
alexander31ae9f02022-02-10 16:15:54 +000062uint32_t get_duration_microseconds(base_time_counter *start,
63 base_time_counter *end);
alexander3c798932021-03-26 21:42:19 +000064
65/**
66 * @brief Gets the cycle counts elapsed between start and end.
alexander31ae9f02022-02-10 16:15:54 +000067 * @param[in] start Pointer to base_time_counter value at start time.
68 * @param[in] end Pointer to base_time_counter value at end.
alexander3c798932021-03-26 21:42:19 +000069 * @return Difference in counter values as 32 bit unsigned integer.
70 **/
alexander31ae9f02022-02-10 16:15:54 +000071uint64_t get_cycle_count_diff(base_time_counter *start,
72 base_time_counter *end);
alexander3c798932021-03-26 21:42:19 +000073
74/**
75 * @brief Enables or triggers cycle counting mechanism, if required
76 * by the platform.
77 **/
78void start_cycle_counter(void);
79
80/**
81 * @brief Stops cycle counting mechanism, if required by the platform.
82 **/
83void stop_cycle_counter(void);
84
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000085/**
86 * @brief System tick interrupt handler.
87 **/
88void SysTick_Handler(void);
89
alexander3c798932021-03-26 21:42:19 +000090#endif /* TIMER_MPS3_H */