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 | */ |
Kshitij Sisodia | 659fcd9 | 2021-05-19 10:30:06 +0100 | [diff] [blame] | 17 | #include "timer_simple_platform.h" |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 18 | |
| 19 | #include "irqs.h" |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame^] | 20 | #include "log_macros.h" |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 21 | |
Kshitij Sisodia | 659fcd9 | 2021-05-19 10:30:06 +0100 | [diff] [blame] | 22 | #include <inttypes.h> |
| 23 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame^] | 24 | base_time_counter get_time_counter(void) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 25 | { |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame^] | 26 | base_time_counter t = { |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 27 | .counter_systick = Get_SysTick_Cycle_Count() |
| 28 | }; |
Kshitij Sisodia | 659fcd9 | 2021-05-19 10:30:06 +0100 | [diff] [blame] | 29 | debug("counter_systick: %" PRIu64 "\n", t.counter_systick); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 30 | return t; |
| 31 | } |
| 32 | |
| 33 | void timer_reset(void) |
| 34 | { |
| 35 | if (0 != Init_SysTick()) { |
| 36 | printf_err("Failed to initialise system tick config\n"); |
| 37 | } |
| 38 | debug("system tick config ready\n"); |
| 39 | } |
| 40 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame^] | 41 | uint64_t get_cycle_count_diff(base_time_counter *start, |
| 42 | base_time_counter *end) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 43 | { |
| 44 | if (start->counter_systick > end->counter_systick) { |
| 45 | warn("start > end; counter might have overflown\n"); |
| 46 | } |
| 47 | return end->counter_systick - start->counter_systick; |
| 48 | } |
| 49 | |
| 50 | void start_cycle_counter(void) |
| 51 | { |
| 52 | /* Add any custom requirement for this platform here */ |
| 53 | } |
| 54 | |
| 55 | void stop_cycle_counter(void) |
| 56 | { |
| 57 | /* Add any custom requirement for this platform here */ |
| 58 | } |