Software APIs
dt_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 darjeeling.
10 */
11
12#include "dt/dt_ast.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_ast {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t base_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 */
25
26
27
28
29static const dt_desc_ast_t ast_desc[kDtAstCount] = {
30 [kDtAst] = {
31 .inst_id = kDtInstanceIdAst,
32 .base_addr = {
33 [kDtAstRegBlockCore] = 0x30480000,
34 },
35 .clock = {
40 },
41 .reset = {
46 },
47 },
48};
49
50/**
51 * Return a pointer to the `dt_ast_desc_t` structure of the requested
52 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
53 * the function) with the provided default value.
54 */
55#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_ast_t)0 || (dt) >= kDtAstCount) return (default); &ast_desc[dt]; })
56
58 if (inst_id >= kDtInstanceIdAst && inst_id <= kDtInstanceIdAst) {
59 return (dt_ast_t)(inst_id - kDtInstanceIdAst);
60 }
61 return (dt_ast_t)0;
62}
63
68
70 dt_ast_t dt,
71 dt_ast_reg_block_t reg_block) {
72 // Return a recognizable address in case of wrong argument.
73 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
74}
75
76
77
78
80 dt_ast_t dt,
81 dt_ast_clock_t clk) {
82 // Return the first clock in case of invalid argument.
83 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
84}
85
87 dt_ast_t dt,
88 dt_ast_reset_t rst) {
89 const dt_ast_reset_t count = kDtAstResetCount;
90 if (rst >= count) {
91 return kDtResetUnknown;
92 }
93 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
94}
95
96