menu "ESP32S3-Specific"
    visible if IDF_TARGET_ESP32S3

    menu "Cache config"

        choice ESP32S3_INSTRUCTION_CACHE_SIZE
            prompt "Instruction cache size"
            default ESP32S3_INSTRUCTION_CACHE_16KB
            help
                Instruction cache size to be set on application startup.
                If you use 16KB instruction cache rather than 32KB instruction cache,
                then the other 16KB will be managed by heap allocator.

            config ESP32S3_INSTRUCTION_CACHE_16KB
                bool "16KB"
            config ESP32S3_INSTRUCTION_CACHE_32KB
                bool "32KB"
        endchoice

        config ESP32S3_INSTRUCTION_CACHE_SIZE
            hex
            default 0x4000 if ESP32S3_INSTRUCTION_CACHE_16KB
            default 0x8000 if ESP32S3_INSTRUCTION_CACHE_32KB

        choice ESP32S3_ICACHE_ASSOCIATED_WAYS
            prompt "Instruction cache associated ways"
            default ESP32S3_INSTRUCTION_CACHE_8WAYS
            help
                Instruction cache associated ways to be set on application startup.

            config ESP32S3_INSTRUCTION_CACHE_4WAYS
                bool "4 ways"
            config ESP32S3_INSTRUCTION_CACHE_8WAYS
                bool "8 ways"
        endchoice

        config ESP32S3_ICACHE_ASSOCIATED_WAYS
            int
            default 4 if ESP32S3_INSTRUCTION_CACHE_4WAYS
            default 8 if ESP32S3_INSTRUCTION_CACHE_8WAYS

        choice ESP32S3_INSTRUCTION_CACHE_LINE_SIZE
            prompt "Instruction cache line size"
            default ESP32S3_INSTRUCTION_CACHE_LINE_32B
            help
                Instruction cache line size to be set on application startup.

            config ESP32S3_INSTRUCTION_CACHE_LINE_16B
                bool "16 Bytes"
                depends on ESP32S3_INSTRUCTION_CACHE_16KB
            config ESP32S3_INSTRUCTION_CACHE_LINE_32B
                bool "32 Bytes"
        endchoice

        config ESP32S3_INSTRUCTION_CACHE_LINE_SIZE
            int
            default 16 if ESP32S3_INSTRUCTION_CACHE_LINE_16B
            default 32 if ESP32S3_INSTRUCTION_CACHE_LINE_32B

        config ESP32S3_INSTRUCTION_CACHE_WRAP
            bool       ## TODO IDF-4307
            default "n"
            depends on !SPIRAM_ECC_ENABLE
            help
                If enabled, instruction cache will use wrap mode to read spi flash or spi ram.
                The wrap length equals to ESP32S3_INSTRUCTION_CACHE_LINE_SIZE.
                However, it depends on complex conditions.

        choice ESP32S3_DATA_CACHE_SIZE
            prompt "Data cache size"
            default ESP32S3_DATA_CACHE_32KB
            help
                Data cache size to be set on application startup.
                If you use 32KB data cache rather than 64KB data cache,
                the other 32KB will be added to the heap.

            config ESP32S3_DATA_CACHE_16KB
                bool "16KB"
            config ESP32S3_DATA_CACHE_32KB
                bool "32KB"
            config ESP32S3_DATA_CACHE_64KB
                bool "64KB"
        endchoice

        config ESP32S3_DATA_CACHE_SIZE
            hex
            # For 16KB the actual configuration is 32kb cache, but 16kb will be reserved for heap at startup
            default 0x8000 if ESP32S3_DATA_CACHE_16KB
            default 0x8000 if ESP32S3_DATA_CACHE_32KB
            default 0x10000 if ESP32S3_DATA_CACHE_64KB

        choice ESP32S3_DCACHE_ASSOCIATED_WAYS
            prompt "Data cache associated ways"
            default ESP32S3_DATA_CACHE_8WAYS
            help
                Data cache associated ways to be set on application startup.

            config ESP32S3_DATA_CACHE_4WAYS
                bool "4 ways"
            config ESP32S3_DATA_CACHE_8WAYS
                bool "8 ways"
        endchoice

        config ESP32S3_DCACHE_ASSOCIATED_WAYS
            int
            default 4 if ESP32S3_DATA_CACHE_4WAYS
            default 8 if ESP32S3_DATA_CACHE_8WAYS

        choice ESP32S3_DATA_CACHE_LINE_SIZE
            prompt "Data cache line size"
            default ESP32S3_DATA_CACHE_LINE_32B
            help
                Data cache line size to be set on application startup.

            config ESP32S3_DATA_CACHE_LINE_16B
                bool "16 Bytes"
                depends on ESP32S3_DATA_CACHE_16KB || ESP32S3_DATA_CACHE_32KB
            config ESP32S3_DATA_CACHE_LINE_32B
                bool "32 Bytes"
            config ESP32S3_DATA_CACHE_LINE_64B
                bool "64 Bytes"
        endchoice

        config ESP32S3_DATA_CACHE_LINE_SIZE
            int
            default 16 if ESP32S3_DATA_CACHE_LINE_16B
            default 32 if ESP32S3_DATA_CACHE_LINE_32B
            default 64 if ESP32S3_DATA_CACHE_LINE_64B

        config ESP32S3_DATA_CACHE_WRAP
            bool        ## TODO IDF-4307
            default "n"
            depends on !SPIRAM_ECC_ENABLE
            help
                If enabled, data cache will use wrap mode to read spi flash or spi ram.
                The wrap length equals to ESP32S3_DATA_CACHE_LINE_SIZE.
                However, it depends on complex conditions.

    endmenu  # Cache config

    # Hint: to support SPIRAM across multiple chips, check CONFIG_SPIRAM instead
    config ESP32S3_SPIRAM_SUPPORT
        bool "Support for external, SPI-connected RAM"
        default "n"
        select SPIRAM
        help
            This enables support for an external SPI RAM chip, connected in parallel with the
            main SPI flash chip.

    menu "SPI RAM config"
        depends on ESP32S3_SPIRAM_SUPPORT

        config SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
            bool
            default "y"

        choice SPIRAM_MODE
            prompt "Mode (QUAD/OCT) of SPI RAM chip in use"
            default SPIRAM_MODE_QUAD

            config SPIRAM_MODE_QUAD
                bool "Quad Mode PSRAM"

            config SPIRAM_MODE_OCT
                bool "Octal Mode PSRAM"
        endchoice

        choice SPIRAM_TYPE
            prompt "Type of SPIRAM chip in use"
            default SPIRAM_TYPE_AUTO

            config SPIRAM_TYPE_AUTO
                bool "Auto-detect"

            config SPIRAM_TYPE_ESPPSRAM16
                bool "ESP-PSRAM16 or APS1604"
                depends on SPIRAM_MODE_QUAD

            config SPIRAM_TYPE_ESPPSRAM32
                bool "ESP-PSRAM32 or IS25WP032"
                depends on SPIRAM_MODE_QUAD

            config SPIRAM_TYPE_ESPPSRAM64
                bool "ESP-PSRAM64 , LY68L6400 or APS6408"
        endchoice

        config SPIRAM_SIZE
            int
            default -1 if SPIRAM_TYPE_AUTO
            default 2097152 if SPIRAM_TYPE_ESPPSRAM16
            default 4194304 if SPIRAM_TYPE_ESPPSRAM32
            default 8388608 if SPIRAM_TYPE_ESPPSRAM64
            default 16777216 if SPIRAM_TYPE_ESPPSRAM128
            default 33554432 if SPIRAM_TYPE_ESPPSRAM256
            default 0

        menu "PSRAM Clock and CS IO for ESP32S3"
            depends on ESP32S3_SPIRAM_SUPPORT
            config DEFAULT_PSRAM_CLK_IO
                int "PSRAM CLK IO number"
                range 0 33
                default 30
                help
                    The PSRAM Clock IO can be any unused GPIO, please refer to your hardware design.

            config DEFAULT_PSRAM_CS_IO
                int "PSRAM CS IO number"
                range 0 33
                default 26
                help
                    The PSRAM CS IO can be any unused GPIO, please refer to your hardware design.
        endmenu
        config SPIRAM_FETCH_INSTRUCTIONS
            bool "Cache fetch instructions from SPI RAM"
            default n
            help
                If enabled, instruction in flash will be copied into SPIRAM.
                If SPIRAM_RODATA also enabled, you can run the instruction when erasing or programming the flash.

        config SPIRAM_RODATA
            bool "Cache load read only data from SPI RAM"
            default n
            help
                If enabled, rodata in flash will be copied into SPIRAM.
                If SPIRAM_FETCH_INSTRUCTIONS is also enabled,
                you can run the instruction when erasing or programming the flash.

        choice SPIRAM_SPEED
            prompt "Set RAM clock speed"
            default SPIRAM_SPEED_40M
            help
                Select the speed for the SPI RAM chip.

            config SPIRAM_SPEED_120M
                depends on SPIRAM_MODE_QUAD
                bool "120MHz clock speed"
            config SPIRAM_SPEED_80M
                bool "80MHz clock speed"
            config SPIRAM_SPEED_40M
                bool "40Mhz clock speed"
        endchoice

        config SPIRAM_SPEED
            int
            default 120 if SPIRAM_SPEED_120M
            default 80 if SPIRAM_SPEED_80M
            default 40 if SPIRAM_SPEED_40M

        source "$IDF_PATH/components/esp_hw_support/Kconfig.spiram.common"      # insert non-chip-specific items here

    endmenu

    config ESP32S3_MEMMAP_TRACEMEM
        bool
        default "n"

    config ESP32S3_MEMMAP_TRACEMEM_TWOBANKS
        bool
        default "n"

    config ESP32S3_TRAX
        bool "Use TRAX tracing feature"
        default "n"
        select ESP32S3_MEMMAP_TRACEMEM
        help
            The esp32-s3 contains a feature which allows you to trace the execution path the processor
            has taken through the program. This is stored in a chunk of 32K (16K for single-processor)
            of memory that can't be used for general purposes anymore. Disable this if you do not know
            what this is.

    config ESP32S3_TRAX_TWOBANKS
        bool "Reserve memory for tracing both pro as well as app cpu execution"
        default "n"
        depends on ESP32S3_TRAX && !FREERTOS_UNICORE
        select ESP32S3_MEMMAP_TRACEMEM_TWOBANKS
        help
            The esp32-s3 contains a feature which allows you to trace the execution path the processor
            has taken through the program. This is stored in a chunk of 32K (16K for single-processor)
            of memory that can't be used for general purposes anymore. Disable this if you do not know
            what this is.

    config ESP32S3_TRACEMEM_RESERVE_DRAM
        hex
        default 0x8000 if ESP32S3_MEMMAP_TRACEMEM && ESP32S3_MEMMAP_TRACEMEM_TWOBANKS
        default 0x4000 if ESP32S3_MEMMAP_TRACEMEM && !ESP32S3_MEMMAP_TRACEMEM_TWOBANKS
        default 0x0


    config ESP32S3_DEEP_SLEEP_WAKEUP_DELAY
        int "Extra delay in deep sleep wake stub (in us)"
        default 2000
        range 0 5000
        help
            When ESP32S3 exits deep sleep, the CPU and the flash chip are powered on
            at the same time. CPU will run deep sleep stub first, and then
            proceed to load code from flash. Some flash chips need sufficient
            time to pass between power on and first read operation. By default,
            without any extra delay, this time is approximately 900us, although
            some flash chip types need more than that.

            By default extra delay is set to 2000us. When optimizing startup time
            for applications which require it, this value may be reduced.

            If you are seeing "flash read err, 1000" message printed to the
            console after deep sleep reset, try increasing this value.

    config ESP32S3_RTCDATA_IN_FAST_MEM
        bool "Place RTC_DATA_ATTR and RTC_RODATA_ATTR variables into RTC fast memory segment"
        default n
        help
            This option allows to place .rtc_data and .rtc_rodata sections into
            RTC fast memory segment to free the slow memory region for ULP programs.

    config ESP32S3_USE_FIXED_STATIC_RAM_SIZE
        bool "Use fixed static RAM size"
        default n
        help
            If this option is disabled, the DRAM part of the heap starts right after the .bss section,
            within the dram0_0 region. As a result, adding or removing some static variables
            will change the available heap size.

            If this option is enabled, the DRAM part of the heap starts right after the dram0_0 region,
            where its length is set with ESP32S3_FIXED_STATIC_RAM_SIZE

    config ESP32S3_FIXED_STATIC_RAM_SIZE
        hex "Fixed Static RAM size"
        default 0x10000
        range 0 0x34000
        depends on ESP32S3_USE_FIXED_STATIC_RAM_SIZE
        help
            RAM size dedicated for static variables (.data & .bss sections).

endmenu  # ESP32S3-Specific