1 // Copyright 2010-2016 Espressif Systems (Shanghai) PTE LTD
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
21 #define BIT31 0x80000000
22 #define BIT30 0x40000000
23 #define BIT29 0x20000000
24 #define BIT28 0x10000000
25 #define BIT27 0x08000000
26 #define BIT26 0x04000000
27 #define BIT25 0x02000000
28 #define BIT24 0x01000000
29 #define BIT23 0x00800000
30 #define BIT22 0x00400000
31 #define BIT21 0x00200000
32 #define BIT20 0x00100000
33 #define BIT19 0x00080000
34 #define BIT18 0x00040000
35 #define BIT17 0x00020000
36 #define BIT16 0x00010000
37 #define BIT15 0x00008000
38 #define BIT14 0x00004000
39 #define BIT13 0x00002000
40 #define BIT12 0x00001000
41 #define BIT11 0x00000800
42 #define BIT10 0x00000400
43 #define BIT9 0x00000200
44 #define BIT8 0x00000100
45 #define BIT7 0x00000080
46 #define BIT6 0x00000040
47 #define BIT5 0x00000020
48 #define BIT4 0x00000010
49 #define BIT3 0x00000008
50 #define BIT2 0x00000004
51 #define BIT1 0x00000002
52 #define BIT0 0x00000001
55 #define PRO_CPU_NUM (0)
56 #define APP_CPU_NUM (1)
58 //Registers Operation {{
59 #define ETS_UNCACHED_ADDR(addr) (addr)
60 #define ETS_CACHED_ADDR(addr) (addr)
62 #define BIT(nr) (1UL << (nr))
64 //write value to register
65 #define REG_WRITE(_r, _v) (*(volatile uint32_t *)(_r)) = (_v)
67 //read value from register
68 #define REG_READ(_r) (*(volatile uint32_t *)(_r))
70 //get bit or get bits from register
71 #define REG_GET_BIT(_r, _b) (*(volatile uint32_t*)(_r) & (_b))
73 //set bit or set bits to register
74 #define REG_SET_BIT(_r, _b) (*(volatile uint32_t*)(_r) |= (_b))
76 //clear bit or clear bits of register
77 #define REG_CLR_BIT(_r, _b) (*(volatile uint32_t*)(_r) &= ~(_b))
79 //set bits of register controlled by mask
80 #define REG_SET_BITS(_r, _b, _m) (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)))
82 //get field from register, used when _f is not left shifted by _f##_S
83 #define REG_GET_FIELD(_r, _f) ((REG_READ(_r) >> (_f##_S)) & (_f))
85 //set field to register, used when _f is not left shifted by _f##_S
86 #define REG_SET_FIELD(_r, _f, _v) (REG_WRITE((_r),((REG_READ(_r) & ~((_f) << (_f##_S)))|(((_v) & (_f))<<(_f##_S)))))
88 //get field value from a variable, used when _f is not left shifted by _f##_S
89 #define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f))
91 //get field value from a variable, used when _f is left shifted by _f##_S
92 #define VALUE_GET_FIELD2(_r, _f) (((_r) & (_f))>> (_f##_S))
94 //set field value to a variable, used when _f is not left shifted by _f##_S
95 #define VALUE_SET_FIELD(_r, _f, _v) ((_r)=(((_r) & ~((_f) << (_f##_S)))|((_v)<<(_f##_S))))
97 //set field value to a variable, used when _f is left shifted by _f##_S
98 #define VALUE_SET_FIELD2(_r, _f, _v) ((_r)=(((_r) & ~(_f))|((_v)<<(_f##_S))))
100 //generate a value from a field value, used when _f is not left shifted by _f##_S
101 #define FIELD_TO_VALUE(_f, _v) (((_v)&(_f))<<_f##_S)
103 //generate a value from a field value, used when _f is left shifted by _f##_S
104 #define FIELD_TO_VALUE2(_f, _v) (((_v)<<_f##_S) & (_f))
106 //read value from register
107 #define READ_PERI_REG(addr) (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr)))
109 //write value to register
110 #define WRITE_PERI_REG(addr, val) (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val)
112 //clear bits of register controlled by mask
113 #define CLEAR_PERI_REG_MASK(reg, mask) WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask))))
115 //set bits of register controlled by mask
116 #define SET_PERI_REG_MASK(reg, mask) WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask)))
118 //get bits of register controlled by mask
119 #define GET_PERI_REG_MASK(reg, mask) (READ_PERI_REG(reg) & (mask))
121 //get bits of register controlled by highest bit and lowest bit
122 #define GET_PERI_REG_BITS(reg, hipos,lowpos) ((READ_PERI_REG(reg)>>(lowpos))&((1<<((hipos)-(lowpos)+1))-1))
124 //set bits of register controlled by mask and shift
125 #define SET_PERI_REG_BITS(reg,bit_map,value,shift) (WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|(((value) & bit_map)<<(shift)) ))
127 //get field of register
128 #define GET_PERI_REG_BITS2(reg, mask,shift) ((READ_PERI_REG(reg)>>(shift))&(mask))
132 #define APB_CLK_FREQ_ROM ( 26*1000000 )
133 #define CPU_CLK_FREQ_ROM APB_CLK_FREQ_ROM
134 #define CPU_CLK_FREQ APB_CLK_FREQ
135 #define APB_CLK_FREQ ( 80*1000000 ) //unit: Hz
136 #define UART_CLK_FREQ APB_CLK_FREQ
137 #define WDT_CLK_FREQ APB_CLK_FREQ
138 #define TIMER_CLK_FREQ (80000000>>4) //80MHz divided by 16
139 #define SPI_CLK_DIV 4
140 #define TICKS_PER_US_ROM 26 // CPU is 80MHz
143 #define DR_REG_DPORT_BASE 0x3ff00000
144 #define DR_REG_RSA_BASE 0x3ff02000
145 #define DR_REG_SHA_BASE 0x3ff03000
146 #define DR_REG_UART_BASE 0x3ff40000
147 #define DR_REG_SPI1_BASE 0x3ff42000
148 #define DR_REG_SPI0_BASE 0x3ff43000
149 #define DR_REG_GPIO_BASE 0x3ff44000
150 #define DR_REG_GPIO_SD_BASE 0x3ff44f00
151 #define DR_REG_FE2_BASE 0x3ff45000
152 #define DR_REG_FE_BASE 0x3ff46000
153 #define DR_REG_FRC_TIMER_BASE 0x3ff47000
154 #define DR_REG_RTCCNTL_BASE 0x3ff48000
155 #define DR_REG_RTCIO_BASE 0x3ff48400
156 #define DR_REG_SARADC_BASE 0x3ff48800
157 #define DR_REG_IO_MUX_BASE 0x3ff49000
158 #define DR_REG_RTCMEM0_BASE 0x3ff61000
159 #define DR_REG_RTCMEM1_BASE 0x3ff62000
160 #define DR_REG_RTCMEM2_BASE 0x3ff63000
161 #define DR_REG_HINF_BASE 0x3ff4B000
162 #define DR_REG_UHCI1_BASE 0x3ff4C000
163 #define DR_REG_I2S_BASE 0x3ff4F000
164 #define DR_REG_UART1_BASE 0x3ff50000
165 #define DR_REG_BT_BASE 0x3ff51000
166 #define DR_REG_I2C_EXT_BASE 0x3ff53000
167 #define DR_REG_UHCI0_BASE 0x3ff54000
168 #define DR_REG_SLCHOST_BASE 0x3ff55000
169 #define DR_REG_RMT_BASE 0x3ff56000
170 #define DR_REG_PCNT_BASE 0x3ff57000
171 #define DR_REG_SLC_BASE 0x3ff58000
172 #define DR_REG_LEDC_BASE 0x3ff59000
173 #define DR_REG_EFUSE_BASE 0x3ff5A000
174 #define DR_REG_SPI_ENCRYPT_BASE 0x3ff5B000
175 #define DR_REG_PWM_BASE 0x3ff5E000
176 #define DR_REG_TIMERGROUP0_BASE 0x3ff5F000
177 #define DR_REG_TIMERGROUP1_BASE 0x3ff60000
178 #define DR_REG_SPI2_BASE 0x3ff64000
179 #define DR_REG_SPI3_BASE 0x3ff65000
180 #define DR_REG_I2C1_EXT_BASE 0x3ff67000
181 #define DR_REG_SDMMC_BASE 0x3ff68000
182 #define DR_REG_EMAC_BASE 0x3ff69000
183 #define DR_REG_PWM1_BASE 0x3ff6C000
184 #define DR_REG_I2S1_BASE 0x3ff6D000
185 #define DR_REG_UART2_BASE 0x3ff6E000
186 #define DR_REG_PWM2_BASE 0x3ff6F000
187 #define DR_REG_PWM3_BASE 0x3ff70000
188 #define PERIPHS_SPI_ENCRYPT_BASEADDR DR_REG_SPI_ENCRYPT_BASE
190 //Interrupt hardware source table
191 //This table is decided by hardware, don't touch this.
192 #define ETS_WIFI_MAC_INTR_SOURCE 0/**< interrupt of WiFi MAC, level*/
193 #define ETS_WIFI_MAC_NMI_SOURCE 1/**< interrupt of WiFi MAC, NMI, use if MAC have bug to fix in NMI*/
194 #define ETS_WIFI_BB_INTR_SOURCE 2/**< interrupt of WiFi BB, level, we can do some calibartion*/
195 #define ETS_BT_MAC_INTR_SOURCE 3/**< will be cancelled*/
196 #define ETS_BT_BB_INTR_SOURCE 4/**< interrupt of BT BB, level*/
197 #define ETS_BT_BB_NMI_SOURCE 5/**< interrupt of BT BB, NMI, use if BB have bug to fix in NMI*/
198 #define ETS_RWBT_INTR_SOURCE 6/**< interrupt of RWBT, level*/
199 #define ETS_RWBLE_INTR_SOURCE 7/**< interrupt of RWBLE, level*/
200 #define ETS_RWBT_NMI_SOURCE 8/**< interrupt of RWBT, NMI, use if RWBT have bug to fix in NMI*/
201 #define ETS_RWBLE_NMI_SOURCE 9/**< interrupt of RWBLE, NMI, use if RWBT have bug to fix in NMI*/
202 #define ETS_SLC0_INTR_SOURCE 10/**< interrupt of SLC0, level*/
203 #define ETS_SLC1_INTR_SOURCE 11/**< interrupt of SLC1, level*/
204 #define ETS_UHCI0_INTR_SOURCE 12/**< interrupt of UHCI0, level*/
205 #define ETS_UHCI1_INTR_SOURCE 13/**< interrupt of UHCI1, level*/
206 #define ETS_TG0_T0_LEVEL_INTR_SOURCE 14/**< interrupt of TIMER_GROUP0, TIMER0, level, we would like use EDGE for timer if permission*/
207 #define ETS_TG0_T1_LEVEL_INTR_SOURCE 15/**< interrupt of TIMER_GROUP0, TIMER1, level, we would like use EDGE for timer if permission*/
208 #define ETS_TG0_WDT_LEVEL_INTR_SOURCE 16/**< interrupt of TIMER_GROUP0, WATCHDOG, level*/
209 #define ETS_TG0_LACT_LEVEL_INTR_SOURCE 17/**< interrupt of TIMER_GROUP0, LACT, level*/
210 #define ETS_TG1_T0_LEVEL_INTR_SOURCE 18/**< interrupt of TIMER_GROUP1, TIMER0, level, we would like use EDGE for timer if permission*/
211 #define ETS_TG1_T1_LEVEL_INTR_SOURCE 19/**< interrupt of TIMER_GROUP1, TIMER1, level, we would like use EDGE for timer if permission*/
212 #define ETS_TG1_WDT_LEVEL_INTR_SOURCE 20/**< interrupt of TIMER_GROUP1, WATCHDOG, level*/
213 #define ETS_TG1_LACT_LEVEL_INTR_SOURCE 21/**< interrupt of TIMER_GROUP1, LACT, level*/
214 #define ETS_GPIO_INTR_SOURCE 22/**< interrupt of GPIO, level*/
215 #define ETS_GPIO_NMI_SOURCE 23/**< interrupt of GPIO, NMI*/
216 #define ETS_FROM_CPU_INTR0_SOURCE 24/**< interrupt0 generated from a CPU, level*/ /* Used for FreeRTOS */
217 #define ETS_FROM_CPU_INTR1_SOURCE 25/**< interrupt1 generated from a CPU, level*/ /* Used for FreeRTOS */
218 #define ETS_FROM_CPU_INTR2_SOURCE 26/**< interrupt2 generated from a CPU, level*/ /* Used for VHCI */
219 #define ETS_FROM_CPU_INTR3_SOURCE 27/**< interrupt3 generated from a CPU, level*/ /* Reserved */
220 #define ETS_SPI0_INTR_SOURCE 28/**< interrupt of SPI0, level, SPI0 is for Cache Access, do not use this*/
221 #define ETS_SPI1_INTR_SOURCE 29/**< interrupt of SPI1, level, SPI1 is for flash read/write, do not use this*/
222 #define ETS_SPI2_INTR_SOURCE 30/**< interrupt of SPI2, level*/
223 #define ETS_SPI3_INTR_SOURCE 31/**< interrupt of SPI3, level*/
224 #define ETS_I2S0_INTR_SOURCE 32/**< interrupt of I2S0, level*/
225 #define ETS_I2S1_INTR_SOURCE 33/**< interrupt of I2S1, level*/
226 #define ETS_UART0_INTR_SOURCE 34/**< interrupt of UART0, level*/
227 #define ETS_UART1_INTR_SOURCE 35/**< interrupt of UART1, level*/
228 #define ETS_UART2_INTR_SOURCE 36/**< interrupt of UART2, level*/
229 #define ETS_SDIO_HOST_INTR_SOURCE 37/**< interrupt of SD/SDIO/MMC HOST, level*/
230 #define ETS_ETH_MAC_INTR_SOURCE 38/**< interrupt of ethernet mac, level*/
231 #define ETS_PWM0_INTR_SOURCE 39/**< interrupt of PWM0, level, Reserved*/
232 #define ETS_PWM1_INTR_SOURCE 40/**< interrupt of PWM1, level, Reserved*/
233 #define ETS_PWM2_INTR_SOURCE 41/**< interrupt of PWM2, level*/
234 #define ETS_PWM3_INTR_SOURCE 42/**< interruot of PWM3, level*/
235 #define ETS_LEDC_INTR_SOURCE 43/**< interrupt of LED PWM, level*/
236 #define ETS_EFUSE_INTR_SOURCE 44/**< interrupt of efuse, level, not likely to use*/
237 #define ETS_CAN_INTR_SOURCE 45/**< interrupt of can, level*/
238 #define ETS_RTC_CORE_INTR_SOURCE 46/**< interrupt of rtc core, level, include rtc watchdog*/
239 #define ETS_RMT_INTR_SOURCE 47/**< interrupt of remote controller, level*/
240 #define ETS_PCNT_INTR_SOURCE 48/**< interrupt of pluse count, level*/
241 #define ETS_I2C_EXT0_INTR_SOURCE 49/**< interrupt of I2C controller1, level*/
242 #define ETS_I2C_EXT1_INTR_SOURCE 50/**< interrupt of I2C controller0, level*/
243 #define ETS_RSA_INTR_SOURCE 51/**< interrupt of RSA accelerator, level*/
244 #define ETS_SPI1_DMA_INTR_SOURCE 52/**< interrupt of SPI1 DMA, SPI1 is for flash read/write, do not use this*/
245 #define ETS_SPI2_DMA_INTR_SOURCE 53/**< interrupt of SPI2 DMA, level*/
246 #define ETS_SPI3_DMA_INTR_SOURCE 54/**< interrupt of SPI3 DMA, level*/
247 #define ETS_WDT_INTR_SOURCE 55/**< will be cancelled*/
248 #define ETS_TIMER1_INTR_SOURCE 56/**< will be cancelled*/
249 #define ETS_TIMER2_INTR_SOURCE 57/**< will be cancelled*/
250 #define ETS_TG0_T0_EDGE_INTR_SOURCE 58/**< interrupt of TIMER_GROUP0, TIMER0, EDGE*/
251 #define ETS_TG0_T1_EDGE_INTR_SOURCE 59/**< interrupt of TIMER_GROUP0, TIMER1, EDGE*/
252 #define ETS_TG0_WDT_EDGE_INTR_SOURCE 60/**< interrupt of TIMER_GROUP0, WATCH DOG, EDGE*/
253 #define ETS_TG0_LACT_EDGE_INTR_SOURCE 61/**< interrupt of TIMER_GROUP0, LACT, EDGE*/
254 #define ETS_TG1_T0_EDGE_INTR_SOURCE 62/**< interrupt of TIMER_GROUP1, TIMER0, EDGE*/
255 #define ETS_TG1_T1_EDGE_INTR_SOURCE 63/**< interrupt of TIMER_GROUP1, TIMER1, EDGE*/
256 #define ETS_TG1_WDT_EDGE_INTR_SOURCE 64/**< interrupt of TIMER_GROUP1, WATCHDOG, EDGE*/
257 #define ETS_TG1_LACT_EDGE_INTR_SOURCE 65/**< interrupt of TIMER_GROUP0, LACT, EDGE*/
258 #define ETS_MMU_IA_INTR_SOURCE 66/**< interrupt of MMU Invalid Access, LEVEL*/
259 #define ETS_MPU_IA_INTR_SOURCE 67/**< interrupt of MPU Invalid Access, LEVEL*/
260 #define ETS_CACHE_IA_INTR_SOURCE 68/**< interrupt of Cache Invalied Access, LEVEL*/
262 //interrupt cpu using table, Please see the core-isa.h
263 /*************************************************************************************************************
264 * Intr num Level Type PRO CPU usage APP CPU uasge
265 * 0 1 extern level WMAC Reserved
266 * 1 1 extern level BT/BLE Host VHCI Reserved
267 * 2 1 extern level FROM_CPU FROM_CPU
268 * 3 1 extern level TG0_WDT Reserved
269 * 4 1 extern level WBB
270 * 5 1 extern level BT Controller
271 * 6 1 timer FreeRTOS Tick(L1) FreeRTOS Tick(L1)
272 * 7 1 software Reserved Reserved
273 * 8 1 extern level BLE Controller
275 * 10 1 extern edge Internal Timer
279 * 14 7 nmi Reserved Reserved
280 * 15 3 timer FreeRTOS Tick(L3) FreeRTOS Tick(L3)
287 * 22 3 extern edge FRC1 timer
289 * 24 4 extern level TG1_WDT
290 * 25 4 extern level Reserved Reserved
291 * 26 5 extern level Reserved Reserved
292 * 27 3 extern level Reserved Reserved
294 * 29 3 software Reserved Reserved
295 * 30 4 extern edge Reserved Reserved
296 * 31 5 extern level Reserved Reserved
297 *************************************************************************************************************
300 //CPU0 Interrupt number reserved, not touch this.
301 #define ETS_WMAC_INUM 0
302 #define ETS_BT_HOST_INUM 1
303 #define ETS_FROM_CPU_INUM 2
304 #define ETS_T0_WDT_INUM 3
305 #define ETS_WBB_INUM 4
306 #define ETS_TG0_T1_INUM 10 /**< use edge interrupt*/
307 #define ETS_FRC1_INUM 22
308 #define ETS_T1_WDT_INUM 24
310 //CPU0 Interrupt number used in ROM, should be cancelled in SDK
311 #define ETS_SLC_INUM 1
312 #define ETS_UART0_INUM 5
313 #define ETS_UART1_INUM 5
314 //Other interrupt number should be managed by the user
317 #endif /* _ESP32_SOC_H_ */