Software APIs
dt_flash_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 flash_ctrl and top englishbreakfast.
10 */
11
12#include "dt/dt_flash_ctrl.h"
13
14
15
16/**
17 * Description of instances.
18 */
19typedef struct dt_desc_flash_ctrl {
20 dt_instance_id_t inst_id; /**< Instance ID */
21 uint32_t base_addr[kDtFlashCtrlRegBlockCount]; /**< 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 */
28 dt_clock_t clock[kDtFlashCtrlClockCount]; /**< Clock signal connected to each clock port */
29 dt_reset_t reset[kDtFlashCtrlResetCount]; /**< Reset signal connected to each reset port */
30 dt_periph_io_t periph_io[kDtFlashCtrlPeriphIoCount]; /**< Description of each peripheral I/O */
32
33
34
35
36static const dt_desc_flash_ctrl_t flash_ctrl_desc[kDtFlashCtrlCount] = {
37 [kDtFlashCtrl] = {
38 .inst_id = kDtInstanceIdFlashCtrl,
39 .base_addr = {
40 [kDtFlashCtrlRegBlockCore] = 0x41000000,
41 [kDtFlashCtrlRegBlockPrim] = 0x41008000,
42 [kDtFlashCtrlRegBlockMem] = 0x20000000,
43 },
45 .clock = {
48 },
49 .reset = {
52 },
53 .periph_io = {
54 [kDtFlashCtrlPeriphIoTck] = {
55 .__internal = {
56 .type = kDtPeriphIoTypeMio,
57 .dir = kDtPeriphIoDirIn,
58 .periph_input_or_direct_pad = kTopEnglishbreakfastPinmuxPeripheralInFlashCtrlTck,
59 .outsel_or_dt_pad = 0,
60 },
61 },
62 [kDtFlashCtrlPeriphIoTms] = {
63 .__internal = {
64 .type = kDtPeriphIoTypeMio,
65 .dir = kDtPeriphIoDirIn,
66 .periph_input_or_direct_pad = kTopEnglishbreakfastPinmuxPeripheralInFlashCtrlTms,
67 .outsel_or_dt_pad = 0,
68 },
69 },
70 [kDtFlashCtrlPeriphIoTdi] = {
71 .__internal = {
72 .type = kDtPeriphIoTypeMio,
73 .dir = kDtPeriphIoDirIn,
74 .periph_input_or_direct_pad = kTopEnglishbreakfastPinmuxPeripheralInFlashCtrlTdi,
75 .outsel_or_dt_pad = 0,
76 },
77 },
78 [kDtFlashCtrlPeriphIoTdo] = {
79 .__internal = {
80 .type = kDtPeriphIoTypeMio,
81 .dir = kDtPeriphIoDirOut,
82 .periph_input_or_direct_pad = 0,
84 },
85 },
86 },
87 },
88};
89
90/**
91 * Return a pointer to the `dt_flash_ctrl_desc_t` structure of the requested
92 * `dt` if it's a valid index. Otherwise, this macro will `return` (i.e. exit
93 * the function) with the provided default value.
94 */
95#define TRY_GET_DT(dt, default) ({ if ((dt) < (dt_flash_ctrl_t)0 || (dt) >= kDtFlashCtrlCount) return (default); &flash_ctrl_desc[dt]; })
96
103
108
111 dt_flash_ctrl_reg_block_t reg_block) {
112 // Return a recognizable address in case of wrong argument.
113 return TRY_GET_DT(dt, 0xdeadbeef)->base_addr[reg_block];
114}
115
119 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, kDtPlicIrqIdNone)->first_irq;
120 if (first_irq == kDtPlicIrqIdNone) {
121 return kDtPlicIrqIdNone;
122 }
123 return (dt_plic_irq_id_t)((uint32_t)first_irq + (uint32_t)irq);
124}
125
128 dt_plic_irq_id_t irq) {
129 dt_flash_ctrl_irq_t count = kDtFlashCtrlIrqCount;
130 dt_plic_irq_id_t first_irq = TRY_GET_DT(dt, count)->first_irq;
131 if (first_irq == kDtPlicIrqIdNone) {
132 return count;
133 }
134 if (irq < first_irq || irq >= first_irq + (dt_plic_irq_id_t)count) {
135 return count;
136 }
137 return (dt_flash_ctrl_irq_t)(irq - first_irq);
138}
139
140
141
145 // Return a harmless value in case of wrong argument.
146 return TRY_GET_DT(dt, kDtPeriphIoConstantHighZ)->periph_io[sig];
147}
148
152 // Return the first clock in case of invalid argument.
153 return TRY_GET_DT(dt, (dt_clock_t)0)->clock[clk];
154}
155
159 const dt_flash_ctrl_reset_t count = kDtFlashCtrlResetCount;
160 if (rst >= count) {
161 return kDtResetUnknown;
162 }
163 return TRY_GET_DT(dt, kDtResetUnknown)->reset[rst];
164}
165
166