blob: 327d078de85f49e3afe3bf26add4cc99a4acdd5a [file] [log] [blame]
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +08001/*
2 * Copyright (C) 2014-2018 Amlogic, Inc. All rights reserved.
3 *
4 * All information contained herein is Amlogic confidential.
5 *
6 * This software is provided to you pursuant to Software License Agreement
7 * (SLA) with Amlogic Inc ("Amlogic"). This software may be used
8 * only in accordance with the terms of this agreement.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification is strictly prohibited without prior written permission from
12 * Amlogic.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *//*
26 * Copyright (C) 2014-2018 Amlogic, Inc. All rights reserved.
27 *
28 * All information contained herein is Amlogic confidential.
29 *
30 * This software is provided to you pursuant to Software License Agreement
31 * (SLA) with Amlogic Inc ("Amlogic"). This software may be used
32 * only in accordance with the terms of this agreement.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification is strictly prohibited without prior written permission from
36 * Amlogic.
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
41 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
42 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
46 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 */
50
51#include "register.h"
52#include "common.h"
53#include "stdio.h"
54#include "timer_source.h"
55
56
57uint32_t timere_read(void)
58{
59 uint32_t time = 0;
60 unsigned long long te = 0, temp = 0;
61
62 /*timeE high+low, first read low, second read high*/
63 te = REG32(TIMERE_LOW_REG);
64 temp = REG32(TIMERE_HIG_REG);
65 te += (temp << 32);
66 te = te/1000000;
67 time = (uint32_t)te;
68 //printf("----------time_e: %us\n", time);
69 return time;
70}
71
72unsigned long long timere_read_us(void)
73{
74 unsigned long long te = 0, temp = 0;
75
76 /*timeE high+low, first read low, second read high*/
77 te = REG32(TIMERE_LOW_REG);
78 temp = REG32(TIMERE_HIG_REG);
79 te += (temp << 32);
80
81 return te;
82}
83
84void udelay(uint32_t uS)
85{
86 unsigned long long t0;
87
88 if (uS == 0)
89 return;
90 t0 = timere_read_us();
91 while (timere_read_us() - t0 < uS);
92}
93
94void mdelay(uint32_t mS)
95{
96 if (mS == 0)
97 return;
98 while (mS--) {
99 udelay(1000);
100 }
101}