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