diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d46807a3..b6c1f45f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,7 @@ before_script: - build artifacts: paths: - - "${IDF_PATH}/${IDF_EXAMPLE_PATH}/build*/build_log.txt" + - "artifacts_*/" when: always expire_in: 4 days script: @@ -21,37 +21,86 @@ before_script: # Replaces esp_hosted component in example's deps with the one from the current repository - export OVERRIDE_PATH=`pwd` - cd ${IDF_PATH}/${IDF_EXAMPLE_PATH} - - cat ${OVERRIDE_PATH}/.gitlab-ci-override-idf-component.yml >> main/idf_component.yml + # Create components directory and link esp_hosted component + - mkdir -p components + - ln -sf ${OVERRIDE_PATH} components/esp_hosted + - echo "Created components directory with esp_hosted link:" + - ls -la components/ + # Override component dependency as backup only if not already present + - | + if ! grep -q "esp_hosted" main/idf_component.yml 2>/dev/null; then + cat ${OVERRIDE_PATH}/.gitlab-ci-override-idf-component.yml >> main/idf_component.yml + echo "Added esp_hosted override to idf_component.yml" + fi + # Add slave target configuration if specified + - | + if [ ! -z "${IDF_SLAVE_TARGET}" ]; then + echo "CONFIG_SLAVE_IDF_TARGET_${IDF_SLAVE_TARGET^^}=y" >> sdkconfig.defaults + echo "Added slave target CONFIG_SLAVE_IDF_TARGET_${IDF_SLAVE_TARGET^^}=y to sdkconfig.defaults" + fi # Build with IDF pedantic flags and IDF build apps script - export PEDANTIC_FLAGS="-DIDF_CI_BUILD -Werror -Werror=deprecated-declarations -Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function" - export EXTRA_CFLAGS="${PEDANTIC_FLAGS} -Wstrict-prototypes" - export EXTRA_CXXFLAGS="${PEDANTIC_FLAGS}" + # Remove the conflicting extconn config that disables hosted + - rm -f sdkconfig.ci.*extconn* - idf-build-apps find --config sdkconfig.ci* -vv --target ${IDF_TARGET} - idf-build-apps build --config sdkconfig.ci* -vv --target ${IDF_TARGET} +# - echo "----------- last sdkconfig.defaults,ci* used (${IDF_TARGET}-${IDF_SLAVE_TARGET}) --------------" +# - cat sdkconfig.defaults +# - cat sdkconfig.ci* +# - echo "----------- last (generated) sdkconfig used (${IDF_TARGET}-${IDF_SLAVE_TARGET}) --------------" +# - cat sdkconfig +# - echo "----------------------------------------------" + # Copy config files back to project directory for artifacts + - mkdir -p ${OVERRIDE_PATH}/artifacts_${IDF_TARGET}_${IDF_SLAVE_TARGET} + - cp sdkconfig* ${OVERRIDE_PATH}/artifacts_${IDF_TARGET}_${IDF_SLAVE_TARGET}/ 2>/dev/null || echo "No sdkconfig files found" + - cp main/idf_component.yml ${OVERRIDE_PATH}/artifacts_${IDF_TARGET}_${IDF_SLAVE_TARGET}/ 2>/dev/null || echo "No component file found" + # Clean up the component symlink + - unlink components/esp_hosted + - echo "Cleaned up esp_hosted component symlink" # Rename back, since post scripts expect the original name - cd ${OVERRIDE_PATH} && cd .. && mv esp_hosted esp_hosted_mcu build_idf_v5.3: extends: .build_template - image: espressif/idf:release-v5.3 + image: espressif/idf:${IDF_VER} parallel: matrix: - - IDF_TARGET: ["esp32p4", "esp32h2", "esp32s3"] + - IDF_VER: ["v5.3.1", "v5.3.2", "v5.3.3", "release-v5.3"] + IDF_TARGET: ["esp32p4", "esp32h2"] + IDF_SLAVE_TARGET: ["esp32c6"] IDF_EXAMPLE_PATH: examples/protocols/mqtt/tcp + #IDF_EXAMPLE_PATH: [examples/wifi/iperf] build_idf_v5.4: extends: .build_template - image: espressif/idf:release-v5.4 + image: espressif/idf:${IDF_VER} parallel: matrix: - - IDF_TARGET: ["esp32p4", "esp32h2", "esp32s3"] + - IDF_VER: ["v5.4", "v5.4.1", "v5.4.2", "release-v5.4"] + IDF_TARGET: ["esp32p4", "esp32h2"] + IDF_SLAVE_TARGET: ["esp32c6"] IDF_EXAMPLE_PATH: examples/protocols/mqtt/tcp + #IDF_EXAMPLE_PATH: [examples/wifi/iperf] build_idf_v5.5: + extends: .build_template + image: espressif/idf:${IDF_VER} + parallel: + matrix: + - IDF_VER: ["release-v5.5"] + IDF_TARGET: ["esp32p4", "esp32h2"] + IDF_SLAVE_TARGET: ["esp32c6", "esp32c5", "esp32", "esp32c2", "esp32c3", "esp32s3" ] + IDF_EXAMPLE_PATH: [examples/wifi/iperf] + +build_idf_master: extends: .build_template image: espressif/idf:latest + allow_failure: true parallel: matrix: - - IDF_TARGET: ["esp32p4", "esp32h2", "esp32s3"] + - IDF_TARGET: ["esp32p4", "esp32h2"] + IDF_SLAVE_TARGET: ["esp32c6", "esp32c5", "esp32", "esp32c2", "esp32c3", "esp32s3" ] IDF_EXAMPLE_PATH: [examples/protocols/mqtt/tcp, examples/wifi/iperf] diff --git a/CMakeLists.txt b/CMakeLists.txt index 7054dfc3..3f79b2fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,80 +3,82 @@ if(CONFIG_ESP_HOSTED_ENABLED) set(FG_root_dir ".") set(host_dir "${FG_root_dir}/host") - set(COMPONENT_SRCS "${host_dir}/esp_hosted_host_init.c" "${host_dir}/api/src/esp_wifi_weak.c" "${host_dir}/api/src/esp_hosted_api.c" "${host_dir}/drivers/transport/transport_drv.c" "${host_dir}/drivers/serial/serial_ll_if.c" "${host_dir}/utils/common.c" "${host_dir}/utils/util.c" "${host_dir}/utils/stats.c" "${host_dir}/drivers/serial/serial_drv.c") + set(srcs "${host_dir}/esp_hosted_host_init.c" "${host_dir}/api/src/esp_wifi_weak.c" "${host_dir}/api/src/esp_hosted_api.c" "${host_dir}/drivers/transport/transport_drv.c" "${host_dir}/drivers/serial/serial_ll_if.c" "${host_dir}/utils/common.c" "${host_dir}/utils/util.c" "${host_dir}/utils/stats.c" "${host_dir}/drivers/serial/serial_drv.c") # only these directories are public. Others are private - set(COMPONENT_ADD_PUBLIC_INCLUDEDIRS "${host_dir}" "${host_dir}/api/include") + set(pub_include "${host_dir}" "${host_dir}/api/include") - set(COMPONENT_ADD_INCLUDEDIRS "${host_dir}/drivers/transport" "${host_dir}/drivers/transport/spi" "${host_dir}/drivers/transport/sdio" "${host_dir}/drivers/serial" "${host_dir}/utils") + set(priv_include "${host_dir}/drivers/transport" "${host_dir}/drivers/transport/spi" "${host_dir}/drivers/transport/sdio" "${host_dir}/drivers/serial" "${host_dir}/utils" "${host_dir}/api/priv") # rpc files - wrap -> slaveif -> core set(rpc_dir "${host_dir}/drivers/rpc") set(rpc_core_dir "${rpc_dir}/core") set(rpc_slaveif_dir "${rpc_dir}/slaveif") set(rpc_wrap_dir "${rpc_dir}/wrap") - list(APPEND COMPONENT_SRCS "${rpc_core_dir}/rpc_core.c" "${rpc_core_dir}/rpc_req.c" "${rpc_core_dir}/rpc_rsp.c" "${rpc_core_dir}/rpc_evt.c" + list(APPEND srcs "${rpc_core_dir}/rpc_core.c" "${rpc_core_dir}/rpc_req.c" "${rpc_core_dir}/rpc_rsp.c" "${rpc_core_dir}/rpc_evt.c" "${rpc_slaveif_dir}/rpc_slave_if.c" "${rpc_wrap_dir}/rpc_wrap.c") - list(APPEND COMPONENT_ADD_INCLUDEDIRS "${rpc_core_dir}" "${rpc_slaveif_dir}" "${rpc_wrap_dir}") + list(APPEND priv_include "${rpc_core_dir}" "${rpc_slaveif_dir}" "${rpc_wrap_dir}") # virtual serial set(virt_serial_dir "${host_dir}/drivers/virtual_serial_if") - list(APPEND COMPONENT_SRCS "${virt_serial_dir}/serial_if.c") - list(APPEND COMPONENT_ADD_INCLUDEDIRS "${virt_serial_dir}") + list(APPEND srcs "${virt_serial_dir}/serial_if.c") + list(APPEND priv_include "${virt_serial_dir}") # mempool - list(APPEND COMPONENT_SRCS "${host_dir}/drivers/mempool/mempool.c") - list(APPEND COMPONENT_ADD_INCLUDEDIRS "${host_dir}/drivers/mempool" ) + list(APPEND srcs "${host_dir}/drivers/mempool/mempool.c") + list(APPEND priv_include "${host_dir}/drivers/mempool" ) # slave and host common files set(common_dir "${FG_root_dir}/common") - list(APPEND COMPONENT_SRCS "${common_dir}/protobuf-c/protobuf-c/protobuf-c.c" "${common_dir}/proto/esp_hosted_rpc.pb-c.c" ) - list(APPEND COMPONENT_ADD_INCLUDEDIRS "${common_dir}" "${common_dir}/log" "${common_dir}/rpc" "${common_dir}/transport" "${common_dir}/protobuf-c" "${common_dir}/proto" ) + list(APPEND srcs "${common_dir}/protobuf-c/protobuf-c/protobuf-c.c" "${common_dir}/proto/esp_hosted_rpc.pb-c.c" ) + list(APPEND priv_include "${common_dir}" "${common_dir}/log" "${common_dir}/rpc" "${common_dir}/transport" "${common_dir}/protobuf-c" "${common_dir}/proto" ) + + # host ESP32 specific files + list(APPEND srcs "${host_dir}/port/esp/freertos/src/esp_hosted_ota.c") # bt (NimBLE) ### TODO config for HCI over UART - list(APPEND COMPONENT_ADD_INCLUDEDIRS "${host_dir}/drivers/bt") + list(APPEND priv_include "${host_dir}/drivers/bt") if(CONFIG_ESP_HOSTED_NIMBLE_HCI_VHCI OR CONFIG_ESP_HOSTED_BLUEDROID_HCI_VHCI) - list(APPEND COMPONENT_SRCS "${host_dir}/drivers/bt/vhci_drv.c") + list(APPEND srcs "${host_dir}/drivers/bt/vhci_drv.c") else() - list(APPEND COMPONENT_SRCS "${host_dir}/drivers/bt/hci_stub_drv.c") + list(APPEND srcs "${host_dir}/drivers/bt/hci_stub_drv.c") endif() # transport files if(CONFIG_ESP_HOSTED_SDIO_HOST_INTERFACE) - list(APPEND COMPONENT_SRCS "${host_dir}/drivers/transport/sdio/sdio_drv.c") + list(APPEND srcs "${host_dir}/drivers/transport/sdio/sdio_drv.c") elseif(CONFIG_ESP_HOSTED_SPI_HD_HOST_INTERFACE) - list(APPEND COMPONENT_SRCS "${host_dir}/drivers/transport/spi_hd/spi_hd_drv.c") + list(APPEND srcs "${host_dir}/drivers/transport/spi_hd/spi_hd_drv.c") elseif(CONFIG_ESP_HOSTED_SPI_HOST_INTERFACE) - list(APPEND COMPONENT_SRCS "${host_dir}/drivers/transport/spi/spi_drv.c") + list(APPEND srcs "${host_dir}/drivers/transport/spi/spi_drv.c") elseif(CONFIG_ESP_HOSTED_UART_HOST_INTERFACE) - list(APPEND COMPONENT_SRCS "${host_dir}/drivers/transport/uart/uart_drv.c") + list(APPEND srcs "${host_dir}/drivers/transport/uart/uart_drv.c") endif() # config files - list(APPEND COMPONENT_ADD_INCLUDEDIRS "${host_dir}/port/include") - list(APPEND COMPONENT_SRCS "${host_dir}/port/src/esp_hosted_config.c" "${host_dir}/port/src/esp_hosted_transport_config.c") + list(APPEND priv_include "${host_dir}/port/esp/freertos/include") + list(APPEND srcs "${host_dir}/port/esp/freertos/src/esp_hosted_config.c" "${host_dir}/port/esp/freertos/src/esp_hosted_transport_config.c") # transport port files - list(APPEND COMPONENT_SRCS "${host_dir}/port/src/os_wrapper.c") + list(APPEND srcs "${host_dir}/port/esp/freertos/src/os_wrapper.c") if(CONFIG_ESP_HOSTED_SDIO_HOST_INTERFACE) - list(APPEND COMPONENT_SRCS "${host_dir}/port/src/sdio_wrapper.c") + list(APPEND srcs "${host_dir}/port/esp/freertos/src/sdio_wrapper.c") elseif(CONFIG_ESP_HOSTED_SPI_HD_HOST_INTERFACE) - list(APPEND COMPONENT_SRCS "${host_dir}/port/src/spi_hd_wrapper.c") + list(APPEND srcs "${host_dir}/port/esp/freertos/src/spi_hd_wrapper.c") elseif(CONFIG_ESP_HOSTED_SPI_HOST_INTERFACE) - list(APPEND COMPONENT_SRCS "${host_dir}/port/src/spi_wrapper.c") + list(APPEND srcs "${host_dir}/port/esp/freertos/src/spi_wrapper.c") elseif(CONFIG_ESP_HOSTED_UART_HOST_INTERFACE) - list(APPEND COMPONENT_SRCS "${host_dir}/port/src/uart_wrapper.c") + list(APPEND srcs "${host_dir}/port/esp/freertos/src/uart_wrapper.c") endif() endif() -idf_component_register(SRCS ${COMPONENT_SRCS} +idf_component_register(SRCS ${srcs} PRIV_REQUIRES soc esp_event esp_netif esp_timer driver esp_wifi bt esp_http_client - EXCLUDE_SRCS ${EXCLUDE_COMPONENT_SRCS} - INCLUDE_DIRS ${COMPONENT_ADD_PUBLIC_INCLUDEDIRS} - PRIV_INCLUDE_DIRS ${COMPONENT_ADD_INCLUDEDIRS}) + INCLUDE_DIRS ${pub_include} + PRIV_INCLUDE_DIRS ${priv_include}) idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE TRUE) diff --git a/Kconfig b/Kconfig index 005c49e7..929e3567 100644 --- a/Kconfig +++ b/Kconfig @@ -27,7 +27,7 @@ menu "ESP-Hosted config" # y if SDIO Transport is available, based on host and slave selection config ESP_HOSTED_PRIV_SDIO_OPTION bool - default y if (IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32P4) && (SLAVE_IDF_TARGET_ESP32 || SLAVE_IDF_TARGET_ESP32C6) + default y if (IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32P4) && (SLAVE_IDF_TARGET_ESP32 || SLAVE_IDF_TARGET_ESP32C6 || SLAVE_IDF_TARGET_ESP32C5) default n # y if SPI HD Transport is available, based on host and slave selection @@ -189,8 +189,10 @@ menu "ESP-Hosted config" depends on ESP_HOSTED_SPI_HSPI int "GPIO pin for Host MOSI" default 14 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C6 + default 23 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 default 13 if IDF_TARGET_ESP32 default 11 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 + default 5 if IDF_TARGET_ESP32H2 default 7 help SPI controller Host MOSI @@ -199,8 +201,10 @@ menu "ESP-Hosted config" depends on ESP_HOSTED_SPI_HSPI int "GPIO pin for Host MISO" default 15 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C6 + default 22 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 default 12 if IDF_TARGET_ESP32 default 13 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 + default 0 if IDF_TARGET_ESP32H2 default 2 help SPI controller Host MISO @@ -209,8 +213,10 @@ menu "ESP-Hosted config" depends on ESP_HOSTED_SPI_HSPI int "GPIO pin for Host CLK" default 18 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C6 + default 33 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 default 14 if IDF_TARGET_ESP32 default 12 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 + default 4 if IDF_TARGET_ESP32H2 default 6 help SPI controller Host CLK @@ -219,8 +225,10 @@ menu "ESP-Hosted config" depends on ESP_HOSTED_SPI_HSPI int "GPIO pin for Host CS" default 19 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C6 + default 4 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 default 15 if IDF_TARGET_ESP32 default 10 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 + default 1 if IDF_TARGET_ESP32H2 default 10 help SPI controller Host CS @@ -276,8 +284,10 @@ menu "ESP-Hosted config" config ESP_HOSTED_SPI_GPIO_HANDSHAKE int "GPIO pin for handshake" default 16 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C6 + default 21 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 default 3 if IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C6 default 17 if IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32S2 + default 22 if IDF_TARGET_ESP32H2 default 26 help GPIO pin to use for handshake with other spi controller @@ -285,6 +295,8 @@ menu "ESP-Hosted config" config ESP_HOSTED_SPI_GPIO_DATA_READY int "GPIO pin for data ready interrupt" default 17 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C6 + default 32 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 12 if IDF_TARGET_ESP32H2 default 4 help GPIO pin for indicating host that SPI slave has data to be read by host @@ -292,6 +304,8 @@ menu "ESP-Hosted config" config ESP_HOSTED_SPI_GPIO_RESET_SLAVE int "GPIO pin for Reseting slave ESP" default 54 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C6 + default 53 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 10 if IDF_TARGET_ESP32H2 default 5 help GPIO pin for Resetting ESP SPI slave device. Should be connected to RST/EN of ESP SPI slave device. @@ -322,7 +336,7 @@ ESP32XX_SPI_CLK_FREQ_RANGE_MAX := 40 config ESP_HOSTED_SPI_FREQ_ESP32XX depends on SLAVE_IDF_TARGET_ESP32C2 || SLAVE_IDF_TARGET_ESP32C3 || SLAVE_IDF_TARGET_ESP32S2 || SLAVE_IDF_TARGET_ESP32S3 || SLAVE_IDF_TARGET_ESP32C5 int "SPI Clock Freq" - default 30 if SLAVE_IDF_TARGET_ESP32C2 || SLAVE_IDF_TARGET_ESP32C3 || SLAVE_IDF_TARGET_ESP32S2 || SLAVE_IDF_TARGET_ESP32S3 || SLAVE_IDF_TARGET_ESP32C5 + default 40 if SLAVE_IDF_TARGET_ESP32C2 || SLAVE_IDF_TARGET_ESP32C3 || SLAVE_IDF_TARGET_ESP32S2 || SLAVE_IDF_TARGET_ESP32S3 || SLAVE_IDF_TARGET_ESP32C5 range $(ESP32XX_SPI_CLK_FREQ_RANGE_MIN) $(ESP32XX_SPI_CLK_FREQ_RANGE_MAX) help "Optimize SPI CLK by increasing till host practically can support" @@ -393,13 +407,45 @@ ESP32XX_SPI_CLK_FREQ_RANGE_MAX := 40 endchoice - config ESP_HOSTED_SDIO_GPIO_RESET_SLAVE - int "GPIO pin for Reseting slave ESP" - default 54 if IDF_TARGET_ESP32P4 - default 42 if IDF_TARGET_ESP32S3 - default 5 + choice + prompt "SDIO Slot To Use" + default ESP_HOSTED_SDIO_SLOT_1 help - GPIO pin for Resetting ESP SDIO slave device. Should be connected to RST/EN of ESP SDIO slave device. + On the ESP32-P4 EV Board: + - Slot 0 connects to the MicroSD Card slot + - Slot 1 connects to the on-board ESP32-C6 + For the ESP32, Slot 0 is usually occupied by SPI Flash and not usable for SDIO. + For the ESP32-P4, Slot 0 is IOMUXed and GPIO values cannot be changed + + config ESP_HOSTED_SDIO_SLOT_0 + depends on IDF_TARGET_ESP32P4 || IDF_TARGET_ESP32S3 + bool "Slot 0" + + config ESP_HOSTED_SDIO_SLOT_1 + bool "Slot 1" + endchoice + + config ESP_HOSTED_SDIO_SLOT + int + default 0 if ESP_HOSTED_SDIO_SLOT_0 + default 1 if ESP_HOSTED_SDIO_SLOT_1 + + config ESP_HOSTED_SD_PWR_CTRL_LDO_INTERNAL_IO + depends on SOC_SDMMC_IO_POWER_EXTERNAL + bool "SDIO power supply comes from internal LDO IO (READ HELP!)" + default n + help + Only needed when the SDIO module is connected to specific IO pins which can be used for high-speed SDIO. + Please read the schematic first and check if the SD VDD is connected to any internal LDO output. + Unselect this option if the SDIO is powered by an external power supply. + For ESP32-P4 EV Board, SDMMC slot 0 may require internal LDO output. + + config ESP_HOSTED_SD_PWR_CTRL_LDO_IO_ID + depends on SOC_SDMMC_IO_POWER_EXTERNAL && ESP_HOSTED_SD_PWR_CTRL_LDO_INTERNAL_IO + int "LDO ID" + default 4 if IDF_TARGET_ESP32P4 + help + Please check your schematic first and input your LDO ID. choice prompt "SDIO Bus Width" @@ -432,64 +478,317 @@ ESP32XX_SDIO_CLK_FREQ_KHZ_RANGE_MAX := 50000 help "Optimize SDIO CLK by increasing till host practically can support. Clock frequency for ESP32-P4 as host <= 40MHz" - config ESP_HOSTED_SDIO_PIN_CMD + config ESP_HOSTED_CUSTOM_SDIO_PINS + bool "Use custom SDIO GPIO pins" + default n + help + Enable this to use custom GPIO pins for SDIO on ESP32-P4 and ESP32-S3. + ESP32 has fixed GPIOs for SDIO host (Do not use custom GPIOs) + ESP32-P4 slot 0 is fixed GPIOs for SDIO host (Do not use custom GPIOs) + ESP32-P4 slot 1, ESP32-S3 slot 0/1 is flexible GPIOs for SDIO host (Flexible GPIOs) + + config ESP_HOSTED_SDIO_CMD_GPIO_RANGE_MIN + int + default 4 if !ESP_HOSTED_CUSTOM_SDIO_PINS && SLAVE_IDF_TARGET_ESP32C5 && IDF_TARGET_ESP32P4 + default 19 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32P4 + default 15 if IDF_TARGET_ESP32 + default 0 + + config ESP_HOSTED_SDIO_CMD_GPIO_RANGE_MAX + int + default 4 if !ESP_HOSTED_CUSTOM_SDIO_PINS && SLAVE_IDF_TARGET_ESP32C5 && IDF_TARGET_ESP32P4 + default 19 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32P4 + default 15 if IDF_TARGET_ESP32 + default 100 + + config ESP_HOSTED_SDIO_CLK_GPIO_RANGE_MIN + int + default 33 if !ESP_HOSTED_CUSTOM_SDIO_PINS && SLAVE_IDF_TARGET_ESP32C5 && IDF_TARGET_ESP32P4 + default 18 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32P4 + default 14 if IDF_TARGET_ESP32 + default 0 + + config ESP_HOSTED_SDIO_CLK_GPIO_RANGE_MAX + int + default 33 if !ESP_HOSTED_CUSTOM_SDIO_PINS && SLAVE_IDF_TARGET_ESP32C5 && IDF_TARGET_ESP32P4 + default 18 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32P4 + default 14 if IDF_TARGET_ESP32 + default 100 + + config ESP_HOSTED_SDIO_D0_GPIO_RANGE_MIN + int + default 20 if !ESP_HOSTED_CUSTOM_SDIO_PINS && SLAVE_IDF_TARGET_ESP32C5 && IDF_TARGET_ESP32P4 + default 14 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32P4 + default 2 if IDF_TARGET_ESP32 + default 0 + + config ESP_HOSTED_SDIO_D0_GPIO_RANGE_MAX + int + default 20 if !ESP_HOSTED_CUSTOM_SDIO_PINS && SLAVE_IDF_TARGET_ESP32C5 && IDF_TARGET_ESP32P4 + default 14 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32P4 + default 2 if IDF_TARGET_ESP32 + default 100 + + config ESP_HOSTED_SDIO_D1_GPIO_RANGE_MIN + int + default 23 if !ESP_HOSTED_CUSTOM_SDIO_PINS && SLAVE_IDF_TARGET_ESP32C5 && IDF_TARGET_ESP32P4 + default 15 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32P4 + default 4 if IDF_TARGET_ESP32 + default 0 + + config ESP_HOSTED_SDIO_D1_GPIO_RANGE_MAX + int + default 23 if !ESP_HOSTED_CUSTOM_SDIO_PINS && SLAVE_IDF_TARGET_ESP32C5 && IDF_TARGET_ESP32P4 + default 15 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32P4 + default 4 if IDF_TARGET_ESP32 + default 100 + + config ESP_HOSTED_SDIO_D2_GPIO_RANGE_MIN + int + default 21 if !ESP_HOSTED_CUSTOM_SDIO_PINS && SLAVE_IDF_TARGET_ESP32C5 && IDF_TARGET_ESP32P4 + default 16 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32P4 + default 12 if IDF_TARGET_ESP32 + default 0 + + config ESP_HOSTED_SDIO_D2_GPIO_RANGE_MAX + int + default 21 if !ESP_HOSTED_CUSTOM_SDIO_PINS && SLAVE_IDF_TARGET_ESP32C5 && IDF_TARGET_ESP32P4 + default 16 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32P4 + default 12 if IDF_TARGET_ESP32 + default 100 + + config ESP_HOSTED_SDIO_D3_GPIO_RANGE_MIN + int + default 22 if !ESP_HOSTED_CUSTOM_SDIO_PINS && SLAVE_IDF_TARGET_ESP32C5 && IDF_TARGET_ESP32P4 + default 17 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32P4 + default 13 if IDF_TARGET_ESP32 + default 0 + + config ESP_HOSTED_SDIO_D3_GPIO_RANGE_MAX + int + default 22 if !ESP_HOSTED_CUSTOM_SDIO_PINS && SLAVE_IDF_TARGET_ESP32C5 && IDF_TARGET_ESP32P4 + default 17 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32P4 + default 13 if IDF_TARGET_ESP32 + default 100 + + config ESP_HOSTED_SDIO_RESET_SLAVE_GPIO_MIN + int + default 53 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 54 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32P4 + default 42 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32S3 + default 5 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32 + default 0 + help + GPIO pin for Resetting ESP SDIO slave device. Should be connected to RST/EN of ESP SDIO slave device. + + config ESP_HOSTED_SDIO_RESET_SLAVE_GPIO_MAX + int + default 53 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 54 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32P4 + default 42 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32S3 + default 5 if !ESP_HOSTED_CUSTOM_SDIO_PINS && IDF_TARGET_ESP32 + default 100 + +### *START* GPIO SDIO pin configurations for Slot 0 and 1 + config ESP_HOSTED_PRIV_SDIO_PIN_CMD_SLOT_0 + depends on ESP_HOSTED_SDIO_SLOT_0 int "CMD GPIO number" default 47 if IDF_TARGET_ESP32S3 - default 19 if IDF_TARGET_ESP32P4 + range 44 44 if IDF_TARGET_ESP32P4 range 15 15 if IDF_TARGET_ESP32 help "Value can only be configured for some targets. Displayed always for reference." - config ESP_HOSTED_SDIO_PIN_CLK + config ESP_HOSTED_PRIV_SDIO_PIN_CMD_SLOT_1 + depends on ESP_HOSTED_SDIO_SLOT_1 + int "CMD GPIO number" + default 47 if IDF_TARGET_ESP32S3 + default 4 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 19 if IDF_TARGET_ESP32P4 + default 15 if IDF_TARGET_ESP32 + range ESP_HOSTED_SDIO_CMD_GPIO_RANGE_MIN ESP_HOSTED_SDIO_CMD_GPIO_RANGE_MAX + help + CMD GPIO pin for SDIO. Range enforced dynamically based on slave target to ensure IOMUX compliance. + Enable 'Use custom SDIO GPIO pins' to disable range restrictions. + + config ESP_HOSTED_PRIV_SDIO_PIN_CLK_SLOT_0 + depends on ESP_HOSTED_SDIO_SLOT_0 int "CLK GPIO number" default 19 if IDF_TARGET_ESP32S3 - default 18 if IDF_TARGET_ESP32P4 + range 43 43 if IDF_TARGET_ESP32P4 range 14 14 if IDF_TARGET_ESP32 help "Value can only be configured for some targets. Displayed always for reference." - config ESP_HOSTED_SDIO_PIN_D0 + config ESP_HOSTED_PRIV_SDIO_PIN_CLK_SLOT_1 + depends on ESP_HOSTED_SDIO_SLOT_1 + int "CLK GPIO number" + default 19 if IDF_TARGET_ESP32S3 + default 33 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 18 if IDF_TARGET_ESP32P4 + default 14 if IDF_TARGET_ESP32 + range ESP_HOSTED_SDIO_CLK_GPIO_RANGE_MIN ESP_HOSTED_SDIO_CLK_GPIO_RANGE_MAX + help + CLK GPIO pin for SDIO. Range enforced dynamically based on slave target to ensure IOMUX compliance. + Enable 'Use custom SDIO GPIO pins' to disable range restrictions. + + config ESP_HOSTED_PRIV_SDIO_PIN_D0_SLOT_0 + depends on ESP_HOSTED_SDIO_SLOT_0 int "D0 GPIO number" default 13 if IDF_TARGET_ESP32S3 - default 14 if IDF_TARGET_ESP32P4 + range 39 39 if IDF_TARGET_ESP32P4 range 2 2 if IDF_TARGET_ESP32 help "Value can only be configured for some targets. Displayed always for reference." + config ESP_HOSTED_PRIV_SDIO_PIN_D0_SLOT_1 + depends on ESP_HOSTED_SDIO_SLOT_1 + int "D0 GPIO number" + default 13 if IDF_TARGET_ESP32S3 + default 20 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 14 if IDF_TARGET_ESP32P4 + default 2 if IDF_TARGET_ESP32 + range ESP_HOSTED_SDIO_D0_GPIO_RANGE_MIN ESP_HOSTED_SDIO_D0_GPIO_RANGE_MAX + help + D0 GPIO pin for SDIO. Range enforced dynamically based on slave target to ensure IOMUX compliance. + Enable 'Use custom SDIO GPIO pins' to disable range restrictions. + if ESP_HOSTED_SDIO_4_BIT_BUS - config ESP_HOSTED_SDIO_PRIV_PIN_D1_4BIT_BUS + config ESP_HOSTED_PRIV_SDIO_PIN_D1_4BIT_BUS_SLOT_0 + depends on ESP_HOSTED_SDIO_SLOT_0 int "D1 GPIO number" default 35 if IDF_TARGET_ESP32S3 - default 15 if IDF_TARGET_ESP32P4 + range 40 40 if IDF_TARGET_ESP32P4 range 4 4 if IDF_TARGET_ESP32 help "Value can only be configured for some targets. Displayed always for reference." - config ESP_HOSTED_SDIO_PIN_D2 + config ESP_HOSTED_PRIV_SDIO_PIN_D1_4BIT_BUS_SLOT_1 + depends on ESP_HOSTED_SDIO_SLOT_1 + int "D1 GPIO number" + default 35 if IDF_TARGET_ESP32S3 + default 23 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 15 if IDF_TARGET_ESP32P4 + default 4 if IDF_TARGET_ESP32 + range ESP_HOSTED_SDIO_D1_GPIO_RANGE_MIN ESP_HOSTED_SDIO_D1_GPIO_RANGE_MAX + help + D1 GPIO pin for SDIO. Range enforced dynamically based on slave target to ensure IOMUX compliance. + Enable 'Use custom SDIO GPIO pins' to disable range restrictions. + + config ESP_HOSTED_PRIV_SDIO_PIN_D2_4BIT_BUS_SLOT_0 + depends on ESP_HOSTED_SDIO_SLOT_0 int "D2 GPIO number" default 20 if IDF_TARGET_ESP32S3 - default 16 if IDF_TARGET_ESP32P4 + range 41 41 if IDF_TARGET_ESP32P4 range 12 12 if IDF_TARGET_ESP32 help "Value can only be configured for some targets. Displayed always for reference." - config ESP_HOSTED_SDIO_PIN_D3 + config ESP_HOSTED_PRIV_SDIO_PIN_D2_4BIT_BUS_SLOT_1 + depends on ESP_HOSTED_SDIO_SLOT_1 + int "D2 GPIO number" + default 20 if IDF_TARGET_ESP32S3 + default 21 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 16 if IDF_TARGET_ESP32P4 + default 12 if IDF_TARGET_ESP32 + range ESP_HOSTED_SDIO_D2_GPIO_RANGE_MIN ESP_HOSTED_SDIO_D2_GPIO_RANGE_MAX + help + D2 GPIO pin for SDIO. Range enforced dynamically based on slave target to ensure IOMUX compliance. + Enable 'Use custom SDIO GPIO pins' to disable range restrictions. + + config ESP_HOSTED_PRIV_SDIO_PIN_D3_4BIT_BUS_SLOT_0 + depends on ESP_HOSTED_SDIO_SLOT_0 int "D3 GPIO number" default 9 if IDF_TARGET_ESP32S3 - default 17 if IDF_TARGET_ESP32P4 + range 42 42 if IDF_TARGET_ESP32P4 range 13 13 if IDF_TARGET_ESP32 help "Value can only be configured for some targets. Displayed always for reference." + + config ESP_HOSTED_PRIV_SDIO_PIN_D3_4BIT_BUS_SLOT_1 + depends on ESP_HOSTED_SDIO_SLOT_1 + int "D3 GPIO number" + default 9 if IDF_TARGET_ESP32S3 + default 22 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 17 if IDF_TARGET_ESP32P4 + default 13 if IDF_TARGET_ESP32 + range ESP_HOSTED_SDIO_D3_GPIO_RANGE_MIN ESP_HOSTED_SDIO_D3_GPIO_RANGE_MAX + help + D3 GPIO pin for SDIO. Range enforced dynamically based on slave target to ensure IOMUX compliance. + Enable 'Use custom SDIO GPIO pins' to disable range restrictions. endif if !ESP_HOSTED_SDIO_4_BIT_BUS - config ESP_HOSTED_SDIO_PRIV_PIN_D1_1BIT_BUS + config ESP_HOSTED_PRIV_SDIO_PIN_D1_1BIT_BUS_SLOT_0 + depends on ESP_HOSTED_SDIO_SLOT_0 int "D1 GPIO number (Interrupt Line)" default 35 if IDF_TARGET_ESP32S3 - default 15 if IDF_TARGET_ESP32P4 + range 40 40 if IDF_TARGET_ESP32P4 range 4 4 if IDF_TARGET_ESP32 help "Value can only be configured for some targets. Displayed always for reference." + config ESP_HOSTED_PRIV_SDIO_PIN_D1_1BIT_BUS_SLOT_1 + depends on ESP_HOSTED_SDIO_SLOT_1 + int "D1 GPIO number (Interrupt Line)" + default 35 if IDF_TARGET_ESP32S3 + default 23 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 15 if IDF_TARGET_ESP32P4 + default 4 if IDF_TARGET_ESP32 + range ESP_HOSTED_SDIO_D1_GPIO_RANGE_MIN ESP_HOSTED_SDIO_D1_GPIO_RANGE_MAX + help + D1 GPIO pin for SDIO. Range enforced dynamically based on slave target to ensure IOMUX compliance. + Enable 'Use custom SDIO GPIO pins' to disable range restrictions. + endif + + config ESP_HOSTED_SDIO_GPIO_RESET_SLAVE + int "GPIO pin for Reseting slave ESP" + range ESP_HOSTED_SDIO_RESET_SLAVE_GPIO_MIN ESP_HOSTED_SDIO_RESET_SLAVE_GPIO_MAX + default 53 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 54 if IDF_TARGET_ESP32P4 + default 42 if IDF_TARGET_ESP32S3 + default 5 if IDF_TARGET_ESP32 + help + GPIO pin for Resetting ESP SDIO slave device. Should be connected to RST/EN of ESP SDIO slave device. + +### *END* GPIO SDIO pin configurations for Slot 0 and 1 + + config ESP_HOSTED_SDIO_PIN_CMD + int + default ESP_HOSTED_PRIV_SDIO_PIN_CMD_SLOT_0 if ESP_HOSTED_SDIO_SLOT_0 + default ESP_HOSTED_PRIV_SDIO_PIN_CMD_SLOT_1 if ESP_HOSTED_SDIO_SLOT_1 + + config ESP_HOSTED_SDIO_PIN_CLK + int + default ESP_HOSTED_PRIV_SDIO_PIN_CLK_SLOT_0 if ESP_HOSTED_SDIO_SLOT_0 + default ESP_HOSTED_PRIV_SDIO_PIN_CLK_SLOT_1 if ESP_HOSTED_SDIO_SLOT_1 + + config ESP_HOSTED_SDIO_PIN_D0 + int + default ESP_HOSTED_PRIV_SDIO_PIN_D0_SLOT_0 if ESP_HOSTED_SDIO_SLOT_0 + default ESP_HOSTED_PRIV_SDIO_PIN_D0_SLOT_1 if ESP_HOSTED_SDIO_SLOT_1 + + if ESP_HOSTED_SDIO_4_BIT_BUS + config ESP_HOSTED_SDIO_PRIV_PIN_D1_4BIT_BUS + int + default ESP_HOSTED_PRIV_SDIO_PIN_D1_4BIT_BUS_SLOT_0 if ESP_HOSTED_SDIO_SLOT_0 + default ESP_HOSTED_PRIV_SDIO_PIN_D1_4BIT_BUS_SLOT_1 if ESP_HOSTED_SDIO_SLOT_1 + + config ESP_HOSTED_SDIO_PIN_D2 + int + default ESP_HOSTED_PRIV_SDIO_PIN_D2_4BIT_BUS_SLOT_0 if ESP_HOSTED_SDIO_SLOT_0 + default ESP_HOSTED_PRIV_SDIO_PIN_D2_4BIT_BUS_SLOT_1 if ESP_HOSTED_SDIO_SLOT_1 + + config ESP_HOSTED_SDIO_PIN_D3 + int + default ESP_HOSTED_PRIV_SDIO_PIN_D3_4BIT_BUS_SLOT_0 if ESP_HOSTED_SDIO_SLOT_0 + default ESP_HOSTED_PRIV_SDIO_PIN_D3_4BIT_BUS_SLOT_1 if ESP_HOSTED_SDIO_SLOT_1 + endif + + if !ESP_HOSTED_SDIO_4_BIT_BUS + config ESP_HOSTED_SDIO_PRIV_PIN_D1_1BIT_BUS + int + default ESP_HOSTED_PRIV_SDIO_PIN_D1_1BIT_BUS_SLOT_0 if ESP_HOSTED_SDIO_SLOT_0 + default ESP_HOSTED_PRIV_SDIO_PIN_D1_1BIT_BUS_SLOT_1 if ESP_HOSTED_SDIO_SLOT_1 endif config ESP_HOSTED_SDIO_PIN_D1 @@ -570,7 +869,9 @@ ESP32XX_SDIO_CLK_FREQ_KHZ_RANGE_MAX := 50000 config ESP_HOSTED_SPI_HD_GPIO_CS int "GPIO pin for Host CS" default 10 if IDF_TARGET_ESP32S3 - default 19 if IDF_TARGET_ESP32P4 + default 4 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 19 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C6 + default 1 if IDF_TARGET_ESP32H2 default 15 help SPI Half-duplex controller Host CS @@ -578,7 +879,9 @@ ESP32XX_SDIO_CLK_FREQ_KHZ_RANGE_MAX := 50000 config ESP_HOSTED_SPI_HD_GPIO_CLK int "GPIO pin for Host CLK" default 12 if IDF_TARGET_ESP32S3 - default 18 if IDF_TARGET_ESP32P4 + default 33 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 18 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C6 + default 4 if IDF_TARGET_ESP32H2 default 18 help SPI Half-duplex controller Host CLK @@ -586,7 +889,9 @@ ESP32XX_SDIO_CLK_FREQ_KHZ_RANGE_MAX := 50000 config ESP_HOSTED_SPI_HD_GPIO_D0 int "GPIO pin for Host D0" default 11 if IDF_TARGET_ESP32S3 - default 14 if IDF_TARGET_ESP32P4 + default 23 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 14 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C6 + default 5 if IDF_TARGET_ESP32H2 default 2 help SPI Half-duplex controller Host D0 @@ -594,7 +899,9 @@ ESP32XX_SDIO_CLK_FREQ_KHZ_RANGE_MAX := 50000 config ESP_HOSTED_SPI_HD_GPIO_D1 int "GPIO pin for Host D1" default 13 if IDF_TARGET_ESP32S3 - default 15 if IDF_TARGET_ESP32P4 + default 22 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 15 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C6 + default 0 if IDF_TARGET_ESP32H2 default 4 help SPI Half-duplex controller Host D1 @@ -603,7 +910,9 @@ ESP32XX_SDIO_CLK_FREQ_KHZ_RANGE_MAX := 50000 depends on ESP_HOSTED_SPI_HD_PRIV_INTERFACE_4_DATA_LINES int "GPIO pin for Host D2" default 14 if IDF_TARGET_ESP32S3 - default 16 if IDF_TARGET_ESP32P4 + default 20 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 16 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C6 + default 2 if IDF_TARGET_ESP32H2 default 12 help SPI Half-duplex controller Host D2 @@ -612,7 +921,9 @@ ESP32XX_SDIO_CLK_FREQ_KHZ_RANGE_MAX := 50000 depends on ESP_HOSTED_SPI_HD_PRIV_INTERFACE_4_DATA_LINES int "GPIO pin for Host D3" default 9 if IDF_TARGET_ESP32S3 - default 17 if IDF_TARGET_ESP32P4 + default 21 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 17 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C6 + default 3 if IDF_TARGET_ESP32H2 default 13 help SPI Half-duplex controller Host D3 @@ -620,7 +931,9 @@ ESP32XX_SDIO_CLK_FREQ_KHZ_RANGE_MAX := 50000 config ESP_HOSTED_SPI_HD_GPIO_DATA_READY int "GPIO pin for data ready interrupt" default 4 if IDF_TARGET_ESP32S3 - default 6 if IDF_TARGET_ESP32P4 + default 32 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 + default 6 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C6 + default 12 if IDF_TARGET_ESP32H2 default 8 help GPIO pin for indicating host that slave has data to be read by host @@ -628,7 +941,9 @@ ESP32XX_SDIO_CLK_FREQ_KHZ_RANGE_MAX := 50000 config ESP_HOSTED_SPI_HD_GPIO_RESET_SLAVE int "GPIO pin for Reseting slave ESP" default 5 if IDF_TARGET_ESP32S3 + default 53 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C5 default 54 if IDF_TARGET_ESP32P4 && SLAVE_IDF_TARGET_ESP32C6 + default 10 if IDF_TARGET_ESP32H2 default 5 help GPIO pin for Resetting ESP slave device. Should be connected to RST/EN of ESP SPI slave device. @@ -651,7 +966,7 @@ ESP32XX_SPI_HD_CLK_FREQ_RANGE_MAX := 40 config ESP_HOSTED_SPI_HD_FREQ_ESP32XX depends on SLAVE_IDF_TARGET_ESP32C2 || SLAVE_IDF_TARGET_ESP32C3 || SLAVE_IDF_TARGET_ESP32S2 || SLAVE_IDF_TARGET_ESP32S3 || SLAVE_IDF_TARGET_ESP32C5 int "SPI HD Clock Freq (MHz)" - default 10 if SLAVE_IDF_TARGET_ESP32C2 || SLAVE_IDF_TARGET_ESP32C3 || SLAVE_IDF_TARGET_ESP32S2 || SLAVE_IDF_TARGET_ESP32S3 || SLAVE_IDF_TARGET_ESP32C5 + default 40 if SLAVE_IDF_TARGET_ESP32C2 || SLAVE_IDF_TARGET_ESP32C3 || SLAVE_IDF_TARGET_ESP32S2 || SLAVE_IDF_TARGET_ESP32S3 || SLAVE_IDF_TARGET_ESP32C5 range $(ESP32XX_SPI_HD_CLK_FREQ_RANGE_MIN) $(ESP32XX_SPI_HD_CLK_FREQ_RANGE_MAX) help "Optimize CLK by increasing till host practically can support" @@ -811,14 +1126,14 @@ ESP32XX_SPI_HD_CLK_FREQ_RANGE_MAX := 40 ENABLE/DISABLE software UART checksum endmenu - config ESP_HOSTED_GPIO_SLAVE_RESET_SLAVE + config ESP_HOSTED_GPIO_SLAVE_RESET_SLAVE int default ESP_HOSTED_SPI_GPIO_RESET_SLAVE if ESP_HOSTED_SPI_HOST_INTERFACE default ESP_HOSTED_SDIO_GPIO_RESET_SLAVE if ESP_HOSTED_SDIO_HOST_INTERFACE default ESP_HOSTED_SPI_HD_GPIO_RESET_SLAVE if ESP_HOSTED_SPI_HD_HOST_INTERFACE default ESP_HOSTED_UART_GPIO_RESET_SLAVE if ESP_HOSTED_UART_HOST_INTERFACE - config ESP_HOSTED_RESET_GPIO_ACTIVE_LOW + config ESP_HOSTED_RESET_GPIO_ACTIVE_LOW bool default n if ESP_HOSTED_SDIO_RESET_ACTIVE_HIGH || ESP_HOSTED_SPI_RESET_ACTIVE_HIGH || ESP_HOSTED_SPI_HD_RESET_ACTIVE_HIGH || ESP_HOSTED_UART_RESET_ACTIVE_HIGH default y if ESP_HOSTED_SDIO_RESET_ACTIVE_LOW || ESP_HOSTED_SPI_RESET_ACTIVE_LOW || ESP_HOSTED_SPI_HD_RESET_ACTIVE_LOW || ESP_HOSTED_UART_RESET_ACTIVE_LOW @@ -1029,4 +1344,13 @@ ESP32XX_SPI_HD_CLK_FREQ_RANGE_MAX := 40 Once the Wi-Fi is no more stressed, data throttling would be stopped, once slave Wi-Fi load is lower than this threshold endmenu + + config ESP_HOSTED_DECODE_WIFI_RESERVED_FIELD + bool "Copy Wi-Fi configuration reserved field values" + default n + help + ESP-IDF Wi-Fi structures contain reserved bitmask values. + Enable this option if you want to copy these values between host and co-processor. + It is usually safe to ignore these reserved values. + endmenu diff --git a/README.md b/README.md index 43135b72..72695cdc 100644 --- a/README.md +++ b/README.md @@ -149,11 +149,15 @@ Legends: - Bluetooth uses dedicated platform, UART and Wi-Fi uses any other base transport - In other platforms, Bluetooth and Wi-Fi re-use same platform and hence use less GPIOs and less complicated - This transport combination allows Bluetooth to use dedicated uart transportt with additional 2 or 4 depending on hardware flow control. -- (S) : Sheild box reading +- (S) : Shield box reading - (O) : Over the air reading - TBD : To be determined - iperf : iperf2 with test resukts in mbps +> [!NOTE] +> +> For the shield box readings maked with (S), full network set up explained in [Shield Box Test Setup](shield-box-test-setup.md) + **Host can be any ESP chipset or any non-ESP MCU.** ###### Hosted Transports table @@ -163,8 +167,8 @@ Legends: | Standard SPI | FD | 6 | jumper or PCB | Any_Slave | udp: 24 tcp: 22 | udp: 25 tcp: 22| Simplest solution for quick test | | Dual SPI | HD | 5 | jumper or PCB | Any_Slave [1] | udp: 32 tcp: 26 (O) | udp: 33 tcp: 25 (O) | Better throughput, but half duplex | | Quad SPI | HD | 7 | PCB only | Any_Slave [1] | udp: 41 tcp: 29 (O) | udp: 42 tcp: 28 (O) | Due to signal integrity, PCB is mandatory | -| SDIO 1-Bit | HD | 4 | jumper or PCB | ESP32, ESP32-C6 | TBD | TBD | Stepping stone for PCB based SDIO 4-bit | -| SDIO 4-Bit | HD | 6 | PCB only | ESP32, ESP32-C6 | udp: 79.5 tcp: 53.4 (S) | udp: 68.1 tcp: 44 (S) | Highest performance | +| SDIO 1-Bit | HD | 4 | jumper or PCB | ESP32, ESP32-C6, ESP32-C5 [3] | TBD | TBD | Stepping stone for PCB based SDIO 4-bit | +| SDIO 4-Bit | HD | 6 | PCB only | ESP32, ESP32-C6, ESP32-C5 [3] | udp: 79.5 tcp: 53.4 (S) | udp: 68.1 tcp: 44 (S) | Highest performance | | Only BT over UART | FD | 2 or 4 | jumper or PCB | Any_Slave | NA | NA | Dedicated Bluetooth over UART pins | | UART | FD | 2 | jumper or PCB | Any_Slave | udp: 0.68 tcp: 0.67 (O) | udp: 0.68 tcp: 0.60 (O) | UART dedicated for BT & Wi-Fi [2] | | Dedicated platforms | FD | Extra 2 or 4 | jumper or PCB | Any_Slave | NA | NA | UART dedicated for BT & Wi-Fi on any other transport | @@ -173,6 +177,8 @@ Legends: > - [1] Dual/Quad SPI is not supported on ESP32 > > - [2] UART is only suitable for low throughput environments +> +> - [3] Currently in BETA support for ESP32-C5 (`--preview` in ESP-IDF master branch) With jumper cables, 'Standard SPI' and 'Dual SPI' solutions are easiest to evaluate, without much of hardware dependencies. SDIO 1-Bit can be tested with jumper cables, but it needs some additional hardware config, such as installation of external pull-up registers. diff --git a/common/proto/esp_hosted_rpc.pb-c.c b/common/proto/esp_hosted_rpc.pb-c.c index eb1a1e39..84b5b4ec 100644 --- a/common/proto/esp_hosted_rpc.pb-c.c +++ b/common/proto/esp_hosted_rpc.pb-c.c @@ -187,6 +187,51 @@ void wifi_scan_time__free_unpacked assert(message->base.descriptor == &wifi_scan_time__descriptor); protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); } +void wifi_scan_channel_bitmap__init + (WifiScanChannelBitmap *message) +{ + static const WifiScanChannelBitmap init_value = WIFI_SCAN_CHANNEL_BITMAP__INIT; + *message = init_value; +} +size_t wifi_scan_channel_bitmap__get_packed_size + (const WifiScanChannelBitmap *message) +{ + assert(message->base.descriptor == &wifi_scan_channel_bitmap__descriptor); + return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); +} +size_t wifi_scan_channel_bitmap__pack + (const WifiScanChannelBitmap *message, + uint8_t *out) +{ + assert(message->base.descriptor == &wifi_scan_channel_bitmap__descriptor); + return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); +} +size_t wifi_scan_channel_bitmap__pack_to_buffer + (const WifiScanChannelBitmap *message, + ProtobufCBuffer *buffer) +{ + assert(message->base.descriptor == &wifi_scan_channel_bitmap__descriptor); + return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); +} +WifiScanChannelBitmap * + wifi_scan_channel_bitmap__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data) +{ + return (WifiScanChannelBitmap *) + protobuf_c_message_unpack (&wifi_scan_channel_bitmap__descriptor, + allocator, len, data); +} +void wifi_scan_channel_bitmap__free_unpacked + (WifiScanChannelBitmap *message, + ProtobufCAllocator *allocator) +{ + if(!message) + return; + assert(message->base.descriptor == &wifi_scan_channel_bitmap__descriptor); + protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); +} void wifi_scan_config__init (WifiScanConfig *message) { @@ -412,6 +457,51 @@ void wifi_pmf_config__free_unpacked assert(message->base.descriptor == &wifi_pmf_config__descriptor); protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); } +void wifi_bss_max_idle_config__init + (WifiBssMaxIdleConfig *message) +{ + static const WifiBssMaxIdleConfig init_value = WIFI_BSS_MAX_IDLE_CONFIG__INIT; + *message = init_value; +} +size_t wifi_bss_max_idle_config__get_packed_size + (const WifiBssMaxIdleConfig *message) +{ + assert(message->base.descriptor == &wifi_bss_max_idle_config__descriptor); + return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); +} +size_t wifi_bss_max_idle_config__pack + (const WifiBssMaxIdleConfig *message, + uint8_t *out) +{ + assert(message->base.descriptor == &wifi_bss_max_idle_config__descriptor); + return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); +} +size_t wifi_bss_max_idle_config__pack_to_buffer + (const WifiBssMaxIdleConfig *message, + ProtobufCBuffer *buffer) +{ + assert(message->base.descriptor == &wifi_bss_max_idle_config__descriptor); + return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); +} +WifiBssMaxIdleConfig * + wifi_bss_max_idle_config__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data) +{ + return (WifiBssMaxIdleConfig *) + protobuf_c_message_unpack (&wifi_bss_max_idle_config__descriptor, + allocator, len, data); +} +void wifi_bss_max_idle_config__free_unpacked + (WifiBssMaxIdleConfig *message, + ProtobufCAllocator *allocator) +{ + if(!message) + return; + assert(message->base.descriptor == &wifi_bss_max_idle_config__descriptor); + protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); +} void wifi_ap_config__init (WifiApConfig *message) { @@ -7297,7 +7387,7 @@ void rpc__free_unpacked assert(message->base.descriptor == &rpc__descriptor); protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); } -static const ProtobufCFieldDescriptor wifi_init_config__field_descriptors[20] = +static const ProtobufCFieldDescriptor wifi_init_config__field_descriptors[24] = { { "static_rx_buf_num", @@ -7539,6 +7629,54 @@ static const ProtobufCFieldDescriptor wifi_init_config__field_descriptors[20] = 0, /* flags */ 0,NULL,NULL /* reserved1,reserved2, etc */ }, + { + "rx_mgmt_buf_type", + 21, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_INT32, + 0, /* quantifier_offset */ + offsetof(WifiInitConfig, rx_mgmt_buf_type), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "rx_mgmt_buf_num", + 22, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_INT32, + 0, /* quantifier_offset */ + offsetof(WifiInitConfig, rx_mgmt_buf_num), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "tx_hetb_queue_num", + 23, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_INT32, + 0, /* quantifier_offset */ + offsetof(WifiInitConfig, tx_hetb_queue_num), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "dump_hesigb_enable", + 24, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_INT32, + 0, /* quantifier_offset */ + offsetof(WifiInitConfig, dump_hesigb_enable), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, }; static const unsigned wifi_init_config__field_indices_by_name[] = { 7, /* field[7] = ampdu_rx_enable */ @@ -7547,6 +7685,7 @@ static const unsigned wifi_init_config__field_indices_by_name[] = { 14, /* field[14] = beacon_max_len */ 5, /* field[5] = cache_tx_buf_num */ 6, /* field[6] = csi_enable */ + 23, /* field[23] = dump_hesigb_enable */ 1, /* field[1] = dynamic_rx_buf_num */ 4, /* field[4] = dynamic_tx_buf_num */ 18, /* field[18] = espnow_max_encrypt_num */ @@ -7556,16 +7695,19 @@ static const unsigned wifi_init_config__field_indices_by_name[] = { 11, /* field[11] = nano_enable */ 10, /* field[10] = nvs_enable */ 12, /* field[12] = rx_ba_win */ + 21, /* field[21] = rx_mgmt_buf_num */ + 20, /* field[20] = rx_mgmt_buf_type */ 17, /* field[17] = sta_disconnected_pm */ 0, /* field[0] = static_rx_buf_num */ 3, /* field[3] = static_tx_buf_num */ 2, /* field[2] = tx_buf_type */ + 22, /* field[22] = tx_hetb_queue_num */ 13, /* field[13] = wifi_task_core_id */ }; static const ProtobufCIntRange wifi_init_config__number_ranges[1 + 1] = { { 1, 0 }, - { 0, 20 } + { 0, 24 } }; const ProtobufCMessageDescriptor wifi_init_config__descriptor = { @@ -7575,7 +7717,7 @@ const ProtobufCMessageDescriptor wifi_init_config__descriptor = "WifiInitConfig", "", sizeof(WifiInitConfig), - 20, + 24, wifi_init_config__field_descriptors, wifi_init_config__field_indices_by_name, 1, wifi_init_config__number_ranges, @@ -7774,7 +7916,58 @@ const ProtobufCMessageDescriptor wifi_scan_time__descriptor = (ProtobufCMessageInit) wifi_scan_time__init, NULL,NULL,NULL /* reserved[123] */ }; -static const ProtobufCFieldDescriptor wifi_scan_config__field_descriptors[7] = +static const ProtobufCFieldDescriptor wifi_scan_channel_bitmap__field_descriptors[2] = +{ + { + "ghz_2_channels", + 1, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_UINT32, + 0, /* quantifier_offset */ + offsetof(WifiScanChannelBitmap, ghz_2_channels), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "ghz_5_channels", + 2, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_UINT32, + 0, /* quantifier_offset */ + offsetof(WifiScanChannelBitmap, ghz_5_channels), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, +}; +static const unsigned wifi_scan_channel_bitmap__field_indices_by_name[] = { + 0, /* field[0] = ghz_2_channels */ + 1, /* field[1] = ghz_5_channels */ +}; +static const ProtobufCIntRange wifi_scan_channel_bitmap__number_ranges[1 + 1] = +{ + { 1, 0 }, + { 0, 2 } +}; +const ProtobufCMessageDescriptor wifi_scan_channel_bitmap__descriptor = +{ + PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, + "wifi_scan_channel_bitmap", + "WifiScanChannelBitmap", + "WifiScanChannelBitmap", + "", + sizeof(WifiScanChannelBitmap), + 2, + wifi_scan_channel_bitmap__field_descriptors, + wifi_scan_channel_bitmap__field_indices_by_name, + 1, wifi_scan_channel_bitmap__number_ranges, + (ProtobufCMessageInit) wifi_scan_channel_bitmap__init, + NULL,NULL,NULL /* reserved[123] */ +}; +static const ProtobufCFieldDescriptor wifi_scan_config__field_descriptors[8] = { { "ssid", @@ -7860,10 +8053,23 @@ static const ProtobufCFieldDescriptor wifi_scan_config__field_descriptors[7] = 0, /* flags */ 0,NULL,NULL /* reserved1,reserved2, etc */ }, + { + "channel_bitmap", + 8, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_MESSAGE, + 0, /* quantifier_offset */ + offsetof(WifiScanConfig, channel_bitmap), + &wifi_scan_channel_bitmap__descriptor, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, }; static const unsigned wifi_scan_config__field_indices_by_name[] = { 1, /* field[1] = bssid */ 2, /* field[2] = channel */ + 7, /* field[7] = channel_bitmap */ 6, /* field[6] = home_chan_dwell_time */ 5, /* field[5] = scan_time */ 4, /* field[4] = scan_type */ @@ -7873,7 +8079,7 @@ static const unsigned wifi_scan_config__field_indices_by_name[] = { static const ProtobufCIntRange wifi_scan_config__number_ranges[1 + 1] = { { 1, 0 }, - { 0, 7 } + { 0, 8 } }; const ProtobufCMessageDescriptor wifi_scan_config__descriptor = { @@ -7883,7 +8089,7 @@ const ProtobufCMessageDescriptor wifi_scan_config__descriptor = "WifiScanConfig", "", sizeof(WifiScanConfig), - 7, + 8, wifi_scan_config__field_descriptors, wifi_scan_config__field_indices_by_name, 1, wifi_scan_config__number_ranges, @@ -8161,7 +8367,7 @@ const ProtobufCMessageDescriptor wifi_ap_record__descriptor = (ProtobufCMessageInit) wifi_ap_record__init, NULL,NULL,NULL /* reserved[123] */ }; -static const ProtobufCFieldDescriptor wifi_scan_threshold__field_descriptors[2] = +static const ProtobufCFieldDescriptor wifi_scan_threshold__field_descriptors[3] = { { "rssi", @@ -8187,15 +8393,28 @@ static const ProtobufCFieldDescriptor wifi_scan_threshold__field_descriptors[2] 0, /* flags */ 0,NULL,NULL /* reserved1,reserved2, etc */ }, + { + "rssi_5g_adjustment", + 3, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_UINT32, + 0, /* quantifier_offset */ + offsetof(WifiScanThreshold, rssi_5g_adjustment), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, }; static const unsigned wifi_scan_threshold__field_indices_by_name[] = { 1, /* field[1] = authmode */ 0, /* field[0] = rssi */ + 2, /* field[2] = rssi_5g_adjustment */ }; static const ProtobufCIntRange wifi_scan_threshold__number_ranges[1 + 1] = { { 1, 0 }, - { 0, 2 } + { 0, 3 } }; const ProtobufCMessageDescriptor wifi_scan_threshold__descriptor = { @@ -8205,7 +8424,7 @@ const ProtobufCMessageDescriptor wifi_scan_threshold__descriptor = "WifiScanThreshold", "", sizeof(WifiScanThreshold), - 2, + 3, wifi_scan_threshold__field_descriptors, wifi_scan_threshold__field_indices_by_name, 1, wifi_scan_threshold__number_ranges, @@ -8263,7 +8482,58 @@ const ProtobufCMessageDescriptor wifi_pmf_config__descriptor = (ProtobufCMessageInit) wifi_pmf_config__init, NULL,NULL,NULL /* reserved[123] */ }; -static const ProtobufCFieldDescriptor wifi_ap_config__field_descriptors[12] = +static const ProtobufCFieldDescriptor wifi_bss_max_idle_config__field_descriptors[2] = +{ + { + "period", + 1, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_UINT32, + 0, /* quantifier_offset */ + offsetof(WifiBssMaxIdleConfig, period), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "protected_keep_alive", + 2, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_BOOL, + 0, /* quantifier_offset */ + offsetof(WifiBssMaxIdleConfig, protected_keep_alive), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, +}; +static const unsigned wifi_bss_max_idle_config__field_indices_by_name[] = { + 0, /* field[0] = period */ + 1, /* field[1] = protected_keep_alive */ +}; +static const ProtobufCIntRange wifi_bss_max_idle_config__number_ranges[1 + 1] = +{ + { 1, 0 }, + { 0, 2 } +}; +const ProtobufCMessageDescriptor wifi_bss_max_idle_config__descriptor = +{ + PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, + "wifi_bss_max_idle_config", + "WifiBssMaxIdleConfig", + "WifiBssMaxIdleConfig", + "", + sizeof(WifiBssMaxIdleConfig), + 2, + wifi_bss_max_idle_config__field_descriptors, + wifi_bss_max_idle_config__field_indices_by_name, + 1, wifi_bss_max_idle_config__number_ranges, + (ProtobufCMessageInit) wifi_bss_max_idle_config__init, + NULL,NULL,NULL /* reserved[123] */ +}; +static const ProtobufCFieldDescriptor wifi_ap_config__field_descriptors[18] = { { "ssid", @@ -8409,25 +8679,103 @@ static const ProtobufCFieldDescriptor wifi_ap_config__field_descriptors[12] = 0, /* flags */ 0,NULL,NULL /* reserved1,reserved2, etc */ }, + { + "csa_count", + 13, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_UINT32, + 0, /* quantifier_offset */ + offsetof(WifiApConfig, csa_count), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "dtim_period", + 14, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_UINT32, + 0, /* quantifier_offset */ + offsetof(WifiApConfig, dtim_period), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "transition_disable", + 15, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_UINT32, + 0, /* quantifier_offset */ + offsetof(WifiApConfig, transition_disable), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "sae_ext", + 16, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_UINT32, + 0, /* quantifier_offset */ + offsetof(WifiApConfig, sae_ext), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "bss_max_idle_cfg", + 17, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_MESSAGE, + 0, /* quantifier_offset */ + offsetof(WifiApConfig, bss_max_idle_cfg), + &wifi_bss_max_idle_config__descriptor, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "gtk_rekey_interval", + 18, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_UINT32, + 0, /* quantifier_offset */ + offsetof(WifiApConfig, gtk_rekey_interval), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, }; static const unsigned wifi_ap_config__field_indices_by_name[] = { 4, /* field[4] = authmode */ 7, /* field[7] = beacon_interval */ + 16, /* field[16] = bss_max_idle_cfg */ 3, /* field[3] = channel */ + 12, /* field[12] = csa_count */ + 13, /* field[13] = dtim_period */ 9, /* field[9] = ftm_responder */ + 17, /* field[17] = gtk_rekey_interval */ 6, /* field[6] = max_connection */ 8, /* field[8] = pairwise_cipher */ 1, /* field[1] = password */ 10, /* field[10] = pmf_cfg */ + 15, /* field[15] = sae_ext */ 11, /* field[11] = sae_pwe_h2e */ 0, /* field[0] = ssid */ 5, /* field[5] = ssid_hidden */ 2, /* field[2] = ssid_len */ + 14, /* field[14] = transition_disable */ }; static const ProtobufCIntRange wifi_ap_config__number_ranges[1 + 1] = { { 1, 0 }, - { 0, 12 } + { 0, 18 } }; const ProtobufCMessageDescriptor wifi_ap_config__descriptor = { @@ -8437,14 +8785,14 @@ const ProtobufCMessageDescriptor wifi_ap_config__descriptor = "WifiApConfig", "", sizeof(WifiApConfig), - 12, + 18, wifi_ap_config__field_descriptors, wifi_ap_config__field_indices_by_name, 1, wifi_ap_config__number_ranges, (ProtobufCMessageInit) wifi_ap_config__init, NULL,NULL,NULL /* reserved[123] */ }; -static const ProtobufCFieldDescriptor wifi_sta_config__field_descriptors[15] = +static const ProtobufCFieldDescriptor wifi_sta_config__field_descriptors[16] = { { "ssid", @@ -8626,6 +8974,18 @@ static const ProtobufCFieldDescriptor wifi_sta_config__field_descriptors[15] = 0, /* flags */ 0,NULL,NULL /* reserved1,reserved2, etc */ }, + { + "sae_pk_mode", + 16, + PROTOBUF_C_LABEL_NONE, + PROTOBUF_C_TYPE_UINT32, + 0, /* quantifier_offset */ + offsetof(WifiStaConfig, sae_pk_mode), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, }; static const unsigned wifi_sta_config__field_indices_by_name[] = { 10, /* field[10] = bitmask */ @@ -8638,6 +8998,7 @@ static const unsigned wifi_sta_config__field_indices_by_name[] = { 1, /* field[1] = password */ 9, /* field[9] = pmf_cfg */ 14, /* field[14] = sae_h2e_identifier */ + 15, /* field[15] = sae_pk_mode */ 11, /* field[11] = sae_pwe_h2e */ 2, /* field[2] = scan_method */ 7, /* field[7] = sort_method */ @@ -8647,7 +9008,7 @@ static const unsigned wifi_sta_config__field_indices_by_name[] = { static const ProtobufCIntRange wifi_sta_config__number_ranges[1 + 1] = { { 1, 0 }, - { 0, 15 } + { 0, 16 } }; const ProtobufCMessageDescriptor wifi_sta_config__descriptor = { @@ -8657,7 +9018,7 @@ const ProtobufCMessageDescriptor wifi_sta_config__descriptor = "WifiStaConfig", "", sizeof(WifiStaConfig), - 15, + 16, wifi_sta_config__field_descriptors, wifi_sta_config__field_indices_by_name, 1, wifi_sta_config__number_ranges, diff --git a/common/proto/esp_hosted_rpc.pb-c.h b/common/proto/esp_hosted_rpc.pb-c.h index 03a11fc5..ca2b379c 100644 --- a/common/proto/esp_hosted_rpc.pb-c.h +++ b/common/proto/esp_hosted_rpc.pb-c.h @@ -19,11 +19,13 @@ typedef struct WifiInitConfig WifiInitConfig; typedef struct WifiCountry WifiCountry; typedef struct WifiActiveScanTime WifiActiveScanTime; typedef struct WifiScanTime WifiScanTime; +typedef struct WifiScanChannelBitmap WifiScanChannelBitmap; typedef struct WifiScanConfig WifiScanConfig; typedef struct WifiHeApInfo WifiHeApInfo; typedef struct WifiApRecord WifiApRecord; typedef struct WifiScanThreshold WifiScanThreshold; typedef struct WifiPmfConfig WifiPmfConfig; +typedef struct WifiBssMaxIdleConfig WifiBssMaxIdleConfig; typedef struct WifiApConfig WifiApConfig; typedef struct WifiStaConfig WifiStaConfig; typedef struct WifiConfig WifiConfig; @@ -801,10 +803,26 @@ struct WifiInitConfig **< WiFi init magic number, it should be the last field */ int32_t magic; + /* + **< WiFi RX MGMT buffer type + */ + int32_t rx_mgmt_buf_type; + /* + **< WiFi RX MGMT buffer number + */ + int32_t rx_mgmt_buf_num; + /* + **< WiFi TX HE TB QUEUE number for STA HE TB PPDU transmission + */ + int32_t tx_hetb_queue_num; + /* + **< enable dump sigb field + */ + int32_t dump_hesigb_enable; }; #define WIFI_INIT_CONFIG__INIT \ { PROTOBUF_C_MESSAGE_INIT (&wifi_init_config__descriptor) \ - , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } + , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } struct WifiCountry @@ -873,6 +891,23 @@ struct WifiScanTime , NULL, 0 } +struct WifiScanChannelBitmap +{ + ProtobufCMessage base; + /* + **< Represents 2.4 GHz channels, that bits can be set as wifi_2g_channel_bit_t shown. + */ + uint32_t ghz_2_channels; + /* + **< Represents 5 GHz channels, that bits can be set as wifi_5g_channel_bit_t shown. + */ + uint32_t ghz_5_channels; +}; +#define WIFI_SCAN_CHANNEL_BITMAP__INIT \ + { PROTOBUF_C_MESSAGE_INIT (&wifi_scan_channel_bitmap__descriptor) \ + , 0, 0 } + + struct WifiScanConfig { ProtobufCMessage base; @@ -904,10 +939,16 @@ struct WifiScanConfig **< time spent at home channel between scanning consecutive channels. */ uint32_t home_chan_dwell_time; + /* + **< Channel bitmap for setting specific channels to be scanned. + *Please note that the 'channel' parameter above needs to be set to 0 to allow scanning by bitmap. + *Also, note that only allowed channels configured by wifi_country_t can be scanned. + */ + WifiScanChannelBitmap *channel_bitmap; }; #define WIFI_SCAN_CONFIG__INIT \ { PROTOBUF_C_MESSAGE_INIT (&wifi_scan_config__descriptor) \ - , {0,NULL}, {0,NULL}, 0, 0, 0, NULL, 0 } + , {0,NULL}, {0,NULL}, 0, 0, 0, NULL, 0, NULL } struct WifiHeApInfo @@ -1027,10 +1068,14 @@ struct WifiScanThreshold *Please set authmode threshold as WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK to connect to WEP/WPA networks */ int32_t authmode; + /* + **< The RSSI value of the 5G AP is within the rssi_5g_adjustment range compared to the 2G AP, the 5G AP will be given priority for connection. + */ + uint32_t rssi_5g_adjustment; }; #define WIFI_SCAN_THRESHOLD__INIT \ { PROTOBUF_C_MESSAGE_INIT (&wifi_scan_threshold__descriptor) \ - , 0, 0 } + , 0, 0, 0 } struct WifiPmfConfig @@ -1050,6 +1095,23 @@ struct WifiPmfConfig , 0, 0 } +struct WifiBssMaxIdleConfig +{ + ProtobufCMessage base; + /* + **< Sets BSS Max idle period (1 Unit = 1000TUs OR 1.024 Seconds). If there are no frames for this period from a STA, SoftAP will disassociate due to inactivity. Setting it to 0 disables the feature + */ + uint32_t period; + /* + **< Requires clients to use protected keep alive frames for BSS Max Idle period + */ + protobuf_c_boolean protected_keep_alive; +}; +#define WIFI_BSS_MAX_IDLE_CONFIG__INIT \ + { PROTOBUF_C_MESSAGE_INIT (&wifi_bss_max_idle_config__descriptor) \ + , 0, 0 } + + struct WifiApConfig { ProtobufCMessage base; @@ -1103,10 +1165,34 @@ struct WifiApConfig **< Configuration for SAE PWE derivation method */ int32_t sae_pwe_h2e; + /* + **< Channel Switch Announcement Count. Notify the station that the channel will switch after the csa_count beacon intervals. Default value: 3 + */ + uint32_t csa_count; + /* + **< Dtim period of soft-AP. Range: 1 ~ 10. Default value: 1 + */ + uint32_t dtim_period; + /* + **< Whether to enable transition disable feature + */ + uint32_t transition_disable; + /* + **< Enable SAE EXT feature. SOC_GCMP_SUPPORT is required for this feature. + */ + uint32_t sae_ext; + /* + **< Configuration for bss max idle, effective if CONFIG_WIFI_BSS_MAX_IDLE_SUPPORT is enabled + */ + WifiBssMaxIdleConfig *bss_max_idle_cfg; + /* + **< GTK rekeying interval in seconds. If set to 0, GTK rekeying is disabled. Range: 60 ~ 65535 including 0. + */ + uint32_t gtk_rekey_interval; }; #define WIFI_AP_CONFIG__INIT \ { PROTOBUF_C_MESSAGE_INIT (&wifi_ap_config__descriptor) \ - , {0,NULL}, {0,NULL}, 0, 0, 0, 0, 0, 0, 0, 0, NULL, 0 } + , {0,NULL}, {0,NULL}, 0, 0, 0, 0, 0, 0, 0, 0, NULL, 0, 0, 0, 0, 0, NULL, 0 } struct WifiStaConfig @@ -1185,17 +1271,24 @@ struct WifiStaConfig *uint32_t he_trig_su_bmforming_feedback_disabled:1; **< Whether to disable support the transmission of SU feedback in an HE TB sounding sequence. * *uint32_t he_trig_mu_bmforming_partial_feedback_disabled:1; **< Whether to disable support the transmission of partial-bandwidth MU feedback in an HE TB sounding sequence. * * uint32_t he_trig_cqi_feedback_disabled:1; **< Whether to disable support the transmission of CQI feedback in an HE TB sounding sequence. * - * uint32_t he_reserved:22; **< Reserved for future feature set * + * uint32_t vht_su_beamformee_disabled: 1; **< Whether to disable support for operation as an VHT SU beamformee. * + * uint32_t vht_mu_beamformee_disabled: 1; **< Whether to disable support for operation as an VHT MU beamformee. * + * uint32_t vht_mcs8_enabled: 1; **< Whether to support VHT-MCS8. The default value is 0. * + * uint32_t he_reserved:19; **< Reserved for future feature set * */ uint32_t he_bitmask; /* **< Password identifier for H2E. this needs to be null terminated string. SAE_H2E_IDENTIFIER_LEN chars */ ProtobufCBinaryData sae_h2e_identifier; + /* + **< Configuration for SAE-PK (Public Key) Authentication method + */ + uint32_t sae_pk_mode; }; #define WIFI_STA_CONFIG__INIT \ { PROTOBUF_C_MESSAGE_INIT (&wifi_sta_config__descriptor) \ - , {0,NULL}, {0,NULL}, 0, 0, {0,NULL}, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, {0,NULL} } + , {0,NULL}, {0,NULL}, 0, 0, {0,NULL}, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, {0,NULL}, 0 } typedef enum { @@ -3548,6 +3641,25 @@ WifiScanTime * void wifi_scan_time__free_unpacked (WifiScanTime *message, ProtobufCAllocator *allocator); +/* WifiScanChannelBitmap methods */ +void wifi_scan_channel_bitmap__init + (WifiScanChannelBitmap *message); +size_t wifi_scan_channel_bitmap__get_packed_size + (const WifiScanChannelBitmap *message); +size_t wifi_scan_channel_bitmap__pack + (const WifiScanChannelBitmap *message, + uint8_t *out); +size_t wifi_scan_channel_bitmap__pack_to_buffer + (const WifiScanChannelBitmap *message, + ProtobufCBuffer *buffer); +WifiScanChannelBitmap * + wifi_scan_channel_bitmap__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data); +void wifi_scan_channel_bitmap__free_unpacked + (WifiScanChannelBitmap *message, + ProtobufCAllocator *allocator); /* WifiScanConfig methods */ void wifi_scan_config__init (WifiScanConfig *message); @@ -3643,6 +3755,25 @@ WifiPmfConfig * void wifi_pmf_config__free_unpacked (WifiPmfConfig *message, ProtobufCAllocator *allocator); +/* WifiBssMaxIdleConfig methods */ +void wifi_bss_max_idle_config__init + (WifiBssMaxIdleConfig *message); +size_t wifi_bss_max_idle_config__get_packed_size + (const WifiBssMaxIdleConfig *message); +size_t wifi_bss_max_idle_config__pack + (const WifiBssMaxIdleConfig *message, + uint8_t *out); +size_t wifi_bss_max_idle_config__pack_to_buffer + (const WifiBssMaxIdleConfig *message, + ProtobufCBuffer *buffer); +WifiBssMaxIdleConfig * + wifi_bss_max_idle_config__unpack + (ProtobufCAllocator *allocator, + size_t len, + const uint8_t *data); +void wifi_bss_max_idle_config__free_unpacked + (WifiBssMaxIdleConfig *message, + ProtobufCAllocator *allocator); /* WifiApConfig methods */ void wifi_ap_config__init (WifiApConfig *message); @@ -6564,6 +6695,9 @@ typedef void (*WifiActiveScanTime_Closure) typedef void (*WifiScanTime_Closure) (const WifiScanTime *message, void *closure_data); +typedef void (*WifiScanChannelBitmap_Closure) + (const WifiScanChannelBitmap *message, + void *closure_data); typedef void (*WifiScanConfig_Closure) (const WifiScanConfig *message, void *closure_data); @@ -6579,6 +6713,9 @@ typedef void (*WifiScanThreshold_Closure) typedef void (*WifiPmfConfig_Closure) (const WifiPmfConfig *message, void *closure_data); +typedef void (*WifiBssMaxIdleConfig_Closure) + (const WifiBssMaxIdleConfig *message, + void *closure_data); typedef void (*WifiApConfig_Closure) (const WifiApConfig *message, void *closure_data); @@ -7054,11 +7191,13 @@ extern const ProtobufCMessageDescriptor wifi_init_config__descriptor; extern const ProtobufCMessageDescriptor wifi_country__descriptor; extern const ProtobufCMessageDescriptor wifi_active_scan_time__descriptor; extern const ProtobufCMessageDescriptor wifi_scan_time__descriptor; +extern const ProtobufCMessageDescriptor wifi_scan_channel_bitmap__descriptor; extern const ProtobufCMessageDescriptor wifi_scan_config__descriptor; extern const ProtobufCMessageDescriptor wifi_he_ap_info__descriptor; extern const ProtobufCMessageDescriptor wifi_ap_record__descriptor; extern const ProtobufCMessageDescriptor wifi_scan_threshold__descriptor; extern const ProtobufCMessageDescriptor wifi_pmf_config__descriptor; +extern const ProtobufCMessageDescriptor wifi_bss_max_idle_config__descriptor; extern const ProtobufCMessageDescriptor wifi_ap_config__descriptor; extern const ProtobufCMessageDescriptor wifi_sta_config__descriptor; extern const ProtobufCMessageDescriptor wifi_config__descriptor; diff --git a/common/proto/esp_hosted_rpc.proto b/common/proto/esp_hosted_rpc.proto index db37ac49..0993b495 100644 --- a/common/proto/esp_hosted_rpc.proto +++ b/common/proto/esp_hosted_rpc.proto @@ -581,6 +581,10 @@ message wifi_init_config { bool sta_disconnected_pm = 18; /**< WiFi Power Management for station at disconnected status */ int32 espnow_max_encrypt_num = 19; /**< Maximum encrypt number of peers supported by espnow */ int32 magic = 20; /**< WiFi init magic number, it should be the last field */ + int32 rx_mgmt_buf_type = 21; /**< WiFi RX MGMT buffer type */ + int32 rx_mgmt_buf_num = 22; /**< WiFi RX MGMT buffer number */ + int32 tx_hetb_queue_num = 23; /**< WiFi TX HE TB QUEUE number for STA HE TB PPDU transmission */ + int32 dump_hesigb_enable = 24; /**< enable dump sigb field */ } message wifi_country { @@ -605,6 +609,11 @@ message wifi_scan_time { cause station to disconnect from AP and are not recommended. */ } +message wifi_scan_channel_bitmap { + uint32 ghz_2_channels = 1; /**< Represents 2.4 GHz channels, that bits can be set as wifi_2g_channel_bit_t shown. */ + uint32 ghz_5_channels = 2; /**< Represents 5 GHz channels, that bits can be set as wifi_5g_channel_bit_t shown. */ +} + message wifi_scan_config { bytes ssid = 1; /**< SSID of AP 33char*/ bytes bssid = 2; /**< MAC address of AP 6char */ @@ -613,6 +622,9 @@ message wifi_scan_config { int32 scan_type = 5; /**< scan type, active or passive */ wifi_scan_time scan_time = 6; /**< scan time per channel */ uint32 home_chan_dwell_time = 7; /**< time spent at home channel between scanning consecutive channels.*/ + wifi_scan_channel_bitmap channel_bitmap = 8; /**< Channel bitmap for setting specific channels to be scanned. + Please note that the 'channel' parameter above needs to be set to 0 to allow scanning by bitmap. + Also, note that only allowed channels configured by wifi_country_t can be scanned. */ } message wifi_he_ap_info { @@ -661,6 +673,7 @@ message wifi_scan_threshold { Note: Incase this value is not set and password is set as per WPA2 standards(password len >= 8), it will be defaulted to WPA2 and device won't connect to deprecated WEP/WPA networks. Please set authmode threshold as WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK to connect to WEP/WPA networks */ + uint32 rssi_5g_adjustment = 3; /**< The RSSI value of the 5G AP is within the rssi_5g_adjustment range compared to the 2G AP, the 5G AP will be given priority for connection. */ } message wifi_pmf_config { @@ -668,6 +681,11 @@ message wifi_pmf_config { bool required = 2; /**< Advertizes that Protected Management Frame is required. Device will not associate to non-PMF capable devices. */ } +message wifi_bss_max_idle_config { + uint32 period = 1; /**< Sets BSS Max idle period (1 Unit = 1000TUs OR 1.024 Seconds). If there are no frames for this period from a STA, SoftAP will disassociate due to inactivity. Setting it to 0 disables the feature */ + bool protected_keep_alive = 2; /**< Requires clients to use protected keep alive frames for BSS Max Idle period */ +} + message wifi_ap_config { bytes ssid = 1; /**< SSID of ESP32 soft-AP. If ssid_len field is 0, this must be a Null terminated string. Otherwise, length is set according to ssid_len. 32 char*/ bytes password = 2; /**< Password of ESP32 soft-AP. 64 char*/ @@ -683,6 +701,12 @@ message wifi_ap_config { bool ftm_responder = 10; /**< Enable FTM Responder mode */ wifi_pmf_config pmf_cfg = 11; /**< Configuration for Protected Management Frame */ int32 sae_pwe_h2e = 12; /**< Configuration for SAE PWE derivation method */ + uint32 csa_count = 13; /**< Channel Switch Announcement Count. Notify the station that the channel will switch after the csa_count beacon intervals. Default value: 3 */ + uint32 dtim_period = 14; /**< Dtim period of soft-AP. Range: 1 ~ 10. Default value: 1 */ + uint32 transition_disable = 15; /**< Whether to enable transition disable feature */ + uint32 sae_ext = 16; /**< Enable SAE EXT feature. SOC_GCMP_SUPPORT is required for this feature. */ + wifi_bss_max_idle_config bss_max_idle_cfg = 17; /**< Configuration for bss max idle, effective if CONFIG_WIFI_BSS_MAX_IDLE_SUPPORT is enabled */ + uint32 gtk_rekey_interval = 18; /**< GTK rekeying interval in seconds. If set to 0, GTK rekeying is disabled. Range: 60 ~ 65535 including 0. */ } message wifi_sta_config { @@ -720,9 +744,13 @@ Units: AP beacon intervals. Defaults to 3 if set to 0. */ //uint32_t he_trig_su_bmforming_feedback_disabled:1; /**< Whether to disable support the transmission of SU feedback in an HE TB sounding sequence. */ //uint32_t he_trig_mu_bmforming_partial_feedback_disabled:1; /**< Whether to disable support the transmission of partial-bandwidth MU feedback in an HE TB sounding sequence. */ // uint32_t he_trig_cqi_feedback_disabled:1; /**< Whether to disable support the transmission of CQI feedback in an HE TB sounding sequence. */ - // uint32_t he_reserved:22; /**< Reserved for future feature set */ + // uint32_t vht_su_beamformee_disabled: 1; /**< Whether to disable support for operation as an VHT SU beamformee. */ + // uint32_t vht_mu_beamformee_disabled: 1; /**< Whether to disable support for operation as an VHT MU beamformee. */ + // uint32_t vht_mcs8_enabled: 1; /**< Whether to support VHT-MCS8. The default value is 0. */ + // uint32_t he_reserved:19; /**< Reserved for future feature set */ uint32 he_bitmask = 14; bytes sae_h2e_identifier = 15; /**< Password identifier for H2E. this needs to be null terminated string. SAE_H2E_IDENTIFIER_LEN chars */ + uint32 sae_pk_mode = 16; /**< Configuration for SAE-PK (Public Key) Authentication method */ } message wifi_config { diff --git a/common/rpc/esp_hosted_bitmasks.h b/common/rpc/esp_hosted_bitmasks.h index 1a432950..198725c0 100644 --- a/common/rpc/esp_hosted_bitmasks.h +++ b/common/rpc/esp_hosted_bitmasks.h @@ -6,29 +6,12 @@ #ifndef __ESP_HOSTED_BITMASKS__H #define __ESP_HOSTED_BITMASKS__H +#include "esp_idf_version.h" + #define H_SET_BIT(pos, val) (val|=(1<>STA_MAX_USED_BIT) - -#define WIFI_CONFIG_STA_SET_RESERVED_VAL(reserved_in,num_out) \ - (num_out|=(reserved_in << STA_MAX_USED_BIT)); - enum { WIFI_SCAN_AP_REC_phy_11b_BIT = 0, WIFI_SCAN_AP_REC_phy_11g_BIT = 1, @@ -46,10 +29,10 @@ enum { #define WIFI_SCAN_AP_RESERVED_BITMASK 0xFC00 #define WIFI_SCAN_AP_GET_RESERVED_VAL(num) \ - ((num&WIFI_SCAN_AP_RESERVED_BITMASK)>>WIFI_SCAN_AP_REC_MAX_USED_BIT) + ((num & WIFI_SCAN_AP_RESERVED_BITMASK) >> WIFI_SCAN_AP_REC_MAX_USED_BIT) #define WIFI_SCAN_AP_SET_RESERVED_VAL(reserved_in,num_out) \ - (num_out|=(reserved_in << WIFI_SCAN_AP_REC_MAX_USED_BIT)); + (num_out |= (reserved_in << WIFI_SCAN_AP_REC_MAX_USED_BIT)); enum { WIFI_STA_INFO_phy_11b_BIT = 0, @@ -64,10 +47,10 @@ enum { #define WIFI_STA_INFO_RESERVED_BITMASK 0xFFC0 #define WIFI_STA_INFO_GET_RESERVED_VAL(num) \ - ((num&WIFI_STA_INFO_RESERVED_BITMASK)>>WIFI_STA_INFO_MAX_USED_BIT) + ((num & WIFI_STA_INFO_RESERVED_BITMASK) >> WIFI_STA_INFO_MAX_USED_BIT) #define WIFI_STA_INFO_SET_RESERVED_VAL(reserved_in,num_out) \ - (num_out|=(reserved_in << WIFI_STA_INFO_MAX_USED_BIT)); + (num_out |= (reserved_in << WIFI_STA_INFO_MAX_USED_BIT)); /* WIFI HE AP Info bitmasks */ enum { @@ -79,27 +62,59 @@ enum { #define WIFI_HE_AP_INFO_BSS_COLOR_BITS 0x3F -/* WIFI HE Station Config bitmasks */ +/*** There are currently two set of bitfields in wifi_sta_config_t */ + +/* WIFI Station Config Bitfield 1 bitmasks */ enum { - WIFI_HE_STA_CONFIG_he_dcm_set_BIT = 0, - // WIFI_HE_STA_CONFIG_he_dcm_max_constellation_tx is two bits wide - WIFI_HE_STA_CONFIG_he_dcm_max_constellation_tx_BITS = 1, - // WIFI_HE_STA_CONFIG_he_dcm_max_constellation_rx is two bits wide - WIFI_HE_STA_CONFIG_he_dcm_max_constellation_rx_BITS = 3, - WIFI_HE_STA_CONFIG_he_mcs9_enabled_BIT = 5, - WIFI_HE_STA_CONFIG_he_su_beamformee_disabled_BIT = 6, - WIFI_HE_STA_CONFIG_he_trig_su_bmforming_feedback_disabled_BIT = 7, - WIFI_HE_STA_CONFIG_he_trig_mu_bmforming_partial_feedback_disabled_BIT = 8, - WIFI_HE_STA_CONFIG_he_trig_cqi_feedback_disabled_BIT = 9, - WIFI_HE_STA_CONFIG_MAX_USED_BIT = 10, + WIFI_STA_CONFIG_1_rm_enabled = 0, + WIFI_STA_CONFIG_1_btm_enabled = 1, + WIFI_STA_CONFIG_1_mbo_enabled = 2, + WIFI_STA_CONFIG_1_ft_enabled = 3, + WIFI_STA_CONFIG_1_owe_enabled = 4, + WIFI_STA_CONFIG_1_transition_disable = 5, + WIFI_STA_CONFIG_1_MAX_USED_BIT = 6, }; -#define WIFI_HE_STA_CONFIG_BITS 0xFC00 +#define WIFI_STA_CONFIG_1_RESERVED_BITMASK 0xFFFFFFC0 + +#define WIFI_STA_CONFIG_1_GET_RESERVED_VAL(num) \ + ((num & WIFI_STA_CONFIG_1_RESERVED_BITMASK) >> WIFI_STA_CONFIG_1_MAX_USED_BIT) + +#define WIFI_STA_CONFIG_1_SET_RESERVED_VAL(reserved_in, num_out) \ + (num_out |= (reserved_in << WIFI_STA_CONFIG_1_MAX_USED_BIT)); + +/* WIFI Station Config Bitfield 2 bitmasks */ +enum { + WIFI_STA_CONFIG_2_he_dcm_set_BIT = 0, + // WIFI_STA_CONFIG_he_dcm_max_constellation_tx is two bits wide + WIFI_STA_CONFIG_2_he_dcm_max_constellation_tx_BITS = 1, + // WIFI_STA_CONFIG_he_dcm_max_constellation_rx is two bits wide + WIFI_STA_CONFIG_2_he_dcm_max_constellation_rx_BITS = 3, + WIFI_STA_CONFIG_2_he_mcs9_enabled_BIT = 5, + WIFI_STA_CONFIG_2_he_su_beamformee_disabled_BIT = 6, + WIFI_STA_CONFIG_2_he_trig_su_bmforming_feedback_disabled_BIT = 7, + WIFI_STA_CONFIG_2_he_trig_mu_bmforming_partial_feedback_disabled_BIT = 8, + WIFI_STA_CONFIG_2_he_trig_cqi_feedback_disabled_BIT = 9, +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 5, 0) + WIFI_STA_CONFIG_2_MAX_USED_BIT = 10, +#else + WIFI_STA_CONFIG_2_vht_su_beamformee_disabled = 10, + WIFI_STA_CONFIG_2_vht_mu_beamformee_disabled = 11, + WIFI_STA_CONFIG_2_vht_mcs8_enabled = 12, + WIFI_STA_CONFIG_2_MAX_USED_BIT = 13, +#endif +}; + +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 5, 0) +#define WIFI_STA_CONFIG_2_RESERVED_BITMASK 0xFFFFFC00 +#else +#define WIFI_STA_CONFIG_2_RESERVED_BITMASK 0xFFFFE000 +#endif -#define WIFI_HE_STA_GET_RESERVED_VAL(num) \ - ((num&WIFI_HE_STA_CONFIG_BITS)>>WIFI_HE_STA_CONFIG_MAX_USED_BIT) +#define WIFI_STA_CONFIG_2_GET_RESERVED_VAL(num) \ + ((num & WIFI_STA_CONFIG_2_RESERVED_BITMASK) >> WIFI_STA_CONFIG_2_MAX_USED_BIT) -#define WIFI_HE_STA_SET_RESERVED_VAL(reserved_in,num_out) \ - (num_out|=(reserved_in << WIFI_HE_STA_CONFIG_MAX_USED_BIT)); +#define WIFI_STA_CONFIG_2_SET_RESERVED_VAL(reserved_in,num_out) \ + (num_out |= (reserved_in << WIFI_STA_CONFIG_2_MAX_USED_BIT)); #endif diff --git a/docs/bluetooth_design.md b/docs/bluetooth_design.md index 408f0b2a..cc52e89c 100644 --- a/docs/bluetooth_design.md +++ b/docs/bluetooth_design.md @@ -39,13 +39,17 @@ hardware. > Check that the memory requirement for your preferred Bluetooth host > stack can be satisfied on the Host. +> [!WARNING] +> The ESP32 only supports Bluetooth v4.2. If you are using a ESP32 as +> the co-processor, the host Bluetooth stack must also be v4.2. + ESP-Hosted is Bluetooth stack agnostic. To showcase ESP-Hosted's Bluetooth support, both `esp-nimble` and `esp-bluedroid` are used here. Users can use their own preferred Bluetooth stack with some porting effort. `esp-nimble` is a fork of Apache NimBLE and available from -ESP-IDF. The NimBLE Bluetooth slack proves Bluetooth Low Energy (BLE) +ESP-IDF. The NimBLE Bluetooth stack provides Bluetooth Low Energy (BLE) only functionality. `esp-bluedroid` is a fork of the Bluedroid based stack and available diff --git a/docs/esp32_p4_function_ev_board.md b/docs/esp32_p4_function_ev_board.md index 368519b4..9061d1f6 100644 --- a/docs/esp32_p4_function_ev_board.md +++ b/docs/esp32_p4_function_ev_board.md @@ -3,21 +3,20 @@
Table of Contents -- [Introduction](#1-introduction) -- [Set-Up ESP-IDF](#2-set-up-esp-idf) -- [Building Host for the P4](#3-building-host-for-the-p4) +- [1. Introduction](#1-introduction) +- [2. Set-Up ESP-IDF](#2-set-up-esp-idf) +- [3. Building Host for the P4](#3-building-host-for-the-p4) - [Adding Components](#31-adding-components) - [Configuring Defaults](#32-configuring-defaults) - [Building Firmware](#33-building-firmware) -- [Checking ESP-Hosted](#4-checking-esp-hosted) -- [Flashing ESP32-C6](#5-flashing-esp32-c6) +- [4. Checking ESP-Hosted](#4-checking-esp-hosted) +- [5. Flashing ESP32-C6](#5-flashing-esp32-c6) - [Using ESP-Prog](#51-using-esp-prog) - [OTA Updates](#52-ota-updates) -- [Troubleshooting](#6-troubleshooting) -- [Flashing the On-board ESP32-P4 through the ESP-Prog](#7-flashing-esp32-p4) -- [Testing ESP-Hosted with SPI-FD with other MCUs](#8-testing-esp-hosted-with-spi-fd-with-other-mcus) -- [References](#9-references) - +- [6. Troubleshooting](#6-troubleshooting) +- [7. Flashing the On-board ESP32-P4 through the ESP-Prog](#7-flashing-esp32-p4) +- [8. Testing ESP-Hosted with SPI-FD with other MCUs](#8-testing-esp-hosted-with-spi-fd-with-other-mcus) +- [9. References](#10-references)
## 1. Introduction @@ -382,6 +381,10 @@ Use GPIOs 36 or lower on the P4 DevKit to avoid LDO power issues with high numbe > [!NOTE] > Avoid using GPIO 35 and 36 as they affect the ESP32-P4 Bootloader Mode. See [ESP32-P4 Boot Mode Selection](https://docs.espressif.com/projects/esptool/en/latest/esp32p4/advanced-topics/boot-mode-selection.html#select-bootloader-mode) for more information. +> [!TIP] +> +> To measure the optimal performance, check out the [Shield Box Test Setup](shield-box-test-setup.md). + ## 9. References - ESP32-P4-Function-EV-Board: https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32p4/esp32-p4-function-ev-board/ diff --git a/docs/images/PerformanceSetup-ShieldBox.png b/docs/images/PerformanceSetup-ShieldBox.png new file mode 100644 index 00000000..6fe02fa4 Binary files /dev/null and b/docs/images/PerformanceSetup-ShieldBox.png differ diff --git a/docs/performance_optimization.md b/docs/performance_optimization.md new file mode 100644 index 00000000..b7cf70c6 --- /dev/null +++ b/docs/performance_optimization.md @@ -0,0 +1,102 @@ +# ESP-Hosted Performance Optimization Guide + +Quick reference for optimizing ESP-Hosted performance across different transport interfaces. + +## Quick Start - High Performance Config + +For immediate performance gains, add these to your host's `sdkconfig.defaults.esp32XX` file: + +``` +# Wi-Fi Performance +CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=16 +CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=64 +CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER_NUM=64 +CONFIG_ESP_WIFI_AMPDU_TX_ENABLED=y +CONFIG_ESP_WIFI_TX_BA_WIN=32 +CONFIG_ESP_WIFI_AMPDU_RX_ENABLED=y +CONFIG_ESP_WIFI_RX_BA_WIN=32 + +# TCP/IP Performance +CONFIG_LWIP_TCP_SND_BUF_DEFAULT=65534 +CONFIG_LWIP_TCP_WND_DEFAULT=65534 +CONFIG_LWIP_TCP_RECVMBOX_SIZE=64 +CONFIG_LWIP_UDP_RECVMBOX_SIZE=64 +CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=64 +CONFIG_LWIP_TCP_SACK_OUT=y +``` + +> **Note**: Adjust values based on your MCU host's memory capacity and as per change as per build system + +## Transport Optimization + +### SDIO (Highest Performance) +- **Clock Speed**: Start at 20 MHz, optimize up to 50 MHz +- **Bus Width**: Use 4-bit mode +- **Hardware**: Use PCB with controlled impedance, external pull-ups (51kΩ) +- **Checksum**: Optional (SDIO hardware handles verification) + +``` +CONFIG_ESP_HOSTED_SDIO_CLOCK_FREQ_KHZ=40000 +CONFIG_ESP_HOSTED_SDIO_BUS_WIDTH=4 +``` + +> [!NOTE] +> See [Performance and Memory Usage](sdio.md#9-performance-and-memory-usage) on the trade-off between SDIO Performance and Memory Use + +### SPI Full-Duplex +- **Clock Speed**: ESP32: ≤10 MHz, Others: ≤40 MHz +- **Hardware**: Use IO_MUX pins, short traces (≤10cm for jumpers) +- **Checksum**: Mandatory (SPI hardware lacks error detection) + +``` +CONFIG_ESP_HOSTED_SPI_CLK_FREQ=40 +``` + +### SPI Half-Duplex +- **Data Lines**: Use 4-line (Quad SPI) mode +- **Similar optimizations as SPI Full-Duplex** + +### UART (Lowest Performance) +- **Baud Rate**: Use 921600 (highest stable rate) +- **Best for**: Low-throughput applications, debugging + +## Memory Optimization + +- Reduce memory footprint for resource-constrained applications: + + ``` + # Reduce queue sizes + CONFIG_ESP_HOSTED_SDIO_TX_Q_SIZE=10 # Default: 20 + CONFIG_ESP_HOSTED_SDIO_RX_Q_SIZE=10 # Default: 20 + + # Enable memory pooling + CONFIG_ESP_HOSTED_USE_MEMPOOL=y + ``` + +- Disable the not-in-use features + - For example, disable bluetooth if not needed +- Use external RAM, for higher memory (PSRAM is supported) +- Optimise internal RAM using [ESP-IDF iram optimization tricks](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/performance/ram-usage.html) +## Hardware Guidelines + +### Critical Requirements +1. **Signal Integrity**: Use PCB designs for production, jumpers only for prototyping +2. **Power Supply**: Stable 3.3V, proper decoupling capacitors +3. **Trace Length**: Match lengths, especially clock vs data lines +4. **Pull-ups**: Required for SDIO (51kΩ) on CMD, D0-D3 lines + +### PCB Design Checklist +- [ ] Equal trace lengths for communication signals +- [ ] Ground plane for signal stability +- [ ] Controlled impedance traces (50Ω typical) +- [ ] Series termination resistors for high-speed signals +- [ ] Extra GPIOs reserved for future features (deep sleep, etc.) + +## Development Workflow +1. **Proof of Concept**: Start with jumper wires, low clock speeds +2. **Incremental Optimization**: Increase transport clock step by step +3. **Hardware Validation**: Move to PCB for final validation +4. **Performance Tuning**: Optimize buffers and configurations +5. **Disable features**: Any unsued components from ESP-IDF or +ESP-Hosted-MCU features could be disabled for more memory +availability. diff --git a/docs/sdio.md b/docs/sdio.md index 1d48c035..219d02d7 100644 --- a/docs/sdio.md +++ b/docs/sdio.md @@ -24,7 +24,9 @@ If you wish to skip the theory, you can refer the [Quick Start Guide](#1-quick-s 8. [Testing and Troubleshooting](#8-testing-and-troubleshooting) -9. [References](#9-references) +9. [Performance and Memory Usage](#9-performance-and-memory-usage) || [9.1 Stream and Packet Mode](#91-stream-and-packet-mode) || [9.2 Double Buffering on the Host](#92-double-buffering-on-the-host) || [9.3 Reducing Memory Usage](#93-reducing-memory-usage) || [9.4 Switching to Packet Mode](#94-switching-to-packet-mode) + +10. [References](#10-references) @@ -37,6 +39,7 @@ This section provides a brief overview of how to get started with ESP-Hosted usi - [6. Flashing the Co-processor](#6-flashing-the-co-processor) - [7. Flashing the Host](#7-flashing-the-host) - [8. Testing and Troubleshooting](#8-testing-and-troubleshooting) +- [9. Performance and Memory Usage](#9-performance-and-memory-usage) These sections will guide you through the process of flashing both the co-processor and host devices, setting up the hardware connections, and verifying successful communication. @@ -127,41 +130,61 @@ For optimal performance and reliability in production designs: Setting up the hardware involves connecting the master and co-processor devices via the SDIO pins and ensuring all extra GPIO signals are properly connected. Below is the table of connections for the SDIO setup between a host ESP chipset and another ESP chipset as co-processor: +### Host Connections + +SDIO-capable host microcontrollers (MCUs) can connect their GPIO lines to the co-processor as detailed in the table below. + +#### GPIO Flexibility + +- The ESP32 supports SDIO host on fixed GPIOs. +- The ESP32-S3 supports SDIO host on flexible GPIOs. +- For the ESP32-P4, Slot 0 supports fixed GPIOs, while Slot 1 supports flexible GPIOs. + +By default, Slot 1 is used on the ESP32-P4 to take advantage of its flexible pin mapping; however, Slot 0 is also supported. Parallel access to both Slot 0 and Slot 1 is supported for all hosts. + +| Signal | ESP32 | ESP32-S3 | +|-----------|-------|----------| +| CLK | 14 | 19 | +| CMD | 15+[ext-pull-up](#34-pull-up-resistors) | 47+[ext-pull-up](#34-pull-up-resistors) | +| D0 | 2+[ext-pull-up](#34-pull-up-resistors) | 13+[ext-pull-up](#34-pull-up-resistors) | +| D1 | 4+[ext-pull-up](#34-pull-up-resistors) | 35+[ext-pull-up](#34-pull-up-resistors) | +| D2 | 12+[ext-pull-up](#34-pull-up-resistors) | 20+[ext-pull-up](#34-pull-up-resistors) | +| D3 | 13+[ext-pull-up](#34-pull-up-resistors) | 9+[ext-pull-up](#34-pull-up-resistors) | +| Reset Out | 5 | 42 | -### Host connections -| Signal | ESP32 | ESP32-S3 | ESP32-P4-Function-EV-Board | -|-------------|-------|----------|----------| -| CLK | 14 | 19 | 18 | -| Reset Out | 5 | 42 | 54 | -| CMD | 15+[ext-pull-up](#34-pull-up-resistors) | 47+[ext-pull-up](#34-pull-up-resistors) | 19+[ext-pull-up](#34-pull-up-resistors) | -| DAT0 | 2+[ext-pull-up](#34-pull-up-resistors) | 13+[ext-pull-up](#34-pull-up-resistors) | 14+[ext-pull-up](#34-pull-up-resistors) | -| DAT1 | 4+[ext-pull-up](#34-pull-up-resistors) | 35+[ext-pull-up](#34-pull-up-resistors) | 15+[ext-pull-up](#34-pull-up-resistors) | -| DAT2 | 12+[ext-pull-up](#34-pull-up-resistors) | 20+[ext-pull-up](#34-pull-up-resistors) | 16+[ext-pull-up](#34-pull-up-resistors) | -| DAT3 | 13+[ext-pull-up](#34-pull-up-resistors) | 9+[ext-pull-up](#34-pull-up-resistors) | 17+[ext-pull-up](#34-pull-up-resistors) | +### ESP32-P4-Function-EV-Board Host Pin Mapping +| Signal | ESP32-P4 with ESP32-C6 Co-processor | ESP32-P4 with ESP32-C5 Co-processor | +|-----------|-------------------------------------|-------------------------------------| +| CLK | 18 | 33 | +| CMD | 19+[ext-pull-up](#34-pull-up-resistors) | 4+[ext-pull-up](#34-pull-up-resistors) | +| D0 | 14+[ext-pull-up](#34-pull-up-resistors) | 20+[ext-pull-up](#34-pull-up-resistors) | +| D1 | 15+[ext-pull-up](#34-pull-up-resistors) | 23+[ext-pull-up](#34-pull-up-resistors) | +| D2 | 16+[ext-pull-up](#34-pull-up-resistors) | 21+[ext-pull-up](#34-pull-up-resistors) | +| D3 | 17+[ext-pull-up](#34-pull-up-resistors) | 22+[ext-pull-up](#34-pull-up-resistors) | +| Reset Out | 54 | 53 | +> ### Co-processor connections -| Signal | ESP32 | ESP32-C6 | -|-------------|-------|----------| -| CLK | 14 | 19 | -| CMD | 15 | 18 | -| DAT0 | 2 | 20 | -| DAT1 | 4 | 21 | -| DAT2 | 12 | 22 | -| DAT3 | 13 | 23 | -| Reset In | EN | EN/RST | +SDIO slave provider ESP chips are : ESP32, ESP32-C5, ESP32-C6.\ +All these chips have fixed GPIOs SDIO support. +| Signal | ESP32 | ESP32-C6 | ESP32-C5 | +|----------|-------|----------|----------| +| CLK | 14 | 19 | 9 | +| CMD | 15 | 18 | 10 | +| D0 | 2 | 20 | 8 | +| D1 | 4 | 21 | 7 | +| D2 | 12 | 22 | 14 | +| D3 | 13 | 23 | 13 | +| Reset In | EN | EN/RST | RST | > [!NOTE] > -> A. Try to use IO_MUX pins from the datasheet for optimal performance on both sides. \ -> B. These GPIO assignments are based on default Kconfig configurations. You can modify these in the menuconfig for both host and co-processor if needed. \ -> C. Once ported, any other host with standard SDIO can be used. \ -> D. ESP32, ESP32-S3, and ESP32-P4 can be used as hosts; ESP32 and ESP32-C6 can be used as co-processors in SDIO mode. \ -> E. External pull-ups are mandatory +> - External pull-ups are mandatory ## 5 Set-Up ESP-IDF @@ -189,8 +212,8 @@ Please follow the [ESP-IDF Get Started Guide](https://docs.espressif.com/project ## 6. Flashing the Co-processor -| Supported Co-processor Targets | ESP32 | ESP32-C6 | -| ------------------------------ | ----- | -------- | +| Supported Co-processor Targets | ESP32 | ESP32-C6 | ESP32-C5 | +| ------------------------------ | ----- | -------- | -------- | There are four steps to flash the ESP-Hosted co-processor firmware: @@ -255,14 +278,11 @@ idf.py -p flash > > Put host in bootloader mode using following command and then retry flashing the co-processor > -> ```bash -> esptool.py -p **** --before default_reset --after no_reset run -> ``` - -Monitor the output (optional): -``` -idf.py -p monitor -``` +> `esptool.py -p **** --before default_reset --after no_reset run` +> +> Flash the co-processor and log the output: +> +> `idf.py -p flash monitor` ##### 6.4.2 Co-processor OTA Flashing (Subsequent Updates) @@ -288,7 +308,7 @@ You can re-use your existing web server or create a new locally for testing. Bel 5. On the **host side**, use the `esp_hosted_slave_ota` function to initiate the OTA update: ```c - #include "esp_hosted_api.h" + #include "esp_hosted.h" const char* image_url = "http://example.com/path/to/network_adapter.bin"; //web server full url esp_err_t ret = esp_hosted_slave_ota(image_url); @@ -524,6 +544,10 @@ After flashing both the co-processor and host devices, follow these steps to con Note: Replace `` with the IP address of the external STA, and `` with the IP address of the ESP-Hosted device. +> [!TIP] +> +> To measure the optimal performance, check out the [Shield Box Test Setup](shield-box-test-setup.md). + 8. Troubleshooting: - Consider using a lower clock speed or checking your [hardware setup](docs/sdio.md#7-hardware-setup) if you experience communication problems. - ESP-Hosted-MCU troubleshooting guide: [docs/troubleshooting.md](docs/troubleshooting.md) @@ -534,10 +558,83 @@ After flashing both the co-processor and host devices, follow these steps to con - Use a logic analyzer or oscilloscope to verify the SDIO signals. - Ensure that the power supply to both devices is stable and within the required voltage levels. -## 9 References +## 9 Performance and Memory Usage + +Quick summary: + +- for maximum network performance, at the cost of more memory usage on host and co-processor, use SDIO Streaming Mode (default mode of operation) +- for lower memory usage, at the cost of lower network performance, use [SDIO Packet Mode](#94-switching-to-packet-mode) + +### 9.1 Stream and Packet Mode + +The co-processor SDIO can operate in two modes: Streaming Mode and Packet Mode. + +| **Streaming Mode** | **Packet Mode** | +| --- | --- | +| Co-processor combines multiple queued Tx packets together into one large packet | Co-processor queues individual Tx packets | +| Host fetches the large packet as one SDIO transfer | Host fetches each packet one at a time | +| Host breaks the large packet back into individual packets to send to the Rx queue | Host sends each packet to the Rx queue | +| More efficient (less SDIO overhead), but requires more memory at Host to hold the large packet | Less efficient (higher SDIO overhead for each packet), but minimises memory required at Host | + +### 9.2 Double Buffering on the Host + +The Host implements a double-buffering scheme to receive data. One thread fetches data (using hardware DMA) from the co-processor and stores it in one Rx buffer, while another thread breaks up previously received data into packets for processing. + +### 9.3 Reducing Memory Usage in Streaming Mode + +#### 9.3.1 Host Receive + +> [!NOTE] +> **Host Receive**: Router --Network Data--> Co-processor --SDIO--> Host + +In SDIO streaming mode, the host receives SDIO data from the co-processor in one large SDIO transfer. For this reason, **Streaming mode consumes more heap memory** compared to Packet mode, and has a higher throughput (less SDIO overhead). + +For Host systems with high heap memory usage, you can reduce the amount of heap memory used by ESP-Hosted for buffers, at the cost of reduced throughput, by adjusting the number of Tx buffers used by the co-processor. + +**On the co-processor**: run `idf.py menuconfig` ---> `Example Configuration` ---> `SDIO Configuration` and adjust `SDIO Tx queue size`. The default queue size is `20`. + +The table below shows the effect of changing `SDIO Tx queue size` on throughput and memory usage on the Host. The throughput numbers are obtained by using the RawTP option in ESP-Hosted to send / receive raw SDIO data. + +| SDIO Tx queue size | Host Rx Raw Throughput (Mbits/s) | Memory Used by Buffers (Tested) | Memory Used by Buffers (Theoretical) | +| ---: | ---: | ---: | ---: | +| 5 | 54 | 12,288 | 15,360 | +| 10 | 70 | 26,624 | 30,720 | +| 15 | 76 | 41,984 | 46,080 | +| 20 | 80 | 56,320 | 61,440 | +| 25 | 82 | 65,536 | 76,800 | +| 30 | 84 | 65,536 | 92,160 | + +> [!NOTE] +> The SDIO packet size is 1536 bytes. The co-processor can send at most `(Tx queue size) * 1536` bytes. Since the Host does double buffering, the theoretical Buffer Size needed is `2 * (Tx queue size) * 1536`. + +From the table above, throughput is more or less stagnant on and above Rx queue size of `25`. For a good trade off between memory consumption vs performance, the Rx queue sizes are currently defaulted to `20`. + +#### 9.3.2 Host Transmit + +> [!NOTE] +> **Host Transmit**: Host --SDIO--> Co-Processor --Network Data--> Router + +To reduce memory usage on the co-processor, you can reduce the number of buffers the co-processor uses to receive data from the Host. + +**On the co-processor**: run `idf.py menuconfig` ---> `Example Configuration` ---> `SDIO Configuration` and adjust `SDIO Rx queue size`. The default queue size is `20`. + +Reducing the number of Rx buffers on the co-processor can affect the Tx throughput from the Host if the number of Rx buffers is set to a small value. + +### 9.4 Switching to Packet Mode + +For mimimal memory usage with a lower throughput, you can switch to Packet Mode. To do this: + +- on the co-processor: run `idf.py menuconfig` ---> `Example Configuration` ---> `SDIO Configuration` and untoggle `Enable SDIO Streaming Mode` +- on the host: run `idf.py menuconfig` ---> `Component config` ---> `ESP-Hosted config` ---> `Hosted SDIO COnfiguration` ---> `SDIO Receive Optimization` and select either `No optimization` or `Always Rx Max Packet size`. `Always Rx Max Packet size` will give a slightly higher throughput. + +In Packet Mode, the host uses `2 * 1536` or `3,072` bytes of memory for Rx buffers. + +- with `No optimization`, Rx Raw Throughput is 33.0 Mbits/s +- with `Always Rx Max Packet size`, Rx Raw Throughput is 33.2 Mbits/s + +## 10 References - [ESP-IDF Programming Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/) - [ESP32 Hardware Design Guidelines](https://www.espressif.com/en/products/hardware/esp32/resources) -- [SDIO Protocol Basics](https://en.wikipedia.org/wiki/Serial_Peripheral_Interface) -- [ESP SDIO Slave Communication](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/protocols/esp_sdio_slave_protocol.html) - +- [ESP SDIO Slave Communication](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/protocols/esp_sdio_slave_protocol.html) +- [ESP SDIO Card Slave Driver](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdio_slave.html) diff --git a/docs/shield-box-test-setup.md b/docs/shield-box-test-setup.md new file mode 100644 index 00000000..c107a3a5 --- /dev/null +++ b/docs/shield-box-test-setup.md @@ -0,0 +1,75 @@ +# Shield Box Test Setup for ESP-Hosted + +Controlled RF environment for consistent throughput measurements and performance evaluation. + +## Overview + +**Shield Box Testing** uses RF-shielded enclosure to eliminate external interference and provide repeatable test conditions. + +**Key Benefits:** +- Controlled RF environment (no external Wi-Fi/cellular interference) +- Repeatable, consistent results +- Better measurement accuracy vs open air + + +## Equipment Required + +### Essential Components +- **RF Shield Box/Chamber**: Faraday cage enclosure +- **ESP32-P4 Function EV Board**: Host device +- **ESP32-C6/C5 Test Board**: Co-processor device +- **External PC**: For iPerf client/server +- **Router/Access Point**: Wi-Fi infrastructure +- **Ethernet Connection**: Wired backhaul to PC + +Please change the host and co-processor nodes as per current use-case under test. + +## Test Setup + +### Physical Configuration + +Shield box testing setup + +### Data Flow +- **PC to MCU Host**: + ``` + PC -> Router -> ESP Co-processor == SDIO/SPI/UART ==> ESP32-P4 + ``` +- **MCU Host to PC**: + ``` + PC <- Router <- ESP Co-processor <== SDIO/SPI/UART == ESP32-P4 + ``` + +**Traffic route:** +- PC-to-Router: Ethernet with static IP (eliminates wireless variables) +- Router-to-ESP: Wi-Fi connection (only wireless link in test chain) + +## Transport Configurations + +### SDIO (Highest Performance) +- **Clock**: 20-50 MHz (start low, optimize up) +- **Bus Width**: 4-bit mode +- **Hardware**: External pull-ups (51kΩ) on CMD, D0-D3 + +### SPI +- **Clock**: ESP32: ≤10 MHz, Others: ≤40 MHz +- **Mode**: Full-duplex (simple) or Quad SPI (highest throughput) + +### UART +- **Baud Rate**: 921600 (highest stable rate) +- **Use Case**: Low-throughput validation, debugging + + +## Shield Box vs Open Air + +| Aspect | Shield Box | Open Air | +|--------|------------|----------| +| **Repeatability** | High | Variable | +| **Interference** | Eliminated | Present | +| **Debugging** | Easier | Complex | +| **Reality** | Lower | Higher | + + +--- + +*For transport setup details: [SDIO](sdio.md) | [SPI Full-Duplex](spi_full_duplex.md) | [SPI Half-Duplex](spi_half_duplex.md) | [UART](uart.md)* \ No newline at end of file diff --git a/docs/spi_full_duplex.md b/docs/spi_full_duplex.md index 3846e4ec..dad9738d 100644 --- a/docs/spi_full_duplex.md +++ b/docs/spi_full_duplex.md @@ -310,14 +310,11 @@ idf.py -p flash > > Put host in bootloader mode using following command and then retry flashing the co-processor > -> ```bash -> esptool.py -p --before default_reset --after no_reset run -> ``` - -Monitor the output (optional): -``` -idf.py -p monitor -``` +> `esptool.py -p **** --before default_reset --after no_reset run` +> +> Flash the co-processor and log the output: +> +> `idf.py -p flash monitor` ##### 7.4.2 Co-processor OTA Flashing (Subsequent Updates) @@ -343,7 +340,7 @@ You can re-use your existing web server or create a new locally for testing. Bel 5. On the **host side**, use the `esp_hosted_slave_ota` function to initiate the OTA update: ```c - #include "esp_hosted_api.h" + #include "esp_hosted.h" const char* image_url = "http://example.com/path/to/network_adapter.bin"; //web server full url esp_err_t ret = esp_hosted_slave_ota(image_url); @@ -538,7 +535,7 @@ After flashing both the co-processor and host devices, follow these steps to con - Set Wi-Fi mode: `wifi_mode ` (where mode can be 'sta', 'ap', or 'apsta') 7. Advanced iperf testing: - Once connected, you can run iperf tests: + Once connected, you can run iperf tests to verify performance: | Test Case | Host Command | External STA Command | |-----------|--------------|----------------------| @@ -549,6 +546,10 @@ After flashing both the co-processor and host devices, follow these steps to con Note: Replace `` with the IP address of the external STA, and `` with the IP address of the ESP-Hosted device. +> [!TIP] +> +> To measure the optimal performance, check out the [Shield Box Test Setup](shield-box-test-setup.md). + 8. Troubleshooting: - If you encounter issues, refer to section 6.3 for testing the SPI connection. - Consider using a lower clock speed or checking your [hardware connections](#5-hardware-setup) if you experience communication problems. diff --git a/docs/spi_half_duplex.md b/docs/spi_half_duplex.md index 1b524321..ed35b539 100644 --- a/docs/spi_half_duplex.md +++ b/docs/spi_half_duplex.md @@ -547,14 +547,11 @@ idf.py -p flash > > Put host in bootloader mode using following command and then retry flashing the co-processor > -> ```bash -> esptool.py -p **** --before default_reset --after no_reset run -> ``` - -Monitor the output (optional): -``` -idf.py -p monitor -``` +> `esptool.py -p **** --before default_reset --after no_reset run` +> +> Flash the co-processor and log the output: +> +> `idf.py -p flash monitor` ##### 9.4.2 Co-processor OTA Flashing (Subsequent Updates) @@ -580,7 +577,7 @@ You can re-use your existing web server or create a new locally for testing. Bel 5. On the **host side**, use the `esp_hosted_slave_ota` function to initiate the OTA update: ```c - #include "esp_hosted_api.h" + #include "esp_hosted.h" const char* image_url = "http://example.com/path/to/network_adapter.bin"; //web server full url esp_err_t ret = esp_hosted_slave_ota(image_url); @@ -784,7 +781,7 @@ After flashing both the co-processor and host devices, follow these steps to con - Set Wi-Fi mode: `wifi_mode ` (where mode can be 'sta', 'ap', or 'apsta') 7. Advanced iperf testing: - Once connected, you can run iperf tests: + Once connected, you can run iperf tests to verify performance: | Test Case | Host Command | External STA Command | | :-------: | :----------: | :------------------: | @@ -795,6 +792,10 @@ After flashing both the co-processor and host devices, follow these steps to con Note: Replace `` with the IP address of the external STA, and `` with the IP address of the ESP-Hosted device. +> [!TIP] +> +> To measure the optimal performance, check out the [Shield Box Test Setup](shield-box-test-setup.md). + 8. Troubleshooting: - If you encounter issues, refer to section 6.3 for testing the SPI connection. - Consider using a lower clock speed or checking your [hardware setup](#7-hardware-setup) if you experience communication problems. diff --git a/docs/uart.md b/docs/uart.md index 725139eb..0caa6eaf 100644 --- a/docs/uart.md +++ b/docs/uart.md @@ -187,14 +187,11 @@ idf.py -p flash > > Put host in bootloader mode using following command and then retry flashing the co-processor > -> ```bash -> esptool.py -p **** --before default_reset --after no_reset run -> ``` - -Monitor the output (optional): -``` -idf.py -p monitor -``` +> `esptool.py -p **** --before default_reset --after no_reset run` +> +> Flash the co-processor and log the output: +> +> `idf.py -p flash monitor` ##### 6.4.2 Co-processor OTA Flashing (Subsequent Updates) @@ -220,7 +217,7 @@ You can re-use your existing web server or create a new locally for testing. Bel 5. On the **host side**, use the `esp_hosted_slave_ota` function to initiate the OTA update: ```c - #include "esp_hosted_api.h" + #include "esp_hosted.h" const char* image_url = "http://example.com/path/to/network_adapter.bin"; //web server full url esp_err_t ret = esp_hosted_slave_ota(image_url); @@ -424,7 +421,7 @@ After flashing both the co-processor and host devices, follow these steps to con - Set Wi-Fi mode: `wifi_mode ` (where mode can be 'sta', 'ap', or 'apsta') 7. Advanced iperf testing: - Once connected, you can run iperf tests: + Once connected, you can run iperf tests to verify performance: | Test Case | Host Command | External STA Command | |-----------|--------------|----------------------| @@ -435,6 +432,10 @@ After flashing both the co-processor and host devices, follow these steps to con Note: Replace `` with the IP address of the external STA, and `` with the IP address of the ESP-Hosted device. +> [!TIP] +> +> To measure the optimal performance, check out the [Shield Box Test Setup](shield-box-test-setup.md). + 8. Troubleshooting: - If you encounter issues, refer to section 3.3 for checking the UART connection. - Consider using a lower baud rate or checking your [hardware setup](#4-hardware-setup) if you experience communication problems. diff --git a/examples/host_bluedroid_ble_compatibility_test/main/idf_component.yml b/examples/host_bluedroid_ble_compatibility_test/main/idf_component.yml index 57b37833..50ffd415 100644 --- a/examples/host_bluedroid_ble_compatibility_test/main/idf_component.yml +++ b/examples/host_bluedroid_ble_compatibility_test/main/idf_component.yml @@ -1,5 +1,9 @@ dependencies: espressif/esp_wifi_remote: - version: "~0.5.1" + version: ">=0.10" + rules: + - if: "target in [esp32p4, esp32h2]" + espressif/esp_hosted: + version: "~2" rules: - if: "target in [esp32p4, esp32h2]" diff --git a/examples/host_bluedroid_ble_compatibility_test/sdkconfig.defaults b/examples/host_bluedroid_ble_compatibility_test/sdkconfig.defaults index 5b03a89c..30fef8e2 100644 --- a/examples/host_bluedroid_ble_compatibility_test/sdkconfig.defaults +++ b/examples/host_bluedroid_ble_compatibility_test/sdkconfig.defaults @@ -1,7 +1,10 @@ # # BT config +# - ESP32 co-processor only supports BLE 4.2 # CONFIG_BT_ENABLED=y +CONFIG_BT_CONTROLLER_DISABLED=y +CONFIG_BT_BLUEDROID_ENABLED=y CONFIG_BT_BLE_50_FEATURES_SUPPORTED=n CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y # CONFIG_BT_LE_50_FEATURE_SUPPORT is not used on ESP32, ESP32-C3 and ESP32-S3. diff --git a/examples/host_bluedroid_bt_hid_mouse_device/main/idf_component.yml b/examples/host_bluedroid_bt_hid_mouse_device/main/idf_component.yml index 57b37833..50ffd415 100644 --- a/examples/host_bluedroid_bt_hid_mouse_device/main/idf_component.yml +++ b/examples/host_bluedroid_bt_hid_mouse_device/main/idf_component.yml @@ -1,5 +1,9 @@ dependencies: espressif/esp_wifi_remote: - version: "~0.5.1" + version: ">=0.10" + rules: + - if: "target in [esp32p4, esp32h2]" + espressif/esp_hosted: + version: "~2" rules: - if: "target in [esp32p4, esp32h2]" diff --git a/examples/host_bluedroid_bt_hid_mouse_device/sdkconfig.defaults b/examples/host_bluedroid_bt_hid_mouse_device/sdkconfig.defaults index f4e3f497..22e6ff19 100644 --- a/examples/host_bluedroid_bt_hid_mouse_device/sdkconfig.defaults +++ b/examples/host_bluedroid_bt_hid_mouse_device/sdkconfig.defaults @@ -1,18 +1,25 @@ # # BT config +# - ESP32 co-processor only supports BLE 4.2 # CONFIG_BT_ENABLED=y -CONFIG_BTDM_CTRL_MODE_BLE_ONLY=n -CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=y -CONFIG_BTDM_CTRL_MODE_BTDM=n +CONFIG_BT_CONTROLLER_DISABLED=y +CONFIG_BT_BLUEDROID_ENABLED=y CONFIG_BT_CLASSIC_ENABLED=y CONFIG_BT_HID_ENABLED=y CONFIG_BT_HID_DEVICE_ENABLED=y +CONFIG_BT_BLE_50_FEATURES_SUPPORTED=n +CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y +CONFIG_BTDM_CTRL_MODE_BLE_ONLY=n +CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=y +CONFIG_BTDM_CTRL_MODE_BTDM=n # # Wi-Fi Remote +# - set ESP32 as default co-processor # CONFIG_ESP_WIFI_REMOTE_LIBRARY_HOSTED=y +CONFIG_SLAVE_IDF_TARGET_ESP32=y # # Enable ESP Hosted BT diff --git a/examples/host_bluedroid_host_only/main/idf_component.yml b/examples/host_bluedroid_host_only/main/idf_component.yml index 57b37833..50ffd415 100644 --- a/examples/host_bluedroid_host_only/main/idf_component.yml +++ b/examples/host_bluedroid_host_only/main/idf_component.yml @@ -1,5 +1,9 @@ dependencies: espressif/esp_wifi_remote: - version: "~0.5.1" + version: ">=0.10" + rules: + - if: "target in [esp32p4, esp32h2]" + espressif/esp_hosted: + version: "~2" rules: - if: "target in [esp32p4, esp32h2]" diff --git a/examples/host_bluedroid_host_only/sdkconfig.defaults b/examples/host_bluedroid_host_only/sdkconfig.defaults index 2cc253b9..02095c4c 100644 --- a/examples/host_bluedroid_host_only/sdkconfig.defaults +++ b/examples/host_bluedroid_host_only/sdkconfig.defaults @@ -1,15 +1,20 @@ # # BT config +# - ESP32 co-processor only supports BLE 4.2 # -CONFIG_BT_CONTROLLER_DISABLED=y CONFIG_BT_ENABLED=y +CONFIG_BT_CONTROLLER_DISABLED=y CONFIG_BT_BLUEDROID_ENABLED=y CONFIG_BT_CLASSIC_ENABLED=y +CONFIG_BT_BLE_50_FEATURES_SUPPORTED=n +CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y # # Wi-Fi Remote +# - set ESP32 as default co-processor # CONFIG_ESP_WIFI_REMOTE_LIBRARY_HOSTED=y +CONFIG_SLAVE_IDF_TARGET_ESP32=y # # Enable ESP Hosted BT diff --git a/examples/host_nimble_bleprph_host_only_uart_hci/main/idf_component.yml b/examples/host_nimble_bleprph_host_only_uart_hci/main/idf_component.yml index aea470e2..6a234b8b 100644 --- a/examples/host_nimble_bleprph_host_only_uart_hci/main/idf_component.yml +++ b/examples/host_nimble_bleprph_host_only_uart_hci/main/idf_component.yml @@ -2,10 +2,10 @@ dependencies: nimble_peripheral_utils: path: ${IDF_PATH}/examples/bluetooth/nimble/common/nimble_peripheral_utils espressif/esp_wifi_remote: - version: "*" + version: ">=0.10" rules: - if: "target in [esp32p4, esp32h2]" espressif/esp_hosted: - version: "~1" + version: "~2" rules: - if: "target in [esp32p4, esp32h2]" diff --git a/examples/host_nimble_bleprph_host_only_vhci/main/idf_component.yml b/examples/host_nimble_bleprph_host_only_vhci/main/idf_component.yml index c2ddf618..6a234b8b 100644 --- a/examples/host_nimble_bleprph_host_only_vhci/main/idf_component.yml +++ b/examples/host_nimble_bleprph_host_only_vhci/main/idf_component.yml @@ -2,6 +2,10 @@ dependencies: nimble_peripheral_utils: path: ${IDF_PATH}/examples/bluetooth/nimble/common/nimble_peripheral_utils espressif/esp_wifi_remote: - version: "~0.5.1" + version: ">=0.10" + rules: + - if: "target in [esp32p4, esp32h2]" + espressif/esp_hosted: + version: "~2" rules: - if: "target in [esp32p4, esp32h2]" diff --git a/host/api/include/esp_hosted_bt_config.h b/host/api/include/esp_hosted_bt_config.h index 4b3aa325..6e95d262 100644 --- a/host/api/include/esp_hosted_bt_config.h +++ b/host/api/include/esp_hosted_bt_config.h @@ -6,6 +6,13 @@ #ifndef __ESP_HOSTED_BT_CONFIG_H__ #define __ESP_HOSTED_BT_CONFIG_H__ +// check: if co-processor SOC is ESP32, only BT BLE 4.2 is supported +#if CONFIG_SLAVE_IDF_TARGET_ESP32 +#if CONFIG_BT_BLE_50_FEATURES_SUPPORTED || CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT +#error "ESP32 co-processor only supports BLE 4.2" +#endif +#endif + // Hosted BT defines for NimBLE #if CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE #define H_BT_HOST_ESP_NIMBLE 1 diff --git a/host/api/include/esp_hosted_config.h b/host/api/include/esp_hosted_config.h index f1053e1a..f4e796d8 100644 --- a/host/api/include/esp_hosted_config.h +++ b/host/api/include/esp_hosted_config.h @@ -16,10 +16,6 @@ #define H_TRANSPORT_SPI 3 #define H_TRANSPORT_UART 4 -#ifdef CONFIG_ESP_HOSTED_SDIO_HOST_INTERFACE -#include "driver/sdmmc_host.h" -#endif - #ifdef CONFIG_ESP_HOSTED_UART_HOST_INTERFACE #include "hal/uart_types.h" #endif @@ -148,7 +144,7 @@ so feel free to change these if needed. #define H_SDIO_CLOCK_FREQ_KHZ CONFIG_ESP_HOSTED_SDIO_CLOCK_FREQ_KHZ #define H_SDIO_BUS_WIDTH CONFIG_ESP_HOSTED_SDIO_BUS_WIDTH -#define H_SDMMC_HOST_SLOT SDMMC_HOST_SLOT_1 +#define H_SDMMC_HOST_SLOT CONFIG_ESP_HOSTED_SDIO_SLOT #ifdef H_SDIO_SOC_USE_GPIO_MATRIX #define H_SDIO_PIN_CLK CONFIG_ESP_HOSTED_SDIO_PIN_CLK @@ -331,7 +327,7 @@ enum { #define H_RESET_ACTIVE_HIGH 1 #endif -#ifdef H_RESET_ACTIVE_HIGH +#if H_RESET_ACTIVE_HIGH #define H_RESET_VAL_ACTIVE H_GPIO_HIGH #define H_RESET_VAL_INACTIVE H_GPIO_LOW #else @@ -379,6 +375,20 @@ enum { #define H_TEST_RAW_TP_DIR (ESP_TEST_RAW_TP_NONE) #endif +/* ---------------------- ESP-IDF Specific Config start -------------------- */ +/* This section is for ESP-IDF specific support. + * Can be ignored on other hosts MCUs. + */ + +/* Controls whether an Internal LDO powers the SDIO connection */ +#if CONFIG_ESP_HOSTED_SD_PWR_CTRL_LDO_INTERNAL_IO +#define H_SDIO_PWR_CTRL_LDO 1 +#define H_SDIO_PWR_CTRL_LDO_ID CONFIG_ESP_HOSTED_SD_PWR_CTRL_LDO_IO_ID +#else +#define H_SDIO_PWR_CTRL_LDO 0 +#endif + +/* ---------------------- ESP-IDF Specific Config end ---------------------- */ esp_err_t esp_hosted_set_default_config(void); bool esp_hosted_is_config_valid(void); diff --git a/host/api/include/esp_hosted_ota.h b/host/api/include/esp_hosted_ota.h new file mode 100644 index 00000000..2a9fffab --- /dev/null +++ b/host/api/include/esp_hosted_ota.h @@ -0,0 +1,35 @@ +/* +* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD +* +* SPDX-License-Identifier: Apache-2.0 +*/ + +/* APIs to do OTA updates of the co-processor + * + * Note: This API is platform dependent + * + * Add additional APIs as required based on how the OTA binary is to + * be fetched. + * + * Source for the API should be in host/port//... + * + * Procedure used by APIs to do OTA update: + * 1. Fetch and prepare OTA binary + * 2. Call rpc_ota_begin() to start OTA + * 3. Repeatedly call rpc_ota_write() with a continuous chunk of OTA data + * 4. Call rpc_ota_end() + * + */ + +#ifndef __ESP_HOSTED_OTA_H__ +#define __ESP_HOSTED_OTA_H__ + +#ifdef ESP_PLATFORM +// OTA API for ESP-IDF +#include "esp_err.h" + +/* Fetch OTA image from a web server (image_url) */ +esp_err_t esp_hosted_slave_ota(const char* image_url); +#endif + +#endif /*__ESP_HOSTED_OTA_H__*/ diff --git a/host/api/include/esp_hosted_transport_config.h b/host/api/include/esp_hosted_transport_config.h index 25b4e449..fd03de33 100644 --- a/host/api/include/esp_hosted_transport_config.h +++ b/host/api/include/esp_hosted_transport_config.h @@ -34,6 +34,7 @@ struct esp_hosted_sdio_config { gpio_pin_t pin_d1; gpio_pin_t pin_d2; gpio_pin_t pin_d3; + gpio_pin_t pin_reset; uint8_t rx_mode; bool block_mode; bool iomux_enable; @@ -51,6 +52,7 @@ struct esp_hosted_spi_hd_config { gpio_pin_t pin_d1; gpio_pin_t pin_d2; gpio_pin_t pin_d3; + gpio_pin_t pin_reset; /* SPI HD configuration */ uint32_t clk_mhz; @@ -71,6 +73,7 @@ struct esp_hosted_spi_config { gpio_pin_t pin_cs; gpio_pin_t pin_handshake; gpio_pin_t pin_data_ready; + gpio_pin_t pin_reset; /* SPI Full Duplex configuration */ uint16_t tx_queue_size; @@ -86,6 +89,7 @@ struct esp_hosted_uart_config { /* UART pins */ gpio_pin_t pin_tx; gpio_pin_t pin_rx; + gpio_pin_t pin_reset; /* UART configuration */ uint8_t num_data_bits; @@ -121,12 +125,12 @@ struct esp_hosted_transport_config { .pin_d1 = {.port = NULL, .pin = H_SDIO_PIN_D1}, \ .pin_d2 = {.port = NULL, .pin = H_SDIO_PIN_D2}, \ .pin_d3 = {.port = NULL, .pin = H_SDIO_PIN_D3}, \ + .pin_reset = {.port = NULL, .pin = H_GPIO_PIN_RESET_Pin }, \ .rx_mode = H_SDIO_HOST_RX_MODE, \ .block_mode = H_SDIO_TX_BLOCK_ONLY_XFER && H_SDIO_RX_BLOCK_ONLY_XFER, \ .iomux_enable = false, \ } - #define INIT_DEFAULT_HOST_SDIO_IOMUX_CONFIG() \ (struct esp_hosted_sdio_config) { \ .clock_freq_khz = H_SDIO_CLOCK_FREQ_KHZ, \ @@ -149,6 +153,7 @@ struct esp_hosted_transport_config { .pin_d1 = {.port = NULL, .pin = H_SPI_HD_PIN_D1}, \ .pin_d2 = {.port = NULL, .pin = H_SPI_HD_PIN_D2}, \ .pin_d3 = {.port = NULL, .pin = H_SPI_HD_PIN_D3}, \ + .pin_reset = {.port = NULL, .pin = H_GPIO_PIN_RESET_Pin }, \ .clk_mhz = H_SPI_HD_CLK_MHZ, \ .mode = H_SPI_HD_MODE, \ .tx_queue_size = H_SPI_HD_TX_QUEUE_SIZE, \ @@ -169,6 +174,7 @@ struct esp_hosted_transport_config { .pin_cs = {.port = NULL, .pin = H_GPIO_CS_Pin}, \ .pin_handshake = {.port = NULL, .pin = H_GPIO_HANDSHAKE_Pin}, \ .pin_data_ready = {.port = NULL, .pin = H_GPIO_DATA_READY_Pin}, \ + .pin_reset = {.port = NULL, .pin = H_GPIO_PIN_RESET_Pin }, \ .tx_queue_size = H_SPI_TX_Q, \ .rx_queue_size = H_SPI_RX_Q, \ .mode = H_SPI_MODE, \ @@ -182,6 +188,7 @@ struct esp_hosted_transport_config { .port = H_UART_PORT, \ .pin_tx = {.port = NULL, .pin = H_UART_TX_PIN}, \ .pin_rx = {.port = NULL, .pin = H_UART_RX_PIN}, \ + .pin_reset = {.port = NULL, .pin = H_GPIO_PIN_RESET_Pin }, \ .num_data_bits = H_UART_NUM_DATA_BITS, \ .parity = H_UART_PARITY, \ .stop_bits = H_UART_STOP_BITS, \ @@ -197,6 +204,8 @@ struct esp_hosted_transport_config { /* Configuration get/set functions */ esp_hosted_transport_err_t esp_hosted_transport_set_default_config(void); esp_hosted_transport_err_t esp_hosted_transport_get_config(struct esp_hosted_transport_config **config); +esp_hosted_transport_err_t esp_hosted_transport_get_reset_config(gpio_pin_t *pin_config); + bool esp_hosted_transport_is_config_valid(void); #if H_TRANSPORT_SDIO == H_TRANSPORT_IN_USE diff --git a/host/api/include/esp_hosted_wifi_remote_glue.h b/host/api/include/esp_hosted_wifi_remote_glue.h new file mode 100644 index 00000000..6e070556 --- /dev/null +++ b/host/api/include/esp_hosted_wifi_remote_glue.h @@ -0,0 +1,44 @@ +/* +* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD +* +* SPDX-License-Identifier: Apache-2.0 +*/ + +#ifndef __ESP_HOSTED_WIFI_REMOTE_GLUE_H__ +#define __ESP_HOSTED_WIFI_REMOTE_GLUE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "esp_hosted_interface.h" +#include "esp_wifi_remote.h" +#include "esp_wifi.h" + +struct esp_remote_channel_config { + esp_hosted_if_type_t if_type; + bool secure; +}; + +typedef struct esp_remote_channel_config * esp_remote_channel_config_t; + +/* Transport/Channel related data structures and macros */ +#define ESP_HOSTED_CHANNEL_CONFIG_DEFAULT() { \ + .secure = true, \ +} + +/* Function pointer types for channel callbacks */ +typedef esp_err_t (*esp_remote_channel_rx_fn_t)(void *h, void *buffer, + void *buff_to_free, size_t len); +typedef esp_err_t (*esp_remote_channel_tx_fn_t)(void *h, void *buffer, size_t len); + +/* Transport/Channel Management API Functions - use managed component typedef */ +esp_remote_channel_t esp_hosted_add_channel(esp_remote_channel_config_t config, + esp_remote_channel_tx_fn_t *tx, const esp_remote_channel_rx_fn_t rx); +esp_err_t esp_hosted_remove_channel(esp_remote_channel_t channel); + +#ifdef __cplusplus +} +#endif + +#endif /* __ESP_HOSTED_WIFI_REMOTE_GLUE_H__ */ diff --git a/host/api/include/esp_hosted_api.h b/host/api/priv/esp_hosted_api_priv.h similarity index 79% rename from host/api/include/esp_hosted_api.h rename to host/api/priv/esp_hosted_api_priv.h index be50610d..94a817bc 100644 --- a/host/api/include/esp_hosted_api.h +++ b/host/api/priv/esp_hosted_api_priv.h @@ -4,43 +4,23 @@ * SPDX-License-Identifier: Apache-2.0 */ -/** prevent recursive inclusion **/ -#ifndef __ESP_HOSTED_API_H__ -#define __ESP_HOSTED_API_H__ +/* prevent recursive inclusion */ +#ifndef __ESP_HOSTED_API_PRIV_H__ +#define __ESP_HOSTED_API_PRIV_H__ #ifdef __cplusplus extern "C" { #endif -/** Includes **/ +/* Includes */ #include "stdbool.h" #include "esp_wifi.h" #include "esp_wifi_remote.h" #include "esp_hosted_api_types.h" +#include "esp_hosted_ota.h" +#include "esp_hosted_wifi_config.h" -/** Exported variables **/ -#define ESP_HOSTED_CHANNEL_CONFIG_DEFAULT() { \ - .secure = true, \ -} - -struct esp_remote_channel_config { - int if_type; // values should be of esp_hosted_if_type_t - bool secure; -}; - -/** Inline functions **/ - -/** Exported Functions **/ -esp_err_t esp_hosted_init(void); -esp_err_t esp_hosted_deinit(void); -esp_err_t esp_hosted_reinit(void); - -esp_err_t esp_hosted_setup(void); -esp_err_t esp_hosted_slave_reset(void); -esp_remote_channel_t esp_hosted_add_channel(esp_remote_channel_config_t config, - esp_remote_channel_tx_fn_t *tx, const esp_remote_channel_rx_fn_t rx); -esp_err_t esp_hosted_remove_channel(esp_remote_channel_t channel); - +/* Remote WiFi API Functions - Port/Implementation Specific */ esp_err_t esp_wifi_remote_init(const wifi_init_config_t *arg); esp_err_t esp_wifi_remote_deinit(void); esp_err_t esp_wifi_remote_set_mode(wifi_mode_t mode); @@ -84,10 +64,9 @@ esp_err_t esp_wifi_remote_set_max_tx_power(int8_t power); esp_err_t esp_wifi_remote_get_max_tx_power(int8_t *power); esp_err_t esp_wifi_remote_sta_get_negotiated_phymode(wifi_phy_mode_t *phymode); esp_err_t esp_wifi_remote_sta_get_aid(uint16_t *aid); -esp_err_t esp_hosted_slave_ota(const char* image_url); -esp_err_t esp_hosted_get_coprocessor_fwversion(esp_hosted_coprocessor_fwver_t *ver_info); #if H_WIFI_DUALBAND_SUPPORT +/* Dual-band WiFi API (Depends upon co-processor used) */ esp_err_t esp_wifi_remote_set_band(wifi_band_t band); esp_err_t esp_wifi_remote_get_band(wifi_band_t *band); esp_err_t esp_wifi_remote_set_band_mode(wifi_band_mode_t band_mode); @@ -102,4 +81,4 @@ esp_err_t esp_wifi_remote_get_bandwidths(wifi_interface_t ifx, wifi_bandwidths_t } #endif -#endif +#endif /* __ESP_HOSTED_API_PRIV_H__ */ \ No newline at end of file diff --git a/host/api/src/esp_hosted_api.c b/host/api/src/esp_hosted_api.c index f5a492cf..01aa034b 100644 --- a/host/api/src/esp_hosted_api.c +++ b/host/api/src/esp_hosted_api.c @@ -10,9 +10,9 @@ extern "C" { /** Includes **/ #include "esp_hosted_transport_config.h" -#include "esp_wifi_remote.h" #include "esp_hosted_wifi_config.h" -#include "esp_hosted_api.h" +#include "esp_hosted_api_priv.h" +#include "esp_hosted_wifi_remote_glue.h" #include "esp_check.h" #include "transport_drv.h" #include "rpc_wrap.h" @@ -30,10 +30,6 @@ struct esp_remote_channel { //static semaphore_handle_t transport_up_sem; -typedef esp_err_t (*esp_remote_channel_rx_fn_t)(void *h, void *buffer, - void *buff_to_free, size_t len); -typedef esp_err_t (*esp_remote_channel_tx_fn_t)(void *h, void *buffer, size_t len); - /** Inline functions **/ /** Exported Functions **/ @@ -96,7 +92,7 @@ static void set_host_modules_log_level(void) esp_log_level_set("rpc_rsp", ESP_LOG_WARN); esp_log_level_set("rpc_evt", ESP_LOG_WARN); } -esp_err_t esp_hosted_init(void) +int esp_hosted_init(void) { if (esp_hosted_init_done) return ESP_OK; @@ -120,7 +116,7 @@ esp_err_t esp_hosted_init(void) return ESP_OK; } -esp_err_t esp_hosted_deinit(void) +int esp_hosted_deinit(void) { ESP_LOGI(TAG, "ESP-Hosted deinit\n"); rpc_unregister_event_callbacks(); @@ -141,16 +137,7 @@ static inline esp_err_t esp_hosted_reconfigure(void) return ESP_OK; } -esp_err_t esp_hosted_reinit(void) -{ - ESP_LOGI(TAG, "ESP-Hosted re-init\n"); - ESP_ERROR_CHECK(esp_hosted_deinit()); - ESP_ERROR_CHECK(esp_hosted_init()); - ESP_ERROR_CHECK(esp_hosted_reconfigure()); - return ESP_OK; -} - -esp_err_t esp_hosted_slave_reset(void) +int esp_hosted_connect_to_slave(void) { ESP_LOGI(TAG, "ESP-Hosted Try to communicate with ESP-Hosted slave\n"); return esp_hosted_reconfigure(); @@ -399,8 +386,8 @@ esp_err_t esp_wifi_remote_sta_get_aid(uint16_t *aid) { return rpc_wifi_sta_get_aid(aid); } - #if H_WIFI_DUALBAND_SUPPORT +/* Dual-band WiFi API - always available at high level, but returns ESP_ERR_NOT_SUPPORTED when co-processor do not support */ esp_err_t esp_wifi_remote_set_band(wifi_band_t band) { return rpc_wifi_set_band(band); @@ -442,11 +429,6 @@ esp_err_t esp_wifi_remote_get_bandwidths(wifi_interface_t ifx, wifi_bandwidths_t } #endif -esp_err_t esp_hosted_slave_ota(const char* image_url) -{ - return rpc_ota(image_url); -} - esp_err_t esp_hosted_get_coprocessor_fwversion(esp_hosted_coprocessor_fwver_t *ver_info) { return rpc_get_coprocessor_fwversion(ver_info); diff --git a/host/api/src/esp_wifi_weak.c b/host/api/src/esp_wifi_weak.c index 33459d72..ba9374d4 100644 --- a/host/api/src/esp_wifi_weak.c +++ b/host/api/src/esp_wifi_weak.c @@ -19,7 +19,7 @@ * Used when WiFi-Remote does not provide required esp_wifi calls */ -#include "esp_hosted_api.h" +#include "esp_hosted_api_priv.h" #include "esp_hosted_wifi_config.h" #define WEAK __attribute__((weak)) diff --git a/host/drivers/bt/vhci_drv.c b/host/drivers/bt/vhci_drv.c index 97e9a999..4a1fa850 100644 --- a/host/drivers/bt/vhci_drv.c +++ b/host/drivers/bt/vhci_drv.c @@ -135,6 +135,11 @@ void ble_transport_ll_init(void) { ESP_ERROR_CHECK(transport_drv_reconfigure()); } + +void ble_transport_ll_deinit(void) +{ + // transport may still be in used for other data (serial, Wi-Fi, ...) +} #endif int ble_transport_to_ll_acl_impl(struct os_mbuf *om) @@ -211,7 +216,7 @@ int hci_rx_handler(interface_buffer_handle_t *buf_handle) s_callback.notify_host_recv(data, len_total_read); } - return ESP_FAIL; + return ESP_OK; } void hosted_hci_bluedroid_open(void) diff --git a/host/drivers/rpc/core/rpc_req.c b/host/drivers/rpc/core/rpc_req.c index 80bb6c69..cfe37cb3 100644 --- a/host/drivers/rpc/core/rpc_req.c +++ b/host/drivers/rpc/core/rpc_req.c @@ -168,6 +168,8 @@ int compose_rpc_req(Rpc *req, ctrl_cmd_t *app_req, int32_t *failure_status) req_payload->cfg->tx_buf_type = p_a->tx_buf_type ; req_payload->cfg->static_tx_buf_num = p_a->static_tx_buf_num ; req_payload->cfg->dynamic_tx_buf_num = p_a->dynamic_tx_buf_num ; + req_payload->cfg->rx_mgmt_buf_type = p_a->rx_mgmt_buf_type ; + req_payload->cfg->rx_mgmt_buf_num = p_a->rx_mgmt_buf_num ; req_payload->cfg->cache_tx_buf_num = p_a->cache_tx_buf_num ; req_payload->cfg->csi_enable = p_a->csi_enable ; req_payload->cfg->ampdu_rx_enable = p_a->ampdu_rx_enable ; @@ -178,9 +180,12 @@ int compose_rpc_req(Rpc *req, ctrl_cmd_t *app_req, int32_t *failure_status) req_payload->cfg->rx_ba_win = p_a->rx_ba_win ; req_payload->cfg->wifi_task_core_id = p_a->wifi_task_core_id ; req_payload->cfg->beacon_max_len = p_a->beacon_max_len ; + req_payload->cfg->feature_caps = p_a->feature_caps ; req_payload->cfg->mgmt_sbuf_num = p_a->mgmt_sbuf_num ; req_payload->cfg->sta_disconnected_pm = p_a->sta_disconnected_pm ; req_payload->cfg->espnow_max_encrypt_num = p_a->espnow_max_encrypt_num ; + req_payload->cfg->tx_hetb_queue_num = p_a->tx_hetb_queue_num ; + req_payload->cfg->dump_hesigb_enable = p_a->dump_hesigb_enable ; req_payload->cfg->magic = p_a->magic ; /* uint64 - TODO: portable? */ @@ -226,60 +231,87 @@ int compose_rpc_req(Rpc *req, ctrl_cmd_t *app_req, int32_t *failure_status) RPC_ALLOC_ELEMENT(WifiScanThreshold, p_c_sta->threshold, wifi_scan_threshold__init); p_c_sta->threshold->rssi = p_a_sta->threshold.rssi; p_c_sta->threshold->authmode = p_a_sta->threshold.authmode; +#if H_PRESENT_IN_ESP_IDF_5_4_0 + p_c_sta->threshold->rssi_5g_adjustment = p_a_sta->threshold.rssi_5g_adjustment; +#endif RPC_ALLOC_ELEMENT(WifiPmfConfig, p_c_sta->pmf_cfg, wifi_pmf_config__init); p_c_sta->pmf_cfg->capable = p_a_sta->pmf_cfg.capable; p_c_sta->pmf_cfg->required = p_a_sta->pmf_cfg.required; if (p_a_sta->rm_enabled) - H_SET_BIT(STA_RM_ENABLED_BIT, p_c_sta->bitmask); + H_SET_BIT(WIFI_STA_CONFIG_1_rm_enabled, p_c_sta->bitmask); if (p_a_sta->btm_enabled) - H_SET_BIT(STA_BTM_ENABLED_BIT, p_c_sta->bitmask); + H_SET_BIT(WIFI_STA_CONFIG_1_btm_enabled, p_c_sta->bitmask); if (p_a_sta->mbo_enabled) - H_SET_BIT(STA_MBO_ENABLED_BIT, p_c_sta->bitmask); + H_SET_BIT(WIFI_STA_CONFIG_1_mbo_enabled, p_c_sta->bitmask); if (p_a_sta->ft_enabled) - H_SET_BIT(STA_FT_ENABLED_BIT, p_c_sta->bitmask); + H_SET_BIT(WIFI_STA_CONFIG_1_ft_enabled, p_c_sta->bitmask); if (p_a_sta->owe_enabled) - H_SET_BIT(STA_OWE_ENABLED_BIT, p_c_sta->bitmask); + H_SET_BIT(WIFI_STA_CONFIG_1_owe_enabled, p_c_sta->bitmask); if (p_a_sta->transition_disable) - H_SET_BIT(STA_TRASITION_DISABLED_BIT, p_c_sta->bitmask); - - WIFI_CONFIG_STA_SET_RESERVED_VAL(p_a_sta->reserved, p_c_sta->bitmask); + H_SET_BIT(WIFI_STA_CONFIG_1_transition_disable, p_c_sta->bitmask); + +#if H_DECODE_WIFI_RESERVED_FIELD + #if H_WIFI_NEW_RESERVED_FIELD_NAMES + WIFI_STA_CONFIG_2_SET_RESERVED_VAL(p_a_sta->reserved2, p_c_sta->he_bitmask); + #else + WIFI_STA_CONFIG_2_SET_RESERVED_VAL(p_a_sta->he_reserved, p_c_sta->he_bitmask); + #endif +#endif p_c_sta->sae_pwe_h2e = p_a_sta->sae_pwe_h2e; + p_c_sta->sae_pk_mode = p_a_sta->sae_pk_mode; p_c_sta->failure_retry_cnt = p_a_sta->failure_retry_cnt; if (p_a_sta->he_dcm_set) - H_SET_BIT(WIFI_HE_STA_CONFIG_he_dcm_set_BIT, p_c_sta->he_bitmask); + H_SET_BIT(WIFI_STA_CONFIG_2_he_dcm_set_BIT, p_c_sta->he_bitmask); // WIFI_HE_STA_CONFIG_he_dcm_max_constellation_tx is two bits wide if (p_a_sta->he_dcm_max_constellation_tx) - p_c_sta->he_bitmask |= ((p_a_sta->he_dcm_max_constellation_tx & 0x03) << WIFI_HE_STA_CONFIG_he_dcm_max_constellation_tx_BITS); + p_c_sta->he_bitmask |= ((p_a_sta->he_dcm_max_constellation_tx & 0x03) << WIFI_STA_CONFIG_2_he_dcm_max_constellation_tx_BITS); // WIFI_HE_STA_CONFIG_he_dcm_max_constellation_rx is two bits wide if (p_a_sta->he_dcm_max_constellation_rx) - p_c_sta->he_bitmask |= ((p_a_sta->he_dcm_max_constellation_rx & 0x03) << WIFI_HE_STA_CONFIG_he_dcm_max_constellation_rx_BITS); + p_c_sta->he_bitmask |= ((p_a_sta->he_dcm_max_constellation_rx & 0x03) << WIFI_STA_CONFIG_2_he_dcm_max_constellation_rx_BITS); if (p_a_sta->he_mcs9_enabled) - H_SET_BIT(WIFI_HE_STA_CONFIG_he_mcs9_enabled_BIT, p_c_sta->he_bitmask); + H_SET_BIT(WIFI_STA_CONFIG_2_he_mcs9_enabled_BIT, p_c_sta->he_bitmask); if (p_a_sta->he_su_beamformee_disabled) - H_SET_BIT(WIFI_HE_STA_CONFIG_he_su_beamformee_disabled_BIT, p_c_sta->he_bitmask); + H_SET_BIT(WIFI_STA_CONFIG_2_he_su_beamformee_disabled_BIT, p_c_sta->he_bitmask); if (p_a_sta->he_trig_su_bmforming_feedback_disabled) - H_SET_BIT(WIFI_HE_STA_CONFIG_he_trig_su_bmforming_feedback_disabled_BIT, p_c_sta->he_bitmask); + H_SET_BIT(WIFI_STA_CONFIG_2_he_trig_su_bmforming_feedback_disabled_BIT, p_c_sta->he_bitmask); if (p_a_sta->he_trig_mu_bmforming_partial_feedback_disabled) - H_SET_BIT(WIFI_HE_STA_CONFIG_he_trig_mu_bmforming_partial_feedback_disabled_BIT, p_c_sta->he_bitmask); + H_SET_BIT(WIFI_STA_CONFIG_2_he_trig_mu_bmforming_partial_feedback_disabled_BIT, p_c_sta->he_bitmask); if (p_a_sta->he_trig_cqi_feedback_disabled) - H_SET_BIT(WIFI_HE_STA_CONFIG_he_trig_cqi_feedback_disabled_BIT, p_c_sta->he_bitmask); + H_SET_BIT(WIFI_STA_CONFIG_2_he_trig_cqi_feedback_disabled_BIT, p_c_sta->he_bitmask); - WIFI_HE_STA_SET_RESERVED_VAL(p_a_sta->he_reserved, p_c_sta->he_bitmask); +#if H_PRESENT_IN_ESP_IDF_5_5_0 + if (p_a_sta->vht_su_beamformee_disabled) + H_SET_BIT(WIFI_STA_CONFIG_2_vht_su_beamformee_disabled, p_c_sta->he_bitmask); + + if (p_a_sta->vht_mu_beamformee_disabled) + H_SET_BIT(WIFI_STA_CONFIG_2_vht_mu_beamformee_disabled, p_c_sta->he_bitmask); + + if (p_a_sta->vht_mcs8_enabled) + H_SET_BIT(WIFI_STA_CONFIG_2_vht_mcs8_enabled, p_c_sta->he_bitmask); +#endif + +#if H_DECODE_WIFI_RESERVED_FIELD + #if H_WIFI_NEW_RESERVED_FIELD_NAMES + WIFI_STA_CONFIG_2_SET_RESERVED_VAL(p_a_sta->reserved2, p_c_sta->he_bitmask); + #else + WIFI_STA_CONFIG_2_SET_RESERVED_VAL(p_a_sta->he_reserved, p_c_sta->he_bitmask); + #endif +#endif RPC_REQ_COPY_BYTES(p_c_sta->sae_h2e_identifier, p_a_sta->sae_h2e_identifier, SAE_H2E_IDENTIFIER_LEN); break; @@ -298,11 +330,24 @@ int compose_rpc_req(Rpc *req, ctrl_cmd_t *app_req, int32_t *failure_status) p_c_ap->ssid_hidden = p_a_ap->ssid_hidden; p_c_ap->max_connection = p_a_ap->max_connection; p_c_ap->beacon_interval = p_a_ap->beacon_interval; + p_c_ap->csa_count = p_a_ap->csa_count; + p_c_ap->dtim_period = p_a_ap->dtim_period; p_c_ap->pairwise_cipher = p_a_ap->pairwise_cipher; p_c_ap->ftm_responder = p_a_ap->ftm_responder; RPC_ALLOC_ELEMENT(WifiPmfConfig, p_c_ap->pmf_cfg, wifi_pmf_config__init); p_c_ap->pmf_cfg->capable = p_a_ap->pmf_cfg.capable; p_c_ap->pmf_cfg->required = p_a_ap->pmf_cfg.required; + p_c_ap->sae_pwe_h2e = p_a_ap->sae_pwe_h2e; +#if H_GOT_AP_CONFIG_PARAM_TRANSITION_DISABLE + p_c_ap->transition_disable = p_a_ap->transition_disable; +#endif +#if H_PRESENT_IN_ESP_IDF_5_5_0 + p_c_ap->sae_ext = p_a_ap->sae_ext; + RPC_ALLOC_ELEMENT(WifiBssMaxIdleConfig, p_c_ap->bss_max_idle_cfg, wifi_bss_max_idle_config__init); + p_c_ap->bss_max_idle_cfg->period = p_a_ap->bss_max_idle_cfg.period; + p_c_ap->bss_max_idle_cfg->protected_keep_alive = p_a_ap->bss_max_idle_cfg.protected_keep_alive; + p_c_ap->gtk_rekey_interval = p_a_ap->gtk_rekey_interval; +#endif break; } default: { ESP_LOGE(TAG, "unexpected wifi iface [%u]\n", p_a->iface); @@ -345,6 +390,10 @@ int compose_rpc_req(Rpc *req, ctrl_cmd_t *app_req, int32_t *failure_status) p_c->home_chan_dwell_time = p_a->home_chan_dwell_time; + RPC_ALLOC_ELEMENT(WifiScanChannelBitmap, p_c->channel_bitmap, wifi_scan_channel_bitmap__init); + p_c->channel_bitmap->ghz_2_channels = p_a->channel_bitmap.ghz_2_channels; + p_c->channel_bitmap->ghz_5_channels = p_a->channel_bitmap.ghz_5_channels; + req_payload->config_set = 1; } ESP_LOGI(TAG, "Scan start Req\n"); diff --git a/host/drivers/rpc/core/rpc_rsp.c b/host/drivers/rpc/core/rpc_rsp.c index cc47f0ac..b96f565d 100644 --- a/host/drivers/rpc/core/rpc_rsp.c +++ b/host/drivers/rpc/core/rpc_rsp.c @@ -7,6 +7,7 @@ #include "esp_hosted_wifi_config.h" #include "esp_hosted_transport.h" #include "esp_hosted_bitmasks.h" +#include "esp_hosted_config.h" DEFINE_LOG_TAG(rpc_rsp); @@ -252,23 +253,64 @@ int rpc_parse_rsp(Rpc *rpc_msg, ctrl_cmd_t *app_resp) p_a_sta->channel = p_c_sta->channel; p_a_sta->listen_interval = p_c_sta->listen_interval; p_a_sta->sort_method = p_c_sta->sort_method; - p_a_sta->threshold.rssi = p_c_sta->threshold->rssi; - p_a_sta->threshold.authmode = p_c_sta->threshold->authmode; + if (p_c_sta->threshold) { + p_a_sta->threshold.rssi = p_c_sta->threshold->rssi; + p_a_sta->threshold.authmode = p_c_sta->threshold->authmode; +#if H_PRESENT_IN_ESP_IDF_5_4_0 + p_a_sta->threshold.rssi_5g_adjustment = p_c_sta->threshold->rssi_5g_adjustment; +#endif + } //p_a_sta->ssid_hidden = p_c_sta->ssid_hidden; //p_a_sta->max_connections = p_c_sta->max_connections; - p_a_sta->pmf_cfg.capable = p_c_sta->pmf_cfg->capable; - p_a_sta->pmf_cfg.required = p_c_sta->pmf_cfg->required; - - p_a_sta->rm_enabled = H_GET_BIT(STA_RM_ENABLED_BIT, p_c_sta->bitmask); - p_a_sta->btm_enabled = H_GET_BIT(STA_BTM_ENABLED_BIT, p_c_sta->bitmask); - p_a_sta->mbo_enabled = H_GET_BIT(STA_MBO_ENABLED_BIT, p_c_sta->bitmask); - p_a_sta->ft_enabled = H_GET_BIT(STA_FT_ENABLED_BIT, p_c_sta->bitmask); - p_a_sta->owe_enabled = H_GET_BIT(STA_OWE_ENABLED_BIT, p_c_sta->bitmask); - p_a_sta->transition_disable = H_GET_BIT(STA_TRASITION_DISABLED_BIT, p_c_sta->bitmask); - p_a_sta->reserved = WIFI_CONFIG_STA_GET_RESERVED_VAL(p_c_sta->bitmask); + if (p_c_sta->pmf_cfg) { + p_a_sta->pmf_cfg.capable = p_c_sta->pmf_cfg->capable; + p_a_sta->pmf_cfg.required = p_c_sta->pmf_cfg->required; + } + p_a_sta->rm_enabled = H_GET_BIT(WIFI_STA_CONFIG_1_rm_enabled, p_c_sta->bitmask); + p_a_sta->btm_enabled = H_GET_BIT(WIFI_STA_CONFIG_1_btm_enabled, p_c_sta->bitmask); + p_a_sta->mbo_enabled = H_GET_BIT(WIFI_STA_CONFIG_1_mbo_enabled, p_c_sta->bitmask); + p_a_sta->ft_enabled = H_GET_BIT(WIFI_STA_CONFIG_1_ft_enabled, p_c_sta->bitmask); + p_a_sta->owe_enabled = H_GET_BIT(WIFI_STA_CONFIG_1_owe_enabled, p_c_sta->bitmask); + p_a_sta->transition_disable = H_GET_BIT(WIFI_STA_CONFIG_1_transition_disable, p_c_sta->bitmask); + +#if H_DECODE_WIFI_RESERVED_FIELD + #if H_WIFI_NEW_RESERVED_FIELD_NAMES + p_a_sta->reserved1 = WIFI_STA_CONFIG_1_GET_RESERVED_VAL(p_c_sta->bitmask); + #else + p_a_sta->reserved = WIFI_STA_CONFIG_1_GET_RESERVED_VAL(p_c_sta->bitmask); + #endif +#endif p_a_sta->sae_pwe_h2e = p_c_sta->sae_pwe_h2e; + p_a_sta->sae_pk_mode = p_c_sta->sae_pk_mode; p_a_sta->failure_retry_cnt = p_c_sta->failure_retry_cnt; + + p_a_sta->he_dcm_set = H_GET_BIT(WIFI_STA_CONFIG_2_he_dcm_set_BIT, p_c_sta->he_bitmask); + + // WIFI_HE_STA_CONFIG_he_dcm_max_constellation_tx is two bits wide + p_a_sta->he_dcm_max_constellation_tx = (p_c_sta->he_bitmask >> WIFI_STA_CONFIG_2_he_dcm_max_constellation_tx_BITS) & 0x03; + // WIFI_HE_STA_CONFIG_he_dcm_max_constellation_rx is two bits wide + p_a_sta->he_dcm_max_constellation_rx = (p_c_sta->he_bitmask >> WIFI_STA_CONFIG_2_he_dcm_max_constellation_rx_BITS) & 0x03; + p_a_sta->he_mcs9_enabled = H_GET_BIT(WIFI_STA_CONFIG_2_he_mcs9_enabled_BIT, p_c_sta->he_bitmask); + p_a_sta->he_su_beamformee_disabled = H_GET_BIT(WIFI_STA_CONFIG_2_he_su_beamformee_disabled_BIT, p_c_sta->he_bitmask); + p_a_sta->he_trig_su_bmforming_feedback_disabled = H_GET_BIT(WIFI_STA_CONFIG_2_he_trig_su_bmforming_feedback_disabled_BIT, p_c_sta->bitmask); + p_a_sta->he_trig_mu_bmforming_partial_feedback_disabled = H_GET_BIT(WIFI_STA_CONFIG_2_he_trig_mu_bmforming_partial_feedback_disabled_BIT, p_c_sta->bitmask); + p_a_sta->he_trig_cqi_feedback_disabled = H_GET_BIT(WIFI_STA_CONFIG_2_he_trig_cqi_feedback_disabled_BIT, p_c_sta->bitmask); + +#if H_PRESENT_IN_ESP_IDF_5_5_0 + p_a_sta->vht_su_beamformee_disabled = H_GET_BIT(WIFI_STA_CONFIG_2_vht_su_beamformee_disabled, p_c_sta->he_bitmask); + p_a_sta->vht_mu_beamformee_disabled = H_GET_BIT(WIFI_STA_CONFIG_2_vht_mu_beamformee_disabled, p_c_sta->he_bitmask); + p_a_sta->vht_mcs8_enabled = H_GET_BIT(WIFI_STA_CONFIG_2_vht_mcs8_enabled, p_c_sta->he_bitmask); +#endif + +#if H_DECODE_WIFI_RESERVED_FIELD + #if H_WIFI_NEW_RESERVED_FIELD_NAMES + p_a_sta->reserved2 = WIFI_STA_CONFIG_2_GET_RESERVED_VAL(p_c_sta->he_bitmask); + #else + p_a_sta->he_reserved = WIFI_STA_CONFIG_2_GET_RESERVED_VAL(p_c_sta->he_bitmask); + #endif +#endif + break; } case WIFI_IF_AP: { @@ -283,10 +325,26 @@ int rpc_parse_rsp(Rpc *rpc_msg, ctrl_cmd_t *app_resp) p_a_ap->ssid_hidden = p_c_ap->ssid_hidden; p_a_ap->max_connection = p_c_ap->max_connection; p_a_ap->beacon_interval = p_c_ap->beacon_interval; + p_a_ap->csa_count = p_c_ap->csa_count; + p_a_ap->dtim_period = p_c_ap->dtim_period; p_a_ap->pairwise_cipher = p_c_ap->pairwise_cipher; p_a_ap->ftm_responder = p_c_ap->ftm_responder; - p_a_ap->pmf_cfg.capable = p_c_ap->pmf_cfg->capable; - p_a_ap->pmf_cfg.required = p_c_ap->pmf_cfg->required; + if (p_c_ap->pmf_cfg) { + p_a_ap->pmf_cfg.capable = p_c_ap->pmf_cfg->capable; + p_a_ap->pmf_cfg.required = p_c_ap->pmf_cfg->required; + } + p_a_ap->sae_pwe_h2e = p_c_ap->sae_pwe_h2e; +#if H_GOT_AP_CONFIG_PARAM_TRANSITION_DISABLE + p_a_ap->transition_disable = p_c_ap->transition_disable; +#endif +#if H_PRESENT_IN_ESP_IDF_5_5_0 + p_a_ap->sae_ext = p_c_ap->sae_ext; + if (p_c_ap->bss_max_idle_cfg) { + p_a_ap->bss_max_idle_cfg.period = p_c_ap->bss_max_idle_cfg->period; + p_a_ap->bss_max_idle_cfg.protected_keep_alive = p_c_ap->bss_max_idle_cfg->protected_keep_alive; + } + p_a_ap->gtk_rekey_interval = p_c_ap->gtk_rekey_interval; +#endif break; } default: diff --git a/host/drivers/rpc/slaveif/rpc_slave_if.c b/host/drivers/rpc/slaveif/rpc_slave_if.c index 75c081ec..7495223e 100644 --- a/host/drivers/rpc/slaveif/rpc_slave_if.c +++ b/host/drivers/rpc/slaveif/rpc_slave_if.c @@ -40,386 +40,332 @@ int rpc_slaveif_deinit(void) } /** Control Req->Resp APIs **/ -ctrl_cmd_t * wifi_get_mac(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_get_mac(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_GetMACAddress); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_set_mac(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_set_mac(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_SetMacAddress); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_get_mode(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_get_mode(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_GetWifiMode); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_set_mode(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_set_mode(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_SetWifiMode); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_set_ps(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_set_ps(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiSetPs); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_get_ps(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_get_ps(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiGetPs); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -//ctrl_cmd_t * wifi_ap_scan_list(ctrl_cmd_t *req) -//{ -// RPC_SEND_REQ(RPC_ID__Req_GetAPScanList); -// RPC_DECODE_RSP_IF_NOT_ASYNC(); -//} -// -//ctrl_cmd_t * wifi_get_ap_config(ctrl_cmd_t *req) -//{ -// RPC_SEND_REQ(RPC_ID__Req_GetAPConfig); -// RPC_DECODE_RSP_IF_NOT_ASYNC(); -//} -// -//ctrl_cmd_t * wifi_connect_ap(ctrl_cmd_t *req) -//{ -// RPC_SEND_REQ(RPC_ID__Req_ConnectAP); -// RPC_DECODE_RSP_IF_NOT_ASYNC(); -//} -// -//ctrl_cmd_t * wifi_disconnect_ap(ctrl_cmd_t *req) -//{ -// RPC_SEND_REQ(RPC_ID__Req_DisconnectAP); -// RPC_DECODE_RSP_IF_NOT_ASYNC(); -//} -// -//ctrl_cmd_t * wifi_start_softap(ctrl_cmd_t *req) -//{ -// RPC_SEND_REQ(RPC_ID__Req_StartSoftAP); -// RPC_DECODE_RSP_IF_NOT_ASYNC(); -//} -// -//ctrl_cmd_t * wifi_get_softap_config(ctrl_cmd_t *req) -//{ -// RPC_SEND_REQ(RPC_ID__Req_GetSoftAPConfig); -// RPC_DECODE_RSP_IF_NOT_ASYNC(); -//} -// -//ctrl_cmd_t * wifi_stop_softap(ctrl_cmd_t *req) -//{ -// RPC_SEND_REQ(RPC_ID__Req_StopSoftAP); -// RPC_DECODE_RSP_IF_NOT_ASYNC(); -//} -// -//ctrl_cmd_t * wifi_get_softap_connected_station_list(ctrl_cmd_t *req) -//{ -// RPC_SEND_REQ(RPC_ID__Req_GetSoftAPConnectedSTAList); -// RPC_DECODE_RSP_IF_NOT_ASYNC(); -//} -// -//ctrl_cmd_t * wifi_set_vendor_specific_ie(ctrl_cmd_t *req) -//{ -// RPC_SEND_REQ(RPC_ID__Req_SetSoftAPVendorSpecificIE); -// RPC_DECODE_RSP_IF_NOT_ASYNC(); -//} - -ctrl_cmd_t * wifi_set_max_tx_power(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_set_max_tx_power(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiSetMaxTxPower); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_get_max_tx_power(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_get_max_tx_power(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiGetMaxTxPower); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * config_heartbeat(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_config_heartbeat(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_ConfigHeartbeat); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * ota_begin(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_ota_begin(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_OTABegin); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * ota_write(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_ota_write(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_OTAWrite); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * ota_end(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_ota_end(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_OTAEnd); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_init(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_init(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiInit); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_deinit(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_deinit(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiDeinit); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_start(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_start(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiStart); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_stop(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_stop(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiStop); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_connect(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_connect(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiConnect); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_disconnect(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_disconnect(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiDisconnect); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_get_config(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_get_config(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiGetConfig); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_set_config(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_set_config(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiSetConfig); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_scan_start(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_scan_start(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiScanStart); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_scan_stop(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_scan_stop(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiScanStop); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_scan_get_ap_num(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_scan_get_ap_num(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiScanGetApNum); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_scan_get_ap_record(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_scan_get_ap_record(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiScanGetApRecord); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_scan_get_ap_records(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_scan_get_ap_records(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiScanGetApRecords); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_clear_ap_list(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_clear_ap_list(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiClearApList); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_restore(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_restore(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiRestore); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_clear_fast_connect(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_clear_fast_connect(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiClearFastConnect); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_deauth_sta(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_deauth_sta(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiDeauthSta); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_sta_get_ap_info(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_sta_get_ap_info(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiStaGetApInfo); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_set_storage(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_set_storage(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiSetStorage); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_set_bandwidth(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_set_bandwidth(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiSetBandwidth); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_get_bandwidth(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_get_bandwidth(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiGetBandwidth); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_set_channel(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_set_channel(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiSetChannel); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_get_channel(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_get_channel(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiGetChannel); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_set_country_code(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_set_country_code(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiSetCountryCode); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_get_country_code(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_get_country_code(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiGetCountryCode); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_set_country(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_set_country(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiSetCountry); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_get_country(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_get_country(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiGetCountry); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_ap_get_sta_list(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_ap_get_sta_list(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiApGetStaList); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_ap_get_sta_aid(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_ap_get_sta_aid(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiApGetStaAid); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_sta_get_rssi(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_sta_get_rssi(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiStaGetRssi); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_set_protocol(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_set_protocol(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiSetProtocol); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_get_protocol(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_get_protocol(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiGetProtocol); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_sta_get_negotiated_phymode(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_sta_get_negotiated_phymode(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiStaGetNegotiatedPhymode); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_sta_get_aid(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_sta_get_aid(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiStaGetAid); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_set_protocols(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_set_protocols(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiSetProtocols); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * get_coprocessor_fwversion(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_get_coprocessor_fwversion(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_GetCoprocessorFwVersion); RPC_DECODE_RSP_IF_NOT_ASYNC(); } #if H_WIFI_DUALBAND_SUPPORT -ctrl_cmd_t * wifi_get_protocols(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_get_protocols(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiGetProtocols); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_set_bandwidths(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_set_bandwidths(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiSetBandwidths); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_get_bandwidths(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_get_bandwidths(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiGetBandwidths); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_set_band(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_set_band(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiSetBand); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_get_band(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_get_band(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiGetBand); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_set_band_mode(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_set_band_mode(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiSetBandMode); RPC_DECODE_RSP_IF_NOT_ASYNC(); } -ctrl_cmd_t * wifi_get_band_mode(ctrl_cmd_t *req) +ctrl_cmd_t * rpc_slaveif_wifi_get_band_mode(ctrl_cmd_t *req) { RPC_SEND_REQ(RPC_ID__Req_WifiGetBandMode); RPC_DECODE_RSP_IF_NOT_ASYNC(); diff --git a/host/drivers/rpc/slaveif/rpc_slave_if.h b/host/drivers/rpc/slaveif/rpc_slave_if.h index 9fd09900..685531a9 100644 --- a/host/drivers/rpc/slaveif/rpc_slave_if.h +++ b/host/drivers/rpc/slaveif/rpc_slave_if.h @@ -46,7 +46,7 @@ extern "C" { * */ //#define WAIT_TIME_B2B_RPC_REQ 5 #define DEFAULT_RPC_RSP_TIMEOUT 5 - +#define DEFAULT_RPC_RSP_SCAN_TIMEOUT 30 #define SUCCESS_STR "success" #define FAILURE_STR "failure" @@ -377,141 +377,92 @@ int rpc_slaveif_init(void); int rpc_slaveif_deinit(void); /* Get the MAC address of station or softAP interface of ESP32 */ -ctrl_cmd_t * wifi_get_mac(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_get_mac(ctrl_cmd_t *req); /* Set MAC address of ESP32 interface for given wifi mode */ -ctrl_cmd_t * wifi_set_mac(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_set_mac(ctrl_cmd_t *req); /* Get Wi-Fi mode of ESP32 */ -ctrl_cmd_t * wifi_get_mode(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_get_mode(ctrl_cmd_t *req); /* Set the Wi-Fi mode of ESP32 */ -ctrl_cmd_t * wifi_set_mode(ctrl_cmd_t *req); - -/* Set Wi-Fi power save mode of ESP32 */ -ctrl_cmd_t * wifi_set_power_save_mode(ctrl_cmd_t *req); - -/* Get the Wi-Fi power save mode of ESP32 */ -ctrl_cmd_t * wifi_get_power_save_mode(ctrl_cmd_t *req); - -///* Get list of available neighboring APs of ESP32 */ -//ctrl_cmd_t * wifi_ap_scan_list(ctrl_cmd_t *req); -// -///* Get the AP config to which ESP32 station is connected */ -//ctrl_cmd_t * wifi_get_ap_config(ctrl_cmd_t *req); -// -///* Set the AP config to which ESP32 station should connect to */ -//ctrl_cmd_t * wifi_connect_ap(ctrl_cmd_t *req); -// -///* Disconnect ESP32 station from AP */ -//ctrl_cmd_t * wifi_disconnect_ap(ctrl_cmd_t *req); -// -///* Set configuration of ESP32 softAP and start broadcasting */ -//ctrl_cmd_t * wifi_start_softap(ctrl_cmd_t *req); -// -///* Get configuration of ESP32 softAP */ -//ctrl_cmd_t * wifi_get_softap_config(ctrl_cmd_t *req); -// -///* Stop ESP32 softAP */ -//ctrl_cmd_t * wifi_stop_softap(ctrl_cmd_t *req); -// -///* Get list of connected stations to ESP32 softAP */ -//ctrl_cmd_t * wifi_get_softap_connected_station_list(ctrl_cmd_t *req); -// -///* Function set 802.11 Vendor-Specific Information Element. -// * It needs to get called before starting of ESP32 softAP */ -//ctrl_cmd_t * wifi_set_vendor_specific_ie(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_set_mode(ctrl_cmd_t *req); /* Sets maximum WiFi transmitting power at ESP32 */ -ctrl_cmd_t * wifi_set_max_tx_power(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_set_max_tx_power(ctrl_cmd_t *req); /* Gets maximum WiFi transmiting power at ESP32 */ -ctrl_cmd_t * wifi_get_max_tx_power(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_get_max_tx_power(ctrl_cmd_t *req); /* Configure heartbeat event. Be default heartbeat is not enabled. * To enable heartbeats, user need to use this API in addition * to setting event callback for heartbeat event */ -ctrl_cmd_t * config_heartbeat(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_config_heartbeat(ctrl_cmd_t *req); /* Performs an OTA begin operation for ESP32 which erases and * prepares existing flash partition for new flash writing */ -ctrl_cmd_t * ota_begin(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_ota_begin(ctrl_cmd_t *req); /* Performs an OTA write operation for ESP32, It writes bytes from `ota_data` * buffer with `ota_data_len` number of bytes to OTA partition in flash. Number * of bytes can be small than size of complete binary to be flashed. In that * case, this caller is expected to repeatedly call this function till * total size written equals size of complete binary */ -ctrl_cmd_t * ota_write(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_ota_write(ctrl_cmd_t *req); /* Performs an OTA end operation for ESP32, It validates written OTA image, * sets newly written OTA partition as boot partition for next boot, * Creates timer which reset ESP32 after 5 sec */ -ctrl_cmd_t * ota_end(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_ota_end(ctrl_cmd_t *req); /* Gets the co-processor FW Version */ -ctrl_cmd_t * get_coprocessor_fwversion(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_get_coprocessor_fwversion(ctrl_cmd_t *req); /* TODO: add descriptions */ -ctrl_cmd_t * wifi_init(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_deinit(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_start(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_stop(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_connect(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_disconnect(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_set_config(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_get_config(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_scan_start(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_scan_stop(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_scan_get_ap_num(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_scan_get_ap_record(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_scan_get_ap_records(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_clear_ap_list(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_restore(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_clear_fast_connect(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_deauth_sta(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_sta_get_ap_info(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_set_ps(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_get_ps(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_set_storage(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_set_bandwidth(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_get_bandwidth(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_set_channel(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_get_channel(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_set_country_code(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_get_country_code(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_set_country(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_get_country(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_ap_get_sta_list(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_ap_get_sta_aid(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_sta_get_rssi(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_set_protocol(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_get_protocol(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_sta_get_negotiated_phymode(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_sta_get_aid(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_set_protocols(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_get_protocols(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_set_bandwidths(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_get_bandwidths(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_set_band(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_get_band(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_set_band_mode(ctrl_cmd_t *req); -ctrl_cmd_t * wifi_get_band_mode(ctrl_cmd_t *req); - -/* Get the interface up for interface `iface` */ -int interface_up(int sockfd, char* iface); - -/* Get the interface down for interface `iface` */ -int interface_down(int sockfd, char* iface); - -/* Set ethernet interface MAC address `mac` to interface `iface` */ -int set_hw_addr(int sockfd, char* iface, char* mac); - -/* Create an endpoint for communication */ -int create_socket(int domain, int type, int protocol, int *sock); - -/* Close an endpoint of the communication */ -int close_socket(int sock); +ctrl_cmd_t * rpc_slaveif_wifi_init(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_deinit(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_start(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_stop(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_connect(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_disconnect(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_set_config(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_get_config(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_scan_start(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_scan_stop(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_scan_get_ap_num(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_scan_get_ap_record(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_scan_get_ap_records(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_clear_ap_list(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_restore(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_clear_fast_connect(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_deauth_sta(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_sta_get_ap_info(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_set_ps(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_get_ps(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_set_storage(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_set_bandwidth(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_get_bandwidth(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_set_channel(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_get_channel(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_set_country_code(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_get_country_code(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_set_country(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_get_country(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_ap_get_sta_list(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_ap_get_sta_aid(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_sta_get_rssi(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_set_protocol(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_get_protocol(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_sta_get_negotiated_phymode(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_sta_get_aid(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_set_protocols(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_get_protocols(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_set_bandwidths(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_get_bandwidths(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_set_band(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_get_band(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_set_band_mode(ctrl_cmd_t *req); +ctrl_cmd_t * rpc_slaveif_wifi_get_band_mode(ctrl_cmd_t *req); #ifdef __cplusplus } diff --git a/host/drivers/rpc/wrap/rpc_wrap.c b/host/drivers/rpc/wrap/rpc_wrap.c index 2a2b59ed..47aa1cdb 100644 --- a/host/drivers/rpc/wrap/rpc_wrap.c +++ b/host/drivers/rpc/wrap/rpc_wrap.c @@ -28,13 +28,10 @@ #include "rpc_wrap.h" #include "esp_hosted_rpc.h" #include "esp_log.h" -#include "esp_http_client.h" #include "esp_hosted_wifi_config.h" -#include "esp_hosted_api.h" #include "esp_hosted_transport.h" DEFINE_LOG_TAG(rpc_wrap); -static char* OTA_TAG = "h_ota"; uint8_t restart_after_slave_ota = 0; @@ -56,7 +53,7 @@ static ctrl_cmd_t * RPC_DEFAULT_REQ(void) assert(new_req); new_req->msg_type = RPC_TYPE__Req; new_req->rpc_rsp_cb = NULL; - new_req->rsp_timeout_sec = DEFAULT_RPC_RSP_TIMEOUT; /* 5 sec */ + new_req->rsp_timeout_sec = DEFAULT_RPC_RSP_TIMEOUT; /* new_req->wait_prev_cmd_completion = WAIT_TIME_B2B_RPC_REQ; */ return new_req; } @@ -77,7 +74,6 @@ static ctrl_cmd_t * RPC_DEFAULT_REQ(void) #define YES 1 #define NO 0 -#define MIN_TIMESTAMP_STR_SIZE 30 #define HEARTBEAT_DURATION_SEC 20 @@ -98,21 +94,9 @@ int rpc_deinit(void) return rpc_slaveif_deinit(); } -static char * get_timestamp_str(char *str, uint16_t str_size) -{ - if (str && str_size>=MIN_TIMESTAMP_STR_SIZE) { - time_t t = time(NULL); - struct tm tm = *localtime(&t); - sprintf(str, "%d-%02d-%02d %02d:%02d:%02d > ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); - return str; - } - return NULL; -} static int rpc_event_callback(ctrl_cmd_t * app_event) { - char ts[MIN_TIMESTAMP_STR_SIZE] = {'\0'}; - ESP_LOGV(TAG, "%u",app_event->msg_id); if (!app_event || (app_event->msg_type != RPC_TYPE__Event)) { if (app_event) @@ -129,19 +113,17 @@ static int rpc_event_callback(ctrl_cmd_t * app_event) switch(app_event->msg_id) { case RPC_ID__Event_ESPInit: { - ESP_LOGD(TAG, "Received Slave ESP Init"); + ESP_LOGI(TAG, "--- ESP Event: Slave ESP Init ---"); break; } case RPC_ID__Event_Heartbeat: { - ESP_LOGV(TAG, "%s ESP EVENT: Heartbeat event [%lu]", - get_timestamp_str(ts, MIN_TIMESTAMP_STR_SIZE), + ESP_LOGI(TAG, "ESP Event: Heartbeat event [%lu]", (long unsigned int)app_event->u.e_heartbeat.hb_num); break; } case RPC_ID__Event_AP_StaConnected: { wifi_event_ap_staconnected_t *p_e = &app_event->u.e_wifi_ap_staconnected; if (strlen((char*)p_e->mac)) { - ESP_LOGV(TAG, "%s ESP EVENT: SoftAP mode: connected station", - get_timestamp_str(ts, MIN_TIMESTAMP_STR_SIZE)); + ESP_LOGV(TAG, "ESP Event: SoftAP mode: connected station"); g_h.funcs->_h_event_wifi_post(WIFI_EVENT_AP_STACONNECTED, p_e, sizeof(wifi_event_ap_staconnected_t), HOSTED_BLOCK_MAX); } @@ -149,22 +131,19 @@ static int rpc_event_callback(ctrl_cmd_t * app_event) } case RPC_ID__Event_AP_StaDisconnected: { wifi_event_ap_stadisconnected_t *p_e = &app_event->u.e_wifi_ap_stadisconnected; if (strlen((char*)p_e->mac)) { - ESP_LOGV(TAG, "%s ESP EVENT: SoftAP mode: disconnected MAC", - get_timestamp_str(ts, MIN_TIMESTAMP_STR_SIZE)); + ESP_LOGV(TAG, "ESP Event: SoftAP mode: disconnected MAC"); g_h.funcs->_h_event_wifi_post(WIFI_EVENT_AP_STADISCONNECTED, p_e, sizeof(wifi_event_ap_stadisconnected_t), HOSTED_BLOCK_MAX); } break; } case RPC_ID__Event_StaConnected: { - ESP_LOGV(TAG, "%s ESP EVENT: Station mode: Connected", - get_timestamp_str(ts, MIN_TIMESTAMP_STR_SIZE)); + ESP_LOGV(TAG, "ESP Event: Station mode: Connected"); wifi_event_sta_connected_t *p_e = &app_event->u.e_wifi_sta_connected; g_h.funcs->_h_event_wifi_post(WIFI_EVENT_STA_CONNECTED, p_e, sizeof(wifi_event_sta_connected_t), HOSTED_BLOCK_MAX); break; } case RPC_ID__Event_StaDisconnected: { - ESP_LOGV(TAG, "%s ESP EVENT: Station mode: Disconnected", - get_timestamp_str(ts, MIN_TIMESTAMP_STR_SIZE)); + ESP_LOGV(TAG, "ESP Event: Station mode: Disconnected"); wifi_event_sta_disconnected_t *p_e = &app_event->u.e_wifi_sta_disconnected; g_h.funcs->_h_event_wifi_post(WIFI_EVENT_STA_DISCONNECTED, p_e, sizeof(wifi_event_sta_disconnected_t), HOSTED_BLOCK_MAX); @@ -175,25 +154,26 @@ static int rpc_event_callback(ctrl_cmd_t * app_event) switch (wifi_event_id) { case WIFI_EVENT_STA_START: - ESP_LOGV(TAG, "%s ESP EVENT: WiFi Event[%s]", - get_timestamp_str(ts, MIN_TIMESTAMP_STR_SIZE), "WIFI_EVENT_STA_START"); + ESP_LOGV(TAG, "ESP Event: wifi station started"); break; case WIFI_EVENT_STA_STOP: - ESP_LOGV(TAG, "%s ESP EVENT: WiFi Event[%s]", - get_timestamp_str(ts, MIN_TIMESTAMP_STR_SIZE), "WIFI_EVENT_STA_STOP"); + ESP_LOGV(TAG, "ESP Event: wifi station stopped"); break; case WIFI_EVENT_AP_START: - ESP_LOGD(TAG,"ESP EVENT: softap started"); + ESP_LOGD(TAG,"ESP Event: softap started"); break; case WIFI_EVENT_AP_STOP: - ESP_LOGD(TAG,"ESP EVENT: softap stopped"); + ESP_LOGD(TAG,"ESP Event: softap stopped"); + break; + + case WIFI_EVENT_HOME_CHANNEL_CHANGE: + ESP_LOGD(TAG,"ESP Event: Home channel changed"); break; default: - ESP_LOGV(TAG, "%s ESP EVENT: WiFi Event[%x]", - get_timestamp_str(ts, MIN_TIMESTAMP_STR_SIZE), wifi_event_id); + ESP_LOGW(TAG, "ESP Event: Event[%x] - unhandled", wifi_event_id); break; } /* inner switch case */ g_h.funcs->_h_event_wifi_post(wifi_event_id, 0, 0, HOSTED_BLOCK_MAX); @@ -201,15 +181,13 @@ static int rpc_event_callback(ctrl_cmd_t * app_event) break; } case RPC_ID__Event_StaScanDone: { wifi_event_sta_scan_done_t *p_e = &app_event->u.e_wifi_sta_scan_done; - ESP_LOGV(TAG, "%s ESP EVENT: StaScanDone", - get_timestamp_str(ts, MIN_TIMESTAMP_STR_SIZE)); + ESP_LOGV(TAG, "ESP Event: StaScanDone"); ESP_LOGV(TAG, "scan: status: %lu number:%u scan_id:%u", p_e->status, p_e->number, p_e->scan_id); g_h.funcs->_h_event_wifi_post(WIFI_EVENT_SCAN_DONE, p_e, sizeof(wifi_event_sta_scan_done_t), HOSTED_BLOCK_MAX); break; } default: { - ESP_LOGW(TAG, "%s Invalid event[0x%x] to parse", - get_timestamp_str(ts, MIN_TIMESTAMP_STR_SIZE), app_event->msg_id); + ESP_LOGW(TAG, "Invalid event[0x%x] to parse", app_event->msg_id); break; } } @@ -306,9 +284,7 @@ int rpc_register_event_callbacks(void) event_callback_table_t events[] = { { RPC_ID__Event_ESPInit, rpc_event_callback }, -#if 0 { RPC_ID__Event_Heartbeat, rpc_event_callback }, -#endif { RPC_ID__Event_AP_StaConnected, rpc_event_callback }, { RPC_ID__Event_AP_StaDisconnected, rpc_event_callback }, { RPC_ID__Event_WifiEventNoArgs, rpc_event_callback }, @@ -504,7 +480,7 @@ int rpc_get_wifi_mode(void) /* register callback for reply */ req->rpc_rsp_cb = rpc_rsp_callback; - wifi_get_mode(req); + rpc_slaveif_wifi_get_mode(req); return SUCCESS; } @@ -517,7 +493,7 @@ int rpc_set_wifi_mode(wifi_mode_t mode) ctrl_cmd_t *resp = NULL; req->u.wifi_mode.mode = mode; - resp = wifi_set_mode(req); + resp = rpc_slaveif_wifi_set_mode(req); return rpc_rsp_callback(resp); } @@ -550,7 +526,7 @@ int rpc_wifi_get_mac(wifi_interface_t mode, uint8_t out_mac[6]) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); req->u.wifi_mac.mode = mode; - resp = wifi_get_mac(req); + resp = rpc_slaveif_wifi_get_mac(req); if (resp && resp->resp_event_status == SUCCESS) { @@ -574,7 +550,7 @@ int rpc_wifi_set_mac(wifi_interface_t mode, const uint8_t mac[6]) req->u.wifi_mac.mode = mode; g_h.funcs->_h_memcpy(req->u.wifi_mac.mac, mac, BSSID_BYTES_SIZE); - resp = wifi_set_mac(req); + resp = rpc_slaveif_wifi_set_mac(req); return rpc_rsp_callback(resp); } @@ -584,235 +560,6 @@ int rpc_softap_mode_get_mac_addr(uint8_t mac[6]) return rpc_wifi_get_mac(WIFI_MODE_AP, mac); } -//int rpc_async_station_mode_connect(char *ssid, char *pwd, char *bssid, -// int is_wpa3_supported, int listen_interval) -//{ -// /* implemented Asynchronous */ -// ctrl_cmd_t *req = RPC_DEFAULT_REQ(); -// -// strcpy((char *)&req->u.hosted_ap_config.ssid, ssid); -// strcpy((char *)&req->u.hosted_ap_config.pwd, pwd); -// strcpy((char *)&req->u.hosted_ap_config.bssid, bssid); -// req->u.hosted_ap_config.is_wpa3_supported = is_wpa3_supported; -// req->u.hosted_ap_config.listen_interval = listen_interval; -// -// /* register callback for handling reply asynch-ly */ -// req->rpc_rsp_cb = rpc_rsp_callback; -// -// wifi_connect_ap(req); -// -// return SUCCESS; -//} -// -//int rpc_station_mode_connect(char *ssid, char *pwd, char *bssid, -// int is_wpa3_supported, int listen_interval) -//{ -// /* implemented Asynchronous */ -// ctrl_cmd_t *req = RPC_DEFAULT_REQ(); -// ctrl_cmd_t *resp = NULL; -// -// strcpy((char *)&req->u.hosted_ap_config.ssid, ssid); -// strcpy((char *)&req->u.hosted_ap_config.pwd, pwd); -// strcpy((char *)&req->u.hosted_ap_config.bssid, bssid); -// req->u.hosted_ap_config.is_wpa3_supported = is_wpa3_supported; -// req->u.hosted_ap_config.listen_interval = listen_interval; -// -// resp = wifi_connect_ap(req); -// -// return rpc_rsp_callback(resp); -//} -// -//int rpc_station_mode_get_info(void) -//{ -// /* implemented synchronous */ -// ctrl_cmd_t *req = RPC_DEFAULT_REQ(); -// ctrl_cmd_t *resp = NULL; -// -// resp = wifi_get_ap_config(req); -// -// return rpc_rsp_callback(resp); -//} -// -//int rpc_get_available_wifi(void) -//{ -// /* implemented synchronous */ -// ctrl_cmd_t *req = RPC_DEFAULT_REQ(); -// req->rsp_timeout_sec = 300; -// -// ctrl_cmd_t *resp = NULL; -// -// resp = wifi_ap_scan_list(req); -// -// return rpc_rsp_callback(resp); -//} -// -//int rpc_station_mode_disconnect(void) -//{ -// /* implemented synchronous */ -// ctrl_cmd_t *req = RPC_DEFAULT_REQ(); -// ctrl_cmd_t *resp = NULL; -// -// resp = wifi_disconnect_ap(req); -// -// return rpc_rsp_callback(resp); -//} -// -//int rpc_softap_mode_start(char *ssid, char *pwd, int channel, -// int encryption_mode, int max_conn, int ssid_hidden, int bw) -//{ -// /* implemented synchronous */ -// ctrl_cmd_t *req = RPC_DEFAULT_REQ(); -// ctrl_cmd_t *resp = NULL; -// -// strncpy((char *)&req->u.wifi_softap_config.ssid, -// ssid, MAX_MAC_STR_LEN-1); -// strncpy((char *)&req->u.wifi_softap_config.pwd, -// pwd, MAX_MAC_STR_LEN-1); -// req->u.wifi_softap_config.channel = channel; -// req->u.wifi_softap_config.encryption_mode = encryption_mode; -// req->u.wifi_softap_config.max_connections = max_conn; -// req->u.wifi_softap_config.ssid_hidden = ssid_hidden; -// req->u.wifi_softap_config.bandwidth = bw; -// -// resp = wifi_start_softap(req); -// -// return rpc_rsp_callback(resp); -//} -// -//int rpc_softap_mode_get_info(void) -//{ -// /* implemented synchronous */ -// ctrl_cmd_t *req = RPC_DEFAULT_REQ(); -// ctrl_cmd_t *resp = NULL; -// -// resp = wifi_get_softap_config(req); -// -// return rpc_rsp_callback(resp); -//} -// -//int rpc_softap_mode_connected_clients_info(void) -//{ -// /* implemented synchronous */ -// ctrl_cmd_t *req = RPC_DEFAULT_REQ(); -// ctrl_cmd_t *resp = NULL; -// -// resp = wifi_get_softap_connected_station_list(req); -// -// return rpc_rsp_callback(resp); -//} -// -//int rpc_softap_mode_stop(void) -//{ -// /* implemented synchronous */ -// ctrl_cmd_t *req = RPC_DEFAULT_REQ(); -// ctrl_cmd_t *resp = NULL; -// -// resp = wifi_stop_softap(req); -// -// return rpc_rsp_callback(resp); -//} - -int rpc_set_wifi_power_save_mode(int psmode) -{ - /* implemented synchronous */ - ctrl_cmd_t *req = RPC_DEFAULT_REQ(); - ctrl_cmd_t *resp = NULL; - - req->u.wifi_ps.ps_mode = psmode; - resp = wifi_set_power_save_mode(req); - - return rpc_rsp_callback(resp); -} - -int rpc_set_wifi_power_save_mode_max(void) -{ - return rpc_set_wifi_power_save_mode(WIFI_PS_MAX_MODEM); -} - -int rpc_set_wifi_power_save_mode_min(void) -{ - return rpc_set_wifi_power_save_mode(WIFI_PS_MIN_MODEM); -} - -int rpc_get_wifi_power_save_mode(void) -{ - /* implemented synchronous */ - ctrl_cmd_t *req = RPC_DEFAULT_REQ(); - ctrl_cmd_t *resp = NULL; - - resp = wifi_get_power_save_mode(req); - - return rpc_rsp_callback(resp); -} - -//int rpc_reset_vendor_specific_ie(void) -//{ -// /* implemented synchronous */ -// ctrl_cmd_t *req = RPC_DEFAULT_REQ(); -// ctrl_cmd_t *resp = NULL; -// char *data = "Example vendor IE data"; -// -// char *v_data = (char*)g_h.funcs->_h_calloc(1, strlen(data)); -// if (!v_data) { -// ESP_LOGE(TAG, "Failed to allocate memory \n"); -// return FAILURE; -// } -// g_h.funcs->_h_memcpy(v_data, data, strlen(data)); -// -// req->u.wifi_softap_vendor_ie.enable = false; -// req->u.wifi_softap_vendor_ie.type = WIFI_VND_IE_TYPE_BEACON; -// req->u.wifi_softap_vendor_ie.idx = WIFI_VND_IE_ID_0; -// req->u.wifi_softap_vendor_ie.vnd_ie.element_id = WIFI_VENDOR_IE_ELEMENT_ID; -// req->u.wifi_softap_vendor_ie.vnd_ie.length = strlen(data)+OFFSET; -// req->u.wifi_softap_vendor_ie.vnd_ie.vendor_oui[0] = VENDOR_OUI_0; -// req->u.wifi_softap_vendor_ie.vnd_ie.vendor_oui[1] = VENDOR_OUI_1; -// req->u.wifi_softap_vendor_ie.vnd_ie.vendor_oui[2] = VENDOR_OUI_2; -// req->u.wifi_softap_vendor_ie.vnd_ie.vendor_oui_type = VENDOR_OUI_TYPE; -// req->u.wifi_softap_vendor_ie.vnd_ie.payload = (uint8_t *)v_data; -// //req->u.wifi_softap_vendor_ie.vnd_ie.payload_len = strlen(data); -// -// req->app_free_buff_func = g_h.funcs->_h_free; -// req->app_free_buff_hdl = v_data; -// -// resp = wifi_set_vendor_specific_ie(req); -// -// return rpc_rsp_callback(resp); -//} -// -//int rpc_set_vendor_specific_ie(void) -//{ -// /* implemented synchronous */ -// ctrl_cmd_t *req = RPC_DEFAULT_REQ(); -// ctrl_cmd_t *resp = NULL; -// char *data = "Example vendor IE data"; -// -// char *v_data = (char*)g_h.funcs->_h_calloc(1, strlen(data)); -// if (!v_data) { -// ESP_LOGE(TAG, "Failed to allocate memory \n"); -// return FAILURE; -// } -// g_h.funcs->_h_memcpy(v_data, data, strlen(data)); -// -// req->u.wifi_softap_vendor_ie.enable = true; -// req->u.wifi_softap_vendor_ie.type = WIFI_VND_IE_TYPE_BEACON; -// req->u.wifi_softap_vendor_ie.idx = WIFI_VND_IE_ID_0; -// req->u.wifi_softap_vendor_ie.vnd_ie.element_id = WIFI_VENDOR_IE_ELEMENT_ID; -// req->u.wifi_softap_vendor_ie.vnd_ie.length = strlen(data)+OFFSET; -// req->u.wifi_softap_vendor_ie.vnd_ie.vendor_oui[0] = VENDOR_OUI_0; -// req->u.wifi_softap_vendor_ie.vnd_ie.vendor_oui[1] = VENDOR_OUI_1; -// req->u.wifi_softap_vendor_ie.vnd_ie.vendor_oui[2] = VENDOR_OUI_2; -// req->u.wifi_softap_vendor_ie.vnd_ie.vendor_oui_type = VENDOR_OUI_TYPE; -// req->u.wifi_softap_vendor_ie.vnd_ie.payload = (uint8_t *)v_data; -// //req->u.wifi_softap_vendor_ie.vnd_ie.payload_len = strlen(data); -// -// req->app_free_buff_func = g_h.funcs->_h_free; -// req->app_free_buff_hdl = v_data; -// -// resp = wifi_set_vendor_specific_ie(req); -// -// return rpc_rsp_callback(resp); -//} - int rpc_ota_begin(void) { /* implemented synchronous */ @@ -822,7 +569,7 @@ int rpc_ota_begin(void) /* OTA begin takes some time to clear the partition */ req->rsp_timeout_sec = OTA_BEGIN_RSP_TIMEOUT_SEC; - resp = ota_begin(req); + resp = rpc_slaveif_ota_begin(req); return rpc_rsp_callback(resp); } @@ -836,7 +583,7 @@ int rpc_ota_write(uint8_t* ota_data, uint32_t ota_data_len) req->u.ota_write.ota_data = ota_data; req->u.ota_write.ota_data_len = ota_data_len; - resp = ota_write(req); + resp = rpc_slaveif_ota_write(req); return rpc_rsp_callback(resp); } @@ -847,227 +594,18 @@ int rpc_ota_end(void) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); ctrl_cmd_t *resp = NULL; - resp = ota_end(req); + resp = rpc_slaveif_ota_end(req); return rpc_rsp_callback(resp); } -#if !OTA_FROM_WEB_URL -/* This assumes full slave binary is present locally */ -int rpc_ota(char* image_path) -{ - FILE* f = NULL; - char ota_chunk[CHUNK_SIZE] = {0}; - int ret = rpc_ota_begin(); - if (ret == SUCCESS) { - f = fopen(image_path,"rb"); - if (f == NULL) { - ESP_LOGE(OTA_TAG, "Failed to open file %s", image_path); - return FAILURE; - } else { - ESP_LOGV(OTA_TAG, "Success in opening %s file", image_path); - } - while (!feof(f)) { - fread(&ota_chunk, CHUNK_SIZE, 1, f); - ret = rpc_ota_write((uint8_t* )&ota_chunk, CHUNK_SIZE); - if (ret) { - ESP_LOGE(OTA_TAG, "OTA procedure failed!!"); - /* TODO: Do we need to do OTA end irrespective of success/failure? */ - rpc_ota_end(); - return FAILURE; - } - } - ret = rpc_ota_end(); - if (ret) { - return FAILURE; - } - } else { - return FAILURE; - } - ESP_LOGE(OTA_TAG, "ESP32 will restart after 5 sec"); - return SUCCESS; - ESP_LOGE(OTA_TAG, "For OTA, user need to integrate HTTP client lib and then invoke OTA"); - return FAILURE; -} -#else -uint8_t http_err = 0; -static esp_err_t http_client_event_handler(esp_http_client_event_t *evt) -{ - switch(evt->event_id) { - - case HTTP_EVENT_ERROR: - ESP_LOGI(OTA_TAG, "HTTP_EVENT_ERROR"); - http_err = 1; - break; - case HTTP_EVENT_ON_CONNECTED: - ESP_LOGI(OTA_TAG, "HTTP_EVENT_ON_CONNECTED"); - break; - case HTTP_EVENT_HEADER_SENT: - ESP_LOGI(OTA_TAG, "HTTP_EVENT_HEADER_SENT"); - break; - case HTTP_EVENT_ON_HEADER: - ESP_LOGI(OTA_TAG, "HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key, evt->header_value); - break; - case HTTP_EVENT_ON_DATA: - /* Nothing to handle here */ - break; - case HTTP_EVENT_ON_FINISH: - ESP_LOGI(OTA_TAG, "HTTP_EVENT_ON_FINISH"); - break; - case HTTP_EVENT_DISCONNECTED: - ESP_LOGI(OTA_TAG, "HTTP_EVENT_DISCONNECTED"); - break; - case HTTP_EVENT_REDIRECT: - ESP_LOGW(TAG, "HTTP_EVENT_REDIRECT"); - break; - } - - return ESP_OK; -} - -static esp_err_t _rpc_ota(const char* image_url) -{ - uint8_t *ota_chunk = NULL; - esp_err_t err = 0; - int data_read = 0; - int ota_failed = 0; - - if (image_url == NULL) { - ESP_LOGE(TAG, "Invalid image URL"); - return FAILURE; - } - - /* Initialize HTTP client configuration */ - esp_http_client_config_t config = { - .url = image_url, - .timeout_ms = 5000, - .event_handler = http_client_event_handler, - }; - - esp_http_client_handle_t client = esp_http_client_init(&config); - - ESP_LOGI(OTA_TAG, "http_open"); - if ((err = esp_http_client_open(client, 0)) != ESP_OK) { - ESP_LOGE(OTA_TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err)); - ESP_LOGE(OTA_TAG, "Check if URL is correct and connectable: %s", image_url); - esp_http_client_cleanup(client); - return FAILURE; - } - - if (http_err) { - ESP_LOGE(TAG, "Exiting OTA, due to http failure"); - esp_http_client_close(client); - esp_http_client_cleanup(client); - http_err = 0; - return FAILURE; - } - - ESP_LOGI(OTA_TAG, "http_fetch_headers"); - int64_t content_length = esp_http_client_fetch_headers(client); - if (content_length <= 0) { - ESP_LOGE(OTA_TAG, "HTTP client fetch headers failed"); - ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %"PRId64, - esp_http_client_get_status_code(client), - esp_http_client_get_content_length(client)); - esp_http_client_close(client); - esp_http_client_cleanup(client); - return FAILURE; - } - - ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %"PRId64, - esp_http_client_get_status_code(client), - esp_http_client_get_content_length(client)); - - ESP_LOGW(OTA_TAG, "********* Started Slave OTA *******************"); - ESP_LOGI(TAG, "*** Please wait for 5 mins to let slave OTA complete ***"); - - ESP_LOGI(OTA_TAG, "Preparing OTA"); - if ((err = rpc_ota_begin())) { - ESP_LOGW(OTA_TAG, "********* Slave OTA Begin Failed *******************"); - ESP_LOGI(OTA_TAG, "esp_ota_begin failed, error=%s", esp_err_to_name(err)); - esp_http_client_close(client); - esp_http_client_cleanup(client); - return FAILURE; - } - - ota_chunk = (uint8_t*)g_h.funcs->_h_calloc(1, CHUNK_SIZE); - if (!ota_chunk) { - ESP_LOGE(OTA_TAG, "Failed to allocate otachunk mem\n"); - err = -ENOMEM; - } - - ESP_LOGI(OTA_TAG, "Starting OTA"); - - if (!err) { - while ((data_read = esp_http_client_read(client, (char*)ota_chunk, CHUNK_SIZE)) > 0) { - - ESP_LOGV(OTA_TAG, "Read image length %d", data_read); - if ((err = rpc_ota_write(ota_chunk, data_read))) { - ESP_LOGI(OTA_TAG, "rpc_ota_write failed"); - ota_failed = err; - break; - } - } - } - - g_h.funcs->_h_free(ota_chunk); - if (err) { - ESP_LOGW(OTA_TAG, "********* Slave OTA Failed *******************"); - ESP_LOGI(OTA_TAG, "esp_ota_write failed, error=%s", esp_err_to_name(err)); - ota_failed = -1; - } - - if (data_read < 0) { - ESP_LOGE(OTA_TAG, "Error: SSL data read error"); - ota_failed = -2; - } - - if ((err = rpc_ota_end())) { - ESP_LOGW(OTA_TAG, "********* Slave OTA Failed *******************"); - ESP_LOGI(OTA_TAG, "esp_ota_end failed, error=%s", esp_err_to_name(err)); - esp_http_client_close(client); - esp_http_client_cleanup(client); - ota_failed = err; - return FAILURE; - } - - esp_http_client_cleanup(client); - if (!ota_failed) { - ESP_LOGW(OTA_TAG, "********* Slave OTA Complete *******************"); - ESP_LOGI(OTA_TAG, "OTA Successful, Slave will restart in while"); - ESP_LOGE(TAG, "Need to restart host after slave OTA is complete, to avoid sync issues"); - sleep(5); - ESP_LOGE(OTA_TAG, "********* Restarting Host **********************"); - restart_after_slave_ota = 1; - esp_restart(); - } - return ota_failed; -} - -esp_err_t rpc_ota(const char* image_url) -{ - uint8_t ota_retry = 2; - int ret = 0; - - do { - ret = _rpc_ota(image_url); - - ota_retry--; - if (ota_retry && ret) - ESP_LOGI(OTA_TAG, "OTA retry left: %u\n", ota_retry); - } while (ota_retry && ret); - - return ret; -} -#endif - esp_err_t rpc_get_coprocessor_fwversion(esp_hosted_coprocessor_fwver_t *ver_info) { /* implemented synchronous */ ctrl_cmd_t *req = RPC_DEFAULT_REQ(); ctrl_cmd_t *resp = NULL; - resp = get_coprocessor_fwversion(req); + resp = rpc_slaveif_get_coprocessor_fwversion(req); if (resp && resp->resp_event_status == SUCCESS) { ver_info->major1 = resp->u.coprocessor_fwversion.major1; ver_info->minor1 = resp->u.coprocessor_fwversion.minor1; @@ -1084,7 +622,7 @@ int rpc_wifi_set_max_tx_power(int8_t in_power) ctrl_cmd_t *resp = NULL; req->u.wifi_tx_power.power = in_power; - resp = wifi_set_max_tx_power(req); + resp = rpc_slaveif_wifi_set_max_tx_power(req); return rpc_rsp_callback(resp); } @@ -1095,7 +633,7 @@ int rpc_wifi_get_max_tx_power(int8_t *power) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); ctrl_cmd_t *resp = NULL; - resp = wifi_get_max_tx_power(req); + resp = rpc_slaveif_wifi_get_max_tx_power(req); if (resp && resp->resp_event_status == SUCCESS) { *power = resp->u.wifi_tx_power.power; } @@ -1108,7 +646,7 @@ esp_err_t rpc_wifi_sta_get_negotiated_phymode(wifi_phy_mode_t *phymode) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); ctrl_cmd_t *resp = NULL; - resp = wifi_sta_get_negotiated_phymode(req); + resp = rpc_slaveif_wifi_sta_get_negotiated_phymode(req); if (resp && resp->resp_event_status == SUCCESS) { *phymode = resp->u.wifi_sta_get_negotiated_phymode.phymode; } @@ -1121,7 +659,7 @@ esp_err_t rpc_wifi_sta_get_aid(uint16_t *aid) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); ctrl_cmd_t *resp = NULL; - resp = wifi_sta_get_aid(req); + resp = rpc_slaveif_wifi_sta_get_aid(req); if (resp && resp->resp_event_status == SUCCESS) { *aid = resp->u.wifi_sta_get_aid.aid; } @@ -1136,7 +674,7 @@ esp_err_t rpc_wifi_set_band(wifi_band_t band) ctrl_cmd_t *resp = NULL; req->u.wifi_band = band; - resp = wifi_set_band(req); + resp = rpc_slaveif_wifi_set_band(req); return rpc_rsp_callback(resp); } @@ -1147,7 +685,7 @@ esp_err_t rpc_wifi_get_band(wifi_band_t *band) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); ctrl_cmd_t *resp = NULL; - resp = wifi_get_band(req); + resp = rpc_slaveif_wifi_get_band(req); if (resp && resp->resp_event_status == SUCCESS) { *band = resp->u.wifi_band; } @@ -1161,7 +699,7 @@ esp_err_t rpc_wifi_set_band_mode(wifi_band_mode_t band_mode) ctrl_cmd_t *resp = NULL; req->u.wifi_band_mode = band_mode; - resp = wifi_set_band_mode(req); + resp = rpc_slaveif_wifi_set_band_mode(req); return rpc_rsp_callback(resp); } @@ -1172,7 +710,7 @@ esp_err_t rpc_wifi_get_band_mode(wifi_band_mode_t *band_mode) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); ctrl_cmd_t *resp = NULL; - resp = wifi_get_band_mode(req); + resp = rpc_slaveif_wifi_get_band_mode(req); if (resp && resp->resp_event_status == SUCCESS) { *band_mode = resp->u.wifi_band_mode; } @@ -1189,7 +727,7 @@ esp_err_t rpc_wifi_set_protocols(wifi_interface_t ifx, wifi_protocols_t *protoco req->u.wifi_protocols.ghz_2g = protocols->ghz_2g; req->u.wifi_protocols.ghz_5g = protocols->ghz_5g; - resp = wifi_set_protocols(req); + resp = rpc_slaveif_wifi_set_protocols(req); return rpc_rsp_callback(resp); } @@ -1201,7 +739,7 @@ esp_err_t rpc_wifi_get_protocols(wifi_interface_t ifx, wifi_protocols_t *protoco req->u.wifi_protocols.ifx = ifx; - resp = wifi_get_protocols(req); + resp = rpc_slaveif_wifi_get_protocols(req); if (resp && resp->resp_event_status == SUCCESS) { protocols->ghz_2g = resp->u.wifi_protocols.ghz_2g; protocols->ghz_5g = resp->u.wifi_protocols.ghz_5g; @@ -1219,7 +757,7 @@ esp_err_t rpc_wifi_set_bandwidths(wifi_interface_t ifx, wifi_bandwidths_t *bw) req->u.wifi_bandwidths.ghz_2g = bw->ghz_2g; req->u.wifi_bandwidths.ghz_5g = bw->ghz_5g; - resp = wifi_set_bandwidths(req); + resp = rpc_slaveif_wifi_set_bandwidths(req); return rpc_rsp_callback(resp); } @@ -1232,7 +770,7 @@ esp_err_t rpc_wifi_get_bandwidths(wifi_interface_t ifx, wifi_bandwidths_t *bw) req->u.wifi_bandwidths.ifx = ifx; - resp = wifi_get_bandwidths(req); + resp = rpc_slaveif_wifi_get_bandwidths(req); if (resp && resp->resp_event_status == SUCCESS) { bw->ghz_2g = resp->u.wifi_bandwidths.ghz_2g; bw->ghz_5g = resp->u.wifi_bandwidths.ghz_5g; @@ -1249,7 +787,7 @@ int rpc_config_heartbeat(void) req->u.e_heartbeat.enable = YES; req->u.e_heartbeat.duration = HEARTBEAT_DURATION_SEC; - resp = config_heartbeat(req); + resp = rpc_slaveif_config_heartbeat(req); return rpc_rsp_callback(resp); } @@ -1261,7 +799,7 @@ int rpc_disable_heartbeat(void) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); req->u.e_heartbeat.enable = NO; - resp = config_heartbeat(req); + resp = rpc_slaveif_config_heartbeat(req); return rpc_rsp_callback(resp); } @@ -1276,7 +814,7 @@ int rpc_wifi_init(const wifi_init_config_t *arg) return FAILURE; g_h.funcs->_h_memcpy(&req->u.wifi_init_config, (void*)arg, sizeof(wifi_init_config_t)); - resp = wifi_init(req); + resp = rpc_slaveif_wifi_init(req); return rpc_rsp_callback(resp); } @@ -1287,7 +825,7 @@ int rpc_wifi_deinit(void) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); ctrl_cmd_t *resp = NULL; - resp = wifi_deinit(req); + resp = rpc_slaveif_wifi_deinit(req); return rpc_rsp_callback(resp); } @@ -1305,7 +843,7 @@ int rpc_wifi_get_mode(wifi_mode_t* mode) if (!mode) return FAILURE; - resp = wifi_get_mode(req); + resp = rpc_slaveif_wifi_get_mode(req); if (resp && resp->resp_event_status == SUCCESS) { *mode = resp->u.wifi_mode.mode; @@ -1320,7 +858,7 @@ int rpc_wifi_start(void) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); ctrl_cmd_t *resp = NULL; - resp = wifi_start(req); + resp = rpc_slaveif_wifi_start(req); return rpc_rsp_callback(resp); } @@ -1333,7 +871,7 @@ int rpc_wifi_stop(void) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); ctrl_cmd_t *resp = NULL; - resp = wifi_stop(req); + resp = rpc_slaveif_wifi_stop(req); return rpc_rsp_callback(resp); } @@ -1344,7 +882,7 @@ int rpc_wifi_connect(void) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); ctrl_cmd_t *resp = NULL; - resp = wifi_connect(req); + resp = rpc_slaveif_wifi_connect(req); return rpc_rsp_callback(resp); return 0; #else @@ -1355,7 +893,7 @@ int rpc_wifi_connect(void) req->rpc_rsp_cb = rpc_rsp_callback; ESP_LOGE(TAG, "Async call registerd: %p", rpc_rsp_callback); - wifi_connect(req); + rpc_slaveif_wifi_connect(req); return SUCCESS; #endif @@ -1367,7 +905,7 @@ int rpc_wifi_disconnect(void) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); ctrl_cmd_t *resp = NULL; - resp = wifi_disconnect(req); + resp = rpc_slaveif_wifi_disconnect(req); return rpc_rsp_callback(resp); } @@ -1383,7 +921,7 @@ int rpc_wifi_set_config(wifi_interface_t interface, wifi_config_t *conf) g_h.funcs->_h_memcpy(&req->u.wifi_config.u, conf, sizeof(wifi_config_t)); req->u.wifi_config.iface = interface; - resp = wifi_set_config(req); + resp = rpc_slaveif_wifi_set_config(req); return rpc_rsp_callback(resp); } @@ -1398,7 +936,7 @@ int rpc_wifi_get_config(wifi_interface_t interface, wifi_config_t *conf) req->u.wifi_config.iface = interface; - resp = wifi_get_config(req); + resp = rpc_slaveif_wifi_get_config(req); g_h.funcs->_h_memcpy(conf, &resp->u.wifi_config.u, sizeof(wifi_config_t)); @@ -1417,8 +955,11 @@ int rpc_wifi_scan_start(const wifi_scan_config_t *config, bool block) } req->u.wifi_scan_config.block = block; - - resp = wifi_scan_start(req); + if (req->u.wifi_scan_config.block) { + // blocking while doing scan may take a long time: increase timeout value + req->rsp_timeout_sec = DEFAULT_RPC_RSP_SCAN_TIMEOUT; + } + resp = rpc_slaveif_wifi_scan_start(req); return rpc_rsp_callback(resp); } @@ -1430,7 +971,7 @@ int rpc_wifi_scan_stop(void) ctrl_cmd_t *resp = NULL; ESP_LOGV(TAG, "scan stop"); - resp = wifi_scan_stop(req); + resp = rpc_slaveif_wifi_scan_stop(req); return rpc_rsp_callback(resp); } @@ -1443,7 +984,7 @@ int rpc_wifi_scan_get_ap_num(uint16_t *number) if (!number) return FAILURE; - resp = wifi_scan_get_ap_num(req); + resp = rpc_slaveif_wifi_scan_get_ap_num(req); if (resp && resp->resp_event_status == SUCCESS) { *number = resp->u.wifi_scan_ap_list.number; @@ -1460,7 +1001,7 @@ int rpc_wifi_scan_get_ap_record(wifi_ap_record_t *ap_record) if (!ap_record) return FAILURE; - resp = wifi_scan_get_ap_record(req); + resp = rpc_slaveif_wifi_scan_get_ap_record(req); if (resp && resp->resp_event_status == SUCCESS) { g_h.funcs->_h_memcpy(ap_record, &resp->u.wifi_ap_record, sizeof(wifi_ap_record_t)); } @@ -1479,7 +1020,7 @@ int rpc_wifi_scan_get_ap_records(uint16_t *number, wifi_ap_record_t *ap_records) g_h.funcs->_h_memset(ap_records, 0, (*number)*sizeof(wifi_ap_record_t)); req->u.wifi_scan_ap_list.number = *number; - resp = wifi_scan_get_ap_records(req); + resp = rpc_slaveif_wifi_scan_get_ap_records(req); if (resp && resp->resp_event_status == SUCCESS) { ESP_LOGV(TAG, "num: %u",resp->u.wifi_scan_ap_list.number); @@ -1495,7 +1036,7 @@ int rpc_wifi_clear_ap_list(void) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); ctrl_cmd_t *resp = NULL; - resp = wifi_clear_ap_list(req); + resp = rpc_slaveif_wifi_clear_ap_list(req); return rpc_rsp_callback(resp); } @@ -1506,7 +1047,7 @@ int rpc_wifi_restore(void) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); ctrl_cmd_t *resp = NULL; - resp = wifi_restore(req); + resp = rpc_slaveif_wifi_restore(req); return rpc_rsp_callback(resp); } @@ -1516,7 +1057,7 @@ int rpc_wifi_clear_fast_connect(void) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); ctrl_cmd_t *resp = NULL; - resp = wifi_clear_fast_connect(req); + resp = rpc_slaveif_wifi_clear_fast_connect(req); return rpc_rsp_callback(resp); } @@ -1527,7 +1068,7 @@ int rpc_wifi_deauth_sta(uint16_t aid) ctrl_cmd_t *resp = NULL; req->u.wifi_deauth_sta.aid = aid; - resp = wifi_deauth_sta(req); + resp = rpc_slaveif_wifi_deauth_sta(req); return rpc_rsp_callback(resp); } @@ -1540,7 +1081,7 @@ int rpc_wifi_sta_get_ap_info(wifi_ap_record_t *ap_info) if (!ap_info) return FAILURE; - resp = wifi_sta_get_ap_info(req); + resp = rpc_slaveif_wifi_sta_get_ap_info(req); if (resp && resp->resp_event_status == SUCCESS) { g_h.funcs->_h_memcpy(ap_info, resp->u.wifi_scan_ap_list.out_list, @@ -1560,7 +1101,7 @@ int rpc_wifi_set_ps(wifi_ps_type_t type) req->u.wifi_ps.ps_mode = type; - resp = wifi_set_ps(req); + resp = rpc_slaveif_wifi_set_ps(req); return rpc_rsp_callback(resp); } @@ -1577,7 +1118,7 @@ int rpc_wifi_get_ps(wifi_ps_type_t *type) if (!type) return FAILURE; - resp = wifi_get_ps(req); + resp = rpc_slaveif_wifi_get_ps(req); *type = resp->u.wifi_ps.ps_mode; @@ -1591,7 +1132,7 @@ int rpc_wifi_set_storage(wifi_storage_t storage) ctrl_cmd_t *resp = NULL; req->u.wifi_storage = storage; - resp = wifi_set_storage(req); + resp = rpc_slaveif_wifi_set_storage(req); return rpc_rsp_callback(resp); } @@ -1603,7 +1144,7 @@ int rpc_wifi_set_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t bw) req->u.wifi_bandwidth.ifx = ifx; req->u.wifi_bandwidth.bw = bw; - resp = wifi_set_bandwidth(req); + resp = rpc_slaveif_wifi_set_bandwidth(req); return rpc_rsp_callback(resp); } @@ -1617,7 +1158,7 @@ int rpc_wifi_get_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t *bw) return FAILURE; req->u.wifi_bandwidth.ifx = ifx; - resp = wifi_get_bandwidth(req); + resp = rpc_slaveif_wifi_get_bandwidth(req); if (resp && resp->resp_event_status == SUCCESS) { *bw = resp->u.wifi_bandwidth.bw; @@ -1633,7 +1174,7 @@ int rpc_wifi_set_channel(uint8_t primary, wifi_second_chan_t second) req->u.wifi_channel.primary = primary; req->u.wifi_channel.second = second; - resp = wifi_set_channel(req); + resp = rpc_slaveif_wifi_set_channel(req); return rpc_rsp_callback(resp); } @@ -1646,7 +1187,7 @@ int rpc_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second) if ((!primary) || (!second)) return FAILURE; - resp = wifi_get_channel(req); + resp = rpc_slaveif_wifi_get_channel(req); if (resp && resp->resp_event_status == SUCCESS) { *primary = resp->u.wifi_channel.primary; @@ -1666,7 +1207,7 @@ int rpc_wifi_set_country_code(const char *country, bool ieee80211d_enabled) memcpy(&req->u.wifi_country_code.cc[0], country, sizeof(req->u.wifi_country_code.cc)); req->u.wifi_country_code.ieee80211d_enabled = ieee80211d_enabled; - resp = wifi_set_country_code(req); + resp = rpc_slaveif_wifi_set_country_code(req); return rpc_rsp_callback(resp); } @@ -1679,7 +1220,7 @@ int rpc_wifi_get_country_code(char *country) if (!country) return FAILURE; - resp = wifi_get_country_code(req); + resp = rpc_slaveif_wifi_get_country_code(req); if (resp && resp->resp_event_status == SUCCESS) { memcpy(country, &resp->u.wifi_country_code.cc[0], sizeof(resp->u.wifi_country_code.cc)); @@ -1702,7 +1243,7 @@ int rpc_wifi_set_country(const wifi_country_t *country) req->u.wifi_country.max_tx_power = country->max_tx_power; req->u.wifi_country.policy = country->policy; - resp = wifi_set_country(req); + resp = rpc_slaveif_wifi_set_country(req); return rpc_rsp_callback(resp); } @@ -1715,7 +1256,7 @@ int rpc_wifi_get_country(wifi_country_t *country) if (!country) return FAILURE; - resp = wifi_get_country(req); + resp = rpc_slaveif_wifi_get_country(req); if (resp && resp->resp_event_status == SUCCESS) { memcpy(&country->cc[0], &resp->u.wifi_country.cc[0], sizeof(resp->u.wifi_country.cc)); country->schan = resp->u.wifi_country.schan; @@ -1735,7 +1276,7 @@ int rpc_wifi_ap_get_sta_list(wifi_sta_list_t *sta) if (!sta) return FAILURE; - resp = wifi_ap_get_sta_list(req); + resp = rpc_slaveif_wifi_ap_get_sta_list(req); if (resp && resp->resp_event_status == SUCCESS) { for (int i = 0; i < ESP_WIFI_MAX_CONN_NUM; i++) { memcpy(sta->sta[i].mac, resp->u.wifi_ap_sta_list.sta[i].mac, 6); @@ -1766,7 +1307,7 @@ int rpc_wifi_ap_get_sta_aid(const uint8_t mac[6], uint16_t *aid) memcpy(&req->u.wifi_ap_get_sta_aid.mac[0], &mac[0], MAC_SIZE_BYTES); - resp = wifi_ap_get_sta_aid(req); + resp = rpc_slaveif_wifi_ap_get_sta_aid(req); if (resp && resp->resp_event_status == SUCCESS) { *aid = resp->u.wifi_ap_get_sta_aid.aid; } @@ -1783,7 +1324,7 @@ int rpc_wifi_sta_get_rssi(int *rssi) if (!rssi) return FAILURE; - resp = wifi_sta_get_rssi(req); + resp = rpc_slaveif_wifi_sta_get_rssi(req); if (resp && resp->resp_event_status == SUCCESS) { *rssi = resp->u.wifi_sta_get_rssi.rssi; } @@ -1800,7 +1341,7 @@ int rpc_wifi_set_protocol(wifi_interface_t ifx, uint8_t protocol_bitmap) req->u.wifi_protocol.ifx = ifx; req->u.wifi_protocol.protocol_bitmap = protocol_bitmap; - resp = wifi_set_protocol(req); + resp = rpc_slaveif_wifi_set_protocol(req); return rpc_rsp_callback(resp); } @@ -1813,7 +1354,7 @@ int rpc_wifi_get_protocol(wifi_interface_t ifx, uint8_t *protocol_bitmap) ctrl_cmd_t *req = RPC_DEFAULT_REQ(); ctrl_cmd_t *resp = NULL; - resp = wifi_get_protocol(req); + resp = rpc_slaveif_wifi_get_protocol(req); if (resp && resp->resp_event_status == SUCCESS) { *protocol_bitmap = resp->u.wifi_protocol.protocol_bitmap; } diff --git a/host/drivers/rpc/wrap/rpc_wrap.h b/host/drivers/rpc/wrap/rpc_wrap.h index ebe39125..04c64f3d 100644 --- a/host/drivers/rpc/wrap/rpc_wrap.h +++ b/host/drivers/rpc/wrap/rpc_wrap.h @@ -25,8 +25,8 @@ extern "C" { #include "common.h" #include "esp_wifi.h" #include "esp_hosted_wifi_config.h" -#include "esp_hosted_api.h" #include "esp_hosted_api_types.h" +#include "esp_hosted_ota.h" /** Exported variables **/ @@ -81,9 +81,13 @@ esp_err_t rpc_wifi_set_max_tx_power(int8_t power); esp_err_t rpc_wifi_get_max_tx_power(int8_t *power); esp_err_t rpc_wifi_sta_get_negotiated_phymode(wifi_phy_mode_t *phymode); esp_err_t rpc_wifi_sta_get_aid(uint16_t *aid); -esp_err_t rpc_ota(const char* image_url); + esp_err_t rpc_get_coprocessor_fwversion(esp_hosted_coprocessor_fwver_t *ver_info); +esp_err_t rpc_ota_begin(void); +esp_err_t rpc_ota_write(uint8_t* ota_data, uint32_t ota_data_len); +esp_err_t rpc_ota_end(void); + #if H_WIFI_DUALBAND_SUPPORT esp_err_t rpc_wifi_set_band(wifi_band_t band); esp_err_t rpc_wifi_get_band(wifi_band_t *band); diff --git a/host/drivers/serial/serial_drv.c b/host/drivers/serial/serial_drv.c index f9605b39..9ed01633 100644 --- a/host/drivers/serial/serial_drv.c +++ b/host/drivers/serial/serial_drv.c @@ -212,8 +212,8 @@ int serial_drv_close(struct serial_drv_handle_t** serial_drv_handle) int rpc_platform_init(void) { /* rpc semaphore */ - readSemaphore = g_h.funcs->_h_create_semaphore(CONFIG_ESP_HOSTED_MAX_SIMULTANEOUS_SYNC_RPC_REQUESTS + - CONFIG_ESP_HOSTED_MAX_SIMULTANEOUS_ASYNC_RPC_REQUESTS); + readSemaphore = g_h.funcs->_h_create_semaphore(H_MAX_SYNC_RPC_REQUESTS + + H_MAX_ASYNC_RPC_REQUESTS); assert(readSemaphore); /* grab the semaphore, so that task will be mandated to wait on semaphore */ diff --git a/host/drivers/transport/sdio/sdio_drv.c b/host/drivers/transport/sdio/sdio_drv.c index 0f991dab..a73aa010 100644 --- a/host/drivers/transport/sdio/sdio_drv.c +++ b/host/drivers/transport/sdio/sdio_drv.c @@ -48,8 +48,8 @@ static const char TAG[] = "H_SDIO_DRV"; // max number of time to try to read write buffer available reg #define MAX_WRITE_BUF_RETRIES 50 -// max number of times to try to write data to slave device -#define MAX_WRITE_RETRIES 2 +/* Actual data sdio_write max retry */ +#define MAX_SDIO_WRITE_RETRY 2 // this locks the sdio transaction at the driver level, instead of at the HAL layer #define USE_DRIVER_LOCK @@ -303,25 +303,40 @@ static int sdio_get_len_from_slave(uint32_t *rx_size, bool is_lock_needed) #endif +#define MAX_BUFF_FETCH_PERIODICITY 30000 + static int sdio_is_write_buffer_available(uint32_t buf_needed) { static uint32_t buf_available = 0; uint8_t retry = MAX_WRITE_BUF_RETRIES; + uint32_t max_retry_sdio_not_responding = 2; + uint32_t interval_us = 400; /*If buffer needed are less than buffer available then only read for available buffer number from slave*/ if (buf_available < buf_needed) { while (retry) { - sdio_get_tx_buffer_num(&buf_available, ACQUIRE_LOCK); + if (sdio_get_tx_buffer_num(&buf_available, ACQUIRE_LOCK) == + ESP_HOSTED_SDIO_UNRESPONSIVE_CODE) { + max_retry_sdio_not_responding--; + /* restart the host to avoid the sdio locked out state */ + + if (!max_retry_sdio_not_responding) { + ESP_LOGE(TAG, "%s: SDIO slave unresponsive, restart host", __func__); + g_h.funcs->_h_restart_host(); + } + continue; + } if (buf_available < buf_needed) { ESP_LOGV(TAG, "Retry get write buffers %d", retry); retry--; - if (retry < MAX_WRITE_BUF_RETRIES/2) - g_h.funcs->_h_msleep(1); - + g_h.funcs->_h_usleep(interval_us); + if (interval_us < MAX_BUFF_FETCH_PERIODICITY) { + interval_us += 400; + } continue; } break; @@ -468,12 +483,14 @@ static void sdio_write_task(void const* pvParameters) ESP_LOGE(TAG, "%s: %d: Failed to send data: %d %ld %ld", __func__, retries, ret, len_to_send, data_left); retries++; - if (retries < MAX_WRITE_RETRIES) { + if (retries < MAX_SDIO_WRITE_RETRY) { ESP_LOGD(TAG, "retry"); continue; } else { - ESP_LOGE(TAG, "abort sending of data"); - goto unlock_done; + SDIO_DRV_UNLOCK(); + ESP_LOGE(TAG, "Unrecoverable host sdio state, reset host mcu"); + g_h.funcs->_h_restart_host(); + goto done; } } @@ -815,6 +832,8 @@ static void sdio_read_task(void const* pvParameters) ESP_LOGE(TAG, "failed to read interrupt register"); SDIO_DRV_UNLOCK(); + ESP_LOGI(TAG, "Host is reseting itself, to avoid any sdio race condition"); + g_h.funcs->_h_restart_host(); continue; } #endif @@ -998,6 +1017,11 @@ static void sdio_process_rx_task(void const* pvParameters) ESP_LOGW(TAG, "unknown type %d ", buf_handle->if_type); } +#if ESP_PKT_STATS + if (buf_handle->if_type == ESP_STA_IF) + pkt_stats.sta_rx_out++; +#endif + /* Free buffer handle */ /* When buffer offloaded to other module, that module is * responsible for freeing buffer. In case not offloaded or diff --git a/host/drivers/transport/sdio/sdio_reg.h b/host/drivers/transport/sdio/sdio_reg.h index 45e8c01a..f272d59a 100644 --- a/host/drivers/transport/sdio/sdio_reg.h +++ b/host/drivers/transport/sdio/sdio_reg.h @@ -69,7 +69,7 @@ #define ESP_HOST_INT_ENA_REG (ESP_SLAVE_SLCHOST_BASE + 0xDC) /* Host side interrupts for ESP_HOST_INT_ENA_REG */ -#if H_SLAVE_TARGET_ESP32 || H_SLAVE_TARGET_ESP32C6 +#if H_SLAVE_TARGET_ESP32 || H_SLAVE_TARGET_ESP32C6 || H_SLAVE_TARGET_ESP32C5 #define SDIO_INT_NEW_PACKET (23) #define SDIO_INT_START_THROTTLE (7) #define SDIO_INT_STOP_THROTTLE (6) diff --git a/host/drivers/transport/spi/spi_drv.c b/host/drivers/transport/spi/spi_drv.c index 8e3751a1..3305a485 100644 --- a/host/drivers/transport/spi/spi_drv.c +++ b/host/drivers/transport/spi/spi_drv.c @@ -578,6 +578,12 @@ static void spi_process_rx_task(void const* pvParameters) } else { ESP_LOGW(TAG, "unknown type %d ", buf_handle->if_type); } + +#if ESP_PKT_STATS + if (buf_handle->if_type == ESP_STA_IF) + pkt_stats.sta_rx_out++; +#endif + /* Free buffer handle */ /* When buffer offloaded to other module, that module is * responsible for freeing buffer. In case not offloaded or diff --git a/host/drivers/transport/spi_hd/spi_hd_drv.c b/host/drivers/transport/spi_hd/spi_hd_drv.c index e51b9e0b..5e37471a 100644 --- a/host/drivers/transport/spi_hd/spi_hd_drv.c +++ b/host/drivers/transport/spi_hd/spi_hd_drv.c @@ -648,6 +648,11 @@ static void spi_hd_process_rx_task(void const* pvParameters) ESP_LOGW(TAG, "unknown type %d ", buf_handle->if_type); } +#if ESP_PKT_STATS + if (buf_handle->if_type == ESP_STA_IF) + pkt_stats.sta_rx_out++; +#endif + /* Free buffer handle */ /* When buffer offloaded to other module, that module is * responsible for freeing buffer. In case not offloaded or diff --git a/host/drivers/transport/transport_drv.c b/host/drivers/transport/transport_drv.c index bc35d503..f3022149 100644 --- a/host/drivers/transport/transport_drv.c +++ b/host/drivers/transport/transport_drv.c @@ -20,6 +20,7 @@ #include "transport_drv.h" #include "esp_hosted_transport.h" #include "esp_hosted_transport_init.h" +#include "esp_hosted_transport_config.h" #include "stats.h" #include "esp_log.h" #include "esp_hosted_log.h" @@ -62,17 +63,23 @@ uint8_t is_transport_tx_ready(void) static void reset_slave(void) { - ESP_LOGI(TAG, "Reset slave using GPIO[%u]", H_GPIO_PIN_RESET_Pin); - g_h.funcs->_h_config_gpio(H_GPIO_PIN_RESET_Port, H_GPIO_PIN_RESET_Pin, H_GPIO_MODE_DEF_OUTPUT); + gpio_pin_t reset_pin = { 0 }; + if (ESP_TRANSPORT_OK != esp_hosted_transport_get_reset_config(&reset_pin)) { + ESP_LOGE(TAG, "Unable to get RESET config for transport"); + return; + } + + ESP_LOGI(TAG, "Reset slave using GPIO[%u]", reset_pin.pin); + g_h.funcs->_h_config_gpio(H_GPIO_PIN_RESET_Port, reset_pin.pin, H_GPIO_MODE_DEF_OUTPUT); - g_h.funcs->_h_write_gpio(H_GPIO_PIN_RESET_Port, H_GPIO_PIN_RESET_Pin, H_RESET_VAL_ACTIVE); + g_h.funcs->_h_write_gpio(reset_pin.port, reset_pin.pin, H_RESET_VAL_ACTIVE); g_h.funcs->_h_msleep(50); - g_h.funcs->_h_write_gpio(H_GPIO_PIN_RESET_Port, H_GPIO_PIN_RESET_Pin, H_RESET_VAL_INACTIVE); + g_h.funcs->_h_write_gpio(reset_pin.port, reset_pin.pin, H_RESET_VAL_INACTIVE); g_h.funcs->_h_msleep(50); - g_h.funcs->_h_write_gpio(H_GPIO_PIN_RESET_Port, H_GPIO_PIN_RESET_Pin, H_RESET_VAL_ACTIVE); + g_h.funcs->_h_write_gpio(reset_pin.port, reset_pin.pin, H_RESET_VAL_ACTIVE); /* stop spi transactions short time to avoid slave sync issues */ - g_h.funcs->_h_sleep(1); + g_h.funcs->_h_msleep(1500); } static void transport_driver_event_handler(uint8_t event) diff --git a/host/drivers/transport/uart/uart_drv.c b/host/drivers/transport/uart/uart_drv.c index a5502ed3..1708149c 100644 --- a/host/drivers/transport/uart/uart_drv.c +++ b/host/drivers/transport/uart/uart_drv.c @@ -167,6 +167,11 @@ static void h_uart_write_task(void const* pvParameters) ESP_LOGE(TAG, "failed to send uart data"); } +#if ESP_PKT_STATS + if (buf_handle.if_type == ESP_STA_IF) + pkt_stats.sta_tx_out++; +#endif + done: if (len && !buf_handle.payload_zcopy) { /* free allocated buffer, only if zerocopy is not requested */ @@ -271,6 +276,11 @@ static void h_uart_process_rx_task(void const* pvParameters) ESP_LOGW(TAG, "unknown type %d ", buf_handle->if_type); } +#if ESP_PKT_STATS + if (buf_handle->if_type == ESP_STA_IF) + pkt_stats.sta_rx_out++; +#endif + /* Free buffer handle */ /* When buffer offloaded to other module, that module is * responsible for freeing buffer. In case not offloaded or diff --git a/host/esp_hosted.h b/host/esp_hosted.h index cfff1d3b..31c77680 100644 --- a/host/esp_hosted.h +++ b/host/esp_hosted.h @@ -7,11 +7,39 @@ #ifndef __ESP_HOSTED_H__ #define __ESP_HOSTED_H__ -#include "esp_hosted_api.h" +#ifdef __cplusplus +extern "C" { +#endif + #include "esp_hosted_config.h" #include "esp_hosted_bt_config.h" #include "esp_hosted_transport_config.h" +#include "esp_hosted_api_types.h" +#include "esp_hosted_ota.h" typedef struct esp_hosted_transport_config esp_hosted_config_t; +/* --------- Hosted Minimal APIs --------- */ +int esp_hosted_init(void); +int esp_hosted_deinit(void); + +int esp_hosted_connect_to_slave(void); +int esp_hosted_get_coprocessor_fwversion(esp_hosted_coprocessor_fwver_t *ver_info); + +/* --------- Exhaustive API list --------- */ +/* + * 1. All Wi-Fi supported APIs + * File: host/api/src/esp_wifi_weak.c + * + * 2. Communication Bus APIs (Set and get transport config) + * File : host/api/include/esp_hosted_transport_config.h + * + * 3. Co-Processor OTA API + * File : host/api/include/esp_hosted_ota.h + */ + +#ifdef __cplusplus +} +#endif + #endif /* __ESP_HOSTED_H__ */ diff --git a/host/esp_hosted_host_init.c b/host/esp_hosted_host_init.c index 30479e06..aa508f25 100644 --- a/host/esp_hosted_host_init.c +++ b/host/esp_hosted_host_init.c @@ -7,7 +7,7 @@ #include "os_header.h" #include "os_wrapper.h" #include "esp_log.h" -#include "esp_hosted_api.h" +#include "esp_hosted.h" #include "esp_private/startup_internal.h" DEFINE_LOG_TAG(host_init); diff --git a/host/hosted_os_abstraction.h b/host/hosted_os_abstraction.h index 6ba1ddd1..dad5e8cb 100644 --- a/host/hosted_os_abstraction.h +++ b/host/hosted_os_abstraction.h @@ -19,7 +19,7 @@ typedef struct { /* 8 */ void (*_h_free_align)(void* ptr); /* Thread */ -/* 11 */ void* (*_h_thread_create)(char *tname, uint32_t tprio, uint32_t tstack_size, void (*start_routine)(void const *), void *sr_arg); +/* 11 */ void* (*_h_thread_create)(const char *tname, uint32_t tprio, uint32_t tstack_size, void (*start_routine)(void const *), void *sr_arg); /* 12 */ int (*_h_thread_cancel)(void *thread_handle); /* Sleeps */ @@ -103,6 +103,8 @@ typedef struct { /* 57 */ int (*_h_uart_read)(void *ctx, uint8_t *data, uint16_t size); /* 58 */ int (*_h_uart_write)(void *ctx, uint8_t *data, uint16_t size); #endif + +/* 59 */ int (*_h_restart_host)(void); } hosted_osi_funcs_t; struct hosted_config_t { diff --git a/host/port/esp/freertos/include/esp_hosted_wifi_config.h b/host/port/esp/freertos/include/esp_hosted_wifi_config.h new file mode 100644 index 00000000..ad6a6916 --- /dev/null +++ b/host/port/esp/freertos/include/esp_hosted_wifi_config.h @@ -0,0 +1,55 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __ESP_HOSTED_WIFI_CONFIG_H__ +#define __ESP_HOSTED_WIFI_CONFIG_H__ + +#include "esp_idf_version.h" +#include "esp_hosted_config.h" + +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 1) +#error ESP-IDF version used is not supported +#endif + +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) + /* dual band API support available */ + #define H_WIFI_DUALBAND_SUPPORT 1 +#else + #define H_WIFI_DUALBAND_SUPPORT 0 +#endif + +/* ESP-IDF 5.5.0 breaking change: reserved/he_reserved renamed to reserved1/reserved2 */ +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0) + #define H_WIFI_NEW_RESERVED_FIELD_NAMES 1 + #define H_PRESENT_IN_ESP_IDF_5_5_0 1 +#else + #define H_WIFI_NEW_RESERVED_FIELD_NAMES 0 + #define H_PRESENT_IN_ESP_IDF_5_5_0 0 +#endif + +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) + #define H_PRESENT_IN_ESP_IDF_5_4_0 1 +#else + #define H_PRESENT_IN_ESP_IDF_5_4_0 0 +#endif + +/* User-controllable reserved field decoding - works regardless of IDF version */ +#ifdef CONFIG_ESP_HOSTED_DECODE_WIFI_RESERVED_FIELD + #define H_DECODE_WIFI_RESERVED_FIELD 1 +#else + #define H_DECODE_WIFI_RESERVED_FIELD 0 +#endif + +/* wifi_ap_config_t::transition_disable only found in + * IDF v5.3.3 and above, or + * IDF v5.4.1 and above + */ +#if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 3)) || (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 4, 1)) +#define H_GOT_AP_CONFIG_PARAM_TRANSITION_DISABLE 0 +#else +#define H_GOT_AP_CONFIG_PARAM_TRANSITION_DISABLE 1 +#endif + +#endif /* __ESP_HOSTED_WIFI_CONFIG_H__ */ diff --git a/host/port/include/os_header.h b/host/port/esp/freertos/include/os_header.h similarity index 100% rename from host/port/include/os_header.h rename to host/port/esp/freertos/include/os_header.h diff --git a/host/port/include/os_wrapper.h b/host/port/esp/freertos/include/os_wrapper.h similarity index 90% rename from host/port/include/os_wrapper.h rename to host/port/esp/freertos/include/os_wrapper.h index 19d5fe21..da061581 100644 --- a/host/port/include/os_wrapper.h +++ b/host/port/esp/freertos/include/os_wrapper.h @@ -17,6 +17,7 @@ #include "hosted_os_abstraction.h" #include "esp_timer.h" #include "esp_event.h" +#include "esp_heap_caps.h" #include "esp_netif_types.h" #include "esp_wifi_types.h" #include "esp_wifi_default.h" @@ -102,17 +103,7 @@ enum { #define MALLOC(x) malloc(x) /* This is [malloc + aligned DMA] */ -#define MEM_ALLOC(x) ({ \ - esp_dma_mem_info_t dma_mem_info = { \ - .extra_heap_caps = 0, \ - .dma_alignment_bytes = 64, \ - }; \ - void *tmp_buf = NULL; \ - size_t actual_size = 0; \ - esp_err_t err = ESP_OK; \ - err = esp_dma_capable_malloc((x), &dma_mem_info, &tmp_buf, &actual_size);\ - if (err) tmp_buf = NULL; \ - tmp_buf;}) +#define MEM_ALLOC(x) heap_caps_aligned_alloc(64, (x), MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA | MALLOC_CAP_8BIT) #define FREE(x) free(x); diff --git a/host/port/include/sdio_wrapper.h b/host/port/esp/freertos/include/sdio_wrapper.h similarity index 97% rename from host/port/include/sdio_wrapper.h rename to host/port/esp/freertos/include/sdio_wrapper.h index eccf243d..9491841f 100644 --- a/host/port/include/sdio_wrapper.h +++ b/host/port/esp/freertos/include/sdio_wrapper.h @@ -22,6 +22,7 @@ #include "sdmmc_cmd.h" #define MAX_TRANSPORT_BUFFER_SIZE MAX_SDIO_BUFFER_SIZE +#define ESP_HOSTED_SDIO_UNRESPONSIVE_CODE 0x107 /* Hosted init function to init the SDIO host * returns a pointer to the sdio context */ diff --git a/host/port/include/spi_hd_wrapper.h b/host/port/esp/freertos/include/spi_hd_wrapper.h similarity index 100% rename from host/port/include/spi_hd_wrapper.h rename to host/port/esp/freertos/include/spi_hd_wrapper.h diff --git a/host/port/include/spi_wrapper.h b/host/port/esp/freertos/include/spi_wrapper.h similarity index 100% rename from host/port/include/spi_wrapper.h rename to host/port/esp/freertos/include/spi_wrapper.h diff --git a/host/port/include/uart_wrapper.h b/host/port/esp/freertos/include/uart_wrapper.h similarity index 100% rename from host/port/include/uart_wrapper.h rename to host/port/esp/freertos/include/uart_wrapper.h diff --git a/host/port/src/esp_hosted_config.c b/host/port/esp/freertos/src/esp_hosted_config.c similarity index 100% rename from host/port/src/esp_hosted_config.c rename to host/port/esp/freertos/src/esp_hosted_config.c diff --git a/host/port/esp/freertos/src/esp_hosted_ota.c b/host/port/esp/freertos/src/esp_hosted_ota.c new file mode 100644 index 00000000..332862f2 --- /dev/null +++ b/host/port/esp/freertos/src/esp_hosted_ota.c @@ -0,0 +1,248 @@ +/* +* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD +* +* SPDX-License-Identifier: Apache-2.0 +*/ + +/* Current OTA method(s) supported: + * - OTA from a HTTP URL + * + * Procedure: + * 1. Prepare OTA binary + * 2. Call rpc_ota_begin() to start OTA + * 3. Repeatedly call rpc_ota_write() with a continuous chunk of OTA data + * 4. Call rpc_ota_end() + */ + +#include "esp_http_client.h" +#include "esp_log.h" + +#include "rpc_wrap.h" +#include "esp_hosted_ota.h" + +#define CHUNK_SIZE 1400 +#define OTA_FROM_WEB_URL 1 + +static char* TAG = "hosted_ota"; + +#if OTA_FROM_WEB_URL +/* Default: Chunk by chunk transfer using esp http client library */ +uint8_t http_err = 0; +static esp_err_t http_client_event_handler(esp_http_client_event_t *evt) +{ + switch(evt->event_id) { + + case HTTP_EVENT_ERROR: + ESP_LOGI(TAG, "HTTP_EVENT_ERROR"); + http_err = 1; + break; + case HTTP_EVENT_ON_CONNECTED: + ESP_LOGI(TAG, "HTTP_EVENT_ON_CONNECTED"); + break; + case HTTP_EVENT_HEADER_SENT: + ESP_LOGI(TAG, "HTTP_EVENT_HEADER_SENT"); + break; + case HTTP_EVENT_ON_HEADER: + ESP_LOGI(TAG, "HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key, evt->header_value); + break; + case HTTP_EVENT_ON_DATA: + /* Nothing to handle here */ + break; + case HTTP_EVENT_ON_FINISH: + ESP_LOGI(TAG, "HTTP_EVENT_ON_FINISH"); + break; + case HTTP_EVENT_DISCONNECTED: + ESP_LOGI(TAG, "HTTP_EVENT_DISCONNECTED"); + break; + case HTTP_EVENT_REDIRECT: + ESP_LOGW(TAG, "HTTP_EVENT_REDIRECT"); + break; + // Other trivial events like HTTP_EVENT_ON_HEADERS_COMPLETE can be handled when needed + default: + ESP_LOGD(TAG, "Unhandled event id: %d", evt->event_id); + break; + } + + return ESP_OK; +} + +static esp_err_t _hosted_ota(const char* image_url) +{ + uint8_t *ota_chunk = NULL; + esp_err_t err = 0; + int data_read = 0; + int ota_failed = 0; + + if (image_url == NULL) { + ESP_LOGE(TAG, "Invalid image URL"); + return ESP_FAIL; + } + + /* Initialize HTTP client configuration */ + esp_http_client_config_t config = { + .url = image_url, + .timeout_ms = 5000, + .event_handler = http_client_event_handler, + }; + + esp_http_client_handle_t client = esp_http_client_init(&config); + + ESP_LOGI(TAG, "http_open"); + if ((err = esp_http_client_open(client, 0)) != ESP_OK) { + ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err)); + ESP_LOGE(TAG, "Check if URL is correct and connectable: %s", image_url); + esp_http_client_cleanup(client); + return ESP_FAIL; + } + + if (http_err) { + ESP_LOGE(TAG, "Exiting OTA, due to http failure"); + esp_http_client_close(client); + esp_http_client_cleanup(client); + http_err = 0; + return ESP_FAIL; + } + + ESP_LOGI(TAG, "http_fetch_headers"); + int64_t content_length = esp_http_client_fetch_headers(client); + if (content_length <= 0) { + ESP_LOGE(TAG, "HTTP client fetch headers failed"); + ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %"PRId64, + esp_http_client_get_status_code(client), + esp_http_client_get_content_length(client)); + esp_http_client_close(client); + esp_http_client_cleanup(client); + return ESP_FAIL; + } + + ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %"PRId64, + esp_http_client_get_status_code(client), + esp_http_client_get_content_length(client)); + + ESP_LOGW(TAG, "********* Started Slave OTA *******************"); + ESP_LOGI(TAG, "*** Please wait for 5 mins to let slave OTA complete ***"); + + ESP_LOGI(TAG, "Preparing OTA"); + if ((err = rpc_ota_begin())) { + ESP_LOGW(TAG, "********* Slave OTA Begin Failed *******************"); + ESP_LOGI(TAG, "esp_ota_begin failed, error=%s", esp_err_to_name(err)); + esp_http_client_close(client); + esp_http_client_cleanup(client); + return ESP_FAIL; + } + + ota_chunk = (uint8_t*)g_h.funcs->_h_calloc(1, CHUNK_SIZE); + if (!ota_chunk) { + ESP_LOGE(TAG, "Failed to allocate otachunk mem\n"); + err = -ENOMEM; + } + + ESP_LOGI(TAG, "Starting OTA"); + + if (!err) { + while ((data_read = esp_http_client_read(client, (char*)ota_chunk, CHUNK_SIZE)) > 0) { + + ESP_LOGV(TAG, "Read image length %d", data_read); + if ((err = rpc_ota_write(ota_chunk, data_read))) { + ESP_LOGI(TAG, "rpc_ota_write failed"); + ota_failed = err; + break; + } + } + } + + g_h.funcs->_h_free(ota_chunk); + if (err) { + ESP_LOGW(TAG, "********* Slave OTA Failed *******************"); + ESP_LOGI(TAG, "esp_ota_write failed, error=%s", esp_err_to_name(err)); + ota_failed = -1; + } + + if (data_read < 0) { + ESP_LOGE(TAG, "Error: SSL data read error"); + ota_failed = -2; + } + + if ((err = rpc_ota_end())) { + ESP_LOGW(TAG, "********* Slave OTA Failed *******************"); + ESP_LOGI(TAG, "esp_ota_end failed, error=%s", esp_err_to_name(err)); + esp_http_client_close(client); + esp_http_client_cleanup(client); + ota_failed = err; + return ESP_FAIL; + } + + esp_http_client_cleanup(client); + if (!ota_failed) { + ESP_LOGW(TAG, "********* Slave OTA Complete *******************"); + ESP_LOGI(TAG, "OTA Successful, Slave will restart in while"); + ESP_LOGE(TAG, "Need to restart host after slave OTA is complete, to avoid sync issues"); + sleep(5); + ESP_LOGE(TAG, "********* Restarting Host **********************"); + esp_restart(); + } + return ota_failed; +} + +static esp_err_t esp_hosted_slave_ota_chunked(const char* image_url) +{ + uint8_t ota_retry = 2; + int ret = 0; + + do { + ret = _hosted_ota(image_url); + + ota_retry--; + if (ota_retry && ret) + ESP_LOGI(TAG, "OTA retry left: %u\n", ota_retry); + } while (ota_retry && ret); + + return ret; +} +#else +/* This assumes full slave binary is present locally */ +static esp_err_t esp_hosted_slave_ota_whole_image(const char* image_path) +{ + FILE* f = NULL; + char ota_chunk[CHUNK_SIZE] = {0}; + int ret = rpc_ota_begin(); + if (ret == ESP_OK) { + f = fopen(image_path,"rb"); + if (f == NULL) { + ESP_LOGE(TAG, "Failed to open file %s", image_path); + return ESP_FAIL; + } else { + ESP_LOGV(TAG, "Success in opening %s file", image_path); + } + while (!feof(f)) { + fread(&ota_chunk, CHUNK_SIZE, 1, f); + ret = rpc_ota_write((uint8_t* )&ota_chunk, CHUNK_SIZE); + if (ret) { + ESP_LOGE(TAG, "OTA procedure failed!!"); + /* TODO: Do we need to do OTA end irrespective of success/failure? */ + rpc_ota_end(); + return ESP_FAIL; + } + } + ret = rpc_ota_end(); + if (ret) { + return ESP_FAIL; + } + } else { + return ESP_FAIL; + } + ESP_LOGE(TAG, "ESP32 will restart after 5 sec"); + return ESP_OK; + ESP_LOGE(TAG, "For OTA, user need to integrate HTTP client lib and then invoke OTA"); + return ESP_FAIL; +} +#endif // ENABLE_HTTP_OTA + +esp_err_t esp_hosted_slave_ota(const char* image_url) +{ +#if OTA_FROM_WEB_URL + return esp_hosted_slave_ota_chunked(image_url); +#else + return esp_hosted_slave_ota_whole_image(image_url); +#endif +} diff --git a/host/port/src/esp_hosted_transport_config.c b/host/port/esp/freertos/src/esp_hosted_transport_config.c similarity index 84% rename from host/port/src/esp_hosted_transport_config.c rename to host/port/esp/freertos/src/esp_hosted_transport_config.c index c9b1f8f5..0c843bc3 100644 --- a/host/port/src/esp_hosted_transport_config.c +++ b/host/port/esp/freertos/src/esp_hosted_transport_config.c @@ -11,7 +11,7 @@ static const char *TAG = "esp_hosted_transport_config"; /* Static configurations */ -static struct esp_hosted_transport_config s_transport_config; +static struct esp_hosted_transport_config s_transport_config = { 0 }; /* Flags to track if configs were set */ static bool esp_hosted_transport_config_set; @@ -48,6 +48,40 @@ esp_hosted_transport_err_t esp_hosted_transport_get_config(struct esp_hosted_tra return ESP_TRANSPORT_OK; } +esp_hosted_transport_err_t esp_hosted_transport_get_reset_config(gpio_pin_t *pin_config) +{ + if (!pin_config) { + return ESP_TRANSPORT_ERR_INVALID_ARG; + } + + switch(s_transport_config.transport_in_use) { + case H_TRANSPORT_SDIO: + pin_config->port = s_transport_config.u.sdio.pin_reset.port; + pin_config->pin = s_transport_config.u.sdio.pin_reset.pin; + break; + case H_TRANSPORT_SPI_HD: + pin_config->port = s_transport_config.u.spi_hd.pin_reset.port; + pin_config->pin = s_transport_config.u.spi_hd.pin_reset.pin; + break; + case H_TRANSPORT_SPI: + pin_config->port = s_transport_config.u.spi.pin_reset.port; + pin_config->pin = s_transport_config.u.spi.pin_reset.pin; + break; + case H_TRANSPORT_UART: + pin_config->port = s_transport_config.u.uart.pin_reset.port; + pin_config->pin = s_transport_config.u.uart.pin_reset.pin; + break; + case H_TRANSPORT_NONE: // drop through to default case + default: + // transport config not yet initialised. Use default Reset pin config + pin_config->port = NULL; + pin_config->pin = H_GPIO_PIN_RESET_Pin; + break; + } + + return ESP_TRANSPORT_OK; +} + #if H_TRANSPORT_IN_USE == H_TRANSPORT_SDIO /* SDIO functions */ esp_hosted_transport_err_t esp_hosted_sdio_get_config(struct esp_hosted_sdio_config **config) diff --git a/host/port/src/os_wrapper.c b/host/port/esp/freertos/src/os_wrapper.c similarity index 97% rename from host/port/src/os_wrapper.c rename to host/port/esp/freertos/src/os_wrapper.c index 009bfd9f..d574a5a0 100644 --- a/host/port/src/os_wrapper.c +++ b/host/port/esp/freertos/src/os_wrapper.c @@ -19,9 +19,11 @@ #include "esp_log.h" #include "driver/gpio.h" #include "esp_event.h" +#include "esp_heap_caps.h" #include "freertos/portmacro.h" #include "esp_macros.h" #include "esp_hosted_config.h" +#include "esp_wifi.h" /* Wi-Fi headers are reused at ESP-Hosted */ #include "esp_wifi_crypto_types.h" @@ -47,7 +49,7 @@ DEFINE_LOG_TAG(os_wrapper_esp); struct mempool * nw_mp_g = NULL; -wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs; +const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs; wifi_osi_funcs_t g_wifi_osi_funcs; //ESP_EVENT_DECLARE_BASE(WIFI_EVENT); @@ -128,18 +130,7 @@ void *hosted_realloc(void *mem, size_t newsize) void *hosted_malloc_align(size_t size, size_t align) { - esp_dma_mem_info_t dma_mem_info = { - .extra_heap_caps = 0, - .dma_alignment_bytes = align, - }; - void *tmp_buf = NULL; - size_t actual_size = 0; - esp_err_t err = ESP_OK; - - err = esp_dma_capable_malloc((size), &dma_mem_info, &tmp_buf, &actual_size); - if (err) tmp_buf = NULL; - - return tmp_buf; + return heap_caps_aligned_alloc(align, size, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA | MALLOC_CAP_8BIT); } void hosted_free_align(void* ptr) @@ -155,7 +146,7 @@ void hosted_init_hook(void) /* -------- Threads ---------- */ -void *hosted_thread_create(char *tname, uint32_t tprio, uint32_t tstack_size, void (*start_routine)(void const *), void *sr_arg) +void *hosted_thread_create(const char *tname, uint32_t tprio, uint32_t tstack_size, void (*start_routine)(void const *), void *sr_arg) { int task_created = RET_OK; @@ -778,6 +769,14 @@ void hosted_log_write(int level, va_end(list); } +int hosted_restart_host(void) +{ + ESP_LOGI(TAG, "Restarting host"); + esp_unregister_shutdown_handler((shutdown_handler_t)esp_wifi_stop); + esp_restart(); + return 0; +} + /* newlib hooks */ hosted_osi_funcs_t g_hosted_osi_funcs = { @@ -851,4 +850,5 @@ hosted_osi_funcs_t g_hosted_osi_funcs = { ._h_uart_read = hosted_uart_read , ._h_uart_write = hosted_uart_write , #endif + ._h_restart_host = hosted_restart_host , }; diff --git a/host/port/src/sdio_wrapper.c b/host/port/esp/freertos/src/sdio_wrapper.c similarity index 89% rename from host/port/src/sdio_wrapper.c rename to host/port/esp/freertos/src/sdio_wrapper.c index a5ff1f81..25fa687d 100644 --- a/host/port/src/sdio_wrapper.c +++ b/host/port/esp/freertos/src/sdio_wrapper.c @@ -22,6 +22,13 @@ #include "esp_hosted_config.h" #include "esp_hosted_transport_config.h" +#if H_SDIO_PWR_CTRL_LDO +#include "sd_pwr_ctrl_by_on_chip_ldo.h" +#endif + +#include "soc/sdmmc_pins.h" +#include "hal/sdmmc_ll.h" + #include "esp_log.h" DEFINE_LOG_TAG(sdio_wrapper); @@ -50,6 +57,42 @@ static sdmmc_context_t context = { 0 }; static void * sdio_bus_lock; +// workarounds for known ESP-IDF SDMMC issues +static void hosted_sdio_workaround(int slot, sdmmc_slot_config_t *slot_config) +{ + if (slot == 0) { +#if !SDMMC_LL_SLOT_SUPPORT_GPIO_MATRIX(0) + /* workaround for 1-bit mode on Slot 0 with IOMUX only pins: + * set gpio pins D2, D3 to pass sdmmc_host.c->sdmmc_host_init_slot() IOMUX GPIO checking + */ + if (slot_config->width == 1) { + ESP_LOGW(TAG, "workaround: setting D2-D3 in 1 bit mode for slot %d", slot); + slot_config->d2 = SDMMC_SLOT0_IOMUX_PIN_NUM_D2; + slot_config->d3 = SDMMC_SLOT0_IOMUX_PIN_NUM_D3; + } +#endif + } +} + +static bool hosted_sdio_enable_ldo(sdmmc_host_t *config) +{ +#if H_SDIO_PWR_CTRL_LDO + // enable LDO Power for slot, if required + sd_pwr_ctrl_ldo_config_t ldo_config = { + .ldo_chan_id = H_SDIO_PWR_CTRL_LDO_ID, + }; + sd_pwr_ctrl_handle_t pwr_ctrl_handle = NULL; + + esp_err_t ret = sd_pwr_ctrl_new_on_chip_ldo(&ldo_config, &pwr_ctrl_handle); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "Failed to create a new on-chip LDO power control driver"); + return false; + } + config->pwr_ctrl_handle = pwr_ctrl_handle; +#endif + return true; +} + static esp_err_t hosted_sdio_print_cis_information(sdmmc_card_t* card) { uint8_t cis_buffer[CIS_BUFFER_SIZE]; @@ -299,6 +342,8 @@ void * hosted_sdio_init(void) slot_config.d3 = context.config.pin_d3.pin; #endif + hosted_sdio_workaround(context.config.slot, &slot_config); + res = sdmmc_host_init_slot(context.config.slot, &slot_config); if (res != ESP_OK) { ESP_LOGE(TAG, "init SDMMC Host slot %d failed", H_SDMMC_HOST_SLOT); @@ -325,13 +370,16 @@ int hosted_sdio_card_init(void *ctx) struct esp_hosted_sdio_config *sdio_config = &context->config; sdmmc_host_t config = SDMMC_HOST_DEFAULT(); + config.slot = sdio_config->slot; // override default slot set + + if (!hosted_sdio_enable_ldo(&config)) { + goto fail; + } - if (sdio_config->bus_width == 4) - config.flags = SDMMC_HOST_FLAG_4BIT; - else - config.flags = SDMMC_HOST_FLAG_1BIT; config.max_freq_khz = sdio_config->clock_freq_khz; - ESP_LOGI(TAG, "SDIO master: Data-Lines: %d-bit Freq(KHz)[%u KHz]", sdio_config->bus_width==4? 4:1, + ESP_LOGI(TAG, "SDIO master: Slot %d, Data-Lines: %d-bit Freq(KHz)[%u KHz]", + config.slot, + sdio_config->bus_width==4? 4:1, config.max_freq_khz); if (sdio_config->bus_width == 4) { ESP_LOGI(TAG, "GPIOs: CLK[%u] CMD[%u] D0[%u] D1[%u] D2[%u] D3[%u] Slave_Reset[%u]", diff --git a/host/port/src/spi_hd_wrapper.c b/host/port/esp/freertos/src/spi_hd_wrapper.c similarity index 100% rename from host/port/src/spi_hd_wrapper.c rename to host/port/esp/freertos/src/spi_hd_wrapper.c diff --git a/host/port/src/spi_wrapper.c b/host/port/esp/freertos/src/spi_wrapper.c similarity index 96% rename from host/port/src/spi_wrapper.c rename to host/port/esp/freertos/src/spi_wrapper.c index 88b8edd3..56cee511 100644 --- a/host/port/src/spi_wrapper.c +++ b/host/port/esp/freertos/src/spi_wrapper.c @@ -51,9 +51,9 @@ void * hosted_spi_init(void) esp_err_t ret; - ESP_LOGI(TAG, "Transport: SPI, Mode:%u Freq:%uMHz TxQ:%u RxQ:%u\n GPIOs: MOSI:%u MISO:%u CLK:%u CS:%u HS:%u DR:%u SlaveReset:%u", + ESP_LOGI(TAG, "Transport: SPI, Mode:%u Freq:%uMHz TxQ:%u RxQ:%u\n GPIOs: CLK:%u MOSI:%u MISO:%u CS:%u HS:%u DR:%u SlaveReset:%u", H_SPI_MODE, H_SPI_INIT_CLK_MHZ, H_SPI_TX_Q, H_SPI_RX_Q, - H_GPIO_MOSI_Pin, H_GPIO_MISO_Pin, H_GPIO_SCLK_Pin, + H_GPIO_SCLK_Pin, H_GPIO_MOSI_Pin, H_GPIO_MISO_Pin, H_GPIO_CS_Pin, H_GPIO_HANDSHAKE_Pin, H_GPIO_DATA_READY_Pin, H_GPIO_PIN_RESET_Pin); diff --git a/host/port/src/uart_wrapper.c b/host/port/esp/freertos/src/uart_wrapper.c similarity index 100% rename from host/port/src/uart_wrapper.c rename to host/port/esp/freertos/src/uart_wrapper.c diff --git a/host/port/include/esp_hosted_wifi_config.h b/host/port/include/esp_hosted_wifi_config.h deleted file mode 100644 index b1e75d9f..00000000 --- a/host/port/include/esp_hosted_wifi_config.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef __ESP_HOSTED_WIFI_CONFIG_H__ -#define __ESP_HOSTED_WIFI_CONFIG_H__ - -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) -// dual band API support available -#define H_WIFI_DUALBAND_SUPPORT 1 -#else -#define H_WIFI_DUALBAND_SUPPORT 0 -#endif - -#endif diff --git a/host/utils/stats.c b/host/utils/stats.c index 88544042..35cd61c8 100644 --- a/host/utils/stats.c +++ b/host/utils/stats.c @@ -23,6 +23,7 @@ #include "transport_drv.h" #endif #include "esp_log.h" +#include "esp_hosted_transport_init.h" // use mempool and zero copy for Tx #include "mempool.h" @@ -208,10 +209,17 @@ struct mem_stats h_stats_g; #if ESP_PKT_STATS void stats_timer_func(void * arg) { - ESP_LOGI(TAG, "slave: sta_rx_in: %lu sta_rx_out: %lu sta_tx_in [pass: %lu drop: %lu] sta_tx_out: %lu ", + ESP_LOGI(TAG, "slave: sta_rx_in: %lu sta_rx_out: %lu sta_tx_in [pass: %lu drop: %lu] sta_tx_out: %lu, throttling %u", pkt_stats.sta_rx_in,pkt_stats.sta_rx_out, - pkt_stats.sta_tx_in_pass, pkt_stats.sta_tx_in_drop, pkt_stats.sta_tx_out); - ESP_LOGI(TAG, "wifi_tx_throttling %u", wifi_tx_throttling); + pkt_stats.sta_tx_in_pass, pkt_stats.sta_tx_in_drop, pkt_stats.sta_tx_out, + wifi_tx_throttling); + ESP_LOGI(TAG, "internal: free %d l-free %d min-free %d, psram: free %d l-free %d min-free %d", + heap_caps_get_free_size(MALLOC_CAP_8BIT) - heap_caps_get_free_size(MALLOC_CAP_SPIRAM), + heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL), + heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL), + heap_caps_get_free_size(MALLOC_CAP_SPIRAM), + heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM), + heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM)); } #endif diff --git a/idf_component.yml b/idf_component.yml index 1076fe38..110e48c7 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -1,4 +1,4 @@ -version: "1.3.2" +version: "2.0.14" description: ESP-Hosted-MCU provide drivers to act any ESP chipset as Wi-Fi or Bluetooth co-processor. url: https://github.com/espressif/esp-hosted-mcu examples: diff --git a/slave/main/Kconfig.projbuild b/slave/main/Kconfig.projbuild index e0a42add..4025af24 100644 --- a/slave/main/Kconfig.projbuild +++ b/slave/main/Kconfig.projbuild @@ -12,19 +12,13 @@ menu "Example Configuration" config ESP_HOST_DEV_BOARD_P4_FUNC_BOARD bool "ESP32-P4-Function-EV-Board" - depends on IDF_TARGET_ESP32C6 endchoice choice ESP_HOST_INTERFACE bool "Transport layer" - default ESP_SPI_HOST_INTERFACE if IDF_TARGET_ESP32 - default ESP_SPI_HOST_INTERFACE if IDF_TARGET_ESP32S2 - default ESP_SPI_HOST_INTERFACE if IDF_TARGET_ESP32S3 - default ESP_SPI_HOST_INTERFACE if IDF_TARGET_ESP32C2 - default ESP_SPI_HOST_INTERFACE if IDF_TARGET_ESP32C3 - default ESP_SDIO_HOST_INTERFACE if IDF_TARGET_ESP32C6 - default ESP_SPI_HOST_INTERFACE if IDF_TARGET_ESP32C5 + default ESP_SDIO_HOST_INTERFACE if SOC_SDIO_SLAVE_SUPPORTED + default ESP_SPI_HOST_INTERFACE help Bus interface to be used for communication with the host @@ -35,7 +29,7 @@ menu "Example Configuration" config ESP_SDIO_HOST_INTERFACE bool "SDIO" - depends on IDF_TARGET_ESP32 || IDF_TARGET_ESP32C6 + depends on SOC_SDIO_SLAVE_SUPPORTED help Enable/Disable SDIO host interface @@ -129,6 +123,7 @@ menu "Example Configuration" depends on SPI_HSPI int "Slave GPIO pin for Host CLK" default 19 if ESP_HOST_DEV_BOARD_P4_FUNC_BOARD + default 3 if IDF_TARGET_ESP32C5 default 14 if IDF_TARGET_ESP32 default 12 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 default 6 @@ -196,6 +191,7 @@ menu "Example Configuration" config ESP_SPI_GPIO_HANDSHAKE int "Slave GPIO pin for handshake" default 22 if ESP_HOST_DEV_BOARD_P4_FUNC_BOARD + default 4 if IDF_TARGET_ESP32C5 default 3 if IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C6 default 17 if IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32S2 default 26 @@ -205,6 +201,7 @@ menu "Example Configuration" config ESP_SPI_GPIO_DATA_READY int "Slave GPIO pin for data ready interrupt" default 23 if ESP_HOST_DEV_BOARD_P4_FUNC_BOARD + default 0 if IDF_TARGET_ESP32C5 default 13 if IDF_TARGET_ESP32C5 default 4 help @@ -217,6 +214,16 @@ menu "Example Configuration" Host uses this pin to reset the slave ESP. To re-use ESP 'RST' or 'EN' GPIO, set value to -1 endmenu + config ESP_SPI_DEASSERT_HS_ON_CS + bool "Deassert Handshake when SPI CS is deasserted" + default y + help + Deassert Handshake and prepare a new SPI transaction only after + CS has been deasserted. This helps prevent data loss with MCUs + that delay deasserting CS after the end of a SPI transaction + by prematurely starting a new slave SPI transaction + since CS is detected by the slave as still asserted. + config ESP_SPI_TX_Q_SIZE int "ESP to Host SPI queue size" default 10 if IDF_TARGET_ESP32 @@ -273,12 +280,13 @@ menu "Example Configuration" bool "High Speed (40 MHz)" endchoice - + # from /components/soc//include/soc/sdio_slave_pins.h menu "Hosted SDIO GPIOs" config ESP_SDIO_PIN_CMD int "CMD GPIO number" range 15 15 if IDF_TARGET_ESP32 range 18 18 if IDF_TARGET_ESP32C6 + range 10 10 if IDF_TARGET_ESP32C5 help "Value cannot be configured. Displayed for reference." @@ -286,6 +294,7 @@ menu "Example Configuration" int "CLK GPIO number" range 14 14 if IDF_TARGET_ESP32 range 19 19 if IDF_TARGET_ESP32C6 + range 9 9 if IDF_TARGET_ESP32C5 help "Value cannot be configured. Displayed for reference." @@ -293,6 +302,7 @@ menu "Example Configuration" int "D0 GPIO number" range 2 2 if IDF_TARGET_ESP32 range 20 20 if IDF_TARGET_ESP32C6 + range 8 8 if IDF_TARGET_ESP32C5 help "Value cannot be configured. Displayed for reference." @@ -300,6 +310,7 @@ menu "Example Configuration" int "D1 GPIO number" range 4 4 if IDF_TARGET_ESP32 range 21 21 if IDF_TARGET_ESP32C6 + range 7 7 if IDF_TARGET_ESP32C5 help "Value cannot be configured. Displayed for reference." @@ -307,6 +318,7 @@ menu "Example Configuration" int "D2 GPIO number" range 12 12 if IDF_TARGET_ESP32 range 22 22 if IDF_TARGET_ESP32C6 + range 14 14 if IDF_TARGET_ESP32C5 help "Value cannot be configured. Displayed for reference." @@ -314,6 +326,7 @@ menu "Example Configuration" int "D3 GPIO number" range 13 13 if IDF_TARGET_ESP32 range 23 23 if IDF_TARGET_ESP32C6 + range 13 13 if IDF_TARGET_ESP32C5 help "Value cannot be configured. Displayed for reference." endmenu @@ -341,6 +354,12 @@ menu "Example Configuration" bool "Send at negative edge, sample at negative edge" endchoice + config ESP_SDIO_TX_Q_SIZE + int "SDIO TX queue size" + default 20 + help + Very small TX queue will lower ESP --> SDIO -- Host data rate + config ESP_SDIO_RX_Q_SIZE int "SDIO RX queue size" default 20 @@ -414,6 +433,7 @@ menu "Example Configuration" config ESP_SPI_HD_GPIO_CLK int "Slave GPIO pin for Host CLK" default 19 if ESP_HOST_DEV_BOARD_P4_FUNC_BOARD + default 3 if IDF_TARGET_ESP32C5 default 6 help SPI HD controller Host CS @@ -451,7 +471,7 @@ menu "Example Configuration" config ESP_SPI_HD_GPIO_DATA_READY int "Slave GPIO pin for Data Ready" default 2 if ESP_HOST_DEV_BOARD_P4_FUNC_BOARD - default 13 if IDF_TARGET_ESP32C5 + default 0 if IDF_TARGET_ESP32C5 default 11 help Slave GPIO pin for indicating host that SPI slave has data to be read by host diff --git a/slave/main/interface.h b/slave/main/interface.h index dc1d4cef..09711247 100644 --- a/slave/main/interface.h +++ b/slave/main/interface.h @@ -22,7 +22,7 @@ #ifdef CONFIG_ESP_SDIO_HOST_INTERFACE -#if defined(CONFIG_IDF_TARGET_ESP32)||defined(CONFIG_IDF_TARGET_ESP32C6) +#if CONFIG_SOC_SDIO_SLAVE_SUPPORTED #include "driver/sdio_slave.h" #else #error "SDIO is not supported for this chipset" diff --git a/slave/main/mempool.c b/slave/main/mempool.c index 5ed61662..098f2723 100644 --- a/slave/main/mempool.c +++ b/slave/main/mempool.c @@ -33,7 +33,7 @@ struct hosted_mempool * hosted_mempool_create(void *pre_allocated_mem, if (!pre_allocated_mem) { /* no pre-allocated mem, allocate new */ - heap = (uint8_t *)CALLOC(1, MEMPOOL_ALIGNED(OS_MEMPOOL_BYTES( + heap = (uint8_t *)MEM_ALLOC(MEMPOOL_ALIGNED(OS_MEMPOOL_BYTES( num_blocks,block_size))); if (!heap) { ESP_LOGE(TAG, "mempool create failed, no mem\n"); diff --git a/slave/main/sdio_slave_api.c b/slave/main/sdio_slave_api.c index 3207d915..40ccbe0a 100644 --- a/slave/main/sdio_slave_api.c +++ b/slave/main/sdio_slave_api.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 -// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD +// Copyright 2015-2025 Espressif Systems (Shanghai) PTE LTD // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -32,10 +32,10 @@ #include "esp_hosted_transport_init.h" //#define SIMPLIFIED_SDIO_SLAVE 1 -#define SDIO_SLAVE_QUEUE_SIZE 20 -#define BUFFER_SIZE MAX_TRANSPORT_BUF_SIZE -#define BUFFER_NUM 20 -static uint8_t sdio_slave_rx_buffer[BUFFER_NUM][BUFFER_SIZE]; +#define SDIO_SLAVE_QUEUE_SIZE CONFIG_ESP_SDIO_TX_Q_SIZE +#define NUM_RX_BUFFERS CONFIG_ESP_SDIO_RX_Q_SIZE +#define BUFFER_SIZE MAX_TRANSPORT_BUF_SIZE +static uint8_t sdio_slave_rx_buffer[NUM_RX_BUFFERS][BUFFER_SIZE]; #define SDIO_MEMPOOL_NUM_BLOCKS 40 static struct hosted_mempool * buf_mp_tx_g; @@ -44,7 +44,7 @@ interface_context_t context; interface_handle_t if_handle_g; static const char TAG[] = "SDIO_SLAVE"; -#define SDIO_RX_QUEUE_SIZE CONFIG_ESP_SDIO_RX_Q_SIZE +#define SDIO_TX_QUEUE_SIZE CONFIG_ESP_SDIO_TX_Q_SIZE #if !SIMPLIFIED_SDIO_SLAVE static SemaphoreHandle_t sdio_rx_sem; @@ -135,7 +135,7 @@ static void start_rx_data_throttling_if_needed(void) pkt_stats.slave_wifi_rx_msg_loaded = queue_load; #endif - load_percent = (queue_load*100/SDIO_RX_QUEUE_SIZE); + load_percent = (queue_load*100/NUM_RX_BUFFERS); if (load_percent > slv_cfg_g.throttle_high_threshold) { slv_state_g.current_throttling = 1; ESP_LOGV(TAG, "start data throttling at host"); @@ -156,7 +156,7 @@ static void stop_rx_data_throttling_if_needed(void) pkt_stats.slave_wifi_rx_msg_loaded = queue_load; #endif - load_percent = (queue_load*100/SDIO_RX_QUEUE_SIZE); + load_percent = (queue_load*100/NUM_RX_BUFFERS); if (load_percent < slv_cfg_g.throttle_low_threshold) { slv_state_g.current_throttling = 0; ESP_LOGV(TAG, "stop data throttling at host"); @@ -244,9 +244,13 @@ void generate_startup_event(uint8_t cap, uint32_t ext_cap) *pos = LENGTH_1_BYTE; pos++;len++; *pos = raw_tp_cap; pos++;len++; + *pos = ESP_PRIV_TX_Q_SIZE; pos++;len++; + *pos = LENGTH_1_BYTE; pos++;len++; + *pos = SDIO_TX_QUEUE_SIZE; pos++;len++; + *pos = ESP_PRIV_RX_Q_SIZE; pos++;len++; *pos = LENGTH_1_BYTE; pos++;len++; - *pos = SDIO_RX_QUEUE_SIZE; pos++;len++; + *pos = NUM_RX_BUFFERS; pos++;len++; /* TLVs end */ event->event_len = len; @@ -316,7 +320,7 @@ static interface_handle_t * sdio_init(void) #else #error Invalid SDIO bus speed selection #endif - .timing = SDIO_SLAVE_TIMING, + .timing = SDIO_SLAVE_TIMING, }; #if CONFIG_ESP_SDIO_STREAMING_MODE @@ -325,20 +329,20 @@ static interface_handle_t * sdio_init(void) ESP_LOGI(TAG, "%s: sending mode: SDIO_SLAVE_SEND_PACKET", __func__); #endif #if defined(CONFIG_IDF_TARGET_ESP32C6) - ESP_LOGI(TAG, "%s: ESP32-C6 SDIO RxQ[%d] timing[%u]\n", __func__, SDIO_RX_QUEUE_SIZE, config.timing); + ESP_LOGI(TAG, "%s: ESP32-C6 SDIO TxQ[%d] timing[%u]\n", __func__, SDIO_TX_QUEUE_SIZE, config.timing); #else - ESP_LOGI(TAG, "%s: ESP32 SDIO RxQ[%d] timing[%u]\n", __func__, SDIO_RX_QUEUE_SIZE, config.timing); + ESP_LOGI(TAG, "%s: ESP32 SDIO TxQ[%d] timing[%u]\n", __func__, SDIO_TX_QUEUE_SIZE, config.timing); #endif #if !SIMPLIFIED_SDIO_SLAVE sdio_send_queue_sem = xSemaphoreCreateCounting(SDIO_SLAVE_QUEUE_SIZE, SDIO_SLAVE_QUEUE_SIZE); assert(sdio_send_queue_sem); - sdio_rx_sem = xSemaphoreCreateCounting(SDIO_RX_QUEUE_SIZE*3, 0); + sdio_rx_sem = xSemaphoreCreateCounting(NUM_RX_BUFFERS * MAX_PRIORITY_QUEUES, 0); assert(sdio_rx_sem != NULL); for (prio_q_idx=0; prio_q_idx + #include "freertos/FreeRTOS.h" #include "freertos/event_groups.h" #include "esp_log.h" @@ -24,6 +25,12 @@ #include "esp_hosted_rpc.h" #include "esp_hosted_transport.h" #include "esp_hosted_bitmasks.h" +#include "slave_wifi_config.h" + +/* Slave-side: Always support reserved field decoding for maximum compatibility + * The host may or may not have CONFIG_ESP_HOSTED_DECODE_WIFI_RESERVED_FIELD enabled + */ +#define H_DECODE_WIFI_RESERVED_FIELD 1 #include "coprocessor_fw_version.h" @@ -732,6 +739,103 @@ static void event_handler(void* arg, esp_event_base_t event_base, } } +// macros to format output +#define PRINT_HEADER() ESP_LOGI(TAG, " Wifi Init Param | Default | Host | Actual"); +#define PRINT_FOOTER() ESP_LOGI(TAG, " End Wifi Init Param |"); +#define PRINT_USE_HOST_VALUE(param_str, default, host, final) \ + ESP_LOGD(TAG, "% 20s | % 7d | % 7d | % 7d", param_str, default, host, final); +#define PRINT_USE_DEFAULT_VALUE(param_str, default, host, final) \ + ESP_LOGW(TAG, "% 20s | % 7d | % 7d | % 7d", param_str, default, host, final); +#define PRINT_HEX64_USE_HOST_VALUE(param_str, default, host, final) \ + ESP_LOGD(TAG, "% 20s | 0x% 5"PRIx32" | 0x% 5"PRIx64" | 0x% 5"PRIx64, param_str, default, host, final); +#define PRINT_HEX64_USE_DEFAULT_VALUE(param_str, default, host, final) \ + ESP_LOGW(TAG, "% 20s | % 7"PRIx32" | % 7"PRIx64" | % 7"PRIx64, param_str, default, host, final); + +// macros to copy host or default value +#define USE_HOST_VALUE(PARAM_STR, DEFAULT, PARAM) \ + do { \ + dst_config->PARAM = src_config->PARAM; \ + PRINT_USE_HOST_VALUE(PARAM_STR, \ + DEFAULT, \ + src_config->PARAM, \ + dst_config->PARAM); \ + } while(0); + +#define USE_DEFAULT_VALUE(PARAM_STR, DEFAULT, PARAM) \ + do { \ + dst_config->PARAM = DEFAULT; \ + PRINT_USE_DEFAULT_VALUE(PARAM_STR, \ + DEFAULT, \ + src_config->PARAM, \ + dst_config->PARAM); \ + } while(0); + +/** Returns the merged wifi init config + * Compares the src config from the host with our Wi-Fi defaults + * and adjust dst_config as necessary. + * + * Also displays the changed configs. + */ +static wifi_init_config_t * get_merged_init_config(wifi_init_config_t *dst_config, WifiInitConfig *src_config) +{ + /* always use value from host, except for + * - cache_tx_buf_num + * - feature_caps + */ + PRINT_HEADER(); + USE_HOST_VALUE("static_rx_buf", CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM, static_rx_buf_num); + USE_HOST_VALUE("dynamic_rx_buf", CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM, dynamic_rx_buf_num); + USE_HOST_VALUE("tx_buf_type", CONFIG_ESP_WIFI_TX_BUFFER_TYPE, tx_buf_type); + USE_HOST_VALUE("static_tx_buf", WIFI_STATIC_TX_BUFFER_NUM, static_tx_buf_num); + USE_HOST_VALUE("dynamic_tx_buf", WIFI_DYNAMIC_TX_BUFFER_NUM, dynamic_tx_buf_num); + USE_HOST_VALUE("rx_mgmt_buf_type", CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUF, rx_mgmt_buf_type); + USE_HOST_VALUE("rx_mgmt_buf", WIFI_RX_MGMT_BUF_NUM_DEF, rx_mgmt_buf_num); + + if (WIFI_ENABLE_CACHE_TX_BUFFER) { + // use setting from host + USE_HOST_VALUE("cache_tx_buf", WIFI_CACHE_TX_BUFFER_NUM, cache_tx_buf_num); + dst_config->feature_caps = src_config->feature_caps; + PRINT_HEX64_USE_HOST_VALUE("feature_caps", WIFI_FEATURE_CAPS, + src_config->feature_caps, + dst_config->feature_caps); + } else { + if (WIFI_FEATURE_CAPS != src_config->feature_caps) { + // don't use host setting, which may have enabled CACHE_TX_BUFFER + USE_DEFAULT_VALUE("cache_tx_buf", WIFI_CACHE_TX_BUFFER_NUM, cache_tx_buf_num); + dst_config->feature_caps = WIFI_FEATURE_CAPS; + PRINT_HEX64_USE_DEFAULT_VALUE("feature_caps", WIFI_FEATURE_CAPS, + src_config->feature_caps, + dst_config->feature_caps); + } else { + USE_HOST_VALUE("cache_tx_buf", WIFI_CACHE_TX_BUFFER_NUM, cache_tx_buf_num); + dst_config->feature_caps = src_config->feature_caps; + PRINT_HEX64_USE_HOST_VALUE("feature_caps", WIFI_FEATURE_CAPS, + src_config->feature_caps, + dst_config->feature_caps); + } + } + + USE_HOST_VALUE("csi_enable", WIFI_CSI_ENABLED, csi_enable); + USE_HOST_VALUE("ampdu_rx_enable", WIFI_AMPDU_RX_ENABLED, ampdu_rx_enable); + USE_HOST_VALUE("ampdu_tx_enable", WIFI_AMPDU_TX_ENABLED, ampdu_tx_enable); + USE_HOST_VALUE("amsdu_tx_enable", WIFI_AMSDU_TX_ENABLED, amsdu_tx_enable); + USE_HOST_VALUE("nvs_enable", WIFI_NVS_ENABLED, nvs_enable); + USE_HOST_VALUE("nano_enable", WIFI_NANO_FORMAT_ENABLED, nano_enable); + USE_HOST_VALUE("rx_ba_win", WIFI_DEFAULT_RX_BA_WIN, rx_ba_win); + USE_HOST_VALUE("wifi_task_core", WIFI_TASK_CORE_ID, wifi_task_core_id); + USE_HOST_VALUE("beacon_max_len", WIFI_SOFTAP_BEACON_MAX_LEN, beacon_max_len); + USE_HOST_VALUE("mgmt_sbuf_num", WIFI_MGMT_SBUF_NUM, mgmt_sbuf_num); + USE_HOST_VALUE("sta_disconnected_pm", WIFI_STA_DISCONNECTED_PM_ENABLED, sta_disconnected_pm); + USE_HOST_VALUE("espnow_max_encrypt",CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM, espnow_max_encrypt_num); + USE_HOST_VALUE("tx_hetb_queue", WIFI_TX_HETB_QUEUE_NUM, tx_hetb_queue_num); + USE_HOST_VALUE("dump_hesigb_enable", WIFI_DUMP_HESIGB_ENABLED, dump_hesigb_enable); + PRINT_FOOTER(); + + dst_config->magic = src_config->magic; + + return dst_config; +} + static esp_err_t req_wifi_init(Rpc *req, Rpc *resp, void *priv_data) { wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); @@ -741,28 +845,7 @@ static esp_err_t req_wifi_init(Rpc *req, Rpc *resp, void *priv_data) rpc__resp__wifi_init__init); RPC_RET_FAIL_IF(!req_payload->cfg); - cfg.static_rx_buf_num = req_payload->cfg->static_rx_buf_num ; - cfg.dynamic_rx_buf_num = req_payload->cfg->dynamic_rx_buf_num ; - cfg.tx_buf_type = req_payload->cfg->tx_buf_type ; - cfg.static_tx_buf_num = req_payload->cfg->static_tx_buf_num ; - cfg.dynamic_tx_buf_num = req_payload->cfg->dynamic_tx_buf_num ; - cfg.cache_tx_buf_num = req_payload->cfg->cache_tx_buf_num ; - cfg.csi_enable = req_payload->cfg->csi_enable ; - cfg.ampdu_rx_enable = req_payload->cfg->ampdu_rx_enable ; - cfg.ampdu_tx_enable = req_payload->cfg->ampdu_tx_enable ; - cfg.amsdu_tx_enable = req_payload->cfg->amsdu_tx_enable ; - cfg.nvs_enable = req_payload->cfg->nvs_enable ; - cfg.nano_enable = req_payload->cfg->nano_enable ; - cfg.rx_ba_win = req_payload->cfg->rx_ba_win ; - cfg.wifi_task_core_id = req_payload->cfg->wifi_task_core_id ; - cfg.beacon_max_len = req_payload->cfg->beacon_max_len ; - cfg.mgmt_sbuf_num = req_payload->cfg->mgmt_sbuf_num ; - cfg.feature_caps = req_payload->cfg->feature_caps ; - cfg.sta_disconnected_pm = req_payload->cfg->sta_disconnected_pm ; - cfg.espnow_max_encrypt_num = req_payload->cfg->espnow_max_encrypt_num ; - cfg.magic = req_payload->cfg->magic ; - - RPC_RET_FAIL_IF(esp_wifi_init(&cfg)); + RPC_RET_FAIL_IF(esp_wifi_init(get_merged_init_config(&cfg, req_payload->cfg))); ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, @@ -861,35 +944,62 @@ static esp_err_t req_wifi_set_config(Rpc *req, Rpc *resp, void *priv_data) p_a_sta->channel = p_c_sta->channel; p_a_sta->listen_interval = p_c_sta->listen_interval; p_a_sta->sort_method = p_c_sta->sort_method; - p_a_sta->threshold.rssi = p_c_sta->threshold->rssi; - p_a_sta->threshold.authmode = p_c_sta->threshold->authmode; + if (p_c_sta->threshold) { + p_a_sta->threshold.rssi = p_c_sta->threshold->rssi; + p_a_sta->threshold.authmode = p_c_sta->threshold->authmode; +#if H_PRESENT_IN_ESP_IDF_5_4_0 + p_a_sta->threshold.rssi_5g_adjustment = p_c_sta->threshold->rssi_5g_adjustment; +#endif + } //p_a_sta->ssid_hidden = p_c_sta->ssid_hidden; //p_a_sta->max_connections = p_c_sta->max_connections; - p_a_sta->pmf_cfg.capable = p_c_sta->pmf_cfg->capable; - p_a_sta->pmf_cfg.required = p_c_sta->pmf_cfg->required; - - p_a_sta->rm_enabled = H_GET_BIT(STA_RM_ENABLED_BIT, p_c_sta->bitmask); - p_a_sta->btm_enabled = H_GET_BIT(STA_BTM_ENABLED_BIT, p_c_sta->bitmask); - p_a_sta->mbo_enabled = H_GET_BIT(STA_MBO_ENABLED_BIT, p_c_sta->bitmask); - p_a_sta->ft_enabled = H_GET_BIT(STA_FT_ENABLED_BIT, p_c_sta->bitmask); - p_a_sta->owe_enabled = H_GET_BIT(STA_OWE_ENABLED_BIT, p_c_sta->bitmask); - p_a_sta->transition_disable = H_GET_BIT(STA_TRASITION_DISABLED_BIT, p_c_sta->bitmask); - p_a_sta->reserved = WIFI_CONFIG_STA_GET_RESERVED_VAL(p_c_sta->bitmask); + if (p_c_sta->pmf_cfg) { + p_a_sta->pmf_cfg.capable = p_c_sta->pmf_cfg->capable; + p_a_sta->pmf_cfg.required = p_c_sta->pmf_cfg->required; + } + p_a_sta->rm_enabled = H_GET_BIT(WIFI_STA_CONFIG_1_rm_enabled, p_c_sta->bitmask); + p_a_sta->btm_enabled = H_GET_BIT(WIFI_STA_CONFIG_1_btm_enabled, p_c_sta->bitmask); + p_a_sta->mbo_enabled = H_GET_BIT(WIFI_STA_CONFIG_1_mbo_enabled, p_c_sta->bitmask); + p_a_sta->ft_enabled = H_GET_BIT(WIFI_STA_CONFIG_1_ft_enabled, p_c_sta->bitmask); + p_a_sta->owe_enabled = H_GET_BIT(WIFI_STA_CONFIG_1_owe_enabled, p_c_sta->bitmask); + p_a_sta->transition_disable = H_GET_BIT(WIFI_STA_CONFIG_1_transition_disable, p_c_sta->bitmask); +#if H_DECODE_WIFI_RESERVED_FIELD +#if H_WIFI_NEW_RESERVED_FIELD_NAMES + p_a_sta->reserved1 = WIFI_STA_CONFIG_1_GET_RESERVED_VAL(p_c_sta->bitmask); +#else + p_a_sta->reserved = WIFI_STA_CONFIG_1_GET_RESERVED_VAL(p_c_sta->bitmask); +#endif +#endif p_a_sta->sae_pwe_h2e = p_c_sta->sae_pwe_h2e; + p_a_sta->sae_pk_mode = p_c_sta->sae_pk_mode; p_a_sta->failure_retry_cnt = p_c_sta->failure_retry_cnt; - p_a_sta->he_dcm_set = H_GET_BIT(WIFI_HE_STA_CONFIG_he_dcm_set_BIT, p_c_sta->he_bitmask); - // WIFI_HE_STA_CONFIG_he_dcm_max_constellation_tx is two bits wide - p_a_sta->he_dcm_max_constellation_tx = (p_c_sta->he_bitmask >> WIFI_HE_STA_CONFIG_he_dcm_max_constellation_tx_BITS) & 0x03; - // WIFI_HE_STA_CONFIG_he_dcm_max_constellation_rx is two bits wide - p_a_sta->he_dcm_max_constellation_rx = (p_c_sta->he_bitmask >> WIFI_HE_STA_CONFIG_he_dcm_max_constellation_rx_BITS) & 0x03; - p_a_sta->he_mcs9_enabled = H_GET_BIT(WIFI_HE_STA_CONFIG_he_mcs9_enabled_BIT, p_c_sta->he_bitmask); - p_a_sta->he_su_beamformee_disabled = H_GET_BIT(WIFI_HE_STA_CONFIG_he_su_beamformee_disabled_BIT, p_c_sta->he_bitmask); - p_a_sta->he_trig_su_bmforming_feedback_disabled = H_GET_BIT(WIFI_HE_STA_CONFIG_he_trig_su_bmforming_feedback_disabled_BIT, p_c_sta->bitmask); - p_a_sta->he_trig_mu_bmforming_partial_feedback_disabled = H_GET_BIT(WIFI_HE_STA_CONFIG_he_trig_mu_bmforming_partial_feedback_disabled_BIT, p_c_sta->bitmask); - p_a_sta->he_trig_cqi_feedback_disabled = H_GET_BIT(WIFI_HE_STA_CONFIG_he_trig_cqi_feedback_disabled_BIT, p_c_sta->bitmask); - p_a_sta->he_reserved = WIFI_HE_STA_GET_RESERVED_VAL(p_c_sta->bitmask); + p_a_sta->he_dcm_set = H_GET_BIT(WIFI_STA_CONFIG_2_he_dcm_set_BIT, p_c_sta->he_bitmask); + /* WIFI_STA_CONFIG_2_he_dcm_max_constellation_tx is two bits wide */ + p_a_sta->he_dcm_max_constellation_tx = (p_c_sta->he_bitmask >> WIFI_STA_CONFIG_2_he_dcm_max_constellation_tx_BITS) & 0x03; + /* WIFI_STA_CONFIG_2_he_dcm_max_constellation_rx is two bits wide */ + p_a_sta->he_dcm_max_constellation_rx = (p_c_sta->he_bitmask >> WIFI_STA_CONFIG_2_he_dcm_max_constellation_rx_BITS) & 0x03; + + p_a_sta->he_mcs9_enabled = H_GET_BIT(WIFI_STA_CONFIG_2_he_mcs9_enabled_BIT, p_c_sta->he_bitmask); + p_a_sta->he_su_beamformee_disabled = H_GET_BIT(WIFI_STA_CONFIG_2_he_su_beamformee_disabled_BIT, p_c_sta->he_bitmask); + p_a_sta->he_trig_su_bmforming_feedback_disabled = H_GET_BIT(WIFI_STA_CONFIG_2_he_trig_su_bmforming_feedback_disabled_BIT, p_c_sta->he_bitmask); + p_a_sta->he_trig_mu_bmforming_partial_feedback_disabled = H_GET_BIT(WIFI_STA_CONFIG_2_he_trig_mu_bmforming_partial_feedback_disabled_BIT, p_c_sta->he_bitmask); + p_a_sta->he_trig_cqi_feedback_disabled = H_GET_BIT(WIFI_STA_CONFIG_2_he_trig_cqi_feedback_disabled_BIT, p_c_sta->he_bitmask); + +#if H_PRESENT_IN_ESP_IDF_5_5_0 + p_a_sta->vht_su_beamformee_disabled = H_GET_BIT(WIFI_STA_CONFIG_2_vht_su_beamformee_disabled, p_c_sta->he_bitmask); + p_a_sta->vht_mu_beamformee_disabled = H_GET_BIT(WIFI_STA_CONFIG_2_vht_mu_beamformee_disabled, p_c_sta->he_bitmask); + p_a_sta->vht_mcs8_enabled = H_GET_BIT(WIFI_STA_CONFIG_2_vht_mcs8_enabled, p_c_sta->he_bitmask); +#endif + +#if H_DECODE_WIFI_RESERVED_FIELD +#if H_WIFI_NEW_RESERVED_FIELD_NAMES + p_a_sta->reserved2 = WIFI_STA_CONFIG_2_GET_RESERVED_VAL(p_c_sta->he_bitmask); +#else + p_a_sta->he_reserved = WIFI_STA_CONFIG_2_GET_RESERVED_VAL(p_c_sta->he_bitmask); +#endif +#endif /* Avoid using fast scan, which leads to faster SSID selection, * but faces data throughput issues when same SSID broadcasted by weaker AP @@ -911,11 +1021,26 @@ static esp_err_t req_wifi_set_config(Rpc *req, Rpc *resp, void *priv_data) p_a_ap->ssid_hidden = p_c_ap->ssid_hidden; p_a_ap->max_connection = p_c_ap->max_connection; p_a_ap->beacon_interval = p_c_ap->beacon_interval; + p_a_ap->csa_count = p_c_ap->csa_count; + p_a_ap->dtim_period = p_c_ap->dtim_period; p_a_ap->pairwise_cipher = p_c_ap->pairwise_cipher; p_a_ap->ftm_responder = p_c_ap->ftm_responder; - p_a_ap->pmf_cfg.capable = p_c_ap->pmf_cfg->capable; - p_a_ap->pmf_cfg.required = p_c_ap->pmf_cfg->required; + if (p_c_ap->pmf_cfg) { + p_a_ap->pmf_cfg.capable = p_c_ap->pmf_cfg->capable; + p_a_ap->pmf_cfg.required = p_c_ap->pmf_cfg->required; + } p_a_ap->sae_pwe_h2e = p_c_ap->sae_pwe_h2e; +#if H_GOT_AP_CONFIG_PARAM_TRANSITION_DISABLE + p_a_ap->transition_disable = p_c_ap->transition_disable; +#endif +#if H_PRESENT_IN_ESP_IDF_5_5_0 + p_a_ap->sae_ext = p_c_ap->sae_ext; + if (p_c_ap->bss_max_idle_cfg) { + p_a_ap->bss_max_idle_cfg.period = p_c_ap->bss_max_idle_cfg->period; + p_a_ap->bss_max_idle_cfg.protected_keep_alive = p_c_ap->bss_max_idle_cfg->protected_keep_alive; + } + p_a_ap->gtk_rekey_interval = p_c_ap->gtk_rekey_interval; +#endif } RPC_RET_FAIL_IF(esp_wifi_set_config(req_payload->iface, &cfg)); @@ -962,32 +1087,90 @@ static esp_err_t req_wifi_get_config(Rpc *req, Rpc *resp, void *priv_data) RPC_ALLOC_ELEMENT(WifiScanThreshold, p_c_sta->threshold, wifi_scan_threshold__init); p_c_sta->threshold->rssi = p_a_sta->threshold.rssi; p_c_sta->threshold->authmode = p_a_sta->threshold.authmode; +#if H_PRESENT_IN_ESP_IDF_5_4_0 + p_c_sta->threshold->rssi_5g_adjustment = p_a_sta->threshold.rssi_5g_adjustment; +#endif RPC_ALLOC_ELEMENT(WifiPmfConfig, p_c_sta->pmf_cfg, wifi_pmf_config__init); p_c_sta->pmf_cfg->capable = p_a_sta->pmf_cfg.capable; p_c_sta->pmf_cfg->required = p_a_sta->pmf_cfg.required; if (p_a_sta->rm_enabled) - H_SET_BIT(STA_RM_ENABLED_BIT, p_c_sta->bitmask); + H_SET_BIT(WIFI_STA_CONFIG_1_rm_enabled, p_c_sta->bitmask); if (p_a_sta->btm_enabled) - H_SET_BIT(STA_BTM_ENABLED_BIT, p_c_sta->bitmask); + H_SET_BIT(WIFI_STA_CONFIG_1_btm_enabled, p_c_sta->bitmask); if (p_a_sta->mbo_enabled) - H_SET_BIT(STA_MBO_ENABLED_BIT, p_c_sta->bitmask); + H_SET_BIT(WIFI_STA_CONFIG_1_mbo_enabled, p_c_sta->bitmask); if (p_a_sta->ft_enabled) - H_SET_BIT(STA_FT_ENABLED_BIT, p_c_sta->bitmask); + H_SET_BIT(WIFI_STA_CONFIG_1_ft_enabled, p_c_sta->bitmask); if (p_a_sta->owe_enabled) - H_SET_BIT(STA_OWE_ENABLED_BIT, p_c_sta->bitmask); + H_SET_BIT(WIFI_STA_CONFIG_1_owe_enabled, p_c_sta->bitmask); if (p_a_sta->transition_disable) - H_SET_BIT(STA_TRASITION_DISABLED_BIT, p_c_sta->bitmask); + H_SET_BIT(WIFI_STA_CONFIG_1_transition_disable, p_c_sta->bitmask); - WIFI_CONFIG_STA_SET_RESERVED_VAL(p_a_sta->reserved, p_c_sta->bitmask); +#if H_DECODE_WIFI_RESERVED_FIELD +#if H_WIFI_NEW_RESERVED_FIELD_NAMES + WIFI_STA_CONFIG_1_SET_RESERVED_VAL(p_a_sta->reserved1, p_c_sta->bitmask); +#else + WIFI_STA_CONFIG_1_SET_RESERVED_VAL(p_a_sta->reserved, p_c_sta->bitmask); +#endif +#endif p_c_sta->sae_pwe_h2e = p_a_sta->sae_pwe_h2e; + p_c_sta->sae_pk_mode = p_a_sta->sae_pk_mode; p_c_sta->failure_retry_cnt = p_a_sta->failure_retry_cnt; + + /* HE field handling */ + if (p_a_sta->he_dcm_set) + H_SET_BIT(WIFI_STA_CONFIG_2_he_dcm_set_BIT, p_c_sta->he_bitmask); + + /* WIFI_STA_CONFIG_2_he_dcm_max_constellation_tx is two bits wide */ + if (p_a_sta->he_dcm_max_constellation_tx & 0x03) { + p_c_sta->he_bitmask |= (p_a_sta->he_dcm_max_constellation_tx & 0x03) << WIFI_STA_CONFIG_2_he_dcm_max_constellation_tx_BITS; + } + /* WIFI_STA_CONFIG_2_he_dcm_max_constellation_rx is two bits wide */ + if (p_a_sta->he_dcm_max_constellation_rx & 0x03) { + p_c_sta->he_bitmask |= (p_a_sta->he_dcm_max_constellation_rx & 0x03) << WIFI_STA_CONFIG_2_he_dcm_max_constellation_rx_BITS; + } + + if (p_a_sta->he_mcs9_enabled) + H_SET_BIT(WIFI_STA_CONFIG_2_he_mcs9_enabled_BIT, p_c_sta->he_bitmask); + + if (p_a_sta->he_su_beamformee_disabled) + H_SET_BIT(WIFI_STA_CONFIG_2_he_su_beamformee_disabled_BIT, p_c_sta->he_bitmask); + + if (p_a_sta->he_trig_su_bmforming_feedback_disabled) + H_SET_BIT(WIFI_STA_CONFIG_2_he_trig_su_bmforming_feedback_disabled_BIT, p_c_sta->he_bitmask); + + if (p_a_sta->he_trig_mu_bmforming_partial_feedback_disabled) + H_SET_BIT(WIFI_STA_CONFIG_2_he_trig_mu_bmforming_partial_feedback_disabled_BIT, p_c_sta->he_bitmask); + + if (p_a_sta->he_trig_cqi_feedback_disabled) + H_SET_BIT(WIFI_STA_CONFIG_2_he_trig_cqi_feedback_disabled_BIT, p_c_sta->he_bitmask); + +#if H_PRESENT_IN_ESP_IDF_5_5_0 + if (p_a_sta->vht_su_beamformee_disabled) + H_SET_BIT(WIFI_STA_CONFIG_2_vht_su_beamformee_disabled, p_c_sta->he_bitmask); + + if (p_a_sta->vht_mu_beamformee_disabled) + H_SET_BIT(WIFI_STA_CONFIG_2_vht_mu_beamformee_disabled, p_c_sta->he_bitmask); + + if (p_a_sta->vht_mcs8_enabled) + H_SET_BIT(WIFI_STA_CONFIG_2_vht_mcs8_enabled, p_c_sta->he_bitmask); +#endif + +#if H_DECODE_WIFI_RESERVED_FIELD +#if H_WIFI_NEW_RESERVED_FIELD_NAMES + WIFI_STA_CONFIG_2_SET_RESERVED_VAL(p_a_sta->reserved2, p_c_sta->he_bitmask); +#else + WIFI_STA_CONFIG_2_SET_RESERVED_VAL(p_a_sta->he_reserved, p_c_sta->he_bitmask); +#endif +#endif + break; } case WIFI_IF_AP: { @@ -998,19 +1181,31 @@ static esp_err_t req_wifi_get_config(Rpc *req, Rpc *resp, void *priv_data) WifiApConfig * p_c_ap = resp_payload->cfg->ap; RPC_RESP_COPY_STR(p_c_ap->password, p_a_ap->password, PASSWORD_LENGTH); p_c_ap->ssid_len = p_a_ap->ssid_len; + if (p_c_ap->ssid_len) + RPC_RESP_COPY_STR(p_c_ap->ssid, p_a_ap->ssid, SSID_LENGTH); p_c_ap->channel = p_a_ap->channel; p_c_ap->authmode = p_a_ap->authmode; p_c_ap->ssid_hidden = p_a_ap->ssid_hidden; p_c_ap->max_connection = p_a_ap->max_connection; p_c_ap->beacon_interval = p_a_ap->beacon_interval; + p_c_ap->csa_count = p_a_ap->csa_count; + p_c_ap->dtim_period = p_a_ap->dtim_period; p_c_ap->pairwise_cipher = p_a_ap->pairwise_cipher; p_c_ap->ftm_responder = p_a_ap->ftm_responder; RPC_ALLOC_ELEMENT(WifiPmfConfig, p_c_ap->pmf_cfg, wifi_pmf_config__init); p_c_ap->pmf_cfg->capable = p_a_ap->pmf_cfg.capable; p_c_ap->pmf_cfg->required = p_a_ap->pmf_cfg.required; - if (p_c_ap->ssid_len) - RPC_RESP_COPY_STR(p_c_ap->ssid, p_a_ap->ssid, SSID_LENGTH); p_c_ap->sae_pwe_h2e = p_a_ap->sae_pwe_h2e; +#if H_GOT_AP_CONFIG_PARAM_TRANSITION_DISABLE + p_c_ap->transition_disable = p_a_ap->transition_disable; +#endif +#if H_PRESENT_IN_ESP_IDF_5_5_0 + p_c_ap->sae_ext = p_a_ap->sae_ext; + RPC_ALLOC_ELEMENT(WifiBssMaxIdleConfig, p_c_ap->bss_max_idle_cfg, wifi_bss_max_idle_config__init); + p_c_ap->bss_max_idle_cfg->period = p_a_ap->bss_max_idle_cfg.period; + p_c_ap->bss_max_idle_cfg->protected_keep_alive = p_a_ap->bss_max_idle_cfg.protected_keep_alive; + p_c_ap->gtk_rekey_interval = p_a_ap->gtk_rekey_interval; +#endif break; } default: @@ -1058,6 +1253,11 @@ static esp_err_t req_wifi_scan_start(Rpc *req, Rpc *resp, void *priv_data) p_a_st->active.max = p_c_st->active->max ; p_a->home_chan_dwell_time = p_c->home_chan_dwell_time; + + if (p_c->channel_bitmap) { + p_a->channel_bitmap.ghz_2_channels = p_c->channel_bitmap->ghz_2_channels; + p_a->channel_bitmap.ghz_5_channels = p_c->channel_bitmap->ghz_5_channels; + } } RPC_RET_FAIL_IF(esp_wifi_scan_start(p_a, req_payload->block)); @@ -1624,7 +1824,7 @@ static esp_err_t req_wifi_sta_get_negotiated_phymode(Rpc *req, Rpc *resp, void * static esp_err_t req_wifi_set_protocols(Rpc *req, Rpc *resp, void *priv_data) { -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) +#if H_PRESENT_IN_ESP_IDF_5_4_0 RPC_TEMPLATE(RpcRespWifiSetProtocols, resp_wifi_set_protocols, RpcReqWifiSetProtocols, req_wifi_set_protocols, rpc__resp__wifi_set_protocols__init); @@ -1651,7 +1851,7 @@ static esp_err_t req_wifi_set_protocols(Rpc *req, Rpc *resp, void *priv_data) static esp_err_t req_wifi_get_protocols(Rpc *req, Rpc *resp, void *priv_data) { -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) +#if H_PRESENT_IN_ESP_IDF_5_4_0 RPC_TEMPLATE(RpcRespWifiGetProtocols, resp_wifi_get_protocols, RpcReqWifiGetProtocols, req_wifi_get_protocols, rpc__resp__wifi_get_protocols__init); @@ -1679,7 +1879,7 @@ static esp_err_t req_wifi_get_protocols(Rpc *req, Rpc *resp, void *priv_data) static esp_err_t req_wifi_set_bandwidths(Rpc *req, Rpc *resp, void *priv_data) { -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) +#if H_PRESENT_IN_ESP_IDF_5_4_0 RPC_TEMPLATE(RpcRespWifiSetBandwidths, resp_wifi_set_bandwidths, RpcReqWifiSetBandwidths, req_wifi_set_bandwidths, rpc__resp__wifi_set_bandwidths__init); @@ -1707,7 +1907,7 @@ static esp_err_t req_wifi_set_bandwidths(Rpc *req, Rpc *resp, void *priv_data) static esp_err_t req_wifi_get_bandwidths(Rpc *req, Rpc *resp, void *priv_data) { -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) +#if H_PRESENT_IN_ESP_IDF_5_4_0 RPC_TEMPLATE(RpcRespWifiGetBandwidths, resp_wifi_get_bandwidths, RpcReqWifiGetBandwidths, req_wifi_get_bandwidths, rpc__resp__wifi_get_bandwidths__init); @@ -1735,7 +1935,7 @@ static esp_err_t req_wifi_get_bandwidths(Rpc *req, Rpc *resp, void *priv_data) static esp_err_t req_wifi_set_band(Rpc *req, Rpc *resp, void *priv_data) { -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) +#if H_PRESENT_IN_ESP_IDF_5_4_0 RPC_TEMPLATE(RpcRespWifiSetBand, resp_wifi_set_band, RpcReqWifiSetBand, req_wifi_set_band, rpc__resp__wifi_set_band__init); @@ -1755,7 +1955,7 @@ static esp_err_t req_wifi_set_band(Rpc *req, Rpc *resp, void *priv_data) static esp_err_t req_wifi_get_band(Rpc *req, Rpc *resp, void *priv_data) { -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) +#if H_PRESENT_IN_ESP_IDF_5_4_0 RPC_TEMPLATE_SIMPLE(RpcRespWifiGetBand, resp_wifi_get_band, RpcReqWifiGetBand, req_wifi_get_band, rpc__resp__wifi_get_band__init); @@ -1775,7 +1975,7 @@ static esp_err_t req_wifi_get_band(Rpc *req, Rpc *resp, void *priv_data) static esp_err_t req_wifi_set_band_mode(Rpc *req, Rpc *resp, void *priv_data) { -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) +#if H_PRESENT_IN_ESP_IDF_5_4_0 RPC_TEMPLATE(RpcRespWifiSetBandMode, resp_wifi_set_bandmode, RpcReqWifiSetBandMode, req_wifi_set_bandmode, rpc__resp__wifi_set_band_mode__init); @@ -1795,7 +1995,7 @@ static esp_err_t req_wifi_set_band_mode(Rpc *req, Rpc *resp, void *priv_data) static esp_err_t req_wifi_get_band_mode(Rpc *req, Rpc *resp, void *priv_data) { -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) +#if H_PRESENT_IN_ESP_IDF_5_4_0 RPC_TEMPLATE_SIMPLE(RpcRespWifiGetBandMode, resp_wifi_get_bandmode, RpcReqWifiGetBandMode, req_wifi_get_bandmode, rpc__resp__wifi_get_band_mode__init); diff --git a/slave/main/slave_wifi_config.h b/slave/main/slave_wifi_config.h new file mode 100644 index 00000000..7283c098 --- /dev/null +++ b/slave/main/slave_wifi_config.h @@ -0,0 +1,40 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __SLAVE_WIFI_CONFIG_H__ +#define __SLAVE_WIFI_CONFIG_H__ + +#include "esp_idf_version.h" + +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 1) +#error ESP-IDF version used is not supported +#endif + +/* ESP-IDF 5.5.0: renamed reserved fields to reserved1/reserved2 */ +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0) +#define H_WIFI_NEW_RESERVED_FIELD_NAMES 1 +#define H_PRESENT_IN_ESP_IDF_5_5_0 1 +#else +#define H_WIFI_NEW_RESERVED_FIELD_NAMES 0 +#define H_PRESENT_IN_ESP_IDF_5_5_0 0 +#endif + +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0) +#define H_PRESENT_IN_ESP_IDF_5_4_0 1 +#else +#define H_PRESENT_IN_ESP_IDF_5_4_0 0 +#endif + +/* wifi_ap_config_t::transition_disable only found in + * IDF v5.3.3 and above, or + * IDF v5.4.1 and above + */ +#if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 3)) || (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 4, 1)) +#define H_GOT_AP_CONFIG_PARAM_TRANSITION_DISABLE 0 +#else +#define H_GOT_AP_CONFIG_PARAM_TRANSITION_DISABLE 1 +#endif + +#endif diff --git a/slave/main/spi_slave_api.c b/slave/main/spi_slave_api.c index b51903e8..a89d71c8 100644 --- a/slave/main/spi_slave_api.c +++ b/slave/main/spi_slave_api.c @@ -50,6 +50,13 @@ static const char TAG[] = "SPI_DRIVER"; #define SPI_RX_QUEUE_SIZE CONFIG_ESP_SPI_RX_Q_SIZE #define SPI_TX_QUEUE_SIZE CONFIG_ESP_SPI_TX_Q_SIZE +// de-assert HS signal on CS, instead of at end of transaction +#if defined(CONFIG_ESP_SPI_DEASSERT_HS_ON_CS) +#define HS_DEASSERT_ON_CS (1) +#else +#define HS_DEASSERT_ON_CS (0) +#endif + /* By default both Handshake and Data Ready used Active High, * unless configured otherwise. * For Active low, set value as 0 */ @@ -80,7 +87,11 @@ static const char TAG[] = "SPI_DRIVER"; #define GPIO_MASK_DATA_READY (1ULL << GPIO_DATA_READY) #define GPIO_MASK_HANDSHAKE (1ULL << GPIO_HANDSHAKE) +#if HS_DEASSERT_ON_CS +#define H_CS_INTR_TO_CLEAR_HS GPIO_INTR_ANYEDGE +#else #define H_CS_INTR_TO_CLEAR_HS GPIO_INTR_NEGEDGE +#endif #if H_HANDSHAKE_ACTIVE_HIGH #define H_HS_VAL_ACTIVE GPIO_OUT_W1TS_REG @@ -106,6 +117,9 @@ static interface_context_t context; static interface_handle_t if_handle_g; static SemaphoreHandle_t spi_tx_sem; static SemaphoreHandle_t spi_rx_sem; +#if HS_DEASSERT_ON_CS +static SemaphoreHandle_t wait_cs_deassert_sem; +#endif static QueueHandle_t spi_rx_queue[MAX_PRIORITY_QUEUES]; static QueueHandle_t spi_tx_queue[MAX_PRIORITY_QUEUES]; #if DUMMY_TRANS_DESIGN @@ -380,9 +394,10 @@ static void IRAM_ATTR spi_post_trans_cb(spi_slave_transaction_t *trans) xSemaphoreGive(spi_sema); } #endif +#if !HS_DEASSERT_ON_CS /* Clear handshake line */ reset_handshake_gpio(); - +#endif } static uint8_t * get_next_tx_buffer(uint32_t *len) @@ -649,8 +664,8 @@ static void spi_transaction_post_process_task(void* pvParameters) /* Await transmission result, after any kind of transmission a new packet * (dummy or real) must be placed in SPI slave */ - spi_slave_get_trans_result(ESP_SPI_CONTROLLER, &spi_trans, - portMAX_DELAY); + ESP_ERROR_CHECK(spi_slave_get_trans_result(ESP_SPI_CONTROLLER, &spi_trans, + portMAX_DELAY)); #if DUMMY_TRANS_DESIGN if (spi_trans->tx_buffer) { header = (struct esp_payload_header *) spi_trans->tx_buffer; @@ -677,6 +692,17 @@ static void spi_transaction_post_process_task(void* pvParameters) if (ret == pdTRUE) queue_dummy_transaction(); #else + +#if HS_DEASSERT_ON_CS + /* Wait until CS has been deasserted before we queue a new transaction. + * + * Some MCUs delay deasserting CS at the end of a transaction. + * If we queue a new transaction without waiting for CS to deassert, + * the slave SPI can start (since CS is still asserted), and data is lost + * as host is not expecting any data. + */ + xSemaphoreTake(wait_cs_deassert_sem, portMAX_DELAY); +#endif /* Queue new transaction to get ready as soon as possible */ queue_next_transaction(); assert(spi_trans); @@ -713,7 +739,19 @@ static void spi_transaction_post_process_task(void* pvParameters) static void IRAM_ATTR gpio_disable_hs_isr_handler(void* arg) { +#if HS_DEASSERT_ON_CS + int level = gpio_get_level(GPIO_CS); + if (level == 0) { + /* CS is asserted, disable HS */ + reset_handshake_gpio(); + } else { + /* Last transaction complete, populate next one */ + if (wait_cs_deassert_sem) + xSemaphoreGive(wait_cs_deassert_sem); + } +#else reset_handshake_gpio(); +#endif } static void register_hs_disable_pin(uint32_t gpio_num) @@ -797,9 +835,9 @@ static interface_handle_t * esp_spi_init(void) gpio_set_pull_mode(GPIO_SCLK, GPIO_PULLUP_ONLY); gpio_set_pull_mode(GPIO_CS, GPIO_PULLUP_ONLY); - ESP_LOGI(TAG, "SPI Ctrl:%u mode: %u, Freq:ConfigAtHost\nGPIOs: MOSI: %u, MISO: %u, CS: %u, CLK: %u HS: %u DR: %u\n", + ESP_LOGI(TAG, "SPI Ctrl:%u mode: %u, Freq:ConfigAtHost\nGPIOs: CLK:%u MOSI:%u MISO:%u CS:%u HS:%u DR:%u\n", ESP_SPI_CONTROLLER, slvcfg.mode, - GPIO_MOSI, GPIO_MISO, GPIO_CS, GPIO_SCLK, + GPIO_SCLK, GPIO_MOSI, GPIO_MISO, GPIO_CS, GPIO_HANDSHAKE, GPIO_DATA_READY); ESP_LOGI(TAG, "Hosted SPI queue size: Tx:%u Rx:%u", SPI_TX_QUEUE_SIZE, SPI_RX_QUEUE_SIZE); @@ -824,6 +862,11 @@ static interface_handle_t * esp_spi_init(void) gpio_set_drive_capability(GPIO_MISO, GPIO_DRIVE_CAP_3); gpio_set_pull_mode(GPIO_MISO, GPIO_PULLDOWN_ONLY); +#if HS_DEASSERT_ON_CS + wait_cs_deassert_sem = xSemaphoreCreateBinary(); + assert(wait_cs_deassert_sem!= NULL); + ret = xSemaphoreTake(wait_cs_deassert_sem, 0); +#endif memset(&if_handle_g, 0, sizeof(if_handle_g)); if_handle_g.state = INIT; @@ -930,11 +973,11 @@ static int32_t esp_spi_write(interface_handle_t *handle, interface_buffer_handle else xQueueSend(spi_tx_queue[PRIO_Q_OTHERS], &tx_buf_handle, portMAX_DELAY); - xSemaphoreGive(spi_tx_sem); - /* indicate waiting data on ready pin */ set_dataready_gpio(); + xSemaphoreGive(spi_tx_sem); + return buf_handle->payload_len; } diff --git a/slave/main/stats.c b/slave/main/stats.c index 202de30d..aa31062a 100644 --- a/slave/main/stats.c +++ b/slave/main/stats.c @@ -17,8 +17,9 @@ #include "stats.h" #include #include "esp_log.h" +#include "esp_hosted_transport_init.h" -#if TEST_RAW_TP || ESP_PKT_STATS +#if TEST_RAW_TP || ESP_PKT_STATS || CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS static const char TAG[] = "stats"; #endif @@ -269,4 +270,3 @@ uint8_t debug_get_raw_tp_conf(void) { #endif return raw_tp_cap; } - diff --git a/slave/sdkconfig.defaults b/slave/sdkconfig.defaults index 9313e28e..2ff48b15 100644 --- a/slave/sdkconfig.defaults +++ b/slave/sdkconfig.defaults @@ -8,3 +8,5 @@ CONFIG_PARTITION_TABLE_TWO_OTA=y # OS CONFIG_FREERTOS_HZ=1000 + +CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF=y