blob: 4bcd07bce9e9845c0d9b2b707b91a423dd6ecd8b [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 */
Kshitij Sisodia659fcd92021-05-19 10:30:06 +010017#include "timer_simple_platform.h"
alexander3c798932021-03-26 21:42:19 +000018
19#include "irqs.h"
alexander31ae9f02022-02-10 16:15:54 +000020#include "log_macros.h"
alexander3c798932021-03-26 21:42:19 +000021
Kshitij Sisodia659fcd92021-05-19 10:30:06 +010022#include <inttypes.h>
23
alexander31ae9f02022-02-10 16:15:54 +000024base_time_counter get_time_counter(void)
alexander3c798932021-03-26 21:42:19 +000025{
alexander31ae9f02022-02-10 16:15:54 +000026 base_time_counter t = {
alexander3c798932021-03-26 21:42:19 +000027 .counter_systick = Get_SysTick_Cycle_Count()
28 };
Kshitij Sisodia659fcd92021-05-19 10:30:06 +010029 debug("counter_systick: %" PRIu64 "\n", t.counter_systick);
alexander3c798932021-03-26 21:42:19 +000030 return t;
31}
32
33void 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
alexander31ae9f02022-02-10 16:15:54 +000041uint64_t get_cycle_count_diff(base_time_counter *start,
42 base_time_counter *end)
alexander3c798932021-03-26 21:42:19 +000043{
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
50void start_cycle_counter(void)
51{
52 /* Add any custom requirement for this platform here */
53}
54
55void stop_cycle_counter(void)
56{
57 /* Add any custom requirement for this platform here */
58}