Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 1 | /* |
yang.li | 2477037 | 2022-01-11 15:21:49 +0800 | [diff] [blame] | 2 | * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved. |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 3 | * |
yang.li | 2477037 | 2022-01-11 15:21:49 +0800 | [diff] [blame] | 4 | * SPDX-License-Identifier: MIT |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include "register.h" |
| 8 | #include "common.h" |
| 9 | #include "stdio.h" |
| 10 | #include "timer_source.h" |
| 11 | |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 12 | uint32_t timere_read(void) |
| 13 | { |
| 14 | uint32_t time = 0; |
| 15 | unsigned long long te = 0, temp = 0; |
| 16 | |
| 17 | /*timeE high+low, first read low, second read high*/ |
| 18 | te = REG32(TIMERE_LOW_REG); |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame] | 19 | temp = REG32(TIMERE_HIG_REG); |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 20 | te += (temp << 32); |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame] | 21 | te = te / 1000000; |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 22 | time = (uint32_t)te; |
| 23 | //printf("----------time_e: %us\n", time); |
| 24 | return time; |
| 25 | } |
| 26 | |
| 27 | unsigned long long timere_read_us(void) |
| 28 | { |
| 29 | unsigned long long te = 0, temp = 0; |
| 30 | |
| 31 | /*timeE high+low, first read low, second read high*/ |
| 32 | te = REG32(TIMERE_LOW_REG); |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame] | 33 | temp = REG32(TIMERE_HIG_REG); |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 34 | te += (temp << 32); |
| 35 | |
| 36 | return te; |
| 37 | } |
| 38 | |
| 39 | void udelay(uint32_t uS) |
| 40 | { |
| 41 | unsigned long long t0; |
| 42 | |
| 43 | if (uS == 0) |
| 44 | return; |
| 45 | t0 = timere_read_us(); |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame] | 46 | while (timere_read_us() - t0 < uS) |
| 47 | ; |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void mdelay(uint32_t mS) |
| 51 | { |
| 52 | if (mS == 0) |
| 53 | return; |
xiaohu.huang | 2beac51 | 2022-05-07 15:10:04 +0800 | [diff] [blame] | 54 | while (mS--) |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 55 | udelay(1000); |
Kelvin Zhang | c4c3dd1 | 2021-12-24 20:59:18 +0800 | [diff] [blame] | 56 | } |