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 "hw/top/dt/dt_sram_ctrl.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_sram_ctrl {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t reg_addr[kDtSramCtrlRegBlockCount]; /**< Base address of each register block */
22 uint32_t mem_addr[kDtSramCtrlMemoryCount]; /**< Base address of each memory */
23 uint32_t mem_size[kDtSramCtrlMemoryCount]; /**< Size in bytes of each memory */
24 dt_clock_t clock[kDtSramCtrlClockCount]; /**< Clock signal connected to each clock port */
25 dt_reset_t reset[kDtSramCtrlResetCount]; /**< Reset signal connected to each reset port */
27
28
29
30
31static const dt_desc_sram_ctrl_t sram_ctrl_desc[kDtSramCtrlCount] = {
32 [kDtSramCtrlMain] = {
34 .reg_addr = {
35 [kDtSramCtrlRegBlockRegs] = 0x411C0000,
36 },
37 .mem_addr = {
38 [kDtSramCtrlMemoryRam] = 0x10000000,
39 },
40 .mem_size = {
41 [kDtSramCtrlMemoryRam] = 0x20000,
42 },
43 .clock = {
46 },
47 .reset = {
50 },
51 },
52};
53
54/**
55 * Return a pointer to the `dt_sram_ctrl_desc_t` structure of the requested
56 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
57 * the function) with the provided default value.
58 */
59#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_sram_ctrl_t)0 || (dt) >= kDtSramCtrlCount) return (default); &sram_ctrl_desc[dt]; })
60
67
72
75 dt_sram_ctrl_reg_block_t reg_block) {
76 // Return a recognizable address in case of wrong argument.
77 return TRY_GET_DT(dt, 0xdeadbeef)->reg_addr[reg_block];
78}
79
83 // Return a recognizable address in case of wrong argument.
84 return TRY_GET_DT(dt, 0xdeadbeef)->mem_addr[mem];
85}
86
90 // Return an empty size in case of wrong argument.
91 return TRY_GET_DT(dt, 0)->mem_size[mem];
92}
93
94
95
96
100 // Return the first clock in case of invalid argument.
101 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
102}
103
107 const dt_sram_ctrl_reset_t count = kDtSramCtrlResetCount;
108 if (rst >= count) {
109 return kDtResetUnknown;
110 }
111 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
112}
113
114