Software APIs
dt_rv_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 rv_timer and top englishbreakfast.
10
*/
11
12
#include "dt/dt_rv_timer.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_rv_timer
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
base_addr
[kDtRvTimerRegBlockCount];
/**< 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
[kDtRvTimerClockCount];
/**< Clock signal connected to each clock port */
29
dt_reset_t
reset
[kDtRvTimerResetCount];
/**< Reset signal connected to each reset port */
30
}
dt_desc_rv_timer_t
;
31
32
33
34
35
static
const
dt_desc_rv_timer_t
rv_timer_desc[kDtRvTimerCount] = {
36
[
kDtRvTimer
] = {
37
.inst_id =
kDtInstanceIdRvTimer
,
38
.base_addr = {
39
[kDtRvTimerRegBlockCore] = 0x40100000,
40
},
41
.first_irq =
kTopEnglishbreakfastPlicIrqIdNone
,
42
.clock = {
43
[
kDtRvTimerClockClk
] =
kDtClockIoDiv4
,
44
},
45
.reset = {
46
[
kDtRvTimerResetRst
] =
kDtResetSysIoDiv4
,
47
},
48
},
49
};
50
51
/**
52
* Return a pointer to the `dt_rv_timer_desc_t` structure of the requested
53
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
54
* the function) with the provided default value.
55
*/
56
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_rv_timer_t)0 || (dt) >= kDtRvTimerCount) return (default); &rv_timer_desc[dt]; })
57
58
dt_rv_timer_t
dt_rv_timer_from_instance_id
(
dt_instance_id_t
inst_id) {
59
if
(inst_id >=
kDtInstanceIdRvTimer
&& inst_id <=
kDtInstanceIdRvTimer
) {
60
return
(
dt_rv_timer_t
)(inst_id -
kDtInstanceIdRvTimer
);
61
}
62
return
(
dt_rv_timer_t
)0;
63
}
64
65
dt_instance_id_t
dt_rv_timer_instance_id
(
66
dt_rv_timer_t
dt) {
67
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
68
}
69
70
uint32_t
dt_rv_timer_reg_block
(
71
dt_rv_timer_t
dt,
72
dt_rv_timer_reg_block_t
reg_block) {
73
// Return a recognizable address in case of wrong argument.
74
return
TRY_GET_DT
(dt, 0xdeadbeef)->base_addr[reg_block];
75
}
76
77
dt_plic_irq_id_t
dt_rv_timer_irq_to_plic_id
(
78
dt_rv_timer_t
dt,
79
dt_rv_timer_irq_t
irq) {
80
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, kDtPlicIrqIdNone)->first_irq;
81
if
(first_irq == kDtPlicIrqIdNone) {
82
return
kDtPlicIrqIdNone;
83
}
84
return
(
dt_plic_irq_id_t
)((uint32_t)first_irq + (uint32_t)irq);
85
}
86
87
dt_rv_timer_irq_t
dt_rv_timer_irq_from_plic_id
(
88
dt_rv_timer_t
dt,
89
dt_plic_irq_id_t
irq) {
90
dt_rv_timer_irq_t
count = kDtRvTimerIrqCount;
91
dt_plic_irq_id_t
first_irq =
TRY_GET_DT
(dt, count)->first_irq;
92
if
(first_irq == kDtPlicIrqIdNone) {
93
return
count;
94
}
95
if
(irq < first_irq || irq >= first_irq + (
dt_plic_irq_id_t
)count) {
96
return
count;
97
}
98
return
(
dt_rv_timer_irq_t
)(irq - first_irq);
99
}
100
101
102
103
104
dt_clock_t
dt_rv_timer_clock
(
105
dt_rv_timer_t
dt,
106
dt_rv_timer_clock_t
clk) {
107
// Return the first clock in case of invalid argument.
108
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
109
}
110
111
dt_reset_t
dt_rv_timer_reset
(
112
dt_rv_timer_t
dt,
113
dt_rv_timer_reset_t
rst) {
114
const
dt_rv_timer_reset_t
count = kDtRvTimerResetCount;
115
if
(rst >= count) {
116
return
kDtResetUnknown
;
117
}
118
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
119
}
120
121
(englishbreakfast)
hw
top
dt
dt_rv_timer.c
Return to
OpenTitan Documentation