alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 1 | /* |
| 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. */ |
| 24 | typedef 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; |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 33 | } base_time_counter; |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * @brief Resets the counters. |
| 37 | */ |
| 38 | void timer_reset(void); |
| 39 | |
| 40 | /** |
| 41 | * @brief Gets the current counter values. |
| 42 | * @returns Mps3 timer counter. |
| 43 | **/ |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 44 | base_time_counter get_time_counter(void); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * @brief Gets the duration elapsed between two counters in milliseconds. |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 48 | * @param[in] start Pointer to base_time_counter value at start time. |
| 49 | * @param[in] end Pointer to base_time_counter value at end. |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 50 | * @returns Difference in milliseconds between the two give counters |
| 51 | * expressed as an unsigned integer. |
| 52 | **/ |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 53 | uint32_t get_duration_milliseconds(base_time_counter *start, |
| 54 | base_time_counter *end); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * @brief Gets the duration elapsed between two counters in microseconds. |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 58 | * @param[in] start Pointer to base_time_counter value at start time. |
| 59 | * @param[in] end Pointer to base_time_counter value at end. |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 60 | * @returns Difference in microseconds between the two give counters |
| 61 | * expressed as an unsigned integer. |
| 62 | **/ |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 63 | uint32_t get_duration_microseconds(base_time_counter *start, |
| 64 | base_time_counter *end); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * @brief Gets the cycle counts elapsed between start and end. |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 68 | * @param[in] start Pointer to base_time_counter value at start time. |
| 69 | * @param[in] end Pointer to base_time_counter value at end. |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 70 | * @return Difference in counter values as 32 bit unsigned integer. |
| 71 | **/ |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 72 | uint64_t get_cycle_count_diff(base_time_counter *start, |
| 73 | base_time_counter *end); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * @brief Enables or triggers cycle counting mechanism, if required |
| 77 | * by the platform. |
| 78 | **/ |
| 79 | void start_cycle_counter(void); |
| 80 | |
| 81 | /** |
| 82 | * @brief Stops cycle counting mechanism, if required by the platform. |
| 83 | **/ |
| 84 | void stop_cycle_counter(void); |
| 85 | |
| 86 | #endif /* TIMER_MPS3_H */ |