Software APIs
ast.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 ast and top earlgrey.
10
*/
11
12
#include "hw/top/dt/ast.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_ast
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
reg_addr
[
kDtAstRegBlockCount
];
/**< Base address of each register block */
22
dt_clock_t
clock
[
kDtAstClockCount
];
/**< Clock signal connected to each clock port */
23
dt_reset_t
reset
[
kDtAstResetCount
];
/**< Reset signal connected to each reset port */
24
}
dt_desc_ast_t
;
25
26
27
28
29
static
const
dt_desc_ast_t
ast_desc[
kDtAstCount
] = {
30
[
kDtAst
] = {
31
.inst_id =
kDtInstanceIdAst
,
32
.reg_addr = {
33
[kDtAstRegBlockCore] = 0x40480000,
34
},
35
.clock = {
36
[
kDtAstClockAstTlul
] =
kDtClockIoDiv4
,
37
[
kDtAstClockAstEs
] =
kDtClockMain
,
38
[
kDtAstClockAstUsb
] =
kDtClockUsb
,
39
[
kDtAstClockAstExt
] = kDtClockAstExt,
40
[
kDtAstClockAstAdc
] =
kDtClockAon
,
41
[
kDtAstClockAstAlert
] =
kDtClockIoDiv4
,
42
[
kDtAstClockAstRng
] =
kDtClockMain
,
43
},
44
.reset = {
45
[
kDtAstResetAstTlul
] =
kDtResetLcIoDiv4
,
46
[
kDtAstResetAstEs
] =
kDtResetLc
,
47
[
kDtAstResetAstUsb
] =
kDtResetUsb
,
48
[
kDtAstResetAstAdc
] =
kDtResetLcAon
,
49
[
kDtAstResetAstAlert
] =
kDtResetLcIoDiv4
,
50
[
kDtAstResetAstRng
] =
kDtResetLc
,
51
},
52
},
53
};
54
55
/**
56
* Return a pointer to the `dt_ast_desc_t` structure of the requested
57
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
58
* the function) with the provided default value.
59
*/
60
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_ast_t)0 || (int)(dt) >= kDtAstCount) return (default); &ast_desc[dt]; })
61
62
dt_ast_t
dt_ast_from_instance_id
(
dt_instance_id_t
inst_id) {
63
if
(inst_id >=
kDtInstanceIdAst
&& inst_id <=
kDtInstanceIdAst
) {
64
return
(
dt_ast_t
)(inst_id -
kDtInstanceIdAst
);
65
}
66
return
(
dt_ast_t
)0;
67
}
68
69
dt_instance_id_t
dt_ast_instance_id
(
70
dt_ast_t
dt) {
71
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
72
}
73
74
uint32_t
dt_ast_reg_block
(
75
dt_ast_t
dt,
76
dt_ast_reg_block_t
reg_block) {
77
// Return a recognizable address in case of wrong argument.
78
return
TRY_GET_DT
(dt, 0xdeadbeef)->reg_addr[reg_block];
79
}
80
81
82
83
84
dt_clock_t
dt_ast_clock
(
85
dt_ast_t
dt,
86
dt_ast_clock_t
clk) {
87
// Return the first clock in case of invalid argument.
88
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
89
}
90
91
dt_reset_t
dt_ast_reset
(
92
dt_ast_t
dt,
93
dt_ast_reset_t
rst) {
94
const
dt_ast_reset_t
count =
kDtAstResetCount
;
95
if
(rst >= count) {
96
return
kDtResetUnknown
;
97
}
98
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
99
}
100
101
(earlgrey)
hw
top
dt
ast.c
Return to
OpenTitan Documentation