blob: cd30c7cb4580fa22f7bd51f3160228228d820c42 [file] [log] [blame]
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +08001/*
yang.li24770372022-01-11 15:21:49 +08002 * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +08003 *
yang.li24770372022-01-11 15:21:49 +08004 * SPDX-License-Identifier: MIT
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +08005 */
6
7#include "register.h"
8#include "common.h"
9#include "stdio.h"
10#include "timer_source.h"
11
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +080012uint32_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.huang2beac512022-05-07 15:10:04 +080019 temp = REG32(TIMERE_HIG_REG);
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +080020 te += (temp << 32);
xiaohu.huang2beac512022-05-07 15:10:04 +080021 te = te / 1000000;
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +080022 time = (uint32_t)te;
23 //printf("----------time_e: %us\n", time);
24 return time;
25}
26
27unsigned 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.huang2beac512022-05-07 15:10:04 +080033 temp = REG32(TIMERE_HIG_REG);
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +080034 te += (temp << 32);
35
36 return te;
37}
38
39void udelay(uint32_t uS)
40{
41 unsigned long long t0;
42
43 if (uS == 0)
44 return;
45 t0 = timere_read_us();
xiaohu.huang2beac512022-05-07 15:10:04 +080046 while (timere_read_us() - t0 < uS)
47 ;
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +080048}
49
50void mdelay(uint32_t mS)
51{
52 if (mS == 0)
53 return;
xiaohu.huang2beac512022-05-07 15:10:04 +080054 while (mS--)
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +080055 udelay(1000);
Kelvin Zhangc4c3dd12021-12-24 20:59:18 +080056}