1 /*
2  * SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef _SOC_BOOT_MODE_H_
8 #define _SOC_BOOT_MODE_H_
9 
10 #include "soc.h"
11 
12 /*SPI Boot*/
13 #define IS_1XXX(v)                              (((v)&0x08)==0x08)
14 
15 /*Download Boot, USB/SPI(or SDIO_V2)/UART0/UART1*/
16 #define IS_01XX(v)                              (((v)&0x0c)==0x04)
17 
18 /*Download Boot, USB/SPI(or SDIO_V2)/UART0/UART1*/
19 #define IS_0100(v)                              (((v)&0x0f)==0x04)
20 
21 /*Download Boot, USB/SPI(or SDIO_V2)/UART0/UART1*/
22 #define IS_0101(v)                              (((v)&0x0f)==0x05)
23 
24 /*Download Boot, USB/SPI(or SDIO_V2)/UART0/UART1*/
25 #define IS_0110(v)                              (((v)&0x0f)==0x06)
26 
27 /*Download Boot, USB/SPI(or SDIO_V2)/UART0/UART1*/
28 #define IS_0111(v)                              (((v)&0x0f)==0x07)
29 
30 /*Diagnostic Mode1+USB download Mode*/
31 #define IS_0000(v)                              (((v)&0x0f)==0x00)
32 
33 /*SPI(or SDIO_V1) download Mode*/
34 #define IS_0001(v)                              (((v)&0x0f)==0x01)
35 
36 /*Diagnostic Mode0+UART0 download Mode*/
37 #define IS_0010(v)                              (((v)&0x0f)==0x02)
38 
39 /*ATE/ANALOG Mode*/
40 #define IS_0011(v)                              (((v)&0x0f)==0x03)
41 
42 /*print control*/
43 #define IS_X1XX(v)                              (((v)&0x04)==0x04)
44 
45 #define BOOT_MODE_GET()                         (GPIO_REG_READ(GPIO_STRAP_REG))
46 
47 #define ETS_PRINT_CONTROL_HIGH_LEVEL()          IS_X1XX(BOOT_MODE_GET())
48 
49 /*do not include download mode*/
50 #define ETS_IS_UART_BOOT()                      IS_0010(BOOT_MODE_GET())
51 
52 #define ETS_IS_USB_BOOT()                       IS_0000(BOOT_MODE_GET())
53 
54 /*all spi boot including spi/legacy*/
55 #define ETS_IS_FLASH_BOOT()                     IS_1XXX(BOOT_MODE_GET())
56 
57 /*all faster spi boot including spi*/
58 #define ETS_IS_FAST_FLASH_BOOT()                IS_1XXX(BOOT_MODE_GET())
59 
60 #if SUPPORT_SDIO_DOWNLOAD
61 
62 /*all sdio V2 of failing edge input, failing edge output*/
63 #define ETS_IS_SDIO_FEI_FEO_V2_BOOT()           IS_0100(BOOT_MODE_GET())
64 
65 /*all sdio V2 of failing edge input, raising edge output*/
66 #define ETS_IS_SDIO_FEI_REO_V2_BOOT()           IS_0101(BOOT_MODE_GET())
67 
68 /*all sdio V2 of raising edge input, failing edge output*/
69 #define ETS_IS_SDIO_REI_FEO_V2_BOOT()           IS_0110(BOOT_MODE_GET())
70 
71 /*all sdio V2 of raising edge input, raising edge output*/
72 #define ETS_IS_SDIO_REI_REO_V2_BOOT()           IS_0111(BOOT_MODE_GET())
73 
74 /*all sdio V1 of raising edge input, failing edge output*/
75 #define ETS_IS_SDIO_REI_FEO_V1_BOOT()           IS_0001(BOOT_MODE_GET())
76 
77 /*do not include joint download mode*/
78 #define ETS_IS_SDIO_BOOT()                      IS_0001(BOOT_MODE_GET())
79 #else
80 
81 /*do not include joint download mode*/
82 #define ETS_IS_SPI_DOWNLOAD_BOOT()              IS_0001(BOOT_MODE_GET())
83 
84 #endif
85 
86 /*joint download boot*/
87 #define ETS_IS_JOINT_DOWNLOAD_BOOT()            IS_01XX(BOOT_MODE_GET())
88 
89 /*ATE mode*/
90 #define ETS_IS_ATE_BOOT()                       IS_0011(BOOT_MODE_GET())
91 
92 /*used by  ETS_IS_SDIO_UART_BOOT*/
93 #define SEL_NO_BOOT                             0
94 #define SEL_SDIO_BOOT                           BIT0
95 #define SEL_UART_BOOT                           BIT1
96 #define SEL_SPI_SLAVE_BOOT                      BIT2
97 #define SEL_USB_BOOT                            BIT3
98 
99 #endif /* _SOC_BOOT_MODE_H_ */
100