1 /*
2  * Copyright (c) 2024 Raspberry Pi Ltd.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef _HARDWARE_PLATFORM_DEFS_H
8 #define _HARDWARE_PLATFORM_DEFS_H
9 
10 // This header is included from C and assembler - intended mostly for #defines; guard other stuff with #ifdef __ASSEMBLER__
11 
12 #ifndef _u
13 #ifdef __ASSEMBLER__
14 #define _u(x) x
15 #else
16 #define _u(x) x ## u
17 #endif
18 #endif
19 
20 #define NUM_CORES _u(2)
21 #define NUM_DMA_CHANNELS _u(16)
22 #define NUM_DMA_TIMERS _u(4)
23 #define NUM_DMA_MPU_REGIONS _u(8)
24 #define NUM_DMA_IRQS _u(4)
25 #define NUM_IRQS _u(52)
26 #define NUM_USER_IRQS _u(6)
27 #define NUM_PIOS _u(3)
28 #define NUM_PIO_STATE_MACHINES _u(4)
29 #define NUM_PIO_IRQS _u(2)
30 #define NUM_PWM_SLICES _u(12)
31 #define NUM_PWM_IRQS _u(2)
32 #define NUM_SPIN_LOCKS _u(32)
33 #define NUM_UARTS _u(2)
34 #define NUM_I2CS _u(2)
35 #define NUM_SPIS _u(2)
36 #define NUM_GENERIC_TIMERS _u(2)
37 #define NUM_ALARMS _u(4)
38 #if PICO_RP2350A
39 #define NUM_ADC_CHANNELS _u(5)
40 #define ADC_BASE_PIN _u(26)
41 #else
42 #define NUM_ADC_CHANNELS _u(9)
43 #define ADC_BASE_PIN _u(40)
44 #endif
45 #define NUM_RESETS _u(28)
46 #define NUM_DOORBELLS _u(8)
47 
48 #if PICO_RP2350A
49 #define NUM_BANK0_GPIOS _u(30)
50 #else
51 #define NUM_BANK0_GPIOS _u(48)
52 #endif
53 #define NUM_QSPI_GPIOS _u(6)
54 
55 #define NUM_OTP_PAGES _u(64)
56 #define NUM_OTP_PAGE_ROWS _u(64)
57 #define NUM_OTP_ROWS (NUM_OTP_PAGES * NUM_OTP_PAGE_ROWS)
58 
59 #define PIO_INSTRUCTION_COUNT _u(32)
60 
61 #define NUM_MPU_REGIONS _u(8)
62 #define NUM_SAU_REGIONS _u(8)
63 #define NUM_BOOT_LOCKS _u(8)
64 
65 #define BOOTRAM_SIZE _u(0x400)
66 #define USBCTRL_DPRAM_SIZE _u(4096)
67 
68 #ifndef __riscv
69 #define HAS_GPIO_COPROCESSOR 1
70 #define HAS_DOUBLE_COPROCESSOR 1
71 #define HAS_REDUNDANCY_COPROCESSOR 1
72 #endif
73 #define HAS_POWMAN_TIMER 1
74 #define HAS_RP2350_TRNG 1
75 #define HAS_HSTX 1
76 
77 // PICO_CONFIG: XOSC_HZ, Crystal oscillator frequency in Hz, type=int, default=12000000, advanced=true, group=hardware_base
78 // NOTE:  The system and USB clocks are generated from the frequency using two PLLs.
79 // If you override this define, or SYS_CLK_HZ/USB_CLK_HZ below, you will *also* need to add your own adjusted PLL set-up defines to
80 // override the defaults which live in src/rp2_common/hardware_clocks/include/hardware/clocks.h
81 // Please see the comments there about calculating the new PLL setting values.
82 #ifndef XOSC_HZ
83 #ifdef XOSC_KHZ
84 #define XOSC_HZ ((XOSC_KHZ) * _u(1000))
85 #elif defined(XOSC_MHZ)
86 #define XOSC_HZ ((XOSC_MHZ) * _u(1000000))
87 #else
88 #define XOSC_HZ _u(12000000)
89 #endif
90 #endif
91 
92 // PICO_CONFIG: SYS_CLK_HZ, System operating frequency in Hz, type=int, default=150000000, advanced=true, group=hardware_base
93 #ifndef SYS_CLK_HZ
94 #ifdef SYS_CLK_KHZ
95 #define SYS_CLK_HZ ((SYS_CLK_KHZ) * _u(1000))
96 #elif defined(SYS_CLK_MHZ)
97 #define SYS_CLK_HZ ((SYS_CLK_MHZ) * _u(1000000))
98 #else
99 #define SYS_CLK_HZ _u(150000000)
100 #endif
101 #endif
102 
103 // PICO_CONFIG: USB_CLK_HZ, USB clock frequency. Must be 48MHz for the USB interface to operate correctly, type=int, default=48000000, advanced=true, group=hardware_base
104 #ifndef USB_CLK_HZ
105 #ifdef USB_CLK_KHZ
106 #define USB_CLK_HZ ((USB_CLK_KHZ) * _u(1000))
107 #elif defined(USB_CLK_MHZ)
108 #define USB_CLK_HZ ((USB_CLK_MHZ) * _u(1000000))
109 #else
110 #define USB_CLK_HZ _u(48000000)
111 #endif
112 #endif
113 
114 // For backwards compatibility define XOSC_KHZ if the frequency is indeed an integer number of Khz.
115 #if defined(XOSC_HZ) && !defined(XOSC_KHZ) && (XOSC_HZ % 1000 == 0)
116 #define XOSC_KHZ (XOSC_HZ / 1000)
117 #endif
118 
119 // For backwards compatibility define XOSC_MHZ if the frequency is indeed an integer number of Mhz.
120 #if defined(XOSC_KHZ) && !defined(XOSC_MHZ) && (XOSC_KHZ % 1000 == 0)
121 #define XOSC_MHZ (XOSC_KHZ / 1000)
122 #endif
123 
124 // For backwards compatibility define SYS_CLK_KHZ if the frequency is indeed an integer number of Khz.
125 #if defined(SYS_CLK_HZ) && !defined(SYS_CLK_KHZ) && (SYS_CLK_HZ % 1000 == 0)
126 #define SYS_CLK_KHZ (SYS_CLK_HZ / 1000)
127 #endif
128 
129 // For backwards compatibility define SYS_CLK_MHZ if the frequency is indeed an integer number of Mhz.
130 #if defined(SYS_CLK_KHZ) && !defined(SYS_CLK_MHZ) && (SYS_CLK_KHZ % 1000 == 0)
131 #define SYS_CLK_MHZ (SYS_CLK_KHZ / 1000)
132 #endif
133 
134 // For backwards compatibility define USB_CLK_KHZ if the frequency is indeed an integer number of Khz.
135 #if defined(USB_CLK_HZ) && !defined(USB_CLK_KHZ) && (USB_CLK_HZ % 1000 == 0)
136 #define USB_CLK_KHZ (USB_CLK_HZ / 1000)
137 #endif
138 
139 // For backwards compatibility define USB_CLK_MHZ if the frequency is indeed an integer number of Mhz.
140 #if defined(USB_CLK_KHZ) && !defined(USB_CLK_MHZ) && (USB_CLK_KHZ % 1000 == 0)
141 #define USB_CLK_MHZ (USB_CLK_KHZ / 1000)
142 #endif
143 
144 #define ACCESSCTRL_PASSWORD_BITS _u(0xacce0000)
145 #define POWMAN_PASSWORD_BITS _u(0x5afe0000)
146 
147 #ifdef __riscv
148 // Note the soft-table dispatch code is between the hard and soft vector
149 // tables, as it's inlined into the last slot of the hard table:
150 #if defined(__riscv_c) || defined(__riscv_zca)
151 // RISC-V with compressed instructions: NOTE that this is dependent on the size of the code in crt0_riscv.S
152 #define VTABLE_FIRST_IRQ 0x34
153 #else
154 // RISC-V without compressed instructions:
155 #define VTABLE_FIRST_IRQ 0x48
156 #endif
157 #else
158 // Armv8-M:
159 #define VTABLE_FIRST_IRQ 16
160 #endif
161 #define FIRST_USER_IRQ (NUM_IRQS - NUM_USER_IRQS)
162 
163 #define REG_FIELD_WIDTH(f) (f ## _MSB + 1 - f ## _LSB)
164 
165 #endif
166