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 | |
| 12 | |
| 13 | uint32_t timere_read(void) |
| 14 | { |
| 15 | uint32_t time = 0; |
| 16 | unsigned long long te = 0, temp = 0; |
| 17 | |
| 18 | /*timeE high+low, first read low, second read high*/ |
| 19 | te = REG32(TIMERE_LOW_REG); |
| 20 | temp = REG32(TIMERE_HIG_REG); |
| 21 | te += (temp << 32); |
| 22 | te = te/1000000; |
| 23 | time = (uint32_t)te; |
| 24 | //printf("----------time_e: %us\n", time); |
| 25 | return time; |
| 26 | } |
| 27 | |
| 28 | unsigned long long timere_read_us(void) |
| 29 | { |
| 30 | unsigned long long te = 0, temp = 0; |
| 31 | |
| 32 | /*timeE high+low, first read low, second read high*/ |
| 33 | te = REG32(TIMERE_LOW_REG); |
| 34 | temp = REG32(TIMERE_HIG_REG); |
| 35 | te += (temp << 32); |
| 36 | |
| 37 | return te; |
| 38 | } |
| 39 | |
| 40 | void udelay(uint32_t uS) |
| 41 | { |
| 42 | unsigned long long t0; |
| 43 | |
| 44 | if (uS == 0) |
| 45 | return; |
| 46 | t0 = timere_read_us(); |
| 47 | while (timere_read_us() - t0 < uS); |
| 48 | } |
| 49 | |
| 50 | void mdelay(uint32_t mS) |
| 51 | { |
| 52 | if (mS == 0) |
| 53 | return; |
| 54 | while (mS--) { |
| 55 | udelay(1000); |
| 56 | } |
| 57 | } |