Software APIs
dt_aon_timer.c
Go to the documentation of this file.
1
// Copyright lowRISC contributors (OpenTitan project).
2
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3
// SPDX-License-Identifier: Apache-2.0
4
//
5
// Device table API auto-generated by `dtgen`
6
7
/**
8
* @file
9
* @brief Device Tables (DT) for IP aon_timer and top englishbreakfast.
10
*/
11
12
#include "dt/dt_aon_timer.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_aon_timer
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
base_addr
[kDtAonTimerRegBlockCount];
/**< Base address of each register block */
22
/**
23
* PLIC ID of the first IRQ of this instance
24
*
25
* This can be `kDtPlicIrqIdNone` if the block is not connected to the PLIC.
26
*/
27
top_englishbreakfast_plic_irq_id_t
first_irq
;
28
dt_clock_t
clock
[kDtAonTimerClockCount];
/**< Clock signal connected to each clock port */
29
dt_reset_t
reset
[kDtAonTimerResetCount];
/**< Reset signal connected to each reset port */
30
}
dt_desc_aon_timer_t
;
31
32
33
34
35
static
const
dt_desc_aon_timer_t
aon_timer_desc[kDtAonTimerCount] = {
36
[
kDtAonTimerAon
] = {
37
.inst_id =
kDtInstanceIdAonTimerAon
,
38
.base_addr = {
39
[kDtAonTimerRegBlockCore] = 0x40470000,
40
},
41
.first_irq =
kTopEnglishbreakfastPlicIrqIdAonTimerAonWkupTimerExpired
,
42
.clock = {
43
[
kDtAonTimerClockClk
] =
kDtClockIoDiv4
,
44
[
kDtAonTimerClockAon
] =
kDtClockAon
,
45
},
46
.reset = {
47
[
kDtAonTimerResetRst
] =
kDtResetSysIoDiv4
,
48
[
kDtAonTimerResetAon
] =
kDtResetSysAon
,
49
},
50
},
51
};
52
53
/**
54
* Return a pointer to the `dt_aon_timer_desc_t` structure of the requested
55
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
56
* the function) with the provided default value.
57
*/
58
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_aon_timer_t)0 || (dt) >= kDtAonTimerCount) return (default); &aon_timer_desc[dt]; })
59
60
dt_aon_timer_t
dt_aon_timer_from_instance_id
(
dt_instance_id_t
inst_id) {
61
if
(inst_id >=
kDtInstanceIdAonTimerAon
&& inst_id <=
kDtInstanceIdAonTimerAon
) {
62
return
(
dt_aon_timer_t
)(inst_id -
kDtInstanceIdAonTimerAon
);
63
}
64
return
(
dt_aon_timer_t
)0;
65
}
66
67
dt_instance_id_t
dt_aon_timer_instance_id
(
68
dt_aon_timer_t
dt) {
69
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
70
}
71
72
uint32_t
dt_aon_timer_reg_block
(
73
dt_aon_timer_t
dt,
74
dt_aon_timer_reg_block_t
reg_block) {
75
// Return a recognizable address in case of wrong argument.
76
return
TRY_GET_DT
(dt, 0xdeadbeef)->base_addr[reg_block];
77
}
78
79
dt_plic_irq_id_t
dt_aon_timer_irq_to_plic_id
(
80
dt_aon_timer_t
dt,
81
dt_aon_timer_irq_t
irq) {
82
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, kDtPlicIrqIdNone)->first_irq;
83
if
(first_irq == kDtPlicIrqIdNone) {
84
return
kDtPlicIrqIdNone;
85
}
86
return
(
dt_plic_irq_id_t
)((uint32_t)first_irq + (uint32_t)irq);
87
}
88
89
dt_aon_timer_irq_t
dt_aon_timer_irq_from_plic_id
(
90
dt_aon_timer_t
dt,
91
dt_plic_irq_id_t
irq) {
92
dt_aon_timer_irq_t
count = kDtAonTimerIrqCount;
93
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, count)->first_irq;
94
if
(first_irq == kDtPlicIrqIdNone) {
95
return
count;
96
}
97
if
(irq < first_irq || irq >= first_irq + (
dt_plic_irq_id_t
)count) {
98
return
count;
99
}
100
return
(
dt_aon_timer_irq_t
)(irq - first_irq);
101
}
102
103
104
105
106
dt_clock_t
dt_aon_timer_clock
(
107
dt_aon_timer_t
dt,
108
dt_aon_timer_clock_t
clk) {
109
// Return the first clock in case of invalid argument.
110
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
111
}
112
113
dt_reset_t
dt_aon_timer_reset
(
114
dt_aon_timer_t
dt,
115
dt_aon_timer_reset_t
rst) {
116
const
dt_aon_timer_reset_t
count = kDtAonTimerResetCount;
117
if
(rst >= count) {
118
return
kDtResetUnknown
;
119
}
120
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
121
}
122
123
(englishbreakfast)
hw
top
dt
dt_aon_timer.c
Return to
OpenTitan Documentation