Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/soc/timer.h
1476 views
1
/*
2
* Timer/Watchdog driver for Tegra X1
3
*
4
* Copyright (c) 2019 CTCaer
5
*
6
* This program is free software; you can redistribute it and/or modify it
7
* under the terms and conditions of the GNU General Public License,
8
* version 2, as published by the Free Software Foundation.
9
*
10
* This program is distributed in the hope it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
* more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#ifndef _TIMER_H_
20
#define _TIMER_H_
21
22
#include <utils/types.h>
23
24
// TMR registers.
25
#define TIMERUS_CNTR_1US (0x10 + 0x0)
26
#define TIMERUS_USEC_CFG (0x10 + 0x4)
27
#define TIMER_TMR8_TMR_PTV 0x78
28
#define TIMER_TMR9_TMR_PTV 0x80
29
#define TIMER_PER_EN BIT(30)
30
#define TIMER_EN BIT(31)
31
#define TIMER_TMR8_TMR_PCR 0x7C
32
#define TIMER_TMR9_TMR_PCR 0x8C
33
#define TIMER_INTR_CLR BIT(30)
34
35
// WDT registers.
36
#define TIMER_WDT4_CONFIG (0x100 + 0x80)
37
#define TIMER_SRC(TMR) ((TMR) & 0xF)
38
#define TIMER_PER(PER) (((PER) & 0xFF) << 4)
39
#define TIMER_IRQENABL_EN BIT(12)
40
#define TIMER_FIQENABL_EN BIT(13)
41
#define TIMER_SYSRESET_EN BIT(14)
42
#define TIMER_PMCRESET_EN BIT(15)
43
#define TIMER_WDT4_COMMAND (0x108 + 0x80)
44
#define TIMER_START_CNT BIT(0)
45
#define TIMER_CNT_DISABLE BIT(1)
46
#define TIMER_WDT4_UNLOCK_PATTERN (0x10C + 0x80)
47
#define TIMER_MAGIC_PTRN 0xC45A
48
49
u32 get_tmr_us();
50
u32 get_tmr_ms();
51
u32 get_tmr_s();
52
void usleep(u32 us);
53
void msleep(u32 ms);
54
#define ILOOP(is) ((is) / 3)
55
void isleep(u32 is);
56
57
void timer_usleep(u32 us);
58
59
void watchdog_start(u32 us, u32 mode);
60
void watchdog_end();
61
void watchdog_handle();
62
bool watchdog_fired();
63
64
#endif
65
66