Software APIs
dt_sram_ctrl.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 sram_ctrl and top englishbreakfast.
10
*/
11
12
#include "dt/dt_sram_ctrl.h"
13
14
15
16
/**
17
* Description of instances.
18
*/
19
typedef
struct
dt_desc_sram_ctrl
{
20
dt_instance_id_t
inst_id
;
/**< Instance ID */
21
uint32_t
base_addr
[kDtSramCtrlRegBlockCount];
/**< Base address of each register block */
22
dt_clock_t
clock
[kDtSramCtrlClockCount];
/**< Clock signal connected to each clock port */
23
dt_reset_t
reset
[kDtSramCtrlResetCount];
/**< Reset signal connected to each reset port */
24
}
dt_desc_sram_ctrl_t
;
25
26
27
28
29
static
const
dt_desc_sram_ctrl_t
sram_ctrl_desc[kDtSramCtrlCount] = {
30
[
kDtSramCtrlMain
] = {
31
.inst_id =
kDtInstanceIdSramCtrlMain
,
32
.base_addr = {
33
[kDtSramCtrlRegBlockRegs] = 0x411C0000,
34
[kDtSramCtrlRegBlockRam] = 0x10000000,
35
},
36
.clock = {
37
[
kDtSramCtrlClockClk
] =
kDtClockMain
,
38
[
kDtSramCtrlClockOtp
] =
kDtClockIoDiv4
,
39
},
40
.reset = {
41
[
kDtSramCtrlResetRst
] =
kDtResetSys
,
42
[
kDtSramCtrlResetOtp
] =
kDtResetLcIoDiv4
,
43
},
44
},
45
};
46
47
/**
48
* Return a pointer to the `dt_sram_ctrl_desc_t` structure of the requested
49
* `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
50
* the function) with the provided default value.
51
*/
52
#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_sram_ctrl_t)0 || (dt) >= kDtSramCtrlCount) return (default); &sram_ctrl_desc[dt]; })
53
54
dt_sram_ctrl_t
dt_sram_ctrl_from_instance_id
(
dt_instance_id_t
inst_id) {
55
if
(inst_id >=
kDtInstanceIdSramCtrlMain
&& inst_id <=
kDtInstanceIdSramCtrlMain
) {
56
return
(
dt_sram_ctrl_t
)(inst_id -
kDtInstanceIdSramCtrlMain
);
57
}
58
return
(
dt_sram_ctrl_t
)0;
59
}
60
61
dt_instance_id_t
dt_sram_ctrl_instance_id
(
62
dt_sram_ctrl_t
dt) {
63
return
TRY_GET_DT
(dt,
kDtInstanceIdUnknown
)->inst_id;
64
}
65
66
uint32_t
dt_sram_ctrl_reg_block
(
67
dt_sram_ctrl_t
dt,
68
dt_sram_ctrl_reg_block_t
reg_block) {
69
// Return a recognizable address in case of wrong argument.
70
return
TRY_GET_DT
(dt, 0xdeadbeef)->base_addr[reg_block];
71
}
72
73
74
75
76
dt_clock_t
dt_sram_ctrl_clock
(
77
dt_sram_ctrl_t
dt,
78
dt_sram_ctrl_clock_t
clk) {
79
// Return the first clock in case of invalid argument.
80
return
TRY_GET_DT
(dt, (
dt_clock_t
)0)->clock[clk];
81
}
82
83
dt_reset_t
dt_sram_ctrl_reset
(
84
dt_sram_ctrl_t
dt,
85
dt_sram_ctrl_reset_t
rst) {
86
const
dt_sram_ctrl_reset_t
count = kDtSramCtrlResetCount;
87
if
(rst >= count) {
88
return
kDtResetUnknown
;
89
}
90
return
TRY_GET_DT
(dt,
kDtResetUnknown
)->reset[rst];
91
}
92
93
(englishbreakfast)
hw
top
dt
dt_sram_ctrl.c
Return to
OpenTitan Documentation