Compare commits

..

1 Commits

1096 changed files with 44528 additions and 44825 deletions

View File

@@ -21,7 +21,7 @@ jobs:
# Disable the job in forks
if: ${{ github.repository_owner == 'espressif' }}
runs-on: ubuntu-24.04-X64-large
runs-on: ubuntu-latest
steps:
# Depending on the branch/tag, set CLONE_BRANCH_OR_TAG variable (used in the Dockerfile
# as a build arg) and TAG_NAME (used when tagging the image).

View File

@@ -117,12 +117,13 @@
/components/esp_ringbuf/ @esp-idf-codeowners/system
/components/esp_rom/ @esp-idf-codeowners/system @esp-idf-codeowners/bluetooth @esp-idf-codeowners/wifi
/components/esp_security/ @esp-idf-codeowners/security
/components/esp_stdio/ @esp-idf-codeowners/storage @esp-idf-codeowners/system
/components/esp_system/ @esp-idf-codeowners/system
/components/esp_tee/ @esp-idf-codeowners/security
/components/esp_timer/ @esp-idf-codeowners/system
/components/esp-tls/ @esp-idf-codeowners/app-utilities
/components/esp_usb_cdc_rom_console/ @esp-idf-codeowners/system @esp-idf-codeowners/peripherals/usb
/components/esp_vfs_*/ @esp-idf-codeowners/storage
/components/esp_vfs_console/ @esp-idf-codeowners/storage @esp-idf-codeowners/system
/components/esp_wifi/ @esp-idf-codeowners/wifi
/components/espcoredump/ @esp-idf-codeowners/debugging
/components/esptool_py/ @esp-idf-codeowners/tools
@@ -135,6 +136,7 @@
/components/http_parser/ @esp-idf-codeowners/app-utilities
/components/idf_test/ @esp-idf-codeowners/peripherals @esp-idf-codeowners/system
/components/ieee802154/ @esp-idf-codeowners/ieee802154
/components/json/ @esp-idf-codeowners/app-utilities
/components/linux/ @esp-idf-codeowners/system
/components/log/ @esp-idf-codeowners/system
/components/lwip/ @esp-idf-codeowners/lwip

View File

@@ -284,11 +284,17 @@ build_docker:
stage: host_test
needs: []
image: espressif/docker-builder:1
tags: [shiny, dind]
tags:
- build_docker_amd64_brno
variables:
DOCKER_TMP_IMAGE_NAME: "idf_tmp_image"
script:
- export DOCKER_BUILD_ARGS="--build-arg IDF_CLONE_URL=${CI_REPOSITORY_URL} --build-arg IDF_CLONE_BRANCH_OR_TAG=${CI_COMMIT_REF_NAME} --build-arg IDF_CHECKOUT_REF=${CI_COMMIT_TAG:-$CI_COMMIT_SHA} --build-arg IDF_CLONE_SHALLOW=1 --build-arg IDF_GITHUB_ASSETS=${INTERNAL_GITHUB_ASSETS}"
- export LOCAL_CI_REPOSITORY_URL=$CI_REPOSITORY_URL
- if [ -n "$LOCAL_GITLAB_HTTPS_HOST" ]; then export LOCAL_CI_REPOSITORY_URL="https://gitlab-ci-token:${CI_JOB_TOKEN}@${LOCAL_GITLAB_HTTPS_HOST}/${CI_PROJECT_PATH}"; fi
- if [ -n "$LOCAL_GIT_MIRROR" ]; then export LOCAL_CI_REPOSITORY_URL="${LOCAL_GIT_MIRROR}/${CI_PROJECT_PATH}"; fi
- echo "Using repository at $LOCAL_CI_REPOSITORY_URL"
- export DOCKER_BUILD_ARGS="--build-arg IDF_CLONE_URL=${LOCAL_CI_REPOSITORY_URL} --build-arg IDF_CLONE_BRANCH_OR_TAG=${CI_COMMIT_REF_NAME} --build-arg IDF_CHECKOUT_REF=${CI_COMMIT_TAG:-$PIPELINE_COMMIT_SHA}"
# Build
- docker build --tag ${DOCKER_TMP_IMAGE_NAME} ${DOCKER_BUILD_ARGS} tools/docker/
# We can't mount $PWD/examples/get-started/blink into the container, see https://gitlab.com/gitlab-org/gitlab-ce/issues/41227.
# The workaround mentioned there works, but leaves around directories which need to be cleaned up manually.
@@ -364,6 +370,6 @@ generate_disabled_apps_report:
expire_in: 1 week
when: always
script:
- pip install dominate idf-build-apps
- pip install dominate idf-build-apps>=2.12.0
- run_cmd python tools/ci/gen_disabled_report.py --output disabled_report.html --verbose --enable-preview-targets
- echo "Report generated at https://${CI_PAGES_HOSTNAME}:${CI_SERVER_PORT}/-/esp-idf/-/jobs/${CI_JOB_ID}/artifacts/disabled_report.html"

View File

@@ -37,7 +37,7 @@ variables:
GIT_FETCH_EXTRA_FLAGS: "--no-recurse-submodules --prune --prune-tags"
# we're using .cache folder for caches
GIT_CLEAN_FLAGS: -ffdx -e .cache/
LATEST_GIT_TAG: v6.0-beta1
LATEST_GIT_TAG: v6.0-dev
SUBMODULE_FETCH_TOOL: "tools/ci/ci_fetch_submodule.py"
# by default we will fetch all submodules
@@ -97,7 +97,6 @@ variables:
CCACHE_MAXSIZE: "50G"
FF_USE_NEW_BASH_EVAL_STRATEGY: "true"
FORCE_COLOR: "1" # rich print with color
################################################
# `before_script` and `after_script` Templates #

View File

@@ -2,12 +2,15 @@
# - extra_default_build_targets:
# besides of the SUPPORTED_TARGETS in IDF,
# enable build for the specified targets by default as well.
# !!! DEPRECATED: use `additional_build_targets` in .idf_build_apps.toml instead
#
# - bypass_check_test_targets:
# suppress the check_build_test_rules check-test-script warnings for the specified targets
#
# This file should ONLY be used during bringup. Should be reset to empty after the bringup process
extra_default_build_targets:
- esp32c5
- esp32c61
- esp32h21
- esp32h4
bypass_check_test_targets:
- esp32h21

View File

@@ -142,10 +142,6 @@ pipeline_variables:
MR_MODIFIED_COMPONENTS=$(run_cmd python tools/ci/ci_get_mr_info.py components --modified-files $MODIFIED_FILES | tr '\n' ';')
echo "MR_MODIFIED_COMPONENTS=\"$MR_MODIFIED_COMPONENTS\"" >> pipeline.env
fi
- |
if [ -n "$PIPELINE_COMMIT_SHA" ]; then
echo "PIPELINE_COMMIT_SHA=$PIPELINE_COMMIT_SHA" >> pipeline.env
fi
- echo "OOCD_DISTRO_URL_ARMHF=$OOCD_DISTRO_URL_ARMHF" >> pipeline.env
- echo "OOCD_DISTRO_URL_ARM64=$OOCD_DISTRO_URL_ARM64" >> pipeline.env
- run_cmd idf-ci gitlab pipeline-variables >> pipeline.env

View File

@@ -147,6 +147,7 @@
- "components/esp_phy/lib"
- "components/esp_wifi/lib"
- "components/esp_coex/lib"
- "components/json/cJSON"
- "components/lwip/lwip"
- "components/mbedtls/mbedtls"
- "components/mqtt/esp-mqtt"

View File

@@ -9,6 +9,11 @@
## Related <!-- Optional -->
<!-- Related Jira issues and Github issues or write "No related issues"-->
## Release notes <!-- Mandatory -->
<!-- Either state release notes or write "No release notes" -->
<!-- ## Breaking change notes --><!-- Optional -->
<!-- ## Dynamic Pipeline Configuration
```yaml
Test Case Filters:

View File

@@ -39,5 +39,27 @@ _For other small/non-public changes, which are not expected to be in the release
* Mention submodule MR, if there is
* Mention backport(ed) MR, if there is
_Don't touch the subsection titles below, they will be parsed by scripts._
## Release notes <!-- Mandatory -->
_Changes made in this MR that should go into the **Release Notes** should be listed here. Please use **past tense** and *specify the area (see maintainers page of IDF internal wiki)*. If there is a subscope, include it and separate with slash (`/`). Minor changes can go to the descriptions above without a release notes entry._
_Write all the changes in a **list** (Start at the beginning of the line with `-` or `*`). If multiple changes are made, each of them should take a single line. If there is only one change to list, it should still be the only line of a list. If this MR does not need any release notes, write "No release notes" here without the `-` or `*`. e.g._
* [WiFi] Changed/fixed/updated xxx
* [WiFi] Added support of xxx
* [Peripheral Drivers/I2S] Fixed xxx (https://github.com/espressif/esp-idf/issues/xxxx)
## Breaking change notes
_Remove this subsection if not used._
_If there are any breaking changes, please mention it here. Talking about (1) what is not accepted any more, (2) the alternative solution and (3) the benefits/reason. e.g._
_Please strictly follow the breaking change restriction, which means, if there is a breaking change but you are merging to non-major versions, you have to separate the breaking part out to another MR for a major version. The breaking change subsection is only accepted in MRs merging to major versions._
* [VFS/UART] Now vfs_uart_set_rts_cts accept one more instance argument, to support configuration to different ports.
<!-- Don't remove the next line - assigns the MR author as the assignee -->
/assign me

14
.gitmodules vendored
View File

@@ -46,6 +46,17 @@
sbom-description = Wear-leveled SPI flash file system for embedded devices
sbom-hash = 0dbb3f71c5f6fae3747a9d935372773762baf852
[submodule "components/json/cJSON"]
path = components/json/cJSON
url = ../../DaveGamble/cJSON.git
sbom-version = 1.7.19
sbom-cpe = cpe:2.3:a:cjson_project:cjson:{}:*:*:*:*:*:*:*
sbom-cpe = cpe:2.3:a:davegamble:cjson:{}:*:*:*:*:*:*:*
sbom-supplier = Person: Dave Gamble
sbom-url = https://github.com/DaveGamble/cJSON
sbom-description = Ultralightweight JSON parser in ANSI C
sbom-hash = c859b25da02955fef659d658b8f324b5cde87be3
[submodule "components/mbedtls/mbedtls"]
path = components/mbedtls/mbedtls
url = ../../espressif/mbedtls.git
@@ -56,8 +67,7 @@
[submodule "components/mqtt/esp-mqtt"]
path = components/mqtt/esp-mqtt
# url = ../../espressif/esp-mqtt.git
url = ../../0xFEEDC0DE64/esp-mqtt.git
url = ../../espressif/esp-mqtt.git
[submodule "components/protobuf-c/protobuf-c"]
path = components/protobuf-c/protobuf-c

View File

@@ -25,11 +25,6 @@ size_json_filename = "size_${CI_JOB_ID}.json"
verbose = 1 # INFO
additional_build_targets = [
'esp32h21',
'esp32h4',
]
# collect
collect_app_info_filename = "app_info_${CI_JOB_NAME_SLUG}.txt"
junitxml = "build_summary_${CI_JOB_NAME_SLUG}.xml"

View File

@@ -144,7 +144,7 @@ repos:
require_serial: true
additional_dependencies:
- PyYAML == 5.3.1
- idf-build-apps~=2.13
- idf-build-apps~=2.12
- id: sort-yaml-files
name: sort yaml files
entry: tools/ci/sort_yaml.py

View File

@@ -1,12 +1,12 @@
cmake_minimum_required(VERSION 3.22)
project(esp-idf C CXX ASM)
if(CMAKE_CURRENT_LIST_DIR STREQUAL CMAKE_SOURCE_DIR)
message(FATAL_ERROR "Current directory '${CMAKE_CURRENT_LIST_DIR}' is not buildable. "
"Change directories to one of the example projects in '${CMAKE_CURRENT_LIST_DIR}/examples' and try again.")
"Change directories to one of the example projects in '${CMAKE_CURRENT_LIST_DIR}/examples' and try "
"again.")
endif()
project(esp-idf C CXX ASM)
# Variables compile_options, c_compile_options, cxx_compile_options, compile_definitions, link_options shall
# not be unset as they may already contain flags, set by toolchain-TARGET.cmake files.
@@ -333,10 +333,7 @@ endforeach()
# Only run validation for the main project, not subprojects like bootloader
idf_build_get_property(bootloader_build BOOTLOADER_BUILD)
idf_build_get_property(esp_tee_build ESP_TEE_BUILD)
if((NOT DEFINED ENV{ESP_IDF_DISABLE_COMPONENT_VALIDATION}
OR "$ENV{ESP_IDF_DISABLE_COMPONENT_VALIDATION}" STREQUAL ""
OR "$ENV{ESP_IDF_DISABLE_COMPONENT_VALIDATION}" STREQUAL "0")
AND NOT bootloader_build AND NOT esp_tee_build)
if(NOT bootloader_build AND NOT esp_tee_build)
include("${CMAKE_CURRENT_LIST_DIR}/tools/cmake/component_validation.cmake")
__component_validation_run_checks()
endif()

View File

@@ -4,26 +4,10 @@ if(${target} STREQUAL "linux")
return() # This component is not supported by the POSIX/Linux simulator
endif()
if(CONFIG_APPTRACE_ENABLE)
set(srcs
"app_trace.c"
"app_trace_util.c"
"host_file_io.c"
)
if(NOT CONFIG_APPTRACE_DEST_UART) # JTAG or ALL
if(CONFIG_IDF_TARGET_ARCH_XTENSA)
list(APPEND srcs "port/xtensa/port_jtag.c")
elseif(CONFIG_IDF_TARGET_ARCH_RISCV)
list(APPEND srcs "port/riscv/port_jtag.c")
endif()
list(APPEND srcs "app_trace_membufs_proto.c")
endif()
if(NOT CONFIG_APPTRACE_DEST_JTAG) # UART or ALL
list(APPEND srcs "port/port_uart.c")
endif()
endif()
set(srcs
"app_trace.c"
"app_trace_util.c"
"host_file_io.c")
if(CONFIG_ESP_DEBUG_STUBS_ENABLE)
list(APPEND srcs "debug_stubs.c")
@@ -33,6 +17,23 @@ set(include_dirs "include")
set(priv_include_dirs "private_include" "port/include")
if(CONFIG_APPTRACE_MEMBUFS_APPTRACE_PROTO_ENABLE)
list(APPEND srcs "app_trace_membufs_proto.c")
endif()
if(CONFIG_APPTRACE_DEST_JTAG)
if(CONFIG_IDF_TARGET_ARCH_XTENSA)
list(APPEND srcs "port/xtensa/port_jtag.c")
endif()
if(CONFIG_IDF_TARGET_ARCH_RISCV)
list(APPEND srcs "port/riscv/port_jtag.c")
endif()
endif()
if(CONFIG_APPTRACE_DEST_UART)
list(APPEND srcs "port/port_uart.c")
endif()
if(CONFIG_APPTRACE_SV_ENABLE)
list(APPEND include_dirs
sys_view/Config
@@ -58,6 +59,6 @@ endif()
idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "${include_dirs}"
PRIV_INCLUDE_DIRS "${priv_include_dirs}"
PRIV_REQUIRES esp_driver_gptimer
REQUIRES esp_timer esp_driver_uart
PRIV_REQUIRES esp_driver_gptimer esp_driver_gpio esp_driver_uart
REQUIRES esp_timer
LDFRAGMENTS linker.lf)

View File

@@ -1,50 +1,36 @@
menu "Application Level Tracing"
config APPTRACE_ENABLE
bool "Enable Application Level Tracing"
default n
choice APPTRACE_DESTINATION1
prompt "Data Destination 1"
default APPTRACE_DEST_NONE
help
Enables/disable application tracing module.
This must be enabled to use any tracing library.
choice APPTRACE_DESTINATION
prompt "Data Destination"
default APPTRACE_DEST_JTAG if !PM_ENABLE
default APPTRACE_DEST_UART if PM_ENABLE
depends on APPTRACE_ENABLE
help
Select destination for application trace: JTAG or UART.
When SystemView is enabled, this also controls the SystemView destination.
Select destination for application trace: JTAG or none (to disable).
config APPTRACE_DEST_JTAG
bool "JTAG"
select APPTRACE_TRAX_ENABLE if IDF_TARGET_ARCH_XTENSA
depends on !PM_ENABLE
select APPTRACE_MEMBUFS_APPTRACE_PROTO_ENABLE
select APPTRACE_ENABLE
config APPTRACE_DEST_NONE
bool "None"
endchoice
choice APPTRACE_DESTINATION2
prompt "Data Destination 2"
default APPTRACE_DEST_UART_NONE
help
Select destination for application trace: UART or none (to disable).
config APPTRACE_DEST_UART
bool "UART"
select APPTRACE_ENABLE
config APPTRACE_DEST_NONE
bool "None (runtime selection)"
help
Compile both JTAG and UART interfaces. Increases IRAM usage.
Allows runtime selection via esp_apptrace_get_user_params().
With this option, destination and configuration must be provided
at runtime. Default JTAG and UART settings are defined in
components/app_trace/include/esp_app_trace_config.h.
Override these by implementing esp_apptrace_get_user_params()
in your application.
config APPTRACE_DEST_UART_NONE
bool "None"
endchoice
config APPTRACE_BUF_SIZE
int "Size of the apptrace buffer"
depends on APPTRACE_DEST_JTAG && !APPTRACE_TRAX_ENABLE
default 16384
help
Size of the memory buffer for trace data in bytes.
config APPTRACE_DEST_UART_NUM
int "UART port number"
depends on APPTRACE_DEST_UART
@@ -121,7 +107,6 @@ menu "Application Level Tracing"
config APPTRACE_UART_TASK_PRIO
int
prompt "UART Task Priority" if APPTRACE_DEST_UART
depends on APPTRACE_DEST_UART
default 1
range 1 32
help
@@ -141,13 +126,23 @@ menu "Application Level Tracing"
help
Enables/disable TRAX tracing HW.
config APPTRACE_LOCK_ENABLE
bool "Internal Sync Lock Enable"
depends on APPTRACE_ENABLE
config APPTRACE_MEMBUFS_APPTRACE_PROTO_ENABLE
bool
default n
help
Enables/disable swapping memory buffers tracing protocol.
config APPTRACE_ENABLE
bool
default n
help
Enables/disable application tracing module.
config APPTRACE_LOCK_ENABLE
bool
default !APPTRACE_SV_ENABLE
help
Enables/disable application tracing module internal sync lock.
Keep in mind this will slow down the trace data transfer to the host.
config APPTRACE_ONPANIC_HOST_FLUSH_TMO
int "Timeout for flushing last trace data to host on panic"
@@ -167,6 +162,13 @@ menu "Application Level Tracing"
Threshold for flushing last trace data to host on panic in post-mortem mode.
This is minimal amount of data needed to perform flush. In bytes.
config APPTRACE_BUF_SIZE
int "Size of the apptrace buffer"
depends on APPTRACE_MEMBUFS_APPTRACE_PROTO_ENABLE && !APPTRACE_TRAX_ENABLE
default 16384
help
Size of the memory buffer for trace data in bytes.
menu "FreeRTOS SystemView Tracing"
depends on APPTRACE_ENABLE
config APPTRACE_SV_ENABLE
@@ -176,9 +178,30 @@ menu "Application Level Tracing"
help
Enables support for SEGGER SystemView tracing functionality.
choice APPTRACE_SV_DEST
prompt "SystemView destination"
depends on APPTRACE_SV_ENABLE
default APPTRACE_SV_DEST_JTAG
help
SystemView will transfer data through the defined interface.
config APPTRACE_SV_DEST_JTAG
bool "Data destination JTAG"
depends on !PM_ENABLE && !APPTRACE_DEST_NONE
help
Send SEGGER SystemView events through JTAG interface.
config APPTRACE_SV_DEST_UART
bool "Data destination UART"
depends on APPTRACE_DEST_UART
help
Send SEGGER SystemView events through UART interface.
endchoice
choice APPTRACE_SV_CPU
prompt "CPU to trace"
depends on APPTRACE_SV_ENABLE && APPTRACE_DEST_UART && !ESP_SYSTEM_SINGLE_CORE_MODE
depends on APPTRACE_SV_DEST_UART && !ESP_SYSTEM_SINGLE_CORE_MODE
default APPTRACE_SV_DEST_CPU_0
help
Define the CPU to trace by SystemView.
@@ -195,6 +218,7 @@ menu "Application Level Tracing"
endchoice
choice APPTRACE_SV_TS_SOURCE
prompt "Timer to use as timestamp source"
depends on APPTRACE_SV_ENABLE

View File

@@ -7,10 +7,8 @@
#include <string.h>
#include "esp_cpu.h"
#include "esp_log.h"
#include "esp_rom_sys.h"
#include "esp_app_trace.h"
#include "esp_app_trace_port.h"
#include "esp_app_trace_types.h"
#include "esp_private/startup_internal.h"
#if CONFIG_ESP_CONSOLE_UART && CONFIG_APPTRACE_DEST_UART && (CONFIG_APPTRACE_DEST_UART_NUM == CONFIG_ESP_CONSOLE_UART_NUM)
@@ -26,205 +24,257 @@ const static char *TAG = "esp_apptrace";
typedef struct {
esp_apptrace_hw_t *hw;
void *hw_data;
esp_apptrace_dest_t dest;
} esp_apptrace_channel_t;
static esp_apptrace_channel_t s_trace_ch;
static volatile int s_trace_ch_hw_initialized = 0;
static esp_apptrace_channel_t s_trace_channels[ESP_APPTRACE_DEST_MAX];
static bool s_inited;
static esp_err_t esp_apptrace_init(const esp_apptrace_config_t *config)
esp_err_t esp_apptrace_init(void)
{
__attribute__((unused)) void *hw_data = NULL;
// 'esp_apptrace_init()' is called on every core, so ensure to do main initialization only once
if (esp_cpu_get_core_id() == 0) {
memset(&s_trace_channels, 0, sizeof(s_trace_channels));
#if CONFIG_APPTRACE_DEST_JTAG
s_trace_ch.hw = esp_apptrace_jtag_hw_get(&hw_data);
s_trace_ch.hw_data = hw_data;
#elif CONFIG_APPTRACE_DEST_UART
const esp_apptrace_uart_config_t *uart_config = &config->dest_cfg.uart;
s_trace_ch.hw = esp_apptrace_uart_hw_get(uart_config->uart_num, &hw_data);
s_trace_ch.hw_data = hw_data;
#else // CONFIG_APPTRACE_DEST_NONE allows runtime selection
if (config->dest == ESP_APPTRACE_DEST_JTAG) {
s_trace_ch.hw = esp_apptrace_jtag_hw_get(&hw_data);
s_trace_ch.hw_data = hw_data;
} else if (config->dest == ESP_APPTRACE_DEST_UART) {
const esp_apptrace_uart_config_t *uart_config = &config->dest_cfg.uart;
s_trace_ch.hw = esp_apptrace_uart_hw_get(uart_config->uart_num, &hw_data);
s_trace_ch.hw_data = hw_data;
} else {
s_trace_ch.hw = NULL;
s_trace_ch.hw_data = NULL;
ESP_APPTRACE_LOGE("Invalid destination type (%d)!", config->dest);
return ESP_ERR_INVALID_ARG;
}
s_trace_channels[ESP_APPTRACE_DEST_JTAG].hw = esp_apptrace_jtag_hw_get(&hw_data);
s_trace_channels[ESP_APPTRACE_DEST_JTAG].hw_data = hw_data;
#endif
s_trace_ch.dest = config->dest;
s_trace_ch_hw_initialized = 1;
} else {
// There is NO guarantee that system init functions will execute on core 0 first
// So we need to wait for core 0 to set up the hardware interface
while (!s_trace_ch_hw_initialized) {
esp_rom_delay_us(10);
}
#if CONFIG_APPTRACE_DEST_UART
s_trace_channels[ESP_APPTRACE_DEST_UART].hw = esp_apptrace_uart_hw_get(CONFIG_APPTRACE_DEST_UART_NUM, &hw_data);
s_trace_channels[ESP_APPTRACE_DEST_UART].hw_data = hw_data;
#endif
s_inited = true;
}
if (s_trace_ch.hw) {
int res = s_trace_ch.hw->init(s_trace_ch.hw_data, config);
if (res != ESP_OK) {
ESP_APPTRACE_LOGE("Failed to init trace channel HW interface (%d)!", res);
return res;
// esp_apptrace_init() is called on every core, so initialize trace channel on every core
for (int i = 0; i < sizeof(s_trace_channels) / sizeof(s_trace_channels[0]); i++) {
esp_apptrace_channel_t *ch = &s_trace_channels[i];
if (ch->hw) {
int res = ch->hw->init(ch->hw_data);
if (res != ESP_OK) {
ESP_APPTRACE_LOGE("Failed to init trace channel HW interface (%d)!", res);
return res;
}
}
}
return ESP_OK;
}
esp_err_t esp_apptrace_down_buffer_config(uint8_t *buf, uint32_t size)
ESP_SYSTEM_INIT_FN(esp_apptrace_init, SECONDARY, ESP_SYSTEM_INIT_ALL_CORES, 115)
{
if (!buf || size == 0) {
return esp_apptrace_init();
}
esp_err_t esp_apptrace_down_buffer_config(esp_apptrace_dest_t dest, uint8_t *buf, uint32_t size)
{
esp_apptrace_channel_t *ch;
if (dest >= ESP_APPTRACE_DEST_MAX) {
return ESP_ERR_INVALID_ARG;
}
if (!s_trace_ch.hw) {
if (buf == NULL || size == 0) {
return ESP_ERR_INVALID_ARG;
}
if (!s_inited) {
return ESP_ERR_INVALID_STATE;
}
if (s_trace_ch.hw->down_buffer_config) {
s_trace_ch.hw->down_buffer_config(s_trace_ch.hw_data, buf, size);
ch = &s_trace_channels[dest];
if (ch->hw == NULL) {
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
return ESP_FAIL;
}
if (ch->hw->down_buffer_config != NULL) {
ch->hw->down_buffer_config(ch->hw_data, buf, size);
}
return ESP_OK;
}
uint8_t *esp_apptrace_down_buffer_get(uint32_t *size, uint32_t user_tmo)
uint8_t *esp_apptrace_down_buffer_get(esp_apptrace_dest_t dest, uint32_t *size, uint32_t user_tmo)
{
ESP_APPTRACE_LOGV("%s(): enter", __func__);
if (!size || *size == 0) {
return NULL;
}
if (!s_trace_ch.hw) {
return NULL;
}
if (!s_trace_ch.hw->get_down_buffer) {
return NULL;
}
esp_apptrace_tmo_t tmo;
esp_apptrace_tmo_init(&tmo, user_tmo);
esp_apptrace_channel_t *ch;
return s_trace_ch.hw->get_down_buffer(s_trace_ch.hw_data, size, &tmo);
ESP_APPTRACE_LOGV("%s(): enter", __func__);
if (dest >= ESP_APPTRACE_DEST_MAX) {
return NULL;
}
if (size == NULL || *size == 0) {
return NULL;
}
if (!s_inited) {
return NULL;
}
ch = &s_trace_channels[dest];
if (ch->hw == NULL) {
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
return NULL;
}
if (ch->hw->get_down_buffer == NULL) {
return NULL;
}
esp_apptrace_tmo_init(&tmo, user_tmo);
return ch->hw->get_down_buffer(ch->hw_data, size, &tmo);
}
esp_err_t esp_apptrace_down_buffer_put(uint8_t *ptr, uint32_t user_tmo)
esp_err_t esp_apptrace_down_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32_t user_tmo)
{
ESP_APPTRACE_LOGV("%s(): enter", __func__);
esp_apptrace_tmo_t tmo;
esp_apptrace_channel_t *ch;
if (!ptr) {
ESP_APPTRACE_LOGV("%s(): enter", __func__);
if (dest >= ESP_APPTRACE_DEST_MAX) {
return ESP_ERR_INVALID_ARG;
}
if (!s_trace_ch.hw) {
if (ptr == NULL) {
return ESP_ERR_INVALID_ARG;
}
if (!s_inited) {
return ESP_ERR_INVALID_STATE;
}
if (!s_trace_ch.hw->get_down_buffer) {
ch = &s_trace_channels[dest];
if (ch->hw == NULL) {
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
return ESP_ERR_NOT_SUPPORTED;
}
if (ch->hw->get_down_buffer == NULL) {
return ESP_ERR_NOT_SUPPORTED;
}
esp_apptrace_tmo_t tmo;
esp_apptrace_tmo_init(&tmo, user_tmo);
return s_trace_ch.hw->put_down_buffer(s_trace_ch.hw_data, ptr, &tmo);
return ch->hw->put_down_buffer(ch->hw_data, ptr, &tmo);
}
esp_err_t esp_apptrace_read(void *buf, uint32_t *size, uint32_t user_tmo)
esp_err_t esp_apptrace_read(esp_apptrace_dest_t dest, void *buf, uint32_t *size, uint32_t user_tmo)
{
ESP_APPTRACE_LOGV("%s(): enter", __func__);
int res = ESP_OK;
esp_apptrace_tmo_t tmo;
esp_apptrace_channel_t *ch;
if (!buf || !size || *size == 0) {
ESP_APPTRACE_LOGV("%s(): enter", __func__);
if (dest >= ESP_APPTRACE_DEST_MAX) {
return ESP_ERR_INVALID_ARG;
}
if (!s_trace_ch.hw) {
if (buf == NULL || size == NULL || *size == 0) {
return ESP_ERR_INVALID_ARG;
}
if (!s_inited) {
return ESP_ERR_INVALID_STATE;
}
if (!s_trace_ch.hw->get_down_buffer || !s_trace_ch.hw->put_down_buffer) {
ch = &s_trace_channels[dest];
if (ch->hw == NULL) {
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
return ESP_ERR_NOT_SUPPORTED;
}
if (ch->hw->get_down_buffer == NULL || ch->hw->put_down_buffer == NULL) {
return ESP_ERR_NOT_SUPPORTED;
}
//TODO: callback system
esp_apptrace_tmo_t tmo;
esp_apptrace_tmo_init(&tmo, user_tmo);
uint32_t act_sz = *size;
*size = 0;
uint8_t *ptr = s_trace_ch.hw->get_down_buffer(s_trace_ch.hw_data, &act_sz, &tmo);
uint8_t *ptr = ch->hw->get_down_buffer(ch->hw_data, &act_sz, &tmo);
if (ptr && act_sz > 0) {
ESP_APPTRACE_LOGD("Read %" PRIu32 " bytes from host", act_sz);
memcpy(buf, ptr, act_sz);
res = ch->hw->put_down_buffer(ch->hw_data, ptr, &tmo);
*size = act_sz;
return s_trace_ch.hw->put_down_buffer(s_trace_ch.hw_data, ptr, &tmo);
} else {
res = ESP_ERR_TIMEOUT;
}
return ESP_ERR_TIMEOUT;
return res;
}
uint8_t *esp_apptrace_buffer_get(uint32_t size, uint32_t user_tmo)
uint8_t *esp_apptrace_buffer_get(esp_apptrace_dest_t dest, uint32_t size, uint32_t user_tmo)
{
ESP_APPTRACE_LOGV("%s(): enter", __func__);
esp_apptrace_tmo_t tmo;
esp_apptrace_channel_t *ch;
ESP_APPTRACE_LOGV("%s(): enter", __func__);
if (dest >= ESP_APPTRACE_DEST_MAX) {
return NULL;
}
if (size == 0) {
return NULL;
}
if (!s_trace_ch.hw) {
if (!s_inited) {
return NULL;
}
if (!s_trace_ch.hw->get_up_buffer) {
ch = &s_trace_channels[dest];
if (ch->hw == NULL) {
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
return NULL;
}
if (ch->hw->get_up_buffer == NULL) {
return NULL;
}
esp_apptrace_tmo_t tmo;
esp_apptrace_tmo_init(&tmo, user_tmo);
return s_trace_ch.hw->get_up_buffer(s_trace_ch.hw_data, size, &tmo);
return ch->hw->get_up_buffer(ch->hw_data, size, &tmo);
}
esp_err_t esp_apptrace_buffer_put(uint8_t *ptr, uint32_t user_tmo)
esp_err_t esp_apptrace_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32_t user_tmo)
{
ESP_APPTRACE_LOGV("%s(): enter", __func__);
esp_apptrace_tmo_t tmo;
esp_apptrace_channel_t *ch;
if (!ptr) {
ESP_APPTRACE_LOGV("%s(): enter", __func__);
if (dest >= ESP_APPTRACE_DEST_MAX) {
return ESP_ERR_INVALID_ARG;
}
if (!s_trace_ch.hw) {
if (ptr == NULL) {
return ESP_ERR_INVALID_ARG;
}
if (!s_inited) {
return ESP_ERR_INVALID_STATE;
}
if (!s_trace_ch.hw->put_up_buffer) {
ch = &s_trace_channels[dest];
if (ch->hw == NULL) {
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
return ESP_ERR_NOT_SUPPORTED;
}
if (ch->hw->put_up_buffer == NULL) {
return ESP_ERR_NOT_SUPPORTED;
}
esp_apptrace_tmo_t tmo;
esp_apptrace_tmo_init(&tmo, user_tmo);
return s_trace_ch.hw->put_up_buffer(s_trace_ch.hw_data, ptr, &tmo);
return ch->hw->put_up_buffer(ch->hw_data, ptr, &tmo);
}
esp_err_t esp_apptrace_write(const void *data, uint32_t size, uint32_t user_tmo)
esp_err_t esp_apptrace_write(esp_apptrace_dest_t dest, const void *data, uint32_t size, uint32_t user_tmo)
{
ESP_APPTRACE_LOGV("%s(): enter", __func__);
uint8_t *ptr = NULL;
esp_apptrace_tmo_t tmo;
esp_apptrace_channel_t *ch;
if (!data || size == 0) {
ESP_APPTRACE_LOGV("%s(): enter", __func__);
if (dest >= ESP_APPTRACE_DEST_MAX) {
return ESP_ERR_INVALID_ARG;
}
if (!s_trace_ch.hw) {
if (data == NULL || size == 0) {
return ESP_ERR_INVALID_ARG;
}
if (!s_inited) {
return ESP_ERR_INVALID_STATE;
}
if (!s_trace_ch.hw->get_up_buffer || !s_trace_ch.hw->put_up_buffer) {
ch = &s_trace_channels[dest];
if (ch->hw == NULL) {
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
return ESP_ERR_NOT_SUPPORTED;
}
if (ch->hw->get_up_buffer == NULL || ch->hw->put_up_buffer == NULL) {
return ESP_ERR_NOT_SUPPORTED;
}
esp_apptrace_tmo_t tmo;
esp_apptrace_tmo_init(&tmo, user_tmo);
uint8_t *ptr = s_trace_ch.hw->get_up_buffer(s_trace_ch.hw_data, size, &tmo);
if (!ptr) {
ptr = ch->hw->get_up_buffer(ch->hw_data, size, &tmo);
if (ptr == NULL) {
return ESP_ERR_NO_MEM;
}
@@ -233,29 +283,36 @@ esp_err_t esp_apptrace_write(const void *data, uint32_t size, uint32_t user_tmo)
memcpy(ptr, data, size);
// now indicate that this buffer is ready to be sent off to host
return s_trace_ch.hw->put_up_buffer(s_trace_ch.hw_data, ptr, &tmo);
return ch->hw->put_up_buffer(ch->hw_data, ptr, &tmo);
}
int esp_apptrace_vprintf_to(uint32_t user_tmo, const char *fmt, va_list ap)
int esp_apptrace_vprintf_to(esp_apptrace_dest_t dest, uint32_t user_tmo, const char *fmt, va_list ap)
{
uint16_t nargs = 0;
uint8_t *pout, *p = (uint8_t *)fmt;
esp_apptrace_tmo_t tmo;
esp_apptrace_channel_t *ch;
ESP_APPTRACE_LOGV("%s(): enter", __func__);
if (!fmt) {
if (dest >= ESP_APPTRACE_DEST_MAX) {
return -1;
}
if (!s_trace_ch.hw) {
if (fmt == NULL) {
return -1;
}
if (!s_trace_ch.hw->get_up_buffer || !s_trace_ch.hw->put_up_buffer) {
if (!s_inited) {
return -1;
}
ch = &s_trace_channels[dest];
if (ch->hw == NULL) {
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
return -1;
}
if (ch->hw->get_up_buffer == NULL || ch->hw->put_up_buffer == NULL) {
return -1;
}
esp_apptrace_tmo_t tmo;
esp_apptrace_tmo_init(&tmo, user_tmo);
ESP_APPTRACE_LOGD("fmt %p", fmt);
while ((p = (uint8_t *)strchr((char *)p, '%')) && nargs < ESP_APPTRACE_MAX_VPRINTF_ARGS) {
p++;
@@ -268,8 +325,8 @@ int esp_apptrace_vprintf_to(uint32_t user_tmo, const char *fmt, va_list ap)
ESP_APPTRACE_LOGE("Failed to store all printf args!");
}
pout = s_trace_ch.hw->get_up_buffer(s_trace_ch.hw_data, 1 + sizeof(char *) + nargs * sizeof(uint32_t), &tmo);
if (!pout) {
pout = ch->hw->get_up_buffer(ch->hw_data, 1 + sizeof(char *) + nargs * sizeof(uint32_t), &tmo);
if (pout == NULL) {
ESP_APPTRACE_LOGE("Failed to get buffer!");
return -1;
}
@@ -285,7 +342,7 @@ int esp_apptrace_vprintf_to(uint32_t user_tmo, const char *fmt, va_list ap)
ESP_APPTRACE_LOGD("arg %" PRIx32, arg);
}
int ret = s_trace_ch.hw->put_up_buffer(s_trace_ch.hw_data, p, &tmo);
int ret = ch->hw->put_up_buffer(ch->hw_data, p, &tmo);
if (ret != ESP_OK) {
ESP_APPTRACE_LOGE("Failed to put printf buf (%d)!", ret);
return -1;
@@ -296,81 +353,78 @@ int esp_apptrace_vprintf_to(uint32_t user_tmo, const char *fmt, va_list ap)
int esp_apptrace_vprintf(const char *fmt, va_list ap)
{
return esp_apptrace_vprintf_to(0, fmt, ap);
return esp_apptrace_vprintf_to(ESP_APPTRACE_DEST_JTAG, 0, fmt, ap);
}
esp_err_t esp_apptrace_flush_nolock(uint32_t min_sz, uint32_t usr_tmo)
esp_err_t esp_apptrace_flush_nolock(esp_apptrace_dest_t dest, uint32_t min_sz, uint32_t usr_tmo)
{
ESP_APPTRACE_LOGV("%s(): enter", __func__);
esp_apptrace_tmo_t tmo;
esp_apptrace_channel_t *ch;
if (!s_trace_ch.hw) {
ESP_APPTRACE_LOGV("%s(): enter", __func__);
if (dest >= ESP_APPTRACE_DEST_MAX) {
return ESP_ERR_INVALID_ARG;
}
if (!s_inited) {
return ESP_ERR_INVALID_STATE;
}
if (!s_trace_ch.hw->flush_up_buffer_nolock) {
ch = &s_trace_channels[dest];
if (ch->hw == NULL) {
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
return ESP_ERR_NOT_SUPPORTED;
}
if (ch->hw->flush_up_buffer_nolock == NULL) {
return ESP_ERR_NOT_SUPPORTED;
}
esp_apptrace_tmo_t tmo;
esp_apptrace_tmo_init(&tmo, usr_tmo);
return s_trace_ch.hw->flush_up_buffer_nolock(s_trace_ch.hw_data, min_sz, &tmo);
return ch->hw->flush_up_buffer_nolock(ch->hw_data, min_sz, &tmo);
}
esp_err_t esp_apptrace_flush(uint32_t usr_tmo)
esp_err_t esp_apptrace_flush(esp_apptrace_dest_t dest, uint32_t usr_tmo)
{
ESP_APPTRACE_LOGV("%s(): enter", __func__);
esp_apptrace_tmo_t tmo;
esp_apptrace_channel_t *ch;
if (!s_trace_ch.hw) {
ESP_APPTRACE_LOGV("%s(): enter", __func__);
if (dest >= ESP_APPTRACE_DEST_MAX) {
return ESP_ERR_INVALID_ARG;
}
if (!s_inited) {
return ESP_ERR_INVALID_STATE;
}
if (!s_trace_ch.hw->flush_up_buffer) {
ch = &s_trace_channels[dest];
if (ch->hw == NULL) {
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
return ESP_ERR_NOT_SUPPORTED;
}
if (ch->hw->flush_up_buffer == NULL) {
return ESP_ERR_NOT_SUPPORTED;
}
esp_apptrace_tmo_t tmo;
esp_apptrace_tmo_init(&tmo, usr_tmo);
return s_trace_ch.hw->flush_up_buffer(s_trace_ch.hw_data, &tmo);
return ch->hw->flush_up_buffer(ch->hw_data, &tmo);
}
bool esp_apptrace_host_is_connected(void)
bool esp_apptrace_host_is_connected(esp_apptrace_dest_t dest)
{
esp_apptrace_channel_t *ch;
ESP_APPTRACE_LOGV("%s(): enter", __func__);
if (!s_trace_ch.hw) {
if (dest >= ESP_APPTRACE_DEST_MAX) {
return false;
}
if (!s_trace_ch.hw->host_is_connected) {
if (!s_inited) {
return false;
}
ch = &s_trace_channels[dest];
if (ch->hw == NULL) {
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
return false;
}
if (ch->hw->host_is_connected == NULL) {
return false;
}
return s_trace_ch.hw->host_is_connected(s_trace_ch.hw_data);
}
esp_apptrace_dest_t esp_apptrace_get_destination(void)
{
return s_trace_ch.dest;
}
esp_err_t esp_apptrace_set_header_size(esp_apptrace_header_size_t header_size)
{
if (!s_trace_ch.hw) {
return ESP_ERR_INVALID_STATE;
}
if (s_trace_ch.hw->set_header_size) {
s_trace_ch.hw->set_header_size(s_trace_ch.hw_data, header_size);
}
return ESP_OK;
}
esp_apptrace_config_t __attribute__((weak)) esp_apptrace_get_user_params(void)
{
esp_apptrace_config_t default_config = APPTRACE_CONFIG_DEFAULT();
return default_config;
}
ESP_SYSTEM_INIT_FN(apptrace_early_init, SECONDARY, ESP_SYSTEM_INIT_ALL_CORES, 115)
{
esp_apptrace_config_t config = esp_apptrace_get_user_params();
return esp_apptrace_init(&config);
return ch->hw->host_is_connected(ch->hw_data);
}

View File

@@ -18,16 +18,13 @@
* In this case host SW will see that wr_sz < block_sz and will report error.
*/
typedef struct {
union {
struct {
uint8_t block_sz_8;
uint8_t wr_sz_8;
};
struct {
uint16_t block_sz_16;
uint16_t wr_sz_16;
};
};
#if CONFIG_APPTRACE_SV_ENABLE
uint8_t block_sz; // size of allocated block for user data
uint8_t wr_sz; // size of actually written data
#else
uint16_t block_sz; // size of allocated block for user data
uint16_t wr_sz; // size of actually written data
#endif
} esp_tracedata_hdr_t;
/** TODO: docs
@@ -36,24 +33,31 @@ typedef struct {
uint16_t block_sz; // size of allocated block for user data
} esp_hostdata_hdr_t;
#define ESP_APPTRACE_INBLOCK_MARKER(_hw_data_) \
((_hw_data_)->state.markers[(_hw_data_)->state.in_block % 2])
#if CONFIG_APPTRACE_SV_ENABLE
#define ESP_APPTRACE_USR_BLOCK_CORE(_cid_) (0)
#define ESP_APPTRACE_USR_BLOCK_LEN(_v_) (_v_)
#define ESP_APPTRACE_USR_DATA_LEN_MAX(_hw_data_) 255UL
#else
#define ESP_APPTRACE_USR_BLOCK_CORE(_cid_) ((_cid_) << 15)
#define ESP_APPTRACE_USR_BLOCK_LEN(_v_) (~(1 << 15) & (_v_))
#define ESP_APPTRACE_USR_DATA_LEN_MAX(_hw_data_) (ESP_APPTRACE_INBLOCK(_hw_data_)->sz - sizeof(esp_tracedata_hdr_t))
#endif
#define ESP_APPTRACE_USR_BLOCK_RAW_SZ(_s_) ((_s_) + sizeof(esp_tracedata_hdr_t))
#define ESP_APPTRACE_INBLOCK(_hw_data_) \
(&(_hw_data_)->blocks[(_hw_data_)->state.in_block % 2])
#define ESP_APPTRACE_INBLOCK_MARKER(_hw_data_) ((_hw_data_)->state.markers[(_hw_data_)->state.in_block % 2])
#define ESP_APPTRACE_INBLOCK_MARKER_UPD(_hw_data_, _v_) do {(_hw_data_)->state.markers[(_hw_data_)->state.in_block % 2] += (_v_);}while(0)
#define ESP_APPTRACE_INBLOCK(_hw_data_) (&(_hw_data_)->blocks[(_hw_data_)->state.in_block % 2])
const static char *TAG = "esp_apptrace";
static uint32_t esp_apptrace_membufs_down_buffer_write_nolock(esp_apptrace_membufs_proto_data_t *proto,
uint8_t *data, uint32_t size);
static uint32_t esp_apptrace_membufs_down_buffer_write_nolock(esp_apptrace_membufs_proto_data_t *proto, uint8_t *data, uint32_t size);
esp_err_t esp_apptrace_membufs_init(esp_apptrace_membufs_proto_data_t *proto,
const esp_apptrace_mem_block_t blocks_cfg[2])
esp_err_t esp_apptrace_membufs_init(esp_apptrace_membufs_proto_data_t *proto, const esp_apptrace_mem_block_t blocks_cfg[2])
{
// disabled by default
esp_apptrace_rb_init(&proto->rb_down, NULL, 0);
// membufs proto init
for (unsigned int i = 0; i < 2; i++) {
for (unsigned i = 0; i < 2; i++) {
proto->blocks[i].start = blocks_cfg[i].start;
proto->blocks[i].sz = blocks_cfg[i].sz;
proto->state.markers[i] = 0;
@@ -100,8 +104,7 @@ static esp_err_t esp_apptrace_membufs_swap(esp_apptrace_membufs_proto_data_t *pr
*(p - 8), *(p - 7), *(p - 6), *(p - 5), *(p - 4), *(p - 3), *(p - 2), *(p - 1));
uint32_t sz = esp_apptrace_membufs_down_buffer_write_nolock(proto, (uint8_t *)(hdr + 1), hdr->block_sz);
if (sz != hdr->block_sz) {
ESP_APPTRACE_LOGE("Failed to write %" PRIu32 " bytes to down buffer (%" PRIu16 " %" PRIu32 ")!",
hdr->block_sz - sz, hdr->block_sz, sz);
ESP_APPTRACE_LOGE("Failed to write %" PRIu32 " bytes to down buffer (%" PRIu16 " %" PRIu32 ")!", hdr->block_sz - sz, hdr->block_sz, sz);
}
hdr->block_sz = 0;
}
@@ -134,8 +137,7 @@ static esp_err_t esp_apptrace_membufs_swap_waitus(esp_apptrace_membufs_proto_dat
return res;
}
uint8_t *esp_apptrace_membufs_down_buffer_get(esp_apptrace_membufs_proto_data_t *proto,
uint32_t *size, esp_apptrace_tmo_t *tmo)
uint8_t *esp_apptrace_membufs_down_buffer_get(esp_apptrace_membufs_proto_data_t *proto, uint32_t *size, esp_apptrace_tmo_t *tmo)
{
uint8_t *ptr = NULL;
@@ -168,15 +170,13 @@ uint8_t *esp_apptrace_membufs_down_buffer_get(esp_apptrace_membufs_proto_data_t
return ptr;
}
esp_err_t esp_apptrace_membufs_down_buffer_put(esp_apptrace_membufs_proto_data_t *proto,
uint8_t *ptr, esp_apptrace_tmo_t *tmo)
esp_err_t esp_apptrace_membufs_down_buffer_put(esp_apptrace_membufs_proto_data_t *proto, uint8_t *ptr, esp_apptrace_tmo_t *tmo)
{
/* nothing todo */
return ESP_OK;
}
static uint32_t esp_apptrace_membufs_down_buffer_write_nolock(esp_apptrace_membufs_proto_data_t *proto,
uint8_t *data, uint32_t size)
static uint32_t esp_apptrace_membufs_down_buffer_write_nolock(esp_apptrace_membufs_proto_data_t *proto, uint8_t *data, uint32_t size)
{
uint32_t total_sz = 0;
@@ -204,21 +204,29 @@ static uint32_t esp_apptrace_membufs_down_buffer_write_nolock(esp_apptrace_membu
return total_sz;
}
static inline uint32_t esp_apptrace_membufs_usr_data_len_max(esp_apptrace_membufs_proto_data_t *proto)
static inline uint8_t *esp_apptrace_membufs_pkt_start(uint8_t *ptr, uint16_t size)
{
return proto->header_size == ESP_APPTRACE_HEADER_SIZE_32 ?
ESP_APPTRACE_INBLOCK(proto)->sz - ESP_APPTRACE_HEADER_SIZE_32 : 255;
// it is safe to use esp_cpu_get_core_id() in macro call because arg is used only once inside it
((esp_tracedata_hdr_t *)ptr)->block_sz = ESP_APPTRACE_USR_BLOCK_CORE(esp_cpu_get_core_id()) | size;
((esp_tracedata_hdr_t *)ptr)->wr_sz = 0;
return ptr + sizeof(esp_tracedata_hdr_t);
}
uint8_t *esp_apptrace_membufs_up_buffer_get(esp_apptrace_membufs_proto_data_t *proto,
uint32_t size, esp_apptrace_tmo_t *tmo)
static inline void esp_apptrace_membufs_pkt_end(uint8_t *ptr)
{
if (size > esp_apptrace_membufs_usr_data_len_max(proto)) {
esp_tracedata_hdr_t *hdr = (esp_tracedata_hdr_t *)(ptr - sizeof(esp_tracedata_hdr_t));
// update written size
hdr->wr_sz = hdr->block_sz;
}
uint8_t *esp_apptrace_membufs_up_buffer_get(esp_apptrace_membufs_proto_data_t *proto, uint32_t size, esp_apptrace_tmo_t *tmo)
{
if (size > ESP_APPTRACE_USR_DATA_LEN_MAX(proto)) {
ESP_APPTRACE_LOGE("Too large user data size %" PRIu32 "!", size);
return NULL;
}
if (ESP_APPTRACE_INBLOCK_MARKER(proto) + size + proto->header_size > ESP_APPTRACE_INBLOCK(proto)->sz) {
if (ESP_APPTRACE_INBLOCK_MARKER(proto) + ESP_APPTRACE_USR_BLOCK_RAW_SZ(size) > ESP_APPTRACE_INBLOCK(proto)->sz) {
int res = esp_apptrace_membufs_swap_waitus(proto, tmo);
if (res != ESP_OK) {
return NULL;
@@ -227,32 +235,16 @@ uint8_t *esp_apptrace_membufs_up_buffer_get(esp_apptrace_membufs_proto_data_t *p
uint8_t *buf_ptr = ESP_APPTRACE_INBLOCK(proto)->start + ESP_APPTRACE_INBLOCK_MARKER(proto);
// update cur block marker
proto->state.markers[proto->state.in_block % 2] += size + proto->header_size;
// update header
esp_tracedata_hdr_t *hdr = (esp_tracedata_hdr_t *)buf_ptr;
if (proto->header_size == ESP_APPTRACE_HEADER_SIZE_32) {
hdr->block_sz_16 = (esp_cpu_get_core_id() << 15) | size;
hdr->wr_sz_16 = 0;
} else {
hdr->block_sz_8 = size;
hdr->wr_sz_8 = 0;
}
ESP_APPTRACE_INBLOCK_MARKER_UPD(proto, ESP_APPTRACE_USR_BLOCK_RAW_SZ(size));
buf_ptr = esp_apptrace_membufs_pkt_start(buf_ptr, size);
ESP_APPTRACE_LOGD("Got %" PRIu32 " bytes from block", size);
return buf_ptr + proto->header_size;
return buf_ptr;
}
esp_err_t esp_apptrace_membufs_up_buffer_put(esp_apptrace_membufs_proto_data_t *proto,
uint8_t *ptr, esp_apptrace_tmo_t *tmo)
esp_err_t esp_apptrace_membufs_up_buffer_put(esp_apptrace_membufs_proto_data_t *proto, uint8_t *ptr, esp_apptrace_tmo_t *tmo)
{
// update header
esp_tracedata_hdr_t *hdr = (esp_tracedata_hdr_t *)(ptr - proto->header_size);
if (proto->header_size == ESP_APPTRACE_HEADER_SIZE_32) {
hdr->wr_sz_16 = hdr->block_sz_16;
} else {
hdr->wr_sz_8 = hdr->block_sz_8;
}
esp_apptrace_membufs_pkt_end(ptr);
// TODO: mark block as busy in order not to reuse it for other tracing calls until it is completely written
// TODO: avoid potential situation when all memory is consumed by low prio tasks which can not complete writing due to
// higher prio tasks and the latter can not allocate buffers at all
@@ -261,8 +253,7 @@ esp_err_t esp_apptrace_membufs_up_buffer_put(esp_apptrace_membufs_proto_data_t *
return ESP_OK;
}
esp_err_t esp_apptrace_membufs_flush_nolock(esp_apptrace_membufs_proto_data_t *proto,
uint32_t min_sz, esp_apptrace_tmo_t *tmo)
esp_err_t esp_apptrace_membufs_flush_nolock(esp_apptrace_membufs_proto_data_t *proto, uint32_t min_sz, esp_apptrace_tmo_t *tmo)
{
int res = ESP_OK;
@@ -276,7 +267,7 @@ esp_err_t esp_apptrace_membufs_flush_nolock(esp_apptrace_membufs_proto_data_t *p
res = esp_apptrace_membufs_swap_waitus(proto, tmo);
if (res != ESP_OK) {
if (res == ESP_ERR_TIMEOUT) {
ESP_APPTRACE_LOGW("Failed to switch to another block in %" PRId32 " us!", (int32_t)tmo->elapsed);
ESP_APPTRACE_LOGW("Failed to switch to another block in %" PRIi32 " us!", (int32_t)tmo->elapsed);
} else {
ESP_APPTRACE_LOGE("Failed to switch to another block, res: %d", res);
}

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*/
@@ -57,12 +57,6 @@ esp_err_t esp_apptrace_tmo_check(esp_apptrace_tmo_t *tmo)
///////////////////////////////// LOCK ////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void esp_apptrace_lock_init(esp_apptrace_lock_t *lock)
{
portMUX_INITIALIZE(&lock->mux);
lock->int_state = 0;
}
esp_err_t esp_apptrace_lock_take(esp_apptrace_lock_t *lock, esp_apptrace_tmo_t *tmo)
{
esp_err_t ret;

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "esp_heap_trace.h"
#include "esp_heap_caps.h"
#if CONFIG_APPTRACE_SV_ENABLE

View File

@@ -17,6 +17,8 @@
#include <string.h>
#include "esp_app_trace.h"
#if CONFIG_APPTRACE_ENABLE
#include "esp_log.h"
const static char *TAG = "esp_host_file_io";
@@ -77,13 +79,13 @@ typedef struct {
void *file;
} esp_apptrace_ftell_args_t;
static esp_err_t esp_apptrace_file_cmd_send(uint8_t cmd, void (*prep_args)(uint8_t *, void *), void *args, uint32_t args_len)
static esp_err_t esp_apptrace_file_cmd_send(esp_apptrace_dest_t dest, uint8_t cmd, void (*prep_args)(uint8_t *, void *), void *args, uint32_t args_len)
{
esp_err_t ret;
esp_apptrace_fcmd_hdr_t *hdr;
ESP_EARLY_LOGV(TAG, "%s %d", __func__, cmd);
uint8_t *ptr = esp_apptrace_buffer_get(sizeof(*hdr) + args_len, ESP_APPTRACE_TMO_INFINITE); //TODO: finite tmo
uint8_t *ptr = esp_apptrace_buffer_get(dest, sizeof(*hdr) + args_len, ESP_APPTRACE_TMO_INFINITE); //TODO: finite tmo
if (ptr == NULL) {
return ESP_ERR_NO_MEM;
}
@@ -95,13 +97,13 @@ static esp_err_t esp_apptrace_file_cmd_send(uint8_t cmd, void (*prep_args)(uint8
}
// now indicate that this buffer is ready to be sent off to host
ret = esp_apptrace_buffer_put(ptr, ESP_APPTRACE_TMO_INFINITE);//TODO: finite tmo
ret = esp_apptrace_buffer_put(dest, ptr, ESP_APPTRACE_TMO_INFINITE);//TODO: finite tmo
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to put apptrace buffer (%d)!", ret);
return ret;
}
ret = esp_apptrace_flush(ESP_APPTRACE_TMO_INFINITE);//TODO: finite tmo
ret = esp_apptrace_flush(dest, ESP_APPTRACE_TMO_INFINITE);//TODO: finite tmo
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to flush apptrace buffer (%d)!", ret);
return ret;
@@ -110,12 +112,12 @@ static esp_err_t esp_apptrace_file_cmd_send(uint8_t cmd, void (*prep_args)(uint8
return ESP_OK;
}
static esp_err_t esp_apptrace_file_rsp_recv(uint8_t *buf, uint32_t buf_len)
static esp_err_t esp_apptrace_file_rsp_recv(esp_apptrace_dest_t dest, uint8_t *buf, uint32_t buf_len)
{
uint32_t tot_rd = 0;
while (tot_rd < buf_len) {
uint32_t rd_size = buf_len - tot_rd;
esp_err_t ret = esp_apptrace_read(buf + tot_rd, &rd_size, ESP_APPTRACE_TMO_INFINITE); //TODO: finite tmo
esp_err_t ret = esp_apptrace_read(dest, buf + tot_rd, &rd_size, ESP_APPTRACE_TMO_INFINITE); //TODO: finite tmo
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to read (%d)!", ret);
return ret;
@@ -135,7 +137,7 @@ static void esp_apptrace_fopen_args_prepare(uint8_t *buf, void *priv)
memcpy(buf + args->path_len, args->mode, args->mode_len);
}
void *esp_apptrace_fopen(const char *path, const char *mode)
void *esp_apptrace_fopen(esp_apptrace_dest_t dest, const char *path, const char *mode)
{
esp_apptrace_fopen_args_t cmd_args;
@@ -149,7 +151,7 @@ void *esp_apptrace_fopen(const char *path, const char *mode)
cmd_args.mode = mode;
cmd_args.mode_len = strlen(mode) + 1;
esp_err_t ret = esp_apptrace_file_cmd_send(ESP_APPTRACE_FILE_CMD_FOPEN, esp_apptrace_fopen_args_prepare,
esp_err_t ret = esp_apptrace_file_cmd_send(dest, ESP_APPTRACE_FILE_CMD_FOPEN, esp_apptrace_fopen_args_prepare,
&cmd_args, cmd_args.path_len + cmd_args.mode_len);
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to send file cmd (%d)!", ret);
@@ -158,7 +160,7 @@ void *esp_apptrace_fopen(const char *path, const char *mode)
// now read the answer
void *resp;
ret = esp_apptrace_file_rsp_recv((uint8_t *)&resp, sizeof(resp));
ret = esp_apptrace_file_rsp_recv(dest, (uint8_t *)&resp, sizeof(resp));
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to read response (%d)!", ret);
return NULL;
@@ -174,12 +176,12 @@ static void esp_apptrace_fclose_args_prepare(uint8_t *buf, void *priv)
memcpy(buf, &args->file, sizeof(args->file));
}
int esp_apptrace_fclose(void *stream)
int esp_apptrace_fclose(esp_apptrace_dest_t dest, void *stream)
{
esp_apptrace_fclose_args_t cmd_args;
cmd_args.file = stream;
esp_err_t ret = esp_apptrace_file_cmd_send(ESP_APPTRACE_FILE_CMD_FCLOSE, esp_apptrace_fclose_args_prepare,
esp_err_t ret = esp_apptrace_file_cmd_send(dest, ESP_APPTRACE_FILE_CMD_FCLOSE, esp_apptrace_fclose_args_prepare,
&cmd_args, sizeof(cmd_args));
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to send file cmd (%d)!", ret);
@@ -188,7 +190,7 @@ int esp_apptrace_fclose(void *stream)
// now read the answer
int resp;
ret = esp_apptrace_file_rsp_recv((uint8_t *)&resp, sizeof(resp));
ret = esp_apptrace_file_rsp_recv(dest, (uint8_t *)&resp, sizeof(resp));
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to read response (%d)!", ret);
return EOF;
@@ -205,7 +207,7 @@ static void esp_apptrace_fwrite_args_prepare(uint8_t *buf, void *priv)
memcpy(buf + sizeof(args->file), args->buf, args->size);
}
size_t esp_apptrace_fwrite(const void *ptr, size_t size, size_t nmemb, void *stream)
size_t esp_apptrace_fwrite(esp_apptrace_dest_t dest, const void *ptr, size_t size, size_t nmemb, void *stream)
{
esp_apptrace_fwrite_args_t cmd_args;
@@ -218,7 +220,7 @@ size_t esp_apptrace_fwrite(const void *ptr, size_t size, size_t nmemb, void *str
cmd_args.buf = (void *)ptr;
cmd_args.size = size * nmemb;
cmd_args.file = stream;
esp_err_t ret = esp_apptrace_file_cmd_send(ESP_APPTRACE_FILE_CMD_FWRITE, esp_apptrace_fwrite_args_prepare,
esp_err_t ret = esp_apptrace_file_cmd_send(dest, ESP_APPTRACE_FILE_CMD_FWRITE, esp_apptrace_fwrite_args_prepare,
&cmd_args, sizeof(cmd_args.file) + cmd_args.size);
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to send file cmd (%d)!", ret);
@@ -227,7 +229,7 @@ size_t esp_apptrace_fwrite(const void *ptr, size_t size, size_t nmemb, void *str
// now read the answer
size_t resp;
ret = esp_apptrace_file_rsp_recv((uint8_t *)&resp, sizeof(resp));
ret = esp_apptrace_file_rsp_recv(dest, (uint8_t *)&resp, sizeof(resp));
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to read response (%d)!", ret);
return 0;
@@ -247,7 +249,7 @@ static void esp_apptrace_fread_args_prepare(uint8_t *buf, void *priv)
memcpy(buf + sizeof(args->file), &args->size, sizeof(args->size));
}
size_t esp_apptrace_fread(void *ptr, size_t size, size_t nmemb, void *stream)
size_t esp_apptrace_fread(esp_apptrace_dest_t dest, void *ptr, size_t size, size_t nmemb, void *stream)
{
esp_apptrace_fread_args_t cmd_args;
@@ -259,7 +261,7 @@ size_t esp_apptrace_fread(void *ptr, size_t size, size_t nmemb, void *stream)
cmd_args.size = size * nmemb;
cmd_args.file = stream;
esp_err_t ret = esp_apptrace_file_cmd_send(ESP_APPTRACE_FILE_CMD_FREAD, esp_apptrace_fread_args_prepare,
esp_err_t ret = esp_apptrace_file_cmd_send(dest, ESP_APPTRACE_FILE_CMD_FREAD, esp_apptrace_fread_args_prepare,
&cmd_args, sizeof(cmd_args));
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to send file cmd (%d)!", ret);
@@ -268,7 +270,7 @@ size_t esp_apptrace_fread(void *ptr, size_t size, size_t nmemb, void *stream)
// now read the answer
size_t resp;
ret = esp_apptrace_file_rsp_recv((uint8_t *)&resp, sizeof(resp));
ret = esp_apptrace_file_rsp_recv(dest, (uint8_t *)&resp, sizeof(resp));
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to read response (%d)!", ret);
return 0;
@@ -277,7 +279,7 @@ size_t esp_apptrace_fread(void *ptr, size_t size, size_t nmemb, void *stream)
return 0;
}
ret = esp_apptrace_file_rsp_recv(ptr, resp);
ret = esp_apptrace_file_rsp_recv(dest, ptr, resp);
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to read file data (%d)!", ret);
return 0;
@@ -298,7 +300,7 @@ static void esp_apptrace_fseek_args_prepare(uint8_t *buf, void *priv)
memcpy(buf + sizeof(args->file) + sizeof(args->offset), &args->whence, sizeof(args->whence));
}
int esp_apptrace_fseek(void *stream, long offset, int whence)
int esp_apptrace_fseek(esp_apptrace_dest_t dest, void *stream, long offset, int whence)
{
esp_apptrace_fseek_args_t cmd_args;
@@ -307,7 +309,7 @@ int esp_apptrace_fseek(void *stream, long offset, int whence)
cmd_args.file = stream;
cmd_args.offset = offset;
cmd_args.whence = whence;
esp_err_t ret = esp_apptrace_file_cmd_send(ESP_APPTRACE_FILE_CMD_FSEEK, esp_apptrace_fseek_args_prepare,
esp_err_t ret = esp_apptrace_file_cmd_send(dest, ESP_APPTRACE_FILE_CMD_FSEEK, esp_apptrace_fseek_args_prepare,
&cmd_args, sizeof(cmd_args));
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to send file cmd (%d)!", ret);
@@ -316,7 +318,7 @@ int esp_apptrace_fseek(void *stream, long offset, int whence)
// now read the answer
int resp;
ret = esp_apptrace_file_rsp_recv((uint8_t *)&resp, sizeof(resp));
ret = esp_apptrace_file_rsp_recv(dest, (uint8_t *)&resp, sizeof(resp));
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to read response (%d)!", ret);
return -1;
@@ -332,12 +334,12 @@ static void esp_apptrace_ftell_args_prepare(uint8_t *buf, void *priv)
memcpy(buf, &args->file, sizeof(args->file));
}
int esp_apptrace_ftell(void *stream)
int esp_apptrace_ftell(esp_apptrace_dest_t dest, void *stream)
{
esp_apptrace_ftell_args_t cmd_args;
cmd_args.file = stream;
esp_err_t ret = esp_apptrace_file_cmd_send(ESP_APPTRACE_FILE_CMD_FTELL, esp_apptrace_ftell_args_prepare,
esp_err_t ret = esp_apptrace_file_cmd_send(dest, ESP_APPTRACE_FILE_CMD_FTELL, esp_apptrace_ftell_args_prepare,
&cmd_args, sizeof(cmd_args));
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to send file cmd (%d)!", ret);
@@ -346,7 +348,7 @@ int esp_apptrace_ftell(void *stream)
// now read the answer
int resp;
ret = esp_apptrace_file_rsp_recv((uint8_t *)&resp, sizeof(resp));
ret = esp_apptrace_file_rsp_recv(dest, (uint8_t *)&resp, sizeof(resp));
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to read response (%d)!", ret);
return -1;
@@ -355,10 +357,10 @@ int esp_apptrace_ftell(void *stream)
return resp;
}
int esp_apptrace_fstop(void)
int esp_apptrace_fstop(esp_apptrace_dest_t dest)
{
ESP_EARLY_LOGV(TAG, "%s", __func__);
esp_err_t ret = esp_apptrace_file_cmd_send(ESP_APPTRACE_FILE_CMD_STOP, NULL, NULL, 0);
esp_err_t ret = esp_apptrace_file_cmd_send(dest, ESP_APPTRACE_FILE_CMD_STOP, NULL, NULL, 0);
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to send files transfer stop cmd (%d)!", ret);
}
@@ -372,12 +374,12 @@ static void esp_apptrace_feof_args_prepare(uint8_t *buf, void *priv)
memcpy(buf, &args->file, sizeof(args->file));
}
int esp_apptrace_feof(void *stream)
int esp_apptrace_feof(esp_apptrace_dest_t dest, void *stream)
{
esp_apptrace_feof_args_t cmd_args;
cmd_args.file = stream;
esp_err_t ret = esp_apptrace_file_cmd_send(ESP_APPTRACE_FILE_CMD_FEOF, esp_apptrace_feof_args_prepare,
esp_err_t ret = esp_apptrace_file_cmd_send(dest, ESP_APPTRACE_FILE_CMD_FEOF, esp_apptrace_feof_args_prepare,
&cmd_args, sizeof(cmd_args));
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to send file cmd (%d)!", ret);
@@ -386,7 +388,7 @@ int esp_apptrace_feof(void *stream)
// now read the answer
int resp;
ret = esp_apptrace_file_rsp_recv((uint8_t *)&resp, sizeof(resp));
ret = esp_apptrace_file_rsp_recv(dest, (uint8_t *)&resp, sizeof(resp));
if (ret != ESP_OK) {
ESP_EARLY_LOGE(TAG, "Failed to read response (%d)!", ret);
return EOF;
@@ -394,3 +396,5 @@ int esp_apptrace_feof(void *stream)
return resp;
}
#endif

View File

@@ -8,7 +8,6 @@
#include <stdarg.h>
#include "esp_err.h"
#include "esp_app_trace_config.h"
#include "esp_app_trace_util.h" // ESP_APPTRACE_TMO_INFINITE
#ifdef __cplusplus
@@ -16,73 +15,83 @@ extern "C" {
#endif
/**
* @brief Get custom trace initialization parameters (optional callback)
*
* This is an optional callback function that user applications can implement to provide
* custom trace configuration. A weak default implementation exists in the app_trace component
* that returns menuconfig defaults (APPTRACE_CONFIG_DEFAULT()). User applications can override
* this by providing their own implementation.
*
* This function is called during early system initialization (before app_main) on all cores.
*
* Application trace data destinations bits.
*/
esp_apptrace_config_t esp_apptrace_get_user_params(void);
typedef enum {
ESP_APPTRACE_DEST_JTAG, ///< JTAG destination
ESP_APPTRACE_DEST_UART, ///< UART destination
ESP_APPTRACE_DEST_MAX,
} esp_apptrace_dest_t;
/**
* @brief Initializes application tracing module.
*
* @note Should be called before any esp_apptrace_xxx call.
*
* @return ESP_OK on success, otherwise see esp_err_t
*/
esp_err_t esp_apptrace_init(void);
/**
* @brief Configures down buffer.
* @note Needs to be called before attempting to receive any data using esp_apptrace_down_buffer_get and esp_apptrace_read.
* This function does not protect internal data by lock.
*
* @param dest Indicates HW interface to configure.
* @param buf Address of buffer to use for down channel (host to target) data.
* @param size Size of the buffer.
*
* @return ESP_OK on success, otherwise see esp_err_t
*/
esp_err_t esp_apptrace_down_buffer_config(uint8_t *buf, uint32_t size);
esp_err_t esp_apptrace_down_buffer_config(esp_apptrace_dest_t dest, uint8_t *buf, uint32_t size);
/**
* @brief Allocates buffer for trace data.
* Once the data in the buffer is ready to be sent, esp_apptrace_buffer_put must be called to indicate it.
*
* @param dest Indicates HW interface to send data.
* @param size Size of data to write to trace buffer.
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
*
* @return non-NULL on success, otherwise NULL.
*/
uint8_t *esp_apptrace_buffer_get(uint32_t size, uint32_t tmo);
uint8_t *esp_apptrace_buffer_get(esp_apptrace_dest_t dest, uint32_t size, uint32_t tmo);
/**
* @brief Indicates that the data in the buffer is ready to be sent.
* This function is a counterpart of and must be preceded by esp_apptrace_buffer_get.
*
* @param dest Indicates HW interface to send data. Should be identical to the same parameter in call to esp_apptrace_buffer_get.
* @param ptr Address of trace buffer to release. Should be the value returned by call to esp_apptrace_buffer_get.
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
*
* @return ESP_OK on success, otherwise see esp_err_t
*/
esp_err_t esp_apptrace_buffer_put(uint8_t *ptr, uint32_t tmo);
esp_err_t esp_apptrace_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32_t tmo);
/**
* @brief Writes data to trace buffer.
*
* @param dest Indicates HW interface to send data.
* @param data Address of data to write to trace buffer.
* @param size Size of data to write to trace buffer.
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
*
* @return ESP_OK on success, otherwise see esp_err_t
*/
esp_err_t esp_apptrace_write(const void *data, uint32_t size, uint32_t tmo);
esp_err_t esp_apptrace_write(esp_apptrace_dest_t dest, const void *data, uint32_t size, uint32_t tmo);
/**
* @brief vprintf-like function to send log messages to host via specified HW interface.
*
* @param dest Indicates HW interface to send data.
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
* @param fmt Address of format string.
* @param ap List of arguments.
*
* @return Number of bytes written.
*/
int esp_apptrace_vprintf_to(uint32_t tmo, const char *fmt, va_list ap);
int esp_apptrace_vprintf_to(esp_apptrace_dest_t dest, uint32_t tmo, const char *fmt, va_list ap);
/**
* @brief vprintf-like function to send log messages to host.
@@ -97,104 +106,98 @@ int esp_apptrace_vprintf(const char *fmt, va_list ap);
/**
* @brief Flushes remaining data in trace buffer to host.
*
* @param dest Indicates HW interface to flush data on.
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
*
* @return ESP_OK on success, otherwise see esp_err_t
*/
esp_err_t esp_apptrace_flush(uint32_t tmo);
esp_err_t esp_apptrace_flush(esp_apptrace_dest_t dest, uint32_t tmo);
/**
* @brief Flushes remaining data in trace buffer to host without locking internal data.
* This is a special version of esp_apptrace_flush which should be called from panic handler.
*
* @param dest Indicates HW interface to flush data on.
* @param min_sz Threshold for flushing data. If current filling level is above this value, data will be flushed. JTAG destinations only.
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
*
* @return ESP_OK on success, otherwise see esp_err_t
*/
esp_err_t esp_apptrace_flush_nolock(uint32_t min_sz, uint32_t tmo);
esp_err_t esp_apptrace_flush_nolock(esp_apptrace_dest_t dest, uint32_t min_sz, uint32_t tmo);
/**
* @brief Reads host data from trace buffer.
*
* @param dest Indicates HW interface to read the data on.
* @param data Address of buffer to put data from trace buffer.
* @param size Pointer to store size of read data. Before call to this function pointed memory must hold requested size of data
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
*
* @return ESP_OK on success, otherwise see esp_err_t
*/
esp_err_t esp_apptrace_read(void *data, uint32_t *size, uint32_t tmo);
esp_err_t esp_apptrace_read(esp_apptrace_dest_t dest, void *data, uint32_t *size, uint32_t tmo);
/**
* @brief Retrieves incoming data buffer if any.
* Once data in the buffer is processed, esp_apptrace_down_buffer_put must be called to indicate it.
*
* @param dest Indicates HW interface to receive data.
* @param size Address to store size of available data in down buffer. Must be initialized with requested value.
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
*
* @return non-NULL on success, otherwise NULL.
*/
uint8_t *esp_apptrace_down_buffer_get(uint32_t *size, uint32_t tmo);
uint8_t *esp_apptrace_down_buffer_get(esp_apptrace_dest_t dest, uint32_t *size, uint32_t tmo);
/**
* @brief Indicates that the data in the down buffer is processed.
* This function is a counterpart of and must be preceded by esp_apptrace_down_buffer_get.
*
* @param dest Indicates HW interface to receive data. Should be identical to the same parameter in call to esp_apptrace_down_buffer_get.
* @param ptr Address of trace buffer to release. Should be the value returned by call to esp_apptrace_down_buffer_get.
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
*
* @return ESP_OK on success, otherwise see esp_err_t
*/
esp_err_t esp_apptrace_down_buffer_put(uint8_t *ptr, uint32_t tmo);
esp_err_t esp_apptrace_down_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32_t tmo);
/**
* @brief Checks whether host is connected.
*
* @param dest Indicates HW interface to use.
*
* @return true if host is connected, otherwise false
*/
bool esp_apptrace_host_is_connected(void);
/**
* @brief Gets the destination of the application trace.
*
* @return The destination of the application trace.
*/
esp_apptrace_dest_t esp_apptrace_get_destination(void);
/**
* @brief Sets the header size of the application trace packet.
*
* @param header_size The header size to set.
*
* @return ESP_OK on success, otherwise see esp_err_t
*/
esp_err_t esp_apptrace_set_header_size(esp_apptrace_header_size_t header_size);
bool esp_apptrace_host_is_connected(esp_apptrace_dest_t dest);
/**
* @brief Opens file on host.
* This function has the same semantic as 'fopen' except for the first argument.
*
* @param dest Indicates HW interface to use.
* @param path Path to file.
* @param mode Mode string. See fopen for details.
*
* @return non zero file handle on success, otherwise 0
*/
void *esp_apptrace_fopen(const char *path, const char *mode);
void *esp_apptrace_fopen(esp_apptrace_dest_t dest, const char *path, const char *mode);
/**
* @brief Closes file on host.
* This function has the same semantic as 'fclose' except for the first argument.
*
* @param dest Indicates HW interface to use.
* @param stream File handle returned by esp_apptrace_fopen.
*
* @return Zero on success, otherwise non-zero. See fclose for details.
*/
int esp_apptrace_fclose(void *stream);
int esp_apptrace_fclose(esp_apptrace_dest_t dest, void *stream);
/**
* @brief Writes to file on host.
* This function has the same semantic as 'fwrite' except for the first argument.
*
* @param dest Indicates HW interface to use.
* @param ptr Address of data to write.
* @param size Size of an item.
* @param nmemb Number of items to write.
@@ -202,12 +205,13 @@ int esp_apptrace_fclose(void *stream);
*
* @return Number of written items. See fwrite for details.
*/
size_t esp_apptrace_fwrite(const void *ptr, size_t size, size_t nmemb, void *stream);
size_t esp_apptrace_fwrite(esp_apptrace_dest_t dest, const void *ptr, size_t size, size_t nmemb, void *stream);
/**
* @brief Read file on host.
* This function has the same semantic as 'fread' except for the first argument.
*
* @param dest Indicates HW interface to use.
* @param ptr Address to store read data.
* @param size Size of an item.
* @param nmemb Number of items to read.
@@ -215,82 +219,53 @@ size_t esp_apptrace_fwrite(const void *ptr, size_t size, size_t nmemb, void *str
*
* @return Number of read items. See fread for details.
*/
size_t esp_apptrace_fread(void *ptr, size_t size, size_t nmemb, void *stream);
size_t esp_apptrace_fread(esp_apptrace_dest_t dest, void *ptr, size_t size, size_t nmemb, void *stream);
/**
* @brief Set position indicator in file on host.
* This function has the same semantic as 'fseek' except for the first argument.
*
* @param dest Indicates HW interface to use.
* @param stream File handle returned by esp_apptrace_fopen.
* @param offset Offset. See fseek for details.
* @param whence Position in file. See fseek for details.
*
* @return Zero on success, otherwise non-zero. See fseek for details.
*/
int esp_apptrace_fseek(void *stream, long offset, int whence);
int esp_apptrace_fseek(esp_apptrace_dest_t dest, void *stream, long offset, int whence);
/**
* @brief Get current position indicator for file on host.
* This function has the same semantic as 'ftell' except for the first argument.
*
* @param dest Indicates HW interface to use.
* @param stream File handle returned by esp_apptrace_fopen.
*
* @return Current position in file. See ftell for details.
*/
int esp_apptrace_ftell(void *stream);
int esp_apptrace_ftell(esp_apptrace_dest_t dest, void *stream);
/**
* @brief Indicates to the host that all file operations are complete.
* This function should be called after all file operations are finished and
* indicate to the host that it can perform cleanup operations (close open files etc.).
*
* @param dest Indicates HW interface to use.
*
* @return ESP_OK on success, otherwise see esp_err_t
*/
int esp_apptrace_fstop(void);
int esp_apptrace_fstop(esp_apptrace_dest_t dest);
/**
* @brief Test end-of-file indicator on a stream.
* This function has the same semantic as 'feof' except for the first argument.
*
* @param dest Indicates HW interface to use.
* @param stream File handle returned by esp_apptrace_fopen.
*
* @return Non-Zero if end-of-file indicator is set for stream. See feof for details.
*/
int esp_apptrace_feof(void *stream);
#if !CONFIG_APPTRACE_DEST_UART // JTAG or NONE
#define APPTRACE_JTAG_CONFIG_DEFAULT() { \
.dest = ESP_APPTRACE_DEST_JTAG, \
.dest_cfg.jtag = {0}, \
.panic_flush_tmo = CONFIG_APPTRACE_ONPANIC_HOST_FLUSH_TMO, \
.panic_flush_thresh = CONFIG_APPTRACE_POSTMORTEM_FLUSH_THRESH, \
}
#endif
#if !CONFIG_APPTRACE_DEST_JTAG // UART or NONE
#define APPTRACE_UART_CONFIG_DEFAULT() { \
.dest = ESP_APPTRACE_DEST_UART, \
.dest_cfg.uart = { \
.uart_num = CONFIG_APPTRACE_DEST_UART_NUM, \
.tx_pin_num = CONFIG_APPTRACE_UART_TX_GPIO, \
.rx_pin_num = CONFIG_APPTRACE_UART_RX_GPIO, \
.baud_rate = CONFIG_APPTRACE_UART_BAUDRATE, \
.rx_buff_size = CONFIG_APPTRACE_UART_RX_BUFF_SIZE, \
.tx_buff_size = CONFIG_APPTRACE_UART_TX_BUFF_SIZE, \
.tx_msg_size = CONFIG_APPTRACE_UART_TX_MSG_SIZE, \
.task_prio = CONFIG_APPTRACE_UART_TASK_PRIO, \
}, \
.panic_flush_tmo = CONFIG_APPTRACE_ONPANIC_HOST_FLUSH_TMO, \
.panic_flush_thresh = CONFIG_APPTRACE_POSTMORTEM_FLUSH_THRESH, \
}
#endif
// Default picks JTAG if available, otherwise UART
#if !CONFIG_APPTRACE_DEST_UART
#define APPTRACE_CONFIG_DEFAULT() APPTRACE_JTAG_CONFIG_DEFAULT()
#else
#define APPTRACE_CONFIG_DEFAULT() APPTRACE_UART_CONFIG_DEFAULT()
#endif
int esp_apptrace_feof(esp_apptrace_dest_t dest, void *stream);
#ifdef __cplusplus
}

View File

@@ -1,61 +0,0 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ESP_APP_TRACE_CONFIG_H_
#define ESP_APP_TRACE_CONFIG_H_
#include "sdkconfig.h"
/* Default configurations for runtime selection (CONFIG_APPTRACE_DEST_NONE)
* These values are used when CONFIG_APPTRACE_DEST_NONE is selected in menuconfig.
* To customize at runtime, implement esp_apptrace_get_user_params()
* in your application. See esp_app_trace.h for details.
*/
#if !defined(CONFIG_APPTRACE_UART_TX_GPIO) || !defined(CONFIG_APPTRACE_UART_RX_GPIO)
#include "soc/uart_pins.h"
#endif
#ifndef CONFIG_APPTRACE_BUF_SIZE
#define CONFIG_APPTRACE_BUF_SIZE 16384
#endif
#ifndef CONFIG_APPTRACE_UART_RX_BUFF_SIZE
#define CONFIG_APPTRACE_UART_RX_BUFF_SIZE 128
#endif
#ifndef CONFIG_APPTRACE_UART_TX_BUFF_SIZE
#define CONFIG_APPTRACE_UART_TX_BUFF_SIZE 4096
#endif
#ifndef CONFIG_APPTRACE_UART_TX_MSG_SIZE
#define CONFIG_APPTRACE_UART_TX_MSG_SIZE 128
#endif
#ifndef CONFIG_APPTRACE_UART_BAUDRATE
#define CONFIG_APPTRACE_UART_BAUDRATE 1000000
#endif
#ifndef CONFIG_APPTRACE_UART_TASK_PRIO
#define CONFIG_APPTRACE_UART_TASK_PRIO 1
#endif
#ifndef CONFIG_APPTRACE_UART_TX_GPIO
#define CONFIG_APPTRACE_UART_TX_GPIO U1TXD_GPIO_NUM
#endif
#ifndef CONFIG_APPTRACE_UART_RX_GPIO
#define CONFIG_APPTRACE_UART_RX_GPIO U1RXD_GPIO_NUM
#endif
#ifndef CONFIG_APPTRACE_DEST_UART_NUM
#define CONFIG_APPTRACE_DEST_UART_NUM 1
#endif
#ifndef CONFIG_APPTRACE_SV_DEST_CPU_0
#define CONFIG_APPTRACE_SV_DEST_CPU_0 1
#endif
#endif /* ESP_APP_TRACE_CONFIG_H_ */

View File

@@ -1,97 +0,0 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ESP_APP_TRACE_TYPES_H_
#define ESP_APP_TRACE_TYPES_H_
#include <stdint.h>
#include "spinlock.h"
#ifdef __cplusplus
extern "C" {
#endif
/** Structure which holds data necessary for measuring time intervals.
*
* After initialization via esp_apptrace_tmo_init() user needs to call esp_apptrace_tmo_check()
* periodically to check timeout for expiration.
*/
typedef struct {
int64_t start; ///< time interval start (in us)
int64_t tmo; ///< timeout value (in us)
int64_t elapsed; ///< elapsed time (in us)
} esp_apptrace_tmo_t;
/** Tracing module synchronization lock */
typedef struct {
spinlock_t mux;
unsigned int_state;
} esp_apptrace_lock_t;
/** Ring buffer control structure.
*
* @note For purposes of application tracing module if there is no enough space for user data and write pointer can be wrapped
* current ring buffer size can be temporarily shrunk in order to provide buffer with requested size.
*/
typedef struct {
uint8_t *data; ///< pointer to data storage
volatile uint32_t size; ///< size of data storage
volatile uint32_t cur_size; ///< current size of data storage
volatile uint32_t rd; ///< read pointer
volatile uint32_t wr; ///< write pointer
} esp_apptrace_rb_t;
/**
* Application trace data destinations
*/
typedef enum {
ESP_APPTRACE_DEST_JTAG,
ESP_APPTRACE_DEST_UART,
} esp_apptrace_dest_t;
/**
* Application trace configuration for UART destination
*/
typedef struct {
int uart_num; ///< Port number
int tx_pin_num; ///< TX pin number
int rx_pin_num; ///< RX pin number
int baud_rate; ///< Baud rate
uint32_t rx_buff_size; ///< RX ring buffer size
uint32_t tx_buff_size; ///< TX ring buffer size
uint32_t tx_msg_size; ///< Maximum size of the single message to transfer.
int task_prio; ///< Task priority
} esp_apptrace_uart_config_t;
/**
* Application trace trace header size in bytes. It is 2 bytes for SEGGER SystemView
*/
typedef enum {
ESP_APPTRACE_HEADER_SIZE_16 = 2,
ESP_APPTRACE_HEADER_SIZE_32 = 4,
} esp_apptrace_header_size_t;
/**
* Application trace configuration
*/
typedef struct {
esp_apptrace_dest_t dest; ///< Destination type (JTAG or UART)
union {
esp_apptrace_uart_config_t uart; ///< UART configuration (when dest is ESP_APPTRACE_DEST_UART)
struct { ///< Reserved for JTAG (when dest is ESP_APPTRACE_DEST_JTAG)
uint8_t _unused;
} jtag;
} dest_cfg; ///< Destination-specific configuration
uint32_t panic_flush_tmo; ///< Panic flush timeout in milliseconds
uint32_t panic_flush_thresh; ///< Panic flush threshold in bytes
} esp_apptrace_config_t;
#ifdef __cplusplus
}
#endif
#endif /* ESP_APP_TRACE_TYPES_H_ */

View File

@@ -10,13 +10,24 @@
extern "C" {
#endif
#include "freertos/FreeRTOS.h"
#include "esp_err.h"
#include "esp_timer.h"
#include "esp_app_trace_types.h"
/** Infinite waiting timeout */
#define ESP_APPTRACE_TMO_INFINITE ((uint32_t)-1)
/** Structure which holds data necessary for measuring time intervals.
*
* After initialization via esp_apptrace_tmo_init() user needs to call esp_apptrace_tmo_check()
* periodically to check timeout for expiration.
*/
typedef struct {
int64_t start; ///< time interval start (in us)
int64_t tmo; ///< timeout value (in us)
int64_t elapsed; ///< elapsed time (in us)
} esp_apptrace_tmo_t;
/**
* @brief Initializes timeout structure.
*
@@ -44,12 +55,22 @@ static inline uint32_t esp_apptrace_tmo_remaining_us(esp_apptrace_tmo_t *tmo)
return tmo->tmo != (int64_t) -1 ? (tmo->elapsed - tmo->tmo) : ESP_APPTRACE_TMO_INFINITE;
}
/** Tracing module synchronization lock */
typedef struct {
spinlock_t mux;
unsigned int_state;
} esp_apptrace_lock_t;
/**
* @brief Initializes lock structure.
*
* @param lock Pointer to lock structure to be initialized.
*/
void esp_apptrace_lock_init(esp_apptrace_lock_t *lock);
static inline void esp_apptrace_lock_init(esp_apptrace_lock_t *lock)
{
portMUX_INITIALIZE(&lock->mux);
lock->int_state = 0;
}
/**
* @brief Tries to acquire lock in specified time period.
@@ -70,6 +91,19 @@ esp_err_t esp_apptrace_lock_take(esp_apptrace_lock_t *lock, esp_apptrace_tmo_t *
*/
esp_err_t esp_apptrace_lock_give(esp_apptrace_lock_t *lock);
/** Ring buffer control structure.
*
* @note For purposes of application tracing module if there is no enough space for user data and write pointer can be wrapped
* current ring buffer size can be temporarily shrunk in order to provide buffer with requested size.
*/
typedef struct {
uint8_t *data; ///< pointer to data storage
volatile uint32_t size; ///< size of data storage
volatile uint32_t cur_size; ///< current size of data storage
volatile uint32_t rd; ///< read pointer
volatile uint32_t wr; ///< write pointer
} esp_apptrace_rb_t;
/**
* @brief Initializes ring buffer control structure.
*

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2018-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -18,7 +18,7 @@ extern "C" {
/**
* @brief Flushes remaining data in SystemView trace buffer to host.
*
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
*
* @return ESP_OK.
*/

View File

@@ -1,14 +1,14 @@
[mapping:app_trace]
archive: libapp_trace.a
entries:
if APPTRACE_ENABLE = y:
app_trace (noflash)
app_trace_util (noflash)
if APPTRACE_DEST_JTAG = y || APPTRACE_DEST_NONE = y:
port_jtag (noflash)
app_trace_membufs_proto (noflash)
if APPTRACE_DEST_UART = y || APPTRACE_DEST_NONE = y:
port_uart (noflash)
app_trace (noflash)
app_trace_util (noflash)
if APPTRACE_MEMBUFS_APPTRACE_PROTO_ENABLE:
app_trace_membufs_proto (noflash)
if APPTRACE_DEST_JTAG = y:
port_jtag (noflash)
if APPTRACE_DEST_UART = y:
port_uart (noflash)
if APPTRACE_SV_ENABLE = y:
SEGGER_SYSVIEW (noflash)
SEGGER_RTT_esp (noflash)
@@ -19,6 +19,6 @@ entries:
archive: libesp_driver_gptimer.a
entries:
if APPTRACE_SV_TS_SOURCE_GPTIMER = y:
gptimer: gptimer_get_raw_count (noflash)
gptimer: gptimer_get_raw_count (noflash)
else:
* (default)
* (default)

View File

@@ -15,7 +15,7 @@ extern "C" {
/** Apptrace HW interface. */
typedef struct {
esp_err_t (*init)(void *hw_data, const esp_apptrace_config_t *config);
esp_err_t (*init)(void *hw_data);
uint8_t *(*get_up_buffer)(void *hw_data, uint32_t, esp_apptrace_tmo_t *);
esp_err_t (*put_up_buffer)(void *hw_data, uint8_t *, esp_apptrace_tmo_t *);
esp_err_t (*flush_up_buffer_nolock)(void *hw_data, uint32_t, esp_apptrace_tmo_t *);
@@ -24,7 +24,6 @@ typedef struct {
uint8_t *(*get_down_buffer)(void *hw_data, uint32_t *, esp_apptrace_tmo_t *);
esp_err_t (*put_down_buffer)(void *hw_data, uint8_t *, esp_apptrace_tmo_t *);
bool (*host_is_connected)(void *hw_data);
void (*set_header_size)(void *hw_data, esp_apptrace_header_size_t header_size);
} esp_apptrace_hw_t;
esp_apptrace_hw_t *esp_apptrace_jtag_hw_get(void **data);

View File

@@ -3,15 +3,19 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include "soc/soc.h"
#include "esp_log.h"
#include "esp_cpu.h"
#include "esp_app_trace_config.h"
#include "esp_app_trace_port.h"
#include "driver/uart.h"
#include "hal/uart_ll.h"
#include "string.h"
#include "driver/gpio.h"
#define APP_TRACE_MAX_TX_BUFF_UART CONFIG_APPTRACE_UART_TX_BUFF_SIZE
#define APP_TRACE_MAX_TX_MSG_UART CONFIG_APPTRACE_UART_TX_MSG_SIZE
/** UART HW transport data */
typedef struct {
@@ -20,34 +24,28 @@ typedef struct {
esp_apptrace_lock_t lock; // sync lock
#endif
uart_port_t port_num;
/* TX data ring buffer */
// TX data ring buffer
uint8_t *tx_data_buff;
uint32_t tx_data_buff_size;
int32_t tx_data_buff_in;
int32_t tx_data_buff_out;
/* TX message buffer */
// TX message buffer
uint8_t *tx_msg_buff;
uint32_t tx_msg_buff_size;
uint32_t tx_pending_msg_size;
/* RX message buffer */
// RX message buffer
uint8_t *down_buffer;
uint32_t down_buffer_size;
/* Buffer overflow flags */
// Buffer overflow flags
bool message_buff_overflow;
bool circular_buff_overflow;
} esp_apptrace_uart_data_t;
const static char *TAG = "esp_apptrace_uart";
static esp_err_t esp_apptrace_uart_lock(void *hw_data, esp_apptrace_tmo_t *tmo)
static esp_err_t esp_apptrace_uart_lock(esp_apptrace_uart_data_t *hw_data, esp_apptrace_tmo_t *tmo)
{
#if CONFIG_APPTRACE_LOCK_ENABLE
esp_apptrace_uart_data_t *uart_data = hw_data;
esp_err_t ret = esp_apptrace_lock_take(&uart_data->lock, tmo);
esp_err_t ret = esp_apptrace_lock_take(&hw_data->lock, tmo);
if (ret != ESP_OK) {
return ESP_FAIL;
}
@@ -55,12 +53,11 @@ static esp_err_t esp_apptrace_uart_lock(void *hw_data, esp_apptrace_tmo_t *tmo)
return ESP_OK;
}
static esp_err_t esp_apptrace_uart_unlock(void *hw_data)
static esp_err_t esp_apptrace_uart_unlock(esp_apptrace_uart_data_t *hw_data)
{
esp_err_t ret = ESP_OK;
#if CONFIG_APPTRACE_LOCK_ENABLE
esp_apptrace_uart_data_t *uart_data = hw_data;
ret = esp_apptrace_lock_give(&uart_data->lock);
ret = esp_apptrace_lock_give(&hw_data->lock);
#endif
return ret;
}
@@ -74,69 +71,58 @@ static inline void esp_apptrace_uart_hw_init(void)
/***************************** Apptrace HW iface *****************************************/
/*****************************************************************************************/
static esp_err_t esp_apptrace_send_uart_data(void *hw_data, const char *data, uint32_t size, esp_apptrace_tmo_t *tmo)
static esp_err_t esp_apptrace_send_uart_data(esp_apptrace_uart_data_t *hw_data, const char *data, uint32_t size, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_uart_data_t *uart_data = hw_data;
esp_err_t res = esp_apptrace_uart_lock(uart_data, tmo);
esp_err_t res = esp_apptrace_uart_lock(hw_data, tmo);
if (res != ESP_OK) {
return res;
}
// We store current out position to handle it without lock
volatile int32_t out_position = uart_data->tx_data_buff_out;
volatile int32_t out_position = hw_data->tx_data_buff_out;
int len_free = uart_data->tx_data_buff_size - (uart_data->tx_data_buff_in - out_position);
if (out_position > uart_data->tx_data_buff_in) {
len_free = out_position - uart_data->tx_data_buff_in;
int len_free = APP_TRACE_MAX_TX_BUFF_UART - (hw_data->tx_data_buff_in - out_position);
if (out_position > hw_data->tx_data_buff_in) {
len_free = out_position - hw_data->tx_data_buff_in;
}
int check_len = uart_data->tx_data_buff_size - uart_data->tx_data_buff_in;
int check_len = APP_TRACE_MAX_TX_BUFF_UART - hw_data->tx_data_buff_in;
if (size <= len_free) {
if (check_len >= size) {
memcpy(&uart_data->tx_data_buff[uart_data->tx_data_buff_in], data, size);
uart_data->tx_data_buff_in += size;
memcpy(&hw_data->tx_data_buff[hw_data->tx_data_buff_in], data, size);
hw_data->tx_data_buff_in += size;
} else {
memcpy(&uart_data->tx_data_buff[uart_data->tx_data_buff_in],
data,
uart_data->tx_data_buff_size - uart_data->tx_data_buff_in);
memcpy(&uart_data->tx_data_buff[0],
&data[uart_data->tx_data_buff_size - uart_data->tx_data_buff_in],
size - (uart_data->tx_data_buff_size - uart_data->tx_data_buff_in));
uart_data->tx_data_buff_in = size - (uart_data->tx_data_buff_size - uart_data->tx_data_buff_in);
memcpy(&hw_data->tx_data_buff[hw_data->tx_data_buff_in], data, APP_TRACE_MAX_TX_BUFF_UART - hw_data->tx_data_buff_in);
memcpy(&hw_data->tx_data_buff[0], &data[APP_TRACE_MAX_TX_BUFF_UART - hw_data->tx_data_buff_in], size - (APP_TRACE_MAX_TX_BUFF_UART - hw_data->tx_data_buff_in));
hw_data->tx_data_buff_in = size - (APP_TRACE_MAX_TX_BUFF_UART - hw_data->tx_data_buff_in);
}
if (uart_data->tx_data_buff_in >= uart_data->tx_data_buff_size) {
uart_data->tx_data_buff_in = 0;
if (hw_data->tx_data_buff_in >= APP_TRACE_MAX_TX_BUFF_UART) {
hw_data->tx_data_buff_in = 0;
}
} else {
uart_data->circular_buff_overflow = true;
hw_data->circular_buff_overflow = true;
}
if (esp_apptrace_uart_unlock(uart_data) != ESP_OK) {
if (esp_apptrace_uart_unlock(hw_data) != ESP_OK) {
assert(false && "Failed to unlock apptrace data!");
}
return ESP_OK;
}
static void send_buff_data(void *hw_data, esp_apptrace_tmo_t *tmo)
static void send_buff_data(esp_apptrace_uart_data_t *hw_data, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_uart_data_t *uart_data = hw_data;
if (uart_data->tx_data_buff_in == uart_data->tx_data_buff_out) {
if (hw_data->tx_data_buff_in == hw_data->tx_data_buff_out) {
return;
}
// We store current in position to handle it without lock
volatile int32_t in_position = uart_data->tx_data_buff_in;
if (in_position > uart_data->tx_data_buff_out) {
int bytes_sent = uart_write_bytes(uart_data->port_num,
&uart_data->tx_data_buff[uart_data->tx_data_buff_out],
in_position - uart_data->tx_data_buff_out);
uart_data->tx_data_buff_out += bytes_sent;
volatile int32_t in_position = hw_data->tx_data_buff_in;
if (in_position > hw_data->tx_data_buff_out) {
int bytes_sent = uart_write_bytes(hw_data->port_num, &hw_data->tx_data_buff[hw_data->tx_data_buff_out], in_position - hw_data->tx_data_buff_out);
hw_data->tx_data_buff_out += bytes_sent;
} else {
int bytes_sent = uart_write_bytes(uart_data->port_num,
&uart_data->tx_data_buff[uart_data->tx_data_buff_out],
uart_data->tx_data_buff_size - uart_data->tx_data_buff_out);
uart_data->tx_data_buff_out += bytes_sent;
if (uart_data->tx_data_buff_out >= uart_data->tx_data_buff_size) {
uart_data->tx_data_buff_out = 0;
int bytes_sent = uart_write_bytes(hw_data->port_num, &hw_data->tx_data_buff[hw_data->tx_data_buff_out], APP_TRACE_MAX_TX_BUFF_UART - hw_data->tx_data_buff_out);
hw_data->tx_data_buff_out += bytes_sent;
if (hw_data->tx_data_buff_out >= APP_TRACE_MAX_TX_BUFF_UART) {
hw_data->tx_data_buff_out = 0;
}
}
}
@@ -145,21 +131,20 @@ static void send_buff_data(void *hw_data, esp_apptrace_tmo_t *tmo)
static void esp_apptrace_send_uart_tx_task(void *arg)
{
esp_apptrace_uart_data_t *uart_data = arg;
esp_apptrace_uart_data_t *hw_data = (esp_apptrace_uart_data_t *)arg;
esp_apptrace_tmo_t tmo;
esp_apptrace_tmo_init(&tmo, APP_TRACE_UART_STOP_WAIT_TMO);
vTaskDelay(10);
while (1) {
send_buff_data(uart_data, &tmo);
send_buff_data(hw_data, &tmo);
vTaskDelay(10);
if (uart_data->circular_buff_overflow == true) {
uart_data->circular_buff_overflow = false;
if (hw_data->circular_buff_overflow == true) {
hw_data->circular_buff_overflow = false;
ESP_LOGE(TAG, "Buffer overflow. Please increase UART baudrate, or increase UART TX ring buffer size in menuconfig.");
}
if (uart_data->message_buff_overflow == true) {
uart_data->message_buff_overflow = false;
if (hw_data->message_buff_overflow == true) {
hw_data->message_buff_overflow = false;
ESP_LOGE(TAG, "Message size more then message buffer!");
}
}
@@ -167,181 +152,157 @@ static void esp_apptrace_send_uart_tx_task(void *arg)
static const int APP_TRACE_UART_RX_BUF_SIZE = 4024;
static esp_err_t esp_apptrace_uart_init(void *hw_data, const esp_apptrace_config_t *config)
static esp_err_t esp_apptrace_uart_init(esp_apptrace_uart_data_t *hw_data)
{
esp_apptrace_uart_data_t *uart_data = hw_data;
const esp_apptrace_uart_config_t *apptrace_uart_config = &config->dest_cfg.uart;
/* esp_apptrace_uart_init() is called on every core, so ensure to do main initialization only once */
int core_id = esp_cpu_get_core_id();
if (core_id == 0) {
uart_data->tx_data_buff_size = apptrace_uart_config->tx_buff_size;
uart_data->tx_data_buff = heap_caps_malloc(uart_data->tx_data_buff_size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
if (uart_data->tx_data_buff == NULL) {
hw_data->tx_data_buff = (uint8_t *)heap_caps_malloc(APP_TRACE_MAX_TX_BUFF_UART, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
if (hw_data->tx_data_buff == NULL) {
return ESP_ERR_NO_MEM;
}
uart_data->tx_data_buff_in = 0;
uart_data->tx_data_buff_out = 0;
uart_data->tx_msg_buff_size = apptrace_uart_config->tx_msg_size;
uart_data->tx_msg_buff = heap_caps_malloc(uart_data->tx_msg_buff_size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
if (uart_data->tx_msg_buff == NULL) {
hw_data->tx_data_buff_in = 0;
hw_data->tx_data_buff_out = 0;
hw_data->tx_msg_buff = (uint8_t *)heap_caps_malloc(APP_TRACE_MAX_TX_MSG_UART, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
if (hw_data->tx_msg_buff == NULL) {
return ESP_ERR_NO_MEM;
}
uart_data->tx_pending_msg_size = 0;
uart_data->down_buffer_size = 0;
uart_data->message_buff_overflow = false;
uart_data->circular_buff_overflow = false;
hw_data->tx_msg_buff_size = 0;
hw_data->down_buffer_size = 0;
hw_data->message_buff_overflow = false;
hw_data->circular_buff_overflow = false;
assert((uart_data->port_num <= SOC_UART_NUM) && "Not possible to configure UART. Please check selected UART port");
assert((hw_data->port_num <= SOC_UART_NUM) && "Not possible to configure UART. Please check selected UART port");
int source_clk = UART_SCLK_DEFAULT;
#if SOC_UART_LP_NUM > 0
if (uart_data->port_num >= SOC_UART_HP_NUM) {
if (hw_data->port_num >= SOC_UART_HP_NUM) {
source_clk = LP_UART_SCLK_DEFAULT;
}
#endif
const uart_config_t uart_config = {
.baud_rate = apptrace_uart_config->baud_rate,
.baud_rate = CONFIG_APPTRACE_UART_BAUDRATE,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.source_clk = source_clk,
};
ESP_LOGI(TAG, "UART baud rate: %i", apptrace_uart_config->baud_rate);
ESP_LOGI(TAG, "UART baud rate: %i", CONFIG_APPTRACE_UART_BAUDRATE);
// We won't use a buffer for sending data.
esp_err_t __attribute__((unused)) err = uart_driver_install(uart_data->port_num,
APP_TRACE_UART_RX_BUF_SIZE,
APP_TRACE_UART_RX_BUF_SIZE,
0,
NULL,
0);
assert((err == ESP_OK) && "Not possible to install UART. Please check and change uart parameters!");
err = uart_param_config(uart_data->port_num, &uart_config);
assert((err == ESP_OK) && "Not possible to configure UART. Please check and change uart parameters!");
err = uart_set_pin(uart_data->port_num,
apptrace_uart_config->tx_pin_num,
apptrace_uart_config->rx_pin_num,
UART_PIN_NO_CHANGE,
UART_PIN_NO_CHANGE);
assert((err == ESP_OK) && "Not possible to configure UART RX/TX pins. Please check and change the uart pins!");
esp_err_t err = uart_driver_install(hw_data->port_num, APP_TRACE_UART_RX_BUF_SIZE, APP_TRACE_UART_RX_BUF_SIZE, 0, NULL, 0);
assert((err == ESP_OK) && "Not possible to install UART. Please check and change menuconfig parameters!");
err = uart_param_config(hw_data->port_num, &uart_config);
assert((err == ESP_OK) && "Not possible to configure UART. Please check and change menuconfig parameters!");
err = uart_set_pin(hw_data->port_num, CONFIG_APPTRACE_UART_TX_GPIO, CONFIG_APPTRACE_UART_RX_GPIO, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
assert((err == ESP_OK) && "Not possible to configure UART RX/TX pins. Please check and change menuconfig parameters!");
int uart_prio = apptrace_uart_config->task_prio;
int uart_prio = CONFIG_APPTRACE_UART_TASK_PRIO;
if (uart_prio >= (configMAX_PRIORITIES - 1)) {
uart_prio = configMAX_PRIORITIES - 1;
}
err = xTaskCreate(esp_apptrace_send_uart_tx_task, "app_trace_uart_tx_task", 2500, uart_data, uart_prio, NULL);
err = xTaskCreate(esp_apptrace_send_uart_tx_task, "app_trace_uart_tx_task", 2500, hw_data, uart_prio, NULL);
assert((err == pdPASS) && "Not possible to configure UART. Not possible to create task!");
#if CONFIG_APPTRACE_LOCK_ENABLE
esp_apptrace_lock_init(&uart_data->lock);
esp_apptrace_lock_init(&hw_data->lock);
#endif
}
// init UART on this CPU
esp_apptrace_uart_hw_init();
uart_data->inited |= 1 << core_id;
hw_data->inited |= 1 << core_id;
return ESP_OK;
}
static uint8_t *esp_apptrace_uart_up_buffer_get(void *hw_data, uint32_t size, esp_apptrace_tmo_t *tmo)
static uint8_t *esp_apptrace_uart_up_buffer_get(esp_apptrace_uart_data_t *hw_data, uint32_t size, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_uart_data_t *uart_data = hw_data;
if (size > uart_data->tx_msg_buff_size) {
uart_data->message_buff_overflow = true;
uint8_t *ptr;
if (size > APP_TRACE_MAX_TX_MSG_UART) {
hw_data->message_buff_overflow = true;
return NULL;
}
if (uart_data->tx_pending_msg_size != 0) {
if (hw_data->tx_msg_buff_size != 0) {
// A previous message was not sent.
return NULL;
}
esp_err_t res = esp_apptrace_uart_lock(uart_data, tmo);
esp_err_t res = esp_apptrace_uart_lock(hw_data, tmo);
if (res != ESP_OK) {
return NULL;
}
uint8_t *ptr = uart_data->tx_msg_buff;
// Set the amount of data to send
uart_data->tx_pending_msg_size = size;
ptr = hw_data->tx_msg_buff;
hw_data->tx_msg_buff_size = size;
// now we can safely unlock apptrace to allow other tasks/ISRs to get other buffers and write their data
if (esp_apptrace_uart_unlock(uart_data) != ESP_OK) {
if (esp_apptrace_uart_unlock(hw_data) != ESP_OK) {
assert(false && "Failed to unlock apptrace data!");
}
return ptr;
}
static esp_err_t esp_apptrace_uart_up_buffer_put(void *hw_data, uint8_t *ptr, esp_apptrace_tmo_t *tmo)
static esp_err_t esp_apptrace_uart_up_buffer_put(esp_apptrace_uart_data_t *hw_data, uint8_t *ptr, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_uart_data_t *uart_data = hw_data;
esp_err_t res = esp_apptrace_send_uart_data(uart_data, (const char *)ptr, uart_data->tx_pending_msg_size, tmo);
esp_err_t res = esp_apptrace_send_uart_data(hw_data, (const char *)ptr, hw_data->tx_msg_buff_size, tmo);
// Clear size to indicate that we've sent data
uart_data->tx_pending_msg_size = 0;
hw_data->tx_msg_buff_size = 0;
return res;
}
static void esp_apptrace_uart_down_buffer_config(void *hw_data, uint8_t *buf, uint32_t size)
static void esp_apptrace_uart_down_buffer_config(esp_apptrace_uart_data_t *hw_data, uint8_t *buf, uint32_t size)
{
esp_apptrace_uart_data_t *uart_data = hw_data;
uart_data->down_buffer = (uint8_t *)malloc(size);
if (uart_data->down_buffer == NULL) {
hw_data->down_buffer = (uint8_t *)malloc(size);
if (hw_data->down_buffer == NULL) {
assert(false && "Failed to allocate apptrace uart down buffer!");
}
uart_data->down_buffer_size = size;
hw_data->down_buffer_size = size;
}
static uint8_t *esp_apptrace_uart_down_buffer_get(void *hw_data, uint32_t *size, esp_apptrace_tmo_t *tmo)
static uint8_t *esp_apptrace_uart_down_buffer_get(esp_apptrace_uart_data_t *hw_data, uint32_t *size, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_uart_data_t *uart_data = hw_data;
uint8_t *ptr = NULL;
if (*size > uart_data->down_buffer_size) {
if (*size > hw_data->down_buffer_size) {
return NULL;
}
esp_err_t res = esp_apptrace_uart_lock(uart_data, tmo);
esp_err_t res = esp_apptrace_uart_lock(hw_data, tmo);
if (res != ESP_OK) {
return NULL;
}
size_t uart_fifolen = 0;
uart_get_buffered_data_len(uart_data->port_num, &uart_fifolen);
uart_get_buffered_data_len(hw_data->port_num, &uart_fifolen);
if (uart_fifolen > 0) {
if (*size < uart_fifolen) {
uart_fifolen = *size;
}
*size = uart_fifolen;
ptr = uart_data->down_buffer;
*size = uart_read_bytes(uart_data->port_num, ptr, uart_fifolen, 0);
ptr = hw_data->down_buffer;
*size = uart_read_bytes(hw_data->port_num, ptr, uart_fifolen, 0);
}
if (esp_apptrace_uart_unlock(uart_data) != ESP_OK) {
if (esp_apptrace_uart_unlock(hw_data) != ESP_OK) {
assert(false && "Failed to unlock apptrace data!");
}
return ptr;
}
static esp_err_t esp_apptrace_uart_down_buffer_put(void *hw_data, uint8_t *ptr, esp_apptrace_tmo_t *tmo)
static esp_err_t esp_apptrace_uart_down_buffer_put(esp_apptrace_uart_data_t *hw_data, uint8_t *ptr, esp_apptrace_tmo_t *tmo)
{
return ESP_OK;
}
static bool esp_apptrace_uart_host_is_connected(void *hw_data)
static bool esp_apptrace_uart_host_is_connected(esp_apptrace_uart_data_t *hw_data)
{
esp_apptrace_uart_data_t *uart_data = hw_data;
return uart_data->inited & 1;
return hw_data->inited & 1;
}
static esp_err_t esp_apptrace_uart_flush_nolock(void *hw_data, uint32_t min_sz, esp_apptrace_tmo_t *tmo)
static esp_err_t esp_apptrace_uart_flush_nolock(esp_apptrace_uart_data_t *hw_data, uint32_t min_sz, esp_apptrace_tmo_t *tmo)
{
return ESP_OK;
}
static esp_err_t esp_apptrace_uart_flush(void *hw_data, esp_apptrace_tmo_t *tmo)
static esp_err_t esp_apptrace_uart_flush(esp_apptrace_uart_data_t *hw_data, esp_apptrace_tmo_t *tmo)
{
return ESP_OK;
}
@@ -352,15 +313,15 @@ esp_apptrace_hw_t *esp_apptrace_uart_hw_get(int num, void **data)
static esp_apptrace_uart_data_t s_uart_hw_data;
static esp_apptrace_hw_t s_uart_hw = {
.init = esp_apptrace_uart_init,
.get_up_buffer = esp_apptrace_uart_up_buffer_get,
.put_up_buffer = esp_apptrace_uart_up_buffer_put,
.flush_up_buffer_nolock = esp_apptrace_uart_flush_nolock,
.flush_up_buffer = esp_apptrace_uart_flush,
.down_buffer_config = esp_apptrace_uart_down_buffer_config,
.get_down_buffer = esp_apptrace_uart_down_buffer_get,
.put_down_buffer = esp_apptrace_uart_down_buffer_put,
.host_is_connected = esp_apptrace_uart_host_is_connected,
.init = (esp_err_t (*)(void *))esp_apptrace_uart_init,
.get_up_buffer = (uint8_t *(*)(void *, uint32_t, esp_apptrace_tmo_t *))esp_apptrace_uart_up_buffer_get,
.put_up_buffer = (esp_err_t (*)(void *, uint8_t *, esp_apptrace_tmo_t *))esp_apptrace_uart_up_buffer_put,
.flush_up_buffer_nolock = (esp_err_t (*)(void *, uint32_t, esp_apptrace_tmo_t *))esp_apptrace_uart_flush_nolock,
.flush_up_buffer = (esp_err_t (*)(void *, esp_apptrace_tmo_t *))esp_apptrace_uart_flush,
.down_buffer_config = (void (*)(void *, uint8_t *, uint32_t))esp_apptrace_uart_down_buffer_config,
.get_down_buffer = (uint8_t *(*)(void *, uint32_t *, esp_apptrace_tmo_t *))esp_apptrace_uart_down_buffer_get,
.put_down_buffer = (esp_err_t (*)(void *, uint8_t *, esp_apptrace_tmo_t *))esp_apptrace_uart_down_buffer_put,
.host_is_connected = (bool (*)(void *))esp_apptrace_uart_host_is_connected,
};
s_uart_hw_data.port_num = num;
*data = &s_uart_hw_data;

View File

@@ -7,7 +7,6 @@
#include "sdkconfig.h"
#include "esp_cpu.h"
#include "esp_log.h"
#include "esp_app_trace_config.h"
#include "esp_app_trace_membufs_proto.h"
#include "esp_app_trace_port.h"
#include "riscv/semihosting.h"
@@ -75,11 +74,10 @@ __attribute__((weak)) void esp_apptrace_get_up_buffers(esp_apptrace_mem_block_t
mem_blocks_cfg[1].sz = CONFIG_APPTRACE_BUF_SIZE;
}
static esp_err_t esp_apptrace_riscv_lock(void *hw_data, esp_apptrace_tmo_t *tmo)
static esp_err_t esp_apptrace_riscv_lock(esp_apptrace_riscv_data_t *hw_data, esp_apptrace_tmo_t *tmo)
{
#if CONFIG_APPTRACE_LOCK_ENABLE
esp_apptrace_riscv_data_t *riscv_data = hw_data;
esp_err_t ret = esp_apptrace_lock_take(&riscv_data->lock, tmo);
esp_err_t ret = esp_apptrace_lock_take(&hw_data->lock, tmo);
if (ret != ESP_OK) {
return ESP_FAIL;
}
@@ -87,12 +85,11 @@ static esp_err_t esp_apptrace_riscv_lock(void *hw_data, esp_apptrace_tmo_t *tmo)
return ESP_OK;
}
static esp_err_t esp_apptrace_riscv_unlock(void *hw_data)
static esp_err_t esp_apptrace_riscv_unlock(esp_apptrace_riscv_data_t *hw_data)
{
esp_err_t ret = ESP_OK;
#if CONFIG_APPTRACE_LOCK_ENABLE
esp_apptrace_riscv_data_t *riscv_data = hw_data;
ret = esp_apptrace_lock_give(&riscv_data->lock);
ret = esp_apptrace_lock_give(&hw_data->lock);
#endif
return ret;
}
@@ -101,96 +98,50 @@ static esp_err_t esp_apptrace_riscv_unlock(void *hw_data)
/***************************** Apptrace HW iface *****************************************/
/*****************************************************************************************/
static esp_err_t esp_apptrace_riscv_init(void *hw_data, const esp_apptrace_config_t *config)
static esp_err_t esp_apptrace_riscv_init(esp_apptrace_riscv_data_t *hw_data)
{
esp_apptrace_riscv_data_t *riscv_data = hw_data;
/* esp_apptrace_riscv_init() is called on every core, so ensure to do main initialization only once */
int core_id = esp_cpu_get_core_id();
if (core_id == 0) {
if (hw_data->inited == 0) {
esp_apptrace_mem_block_t mem_blocks_cfg[2];
esp_apptrace_get_up_buffers(mem_blocks_cfg);
riscv_data->membufs.header_size = ESP_APPTRACE_HEADER_SIZE_32;
esp_err_t res = esp_apptrace_membufs_init(&riscv_data->membufs, mem_blocks_cfg);
esp_err_t res = esp_apptrace_membufs_init(&hw_data->membufs, mem_blocks_cfg);
if (res != ESP_OK) {
ESP_APPTRACE_LOGE("Failed to init membufs proto (%d)!", res);
return res;
}
#if CONFIG_APPTRACE_LOCK_ENABLE
esp_apptrace_lock_init(&riscv_data->lock);
esp_apptrace_lock_init(&hw_data->lock);
#endif
}
riscv_data->inited |= 1 << core_id;
hw_data->inited |= 1 << core_id;
ESP_APPTRACE_LOGI("Apptrace initialized on CPU%d. Tracing control block @ %p.", core_id, &s_tracing_ctrl[core_id]);
s_tracing_ctrl[core_id].mem_blocks = riscv_data->membufs.blocks;
s_tracing_ctrl[core_id].mem_blocks = hw_data->membufs.blocks;
for (int i = 0; i < 2; i++) {
ESP_APPTRACE_LOGD("Mem buf[%d] %" PRIu32 " bytes @ %p (%p/%p)", i,
s_tracing_ctrl[core_id].mem_blocks[i].sz, s_tracing_ctrl[core_id].mem_blocks[i].start,
&(s_tracing_ctrl[core_id].mem_blocks[i].start), &(s_tracing_ctrl[core_id].mem_blocks[i].sz));
}
// notify host about control block address
int __attribute__((unused)) res = esp_apptrace_advertise_ctrl_block(&s_tracing_ctrl[core_id]);
int res = esp_apptrace_advertise_ctrl_block(&s_tracing_ctrl[core_id]);
assert(res == 0 && "Failed to send config to host!");
return ESP_OK;
}
static uint8_t *esp_apptrace_riscv_up_buffer_get(void *hw_data, uint32_t size, esp_apptrace_tmo_t *tmo)
static uint8_t *esp_apptrace_riscv_up_buffer_get(esp_apptrace_riscv_data_t *hw_data, uint32_t size, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_riscv_data_t *riscv_data = hw_data;
uint8_t *ptr;
if (!ESP_APPTRACE_RISCV_INITED(riscv_data)) {
if (!ESP_APPTRACE_RISCV_INITED(hw_data)) {
return NULL;
}
esp_err_t res = esp_apptrace_riscv_lock(riscv_data, tmo);
esp_err_t res = esp_apptrace_riscv_lock(hw_data, tmo);
if (res != ESP_OK) {
return NULL;
}
uint8_t *ptr = esp_apptrace_membufs_up_buffer_get(&riscv_data->membufs, size, tmo);
// now we can safely unlock apptrace to allow other tasks/ISRs to get other buffers and write their data
if (esp_apptrace_riscv_unlock(riscv_data) != ESP_OK) {
assert(false && "Failed to unlock apptrace data!");
}
return ptr;
}
static esp_err_t esp_apptrace_riscv_up_buffer_put(void *hw_data, uint8_t *ptr, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_riscv_data_t *riscv_data = hw_data;
if (!ESP_APPTRACE_RISCV_INITED(riscv_data)) {
return ESP_ERR_INVALID_STATE;
}
// Can avoid locking because esp_apptrace_membufs_up_buffer_put() just modifies buffer's header
esp_err_t res = esp_apptrace_membufs_up_buffer_put(&riscv_data->membufs, ptr, tmo);
return res;
}
static void esp_apptrace_riscv_down_buffer_config(void *hw_data, uint8_t *buf, uint32_t size)
{
esp_apptrace_riscv_data_t *riscv_data = hw_data;
if (!ESP_APPTRACE_RISCV_INITED(riscv_data)) {
return;
}
esp_apptrace_membufs_down_buffer_config(&riscv_data->membufs, buf, size);
}
static uint8_t *esp_apptrace_riscv_down_buffer_get(void *hw_data, uint32_t *size, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_riscv_data_t *riscv_data = hw_data;
if (!ESP_APPTRACE_RISCV_INITED(riscv_data)) {
return NULL;
}
esp_err_t res = esp_apptrace_riscv_lock(riscv_data, tmo);
if (res != ESP_OK) {
return NULL;
}
uint8_t *ptr = esp_apptrace_membufs_down_buffer_get(&riscv_data->membufs, size, tmo);
ptr = esp_apptrace_membufs_up_buffer_get(&hw_data->membufs, size, tmo);
// now we can safely unlock apptrace to allow other tasks/ISRs to get other buffers and write their data
if (esp_apptrace_riscv_unlock(hw_data) != ESP_OK) {
@@ -199,11 +150,48 @@ static uint8_t *esp_apptrace_riscv_down_buffer_get(void *hw_data, uint32_t *size
return ptr;
}
static esp_err_t esp_apptrace_riscv_down_buffer_put(void *hw_data, uint8_t *ptr, esp_apptrace_tmo_t *tmo)
static esp_err_t esp_apptrace_riscv_up_buffer_put(esp_apptrace_riscv_data_t *hw_data, uint8_t *ptr, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_riscv_data_t *riscv_data = hw_data;
if (!ESP_APPTRACE_RISCV_INITED(hw_data)) {
return ESP_ERR_INVALID_STATE;
}
// Can avoid locking because esp_apptrace_membufs_up_buffer_put() just modifies buffer's header
esp_err_t res = esp_apptrace_membufs_up_buffer_put(&hw_data->membufs, ptr, tmo);
return res;
}
if (!ESP_APPTRACE_RISCV_INITED(riscv_data)) {
static void esp_apptrace_riscv_down_buffer_config(esp_apptrace_riscv_data_t *hw_data, uint8_t *buf, uint32_t size)
{
if (!ESP_APPTRACE_RISCV_INITED(hw_data)) {
return;
}
esp_apptrace_membufs_down_buffer_config(&hw_data->membufs, buf, size);
}
static uint8_t *esp_apptrace_riscv_down_buffer_get(esp_apptrace_riscv_data_t *hw_data, uint32_t *size, esp_apptrace_tmo_t *tmo)
{
uint8_t *ptr;
if (!ESP_APPTRACE_RISCV_INITED(hw_data)) {
return NULL;
}
esp_err_t res = esp_apptrace_riscv_lock(hw_data, tmo);
if (res != ESP_OK) {
return NULL;
}
ptr = esp_apptrace_membufs_down_buffer_get(&hw_data->membufs, size, tmo);
// now we can safely unlock apptrace to allow other tasks/ISRs to get other buffers and write their data
if (esp_apptrace_riscv_unlock(hw_data) != ESP_OK) {
assert(false && "Failed to unlock apptrace data!");
}
return ptr;
}
static esp_err_t esp_apptrace_riscv_down_buffer_put(esp_apptrace_riscv_data_t *hw_data, uint8_t *ptr, esp_apptrace_tmo_t *tmo)
{
if (!ESP_APPTRACE_RISCV_INITED(hw_data)) {
return ESP_ERR_INVALID_STATE;
}
// Can avoid locking because esp_apptrace_membufs_down_buffer_put() does nothing
@@ -212,7 +200,7 @@ static esp_err_t esp_apptrace_riscv_down_buffer_put(void *hw_data, uint8_t *ptr,
return res;
}*/
esp_err_t res = esp_apptrace_membufs_down_buffer_put(&riscv_data->membufs, ptr, tmo);
esp_err_t res = esp_apptrace_membufs_down_buffer_put(&hw_data->membufs, ptr, tmo);
// now we can safely unlock apptrace to allow other tasks/ISRs to get other buffers and write their data
/*if (esp_apptrace_riscv_unlock(hw_data) != ESP_OK) {
@@ -221,42 +209,36 @@ static esp_err_t esp_apptrace_riscv_down_buffer_put(void *hw_data, uint8_t *ptr,
return res;
}
static bool esp_apptrace_riscv_host_is_connected(void *hw_data)
static bool esp_apptrace_riscv_host_is_connected(esp_apptrace_riscv_data_t *hw_data)
{
esp_apptrace_riscv_data_t *riscv_data = hw_data;
if (!ESP_APPTRACE_RISCV_INITED(riscv_data)) {
if (!ESP_APPTRACE_RISCV_INITED(hw_data)) {
return false;
}
return s_tracing_ctrl[esp_cpu_get_core_id()].ctrl & ESP_APPTRACE_RISCV_HOST_CONNECT ? true : false;
}
static esp_err_t esp_apptrace_riscv_flush_nolock(void *hw_data, uint32_t min_sz, esp_apptrace_tmo_t *tmo)
static esp_err_t esp_apptrace_riscv_flush_nolock(esp_apptrace_riscv_data_t *hw_data, uint32_t min_sz, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_riscv_data_t *riscv_data = hw_data;
if (!ESP_APPTRACE_RISCV_INITED(riscv_data)) {
if (!ESP_APPTRACE_RISCV_INITED(hw_data)) {
return ESP_ERR_INVALID_STATE;
}
return esp_apptrace_membufs_flush_nolock(&riscv_data->membufs, min_sz, tmo);
return esp_apptrace_membufs_flush_nolock(&hw_data->membufs, min_sz, tmo);
}
static esp_err_t esp_apptrace_riscv_flush(void *hw_data, esp_apptrace_tmo_t *tmo)
static esp_err_t esp_apptrace_riscv_flush(esp_apptrace_riscv_data_t *hw_data, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_riscv_data_t *riscv_data = hw_data;
if (!ESP_APPTRACE_RISCV_INITED(riscv_data)) {
if (!ESP_APPTRACE_RISCV_INITED(hw_data)) {
return ESP_ERR_INVALID_STATE;
}
esp_err_t res = esp_apptrace_riscv_lock(riscv_data, tmo);
esp_err_t res = esp_apptrace_riscv_lock(hw_data, tmo);
if (res != ESP_OK) {
return res;
}
res = esp_apptrace_membufs_flush_nolock(&riscv_data->membufs, 0, tmo);
res = esp_apptrace_membufs_flush_nolock(&hw_data->membufs, 0, tmo);
// now we can safely unlock apptrace to allow other tasks/ISRs to get other buffers and write their data
if (esp_apptrace_riscv_unlock(riscv_data) != ESP_OK) {
if (esp_apptrace_riscv_unlock(hw_data) != ESP_OK) {
assert(false && "Failed to unlock apptrace data!");
}
return res;
@@ -337,12 +319,6 @@ static bool esp_apptrace_riscv_host_data_pending(void)
return (ctrl_reg & ESP_APPTRACE_RISCV_HOST_DATA) ? true : false;
}
static void esp_apptrace_riscv_set_header_size(void *hw_data, esp_apptrace_header_size_t header_size)
{
esp_apptrace_riscv_data_t *riscv_data = hw_data;
riscv_data->membufs.header_size = header_size;
}
esp_apptrace_hw_t *esp_apptrace_jtag_hw_get(void **data)
{
static esp_apptrace_membufs_proto_hw_t s_trace_proto_hw = {
@@ -357,16 +333,15 @@ esp_apptrace_hw_t *esp_apptrace_jtag_hw_get(void **data)
},
};
static esp_apptrace_hw_t s_trace_hw = {
.init = esp_apptrace_riscv_init,
.get_up_buffer = esp_apptrace_riscv_up_buffer_get,
.put_up_buffer = esp_apptrace_riscv_up_buffer_put,
.flush_up_buffer_nolock = esp_apptrace_riscv_flush_nolock,
.flush_up_buffer = esp_apptrace_riscv_flush,
.down_buffer_config = esp_apptrace_riscv_down_buffer_config,
.get_down_buffer = esp_apptrace_riscv_down_buffer_get,
.put_down_buffer = esp_apptrace_riscv_down_buffer_put,
.host_is_connected = esp_apptrace_riscv_host_is_connected,
.set_header_size = esp_apptrace_riscv_set_header_size,
.init = (esp_err_t (*)(void *))esp_apptrace_riscv_init,
.get_up_buffer = (uint8_t *(*)(void *, uint32_t, esp_apptrace_tmo_t *))esp_apptrace_riscv_up_buffer_get,
.put_up_buffer = (esp_err_t (*)(void *, uint8_t *, esp_apptrace_tmo_t *))esp_apptrace_riscv_up_buffer_put,
.flush_up_buffer_nolock = (esp_err_t (*)(void *, uint32_t, esp_apptrace_tmo_t *))esp_apptrace_riscv_flush_nolock,
.flush_up_buffer = (esp_err_t (*)(void *, esp_apptrace_tmo_t *))esp_apptrace_riscv_flush,
.down_buffer_config = (void (*)(void *, uint8_t *, uint32_t))esp_apptrace_riscv_down_buffer_config,
.get_down_buffer = (uint8_t *(*)(void *, uint32_t *, esp_apptrace_tmo_t *))esp_apptrace_riscv_down_buffer_get,
.put_down_buffer = (esp_err_t (*)(void *, uint8_t *, esp_apptrace_tmo_t *))esp_apptrace_riscv_down_buffer_put,
.host_is_connected = (bool (*)(void *))esp_apptrace_riscv_host_is_connected,
};
*data = &s_trace_hw_data;
return &s_trace_hw;

View File

@@ -195,11 +195,10 @@ static uint8_t * const s_trax_blocks[] = {
(uint8_t *)TRACEMEM_BLK1_ADDR
};
static esp_err_t esp_apptrace_trax_lock(void *hw_data, esp_apptrace_tmo_t *tmo)
static esp_err_t esp_apptrace_trax_lock(esp_apptrace_trax_data_t *hw_data, esp_apptrace_tmo_t *tmo)
{
#if CONFIG_APPTRACE_LOCK_ENABLE
esp_apptrace_trax_data_t *trax_data = hw_data;
esp_err_t ret = esp_apptrace_lock_take(&trax_data->lock, tmo);
esp_err_t ret = esp_apptrace_lock_take(&hw_data->lock, tmo);
if (ret != ESP_OK) {
return ESP_FAIL;
}
@@ -207,12 +206,11 @@ static esp_err_t esp_apptrace_trax_lock(void *hw_data, esp_apptrace_tmo_t *tmo)
return ESP_OK;
}
static esp_err_t esp_apptrace_trax_unlock(void *hw_data)
static esp_err_t esp_apptrace_trax_unlock(esp_apptrace_trax_data_t *hw_data)
{
esp_err_t ret = ESP_OK;
#if CONFIG_APPTRACE_LOCK_ENABLE
esp_apptrace_trax_data_t *trax_data = hw_data;
ret = esp_apptrace_lock_give(&trax_data->lock);
ret = esp_apptrace_lock_give(&hw_data->lock);
#endif
return ret;
}
@@ -264,12 +262,11 @@ static inline void esp_apptrace_trax_memory_enable(void)
/***************************** Apptrace HW iface *****************************************/
/*****************************************************************************************/
static esp_err_t esp_apptrace_trax_init(void *hw_data, const esp_apptrace_config_t *config)
static esp_err_t esp_apptrace_trax_init(esp_apptrace_trax_data_t *hw_data)
{
esp_apptrace_trax_data_t *trax_data = hw_data;
int core_id = esp_cpu_get_core_id();
// 'esp_apptrace_trax_init()' is called on every core, so ensure to do main initialization only once
int core_id = esp_cpu_get_core_id();
if (core_id == 0) {
esp_apptrace_mem_block_t mem_blocks_cfg[2] = {
{
@@ -281,94 +278,87 @@ static esp_err_t esp_apptrace_trax_init(void *hw_data, const esp_apptrace_config
.sz = ESP_APPTRACE_TRAX_BLOCK_SIZE
},
};
trax_data->membufs.header_size = ESP_APPTRACE_HEADER_SIZE_32;
esp_err_t res = esp_apptrace_membufs_init(&trax_data->membufs, mem_blocks_cfg);
esp_err_t res = esp_apptrace_membufs_init(&hw_data->membufs, mem_blocks_cfg);
if (res != ESP_OK) {
ESP_APPTRACE_LOGE("Failed to init membufs proto (%d)!", res);
return res;
}
#if CONFIG_APPTRACE_LOCK_ENABLE
esp_apptrace_lock_init(&trax_data->lock);
esp_apptrace_lock_init(&hw_data->lock);
#endif
esp_apptrace_trax_memory_enable();
esp_apptrace_trax_select_memory_block(0);
}
// init TRAX on this CPU
esp_apptrace_trax_hw_init();
trax_data->inited |= 1 << core_id;
hw_data->inited |= 1 << core_id;
return ESP_OK;
}
static uint8_t *esp_apptrace_trax_up_buffer_get(void *hw_data, uint32_t size, esp_apptrace_tmo_t *tmo)
static uint8_t *esp_apptrace_trax_up_buffer_get(esp_apptrace_trax_data_t *hw_data, uint32_t size, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_trax_data_t *trax_data = hw_data;
uint8_t *ptr;
if (!ESP_APPTRACE_TRAX_INITED(trax_data)) {
if (!ESP_APPTRACE_TRAX_INITED(hw_data)) {
return NULL;
}
esp_err_t res = esp_apptrace_trax_lock(trax_data, tmo);
esp_err_t res = esp_apptrace_trax_lock(hw_data, tmo);
if (res != ESP_OK) {
return NULL;
}
uint8_t *ptr = esp_apptrace_membufs_up_buffer_get(&trax_data->membufs, size, tmo);
ptr = esp_apptrace_membufs_up_buffer_get(&hw_data->membufs, size, tmo);
// now we can safely unlock apptrace to allow other tasks/ISRs to get other buffers and write their data
if (esp_apptrace_trax_unlock(trax_data) != ESP_OK) {
if (esp_apptrace_trax_unlock(hw_data) != ESP_OK) {
assert(false && "Failed to unlock apptrace data!");
}
return ptr;
}
static esp_err_t esp_apptrace_trax_up_buffer_put(void *hw_data, uint8_t *ptr, esp_apptrace_tmo_t *tmo)
static esp_err_t esp_apptrace_trax_up_buffer_put(esp_apptrace_trax_data_t *hw_data, uint8_t *ptr, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_trax_data_t *trax_data = hw_data;
if (!ESP_APPTRACE_TRAX_INITED(trax_data)) {
if (!ESP_APPTRACE_TRAX_INITED(hw_data)) {
return ESP_ERR_INVALID_STATE;
}
// Can avoid locking because esp_apptrace_membufs_up_buffer_put() just modifies buffer's header
esp_err_t res = esp_apptrace_membufs_up_buffer_put(&trax_data->membufs, ptr, tmo);
esp_err_t res = esp_apptrace_membufs_up_buffer_put(&hw_data->membufs, ptr, tmo);
return res;
}
static void esp_apptrace_trax_down_buffer_config(void *hw_data, uint8_t *buf, uint32_t size)
static void esp_apptrace_trax_down_buffer_config(esp_apptrace_trax_data_t *hw_data, uint8_t *buf, uint32_t size)
{
esp_apptrace_trax_data_t *trax_data = hw_data;
if (!ESP_APPTRACE_TRAX_INITED(trax_data)) {
if (!ESP_APPTRACE_TRAX_INITED(hw_data)) {
return;
}
esp_apptrace_membufs_down_buffer_config(&trax_data->membufs, buf, size);
esp_apptrace_membufs_down_buffer_config(&hw_data->membufs, buf, size);
}
static uint8_t *esp_apptrace_trax_down_buffer_get(void *hw_data, uint32_t *size, esp_apptrace_tmo_t *tmo)
static uint8_t *esp_apptrace_trax_down_buffer_get(esp_apptrace_trax_data_t *hw_data, uint32_t *size, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_trax_data_t *trax_data = hw_data;
uint8_t *ptr;
if (!ESP_APPTRACE_TRAX_INITED(trax_data)) {
if (!ESP_APPTRACE_TRAX_INITED(hw_data)) {
return NULL;
}
esp_err_t res = esp_apptrace_trax_lock(trax_data, tmo);
esp_err_t res = esp_apptrace_trax_lock(hw_data, tmo);
if (res != ESP_OK) {
return NULL;
}
uint8_t *ptr = esp_apptrace_membufs_down_buffer_get(&trax_data->membufs, size, tmo);
ptr = esp_apptrace_membufs_down_buffer_get(&hw_data->membufs, size, tmo);
// now we can safely unlock apptrace to allow other tasks/ISRs to get other buffers and write their data
if (esp_apptrace_trax_unlock(trax_data) != ESP_OK) {
if (esp_apptrace_trax_unlock(hw_data) != ESP_OK) {
assert(false && "Failed to unlock apptrace data!");
}
return ptr;
}
static esp_err_t esp_apptrace_trax_down_buffer_put(void *hw_data, uint8_t *ptr, esp_apptrace_tmo_t *tmo)
static esp_err_t esp_apptrace_trax_down_buffer_put(esp_apptrace_trax_data_t *hw_data, uint8_t *ptr, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_trax_data_t *trax_data = hw_data;
if (!ESP_APPTRACE_TRAX_INITED(trax_data)) {
if (!ESP_APPTRACE_TRAX_INITED(hw_data)) {
return ESP_ERR_INVALID_STATE;
}
// Can avoid locking because esp_apptrace_membufs_down_buffer_put() does nothing
@@ -377,7 +367,7 @@ static esp_err_t esp_apptrace_trax_down_buffer_put(void *hw_data, uint8_t *ptr,
return res;
}*/
esp_err_t res = esp_apptrace_membufs_down_buffer_put(&trax_data->membufs, ptr, tmo);
esp_err_t res = esp_apptrace_membufs_down_buffer_put(&hw_data->membufs, ptr, tmo);
// now we can safely unlock apptrace to allow other tasks/ISRs to get other buffers and write their data
/*if (esp_apptrace_trax_unlock(hw_data) != ESP_OK) {
@@ -386,42 +376,36 @@ static esp_err_t esp_apptrace_trax_down_buffer_put(void *hw_data, uint8_t *ptr,
return res;
}
static bool esp_apptrace_trax_host_is_connected(void *hw_data)
static bool esp_apptrace_trax_host_is_connected(esp_apptrace_trax_data_t *hw_data)
{
esp_apptrace_trax_data_t *trax_data = hw_data;
if (!ESP_APPTRACE_TRAX_INITED(trax_data)) {
if (!ESP_APPTRACE_TRAX_INITED(hw_data)) {
return false;
}
return eri_read(ESP_APPTRACE_TRAX_CTRL_REG) & ESP_APPTRACE_TRAX_HOST_CONNECT ? true : false;
}
static esp_err_t esp_apptrace_trax_flush_nolock(void *hw_data, uint32_t min_sz, esp_apptrace_tmo_t *tmo)
static esp_err_t esp_apptrace_trax_flush_nolock(esp_apptrace_trax_data_t *hw_data, uint32_t min_sz, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_trax_data_t *trax_data = hw_data;
if (!ESP_APPTRACE_TRAX_INITED(trax_data)) {
if (!ESP_APPTRACE_TRAX_INITED(hw_data)) {
return ESP_ERR_INVALID_STATE;
}
return esp_apptrace_membufs_flush_nolock(&trax_data->membufs, min_sz, tmo);
return esp_apptrace_membufs_flush_nolock(&hw_data->membufs, min_sz, tmo);
}
static esp_err_t esp_apptrace_trax_flush(void *hw_data, esp_apptrace_tmo_t *tmo)
static esp_err_t esp_apptrace_trax_flush(esp_apptrace_trax_data_t *hw_data, esp_apptrace_tmo_t *tmo)
{
esp_apptrace_trax_data_t *trax_data = hw_data;
if (!ESP_APPTRACE_TRAX_INITED(trax_data)) {
if (!ESP_APPTRACE_TRAX_INITED(hw_data)) {
return ESP_ERR_INVALID_STATE;
}
esp_err_t res = esp_apptrace_trax_lock(trax_data, tmo);
esp_err_t res = esp_apptrace_trax_lock(hw_data, tmo);
if (res != ESP_OK) {
return res;
}
res = esp_apptrace_membufs_flush_nolock(&trax_data->membufs, 0, tmo);
res = esp_apptrace_membufs_flush_nolock(&hw_data->membufs, 0, tmo);
// now we can safely unlock apptrace to allow other tasks/ISRs to get other buffers and write their data
if (esp_apptrace_trax_unlock(trax_data) != ESP_OK) {
if (esp_apptrace_trax_unlock(hw_data) != ESP_OK) {
assert(false && "Failed to unlock apptrace data!");
}
return res;
@@ -510,12 +494,6 @@ static bool esp_apptrace_trax_host_data_pending(void)
return (ctrl_reg & ESP_APPTRACE_TRAX_HOST_DATA) ? true : false;
}
static void esp_apptrace_trax_set_header_size(void *hw_data, esp_apptrace_header_size_t header_size)
{
esp_apptrace_trax_data_t *trax_data = hw_data;
trax_data->membufs.header_size = header_size;
}
esp_apptrace_hw_t *esp_apptrace_jtag_hw_get(void **data)
{
static esp_apptrace_membufs_proto_hw_t s_trax_proto_hw = {
@@ -530,16 +508,15 @@ esp_apptrace_hw_t *esp_apptrace_jtag_hw_get(void **data)
},
};
static esp_apptrace_hw_t s_trax_hw = {
.init = esp_apptrace_trax_init,
.get_up_buffer = esp_apptrace_trax_up_buffer_get,
.put_up_buffer = esp_apptrace_trax_up_buffer_put,
.flush_up_buffer_nolock = esp_apptrace_trax_flush_nolock,
.flush_up_buffer = esp_apptrace_trax_flush,
.down_buffer_config = esp_apptrace_trax_down_buffer_config,
.get_down_buffer = esp_apptrace_trax_down_buffer_get,
.put_down_buffer = esp_apptrace_trax_down_buffer_put,
.host_is_connected = esp_apptrace_trax_host_is_connected,
.set_header_size = esp_apptrace_trax_set_header_size,
.init = (esp_err_t (*)(void *))esp_apptrace_trax_init,
.get_up_buffer = (uint8_t *(*)(void *, uint32_t, esp_apptrace_tmo_t *))esp_apptrace_trax_up_buffer_get,
.put_up_buffer = (esp_err_t (*)(void *, uint8_t *, esp_apptrace_tmo_t *))esp_apptrace_trax_up_buffer_put,
.flush_up_buffer_nolock = (esp_err_t (*)(void *, uint32_t, esp_apptrace_tmo_t *))esp_apptrace_trax_flush_nolock,
.flush_up_buffer = (esp_err_t (*)(void *, esp_apptrace_tmo_t *))esp_apptrace_trax_flush,
.down_buffer_config = (void (*)(void *, uint8_t *, uint32_t))esp_apptrace_trax_down_buffer_config,
.get_down_buffer = (uint8_t *(*)(void *, uint32_t *, esp_apptrace_tmo_t *))esp_apptrace_trax_down_buffer_get,
.put_down_buffer = (esp_err_t (*)(void *, uint8_t *, esp_apptrace_tmo_t *))esp_apptrace_trax_down_buffer_put,
.host_is_connected = (bool (*)(void *))esp_apptrace_trax_host_is_connected,
};
*data = &s_trax_hw_data;
return &s_trax_hw;

View File

@@ -40,7 +40,6 @@ typedef struct {
esp_apptrace_mem_block_t blocks[2]; // memory blocks
// ring buffer control struct for data from host (down buffer)
esp_apptrace_rb_t rb_down;
int header_size; ///< Size of the trace header (2 or 4 bytes)
} esp_apptrace_membufs_proto_data_t;
esp_err_t esp_apptrace_membufs_init(esp_apptrace_membufs_proto_data_t *proto, const esp_apptrace_mem_block_t blocks_cfg[2]);

View File

@@ -2,6 +2,7 @@
# CONFIG_DEPRECATED_OPTION CONFIG_NEW_OPTION
CONFIG_ESP32_APPTRACE_DESTINATION CONFIG_APPTRACE_DESTINATION
CONFIG_ESP32_APPTRACE_DEST_NONE CONFIG_APPTRACE_DEST_NONE
CONFIG_ESP32_APPTRACE_DEST_TRAX CONFIG_APPTRACE_DEST_JTAG
CONFIG_ESP32_APPTRACE_ENABLE CONFIG_APPTRACE_ENABLE
CONFIG_ESP32_APPTRACE_LOCK_ENABLE CONFIG_APPTRACE_LOCK_ENABLE

View File

@@ -32,12 +32,19 @@ static uint8_t s_events_buf[SYSVIEW_EVENTS_BUF_SZ];
static uint16_t s_events_buf_filled;
static uint8_t s_down_buf[SYSVIEW_DOWN_BUF_SIZE];
#if CONFIG_APPTRACE_SV_DEST_UART
#define ESP_APPTRACE_DEST_SYSVIEW ESP_APPTRACE_DEST_UART
#if CONFIG_APPTRACE_SV_DEST_CPU_0 || CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
#define APPTRACE_SV_DEST_CPU 0
#else
#define APPTRACE_SV_DEST_CPU 1
#endif // CONFIG_APPTRACE_SV_DEST_CPU_0
#elif CONFIG_APPTRACE_SV_DEST_JTAG || (CONFIG_APPTRACE_ENABLE && CONFIG_APPTRACE_DEST_UART_NONE)
#define ESP_APPTRACE_DEST_SYSVIEW ESP_APPTRACE_DEST_JTAG
#endif
/*********************************************************************
*
* Public code
@@ -63,13 +70,13 @@ void SEGGER_RTT_ESP_FlushNoLock(unsigned long min_sz, unsigned long tmo)
{
esp_err_t res;
if (s_events_buf_filled > 0) {
res = esp_apptrace_write(s_events_buf, s_events_buf_filled, tmo);
res = esp_apptrace_write(ESP_APPTRACE_DEST_SYSVIEW, s_events_buf, s_events_buf_filled, tmo);
if (res != ESP_OK) {
ESP_LOGE(TAG, "Failed to flush buffered events (%d)!", res);
}
}
// flush even if we failed to write buffered events, because no new events will be sent after STOP
res = esp_apptrace_flush_nolock(min_sz, tmo);
res = esp_apptrace_flush_nolock(ESP_APPTRACE_DEST_SYSVIEW, min_sz, tmo);
if (res != ESP_OK) {
ESP_LOGE(TAG, "Failed to flush apptrace data (%d)!", res);
}
@@ -117,7 +124,7 @@ void SEGGER_RTT_ESP_Flush(unsigned long min_sz, unsigned long tmo)
unsigned SEGGER_RTT_ReadNoLock(unsigned BufferIndex, void* pData, unsigned BufferSize)
{
uint32_t size = BufferSize;
esp_err_t res = esp_apptrace_read(pData, &size, 0);
esp_err_t res = esp_apptrace_read(ESP_APPTRACE_DEST_SYSVIEW, pData, &size, 0);
if (res != ESP_OK) {
return 0;
}
@@ -152,70 +159,70 @@ unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pBuffer, u
{
uint8_t *pbuf = (uint8_t *)pBuffer;
uint8_t event_id = *pbuf;
if (esp_apptrace_get_destination() == ESP_APPTRACE_DEST_UART) {
if (
(APPTRACE_SV_DEST_CPU != esp_cpu_get_core_id()) &&
(
(event_id == SYSVIEW_EVTID_ISR_ENTER) ||
(event_id == SYSVIEW_EVTID_ISR_EXIT) ||
(event_id == SYSVIEW_EVTID_TASK_START_EXEC) ||
(event_id == SYSVIEW_EVTID_TASK_STOP_EXEC) ||
(event_id == SYSVIEW_EVTID_TASK_START_READY) ||
(event_id == SYSVIEW_EVTID_TASK_STOP_READY) ||
(event_id == SYSVIEW_EVTID_MARK_START) ||
(event_id == SYSVIEW_EVTID_MARK_STOP) ||
(event_id == SYSVIEW_EVTID_TIMER_ENTER) ||
(event_id == SYSVIEW_EVTID_TIMER_EXIT) ||
(event_id == SYSVIEW_EVTID_STACK_INFO) ||
(event_id == SYSVIEW_EVTID_MODULEDESC)
)
) {
return NumBytes;
}
// This is workaround for SystemView!
// Without this line SystemView will hangs on when heap tracing enabled.
if (event_id == SYSVIEW_EVTID_MODULEDESC) {
return NumBytes;
}
#if CONFIG_APPTRACE_SV_DEST_UART
if (
(APPTRACE_SV_DEST_CPU != esp_cpu_get_core_id()) &&
(
(event_id == SYSVIEW_EVTID_ISR_ENTER) ||
(event_id == SYSVIEW_EVTID_ISR_EXIT) ||
(event_id == SYSVIEW_EVTID_TASK_START_EXEC) ||
(event_id == SYSVIEW_EVTID_TASK_STOP_EXEC) ||
(event_id == SYSVIEW_EVTID_TASK_START_READY) ||
(event_id == SYSVIEW_EVTID_TASK_STOP_READY) ||
(event_id == SYSVIEW_EVTID_MARK_START) ||
(event_id == SYSVIEW_EVTID_MARK_STOP) ||
(event_id == SYSVIEW_EVTID_TIMER_ENTER) ||
(event_id == SYSVIEW_EVTID_TIMER_EXIT) ||
(event_id == SYSVIEW_EVTID_STACK_INFO) ||
(event_id == SYSVIEW_EVTID_MODULEDESC)
)
) {
return NumBytes;
}
// This is workaround for SystemView!
// Without this line SystemView will hangs on when heap tracing enabled.
if (event_id == SYSVIEW_EVTID_MODULEDESC) {
return NumBytes;
}
#endif // CONFIG_APPTRACE_SV_DEST_UART
if (NumBytes > SYSVIEW_EVENTS_BUF_SZ) {
ESP_LOGE(TAG, "Too large event %u bytes!", NumBytes);
return 0;
}
if (esp_apptrace_get_destination() == ESP_APPTRACE_DEST_JTAG) {
if (esp_cpu_get_core_id()) { // dual core specific code
// use the highest - 1 bit of event ID to indicate core ID
// the highest bit can not be used due to event ID encoding method
// this reduces supported ID range to [0..63] (for 1 byte IDs) plus [128..16383] (for 2 bytes IDs)
if (*pbuf & 0x80) { // 2 bytes ID
*(pbuf + 1) |= (1 << 6);
} else if (NumBytes != 10 || *pbuf != 0) { // ignore sync sequence
*pbuf |= (1 << 6);
}
}
if (s_events_buf_filled + NumBytes > SYSVIEW_EVENTS_BUF_SZ) {
esp_err_t res = esp_apptrace_write(s_events_buf, s_events_buf_filled, SEGGER_HOST_WAIT_TMO);
if (res != ESP_OK) {
return 0; // skip current data buffer only, accumulated events are kept
}
s_events_buf_filled = 0;
#if CONFIG_APPTRACE_SV_DEST_JTAG
if (esp_cpu_get_core_id()) { // dual core specific code
// use the highest - 1 bit of event ID to indicate core ID
// the highest bit can not be used due to event ID encoding method
// this reduces supported ID range to [0..63] (for 1 byte IDs) plus [128..16383] (for 2 bytes IDs)
if (*pbuf & 0x80) { // 2 bytes ID
*(pbuf + 1) |= (1 << 6);
} else if (NumBytes != 10 || *pbuf != 0) { // ignore sync sequence
*pbuf |= (1 << 6);
}
}
memcpy(&s_events_buf[s_events_buf_filled], pBuffer, NumBytes);
s_events_buf_filled += NumBytes;
#endif // CONFIG_APPTRACE_SV_DEST_JTAG
#if CONFIG_APPTRACE_SV_DEST_JTAG
if (s_events_buf_filled + NumBytes > SYSVIEW_EVENTS_BUF_SZ) {
if (esp_apptrace_get_destination() == ESP_APPTRACE_DEST_UART) {
esp_err_t res = esp_apptrace_write(pBuffer, NumBytes, SEGGER_HOST_WAIT_TMO);
esp_err_t res = esp_apptrace_write(ESP_APPTRACE_DEST_SYSVIEW, s_events_buf, s_events_buf_filled, SEGGER_HOST_WAIT_TMO);
if (res != ESP_OK) {
return 0; // skip current data buffer only, accumulated events are kept
}
s_events_buf_filled = 0;
}
#endif
memcpy(&s_events_buf[s_events_buf_filled], pBuffer, NumBytes);
s_events_buf_filled += NumBytes;
#if CONFIG_APPTRACE_SV_DEST_UART
esp_err_t res = esp_apptrace_write(ESP_APPTRACE_DEST_SYSVIEW, pBuffer, NumBytes, SEGGER_HOST_WAIT_TMO);
if (res != ESP_OK) {
return 0; // skip current data buffer only, accumulated events are kept
}
s_events_buf_filled = 0;
#endif
if (event_id == SYSVIEW_EVTID_TRACE_STOP) {
SEGGER_RTT_ESP_FlushNoLock(0, SEGGER_STOP_WAIT_TMO);
@@ -281,20 +288,19 @@ int SEGGER_RTT_ConfigUpBuffer(unsigned BufferIndex, const char* sName, void* pBu
*/
int SEGGER_RTT_ConfigDownBuffer(unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags)
{
return esp_apptrace_down_buffer_config(s_down_buf, sizeof(s_down_buf));
return esp_apptrace_down_buffer_config(ESP_APPTRACE_DEST_SYSVIEW, s_down_buf, sizeof(s_down_buf));
}
/*************************** Init hook ****************************
*
* This init function is placed here because this port file will be linked whenever SystemView is used.
* It is used to initialize SystemView and app trace configuration by the init hook function.
* Otherwise, SystemView and app trace initialization needs to be done later in the app_main.
* This init function is placed here because this port file will be
* linked whenever SystemView is used.
*/
ESP_SYSTEM_INIT_FN(sysview_early_init, SECONDARY, BIT(0), 120)
{
esp_apptrace_set_header_size(ESP_APPTRACE_HEADER_SIZE_16);
SEGGER_SYSVIEW_Conf();
ESP_SYSTEM_INIT_FN(sysview_init, SECONDARY, BIT(0), 120)
{
SEGGER_SYSVIEW_Conf();
return ESP_OK;
}
/*************************** End of file ****************************/

View File

@@ -5,10 +5,9 @@ components/app_trace/test_apps:
- app_trace
- esp_timer
- soc
- driver
- esp_hw_support
- esp_driver_uart
- esp_driver_gptimer
disable:
- if: IDF_TARGET in ["esp32h21", "esp32h4"]
- if: IDF_TARGET in ["esp32c5", "esp32c61", "esp32h21", "esp32h4"]
temporary: true
reason: not support yet # TODO: [ESP32H21] IDF-11539 [ESP32H4] IDF-12325
reason: not support yet # TODO: [ESP32C5] IDF-8705, [ESP32C61] IDF-9306, [ESP32H21] IDF-11539 [ESP32H4] IDF-12325

View File

@@ -1,5 +1,5 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
# app_trace test

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -17,15 +17,16 @@
#include "freertos/semphr.h"
#include "freertos/task.h"
#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
#include "esp_log.h"
#include "esp_app_trace.h"
#include "esp_app_trace_util.h"
#define ESP_APPTRACE_TEST_USE_PRINT_LOCK 0
#define ESP_APPTRACE_TEST_PRN_WRERR_MAX 5
#define ESP_APPTRACE_TEST_BLOCKS_BEFORE_CRASH 100
#define ESP_APPTRACE_TEST_BLOCK_SIZE 1024
#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
#include "esp_log.h"
const static char *TAG = "esp_apptrace_test";
#if ESP_APPTRACE_TEST_USE_PRINT_LOCK == 1
@@ -66,9 +67,9 @@ const static char *TAG = "esp_apptrace_test";
#define ESP_APPTRACE_TEST_LOGO( format, ... ) ESP_APPTRACE_TEST_LOG_LEVEL(E, ESP_LOG_NONE, format, ##__VA_ARGS__)
#if CONFIG_APPTRACE_SV_ENABLE == 0
#define ESP_APPTRACE_TEST_WRITE(_b_, _s_) esp_apptrace_write(_b_, _s_, ESP_APPTRACE_TMO_INFINITE)
#define ESP_APPTRACE_TEST_WRITE_FROM_ISR(_b_, _s_) esp_apptrace_write(_b_, _s_, 0UL)
#define ESP_APPTRACE_TEST_WRITE_NOWAIT(_b_, _s_) esp_apptrace_write(_b_, _s_, 0)
#define ESP_APPTRACE_TEST_WRITE(_b_, _s_) esp_apptrace_write(ESP_APPTRACE_DEST_JTAG, _b_, _s_, ESP_APPTRACE_TMO_INFINITE)
#define ESP_APPTRACE_TEST_WRITE_FROM_ISR(_b_, _s_) esp_apptrace_write(ESP_APPTRACE_DEST_JTAG, _b_, _s_, 0UL)
#define ESP_APPTRACE_TEST_WRITE_NOWAIT(_b_, _s_) esp_apptrace_write(ESP_APPTRACE_DEST_JTAG, _b_, _s_, 0)
typedef struct {
uint8_t *buf;
@@ -624,7 +625,7 @@ static int esp_logtrace_printf(const char *fmt, ...)
va_start(ap, fmt);
int ret = esp_apptrace_vprintf_to(ESP_APPTRACE_TMO_INFINITE, fmt, ap);
int ret = esp_apptrace_vprintf_to(ESP_APPTRACE_DEST_JTAG, ESP_APPTRACE_TMO_INFINITE, fmt, ap);
va_end(ap);
@@ -656,7 +657,7 @@ static void esp_logtrace_task(void *p)
break;
}
}
esp_err_t ret = esp_apptrace_flush(ESP_APPTRACE_TMO_INFINITE);
esp_err_t ret = esp_apptrace_flush(ESP_APPTRACE_DEST_JTAG, ESP_APPTRACE_TMO_INFINITE);
if (ret != ESP_OK) {
ESP_APPTRACE_TEST_LOGE("Failed to flush printf buf (%d)!", ret);
}

View File

@@ -1,3 +1,2 @@
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n
CONFIG_APPTRACE_ENABLE=y
CONFIG_APPTRACE_DEST_JTAG=y

View File

@@ -89,10 +89,6 @@ esp_err_t esp_ota_begin(const esp_partition_t* partition, size_t image_size, esp
* Unlike esp_ota_begin(), this function does not erase the partition which receives the OTA update, but rather expects that part of the image
* has already been written correctly, and it resumes writing from the given offset.
*
* @note When flash encryption is enabled, data writes must be 16-byte aligned.
* Any leftover (non-aligned) data is temporarily cached and may be lost after reboot.
* Therefore, during resumption, ensure that image offset is always 16-byte aligned.
*
* @param partition Pointer to info for the partition which is receiving the OTA update. Required.
* @param erase_size Specifies how much flash memory to erase before resuming OTA, depending on whether a sequential write or a bulk erase is being used.
* @param image_offset Offset from where to resume the OTA process. Should be set to the number of bytes already written.

View File

@@ -32,8 +32,7 @@ set(COMPONENTS
main
efuse
esp_libc
esp_tee
esp_stdio)
esp_tee)
# EXTRA_COMPONENT_DIRS can be populated with directories containing one or several components.
# Make sure this variable contains `bootloader_components` directory of the project being compiled.

View File

@@ -69,9 +69,9 @@ SECTIONS
*libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
*libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
*libspi_flash.a:*.*(.literal .text .literal.* .text.*)
*libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
*libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
*libesp_hal_wdt.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
*libefuse.a:*.*(.literal .text .literal.* .text.*)

View File

@@ -89,10 +89,10 @@ SECTIONS
*libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
*libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
*libspi_flash.a:*.*(.literal .text .literal.* .text.*)
*libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
*libhal.a:cache_hal.*(.literal .text .literal.* .text.*)
*libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
*libesp_hal_wdt.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:regi2c_ctrl.*(.literal .text .literal.* .text.*)

View File

@@ -89,10 +89,10 @@ SECTIONS
*libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
*libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
*libspi_flash.a:*.*(.literal .text .literal.* .text.*)
*libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
*libhal.a:cache_hal.*(.literal .text .literal.* .text.*)
*libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
*libesp_hal_wdt.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:regi2c_ctrl.*(.literal .text .literal.* .text.*)

View File

@@ -87,10 +87,10 @@ SECTIONS
*libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
*libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
*libspi_flash.a:*.*(.literal .text .literal.* .text.*)
*libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
*libhal.a:cache_hal.*(.literal .text .literal.* .text.*)
*libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
*libesp_hal_wdt.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:regi2c_ctrl.*(.literal .text .literal.* .text.*)

View File

@@ -88,10 +88,10 @@ SECTIONS
*libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
*libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
*libspi_flash.a:*.*(.literal .text .literal.* .text.*)
*libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
*libhal.a:cache_hal.*(.literal .text .literal.* .text.*)
*libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
*libesp_hal_wdt.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:regi2c_ctrl.*(.literal .text .literal.* .text.*)

View File

@@ -87,10 +87,10 @@ SECTIONS
*libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
*libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
*libspi_flash.a:*.*(.literal .text .literal.* .text.*)
*libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
*libhal.a:cache_hal.*(.literal .text .literal.* .text.*)
*libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
*libesp_hal_wdt.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:regi2c_ctrl.*(.literal .text .literal.* .text.*)

View File

@@ -87,10 +87,10 @@ SECTIONS
*libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
*libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
*libspi_flash.a:*.*(.literal .text .literal.* .text.*)
*libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
*libhal.a:cache_hal.*(.literal .text .literal.* .text.*)
*libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
*libesp_hal_wdt.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:regi2c_ctrl.*(.literal .text .literal.* .text.*)

View File

@@ -87,10 +87,10 @@ SECTIONS
*libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
*libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
*libspi_flash.a:*.*(.literal .text .literal.* .text.*)
*libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
*libhal.a:cache_hal.*(.literal .text .literal.* .text.*)
*libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
*libesp_hal_wdt.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:regi2c_ctrl.*(.literal .text .literal.* .text.*)

View File

@@ -87,10 +87,10 @@ SECTIONS
*libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
*libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
*libspi_flash.a:*.*(.literal .text .literal.* .text.*)
*libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
*libhal.a:cache_hal.*(.literal .text .literal.* .text.*)
*libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
*libesp_hal_wdt.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:regi2c_ctrl.*(.literal .text .literal.* .text.*)

View File

@@ -86,11 +86,11 @@ SECTIONS
*libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
*libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
*libspi_flash.a:*.*(.literal .text .literal.* .text.*)
*libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
*libhal.a:cache_hal.*(.literal .text .literal.* .text.*)
*libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
*libhal.a:key_mgr_hal.*(.literal.key_mgr_hal_set_key_usage .text.key_mgr_hal_set_key_usage)
*libesp_hal_wdt.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:regi2c_ctrl.*(.literal .text .literal.* .text.*)

View File

@@ -86,11 +86,11 @@ SECTIONS
*libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
*libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
*libspi_flash.a:*.*(.literal .text .literal.* .text.*)
*libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
*libhal.a:cache_hal.*(.literal .text .literal.* .text.*)
*libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
*libhal.a:key_mgr_hal.*(.literal.key_mgr_hal_set_key_usage .text.key_mgr_hal_set_key_usage)
*libesp_hal_wdt.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:regi2c_ctrl.*(.literal .text .literal.* .text.*)

View File

@@ -56,10 +56,10 @@ SECTIONS
*libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
*libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
*libspi_flash.a:*.*(.literal .text .literal.* .text.*)
*libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
*libhal.a:cache_hal.*(.literal .text .literal.* .text.*)
*libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
*libesp_hal_wdt.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:regi2c_ctrl.*(.literal .text .literal.* .text.*)

View File

@@ -91,10 +91,10 @@ SECTIONS
*libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
*libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
*libspi_flash.a:*.*(.literal .text .literal.* .text.*)
*libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
*libhal.a:cache_hal.*(.literal .text .literal.* .text.*)
*libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
*libesp_hal_wdt.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
*libesp_hw_support.a:regi2c_ctrl.*(.literal .text .literal.* .text.*)

View File

@@ -72,7 +72,7 @@ endif()
if(BOOTLOADER_BUILD OR CONFIG_APP_BUILD_TYPE_RAM)
set(include_dirs "include" "bootloader_flash/include"
"private_include")
set(priv_requires micro-ecc spi_flash efuse esp_bootloader_format esp_app_format esptool_py esp_hal_wdt)
set(priv_requires micro-ecc spi_flash efuse esp_bootloader_format esp_app_format esptool_py)
list(APPEND srcs
"src/bootloader_init.c"
"src/bootloader_clock_loader.c"
@@ -84,11 +84,12 @@ if(BOOTLOADER_BUILD OR CONFIG_APP_BUILD_TYPE_RAM)
if(CONFIG_SECURE_ENABLE_TEE)
list(APPEND srcs "src/bootloader_utility_tee.c")
endif()
list(APPEND priv_requires hal)
else()
set(include_dirs "include" "bootloader_flash/include")
set(priv_include_dirs "private_include")
# heap is required for `heap_memory_layout.h` header
set(priv_requires spi_flash mbedtls efuse heap esp_bootloader_format esp_app_format esptool_py esp_hal_wdt)
set(priv_requires spi_flash mbedtls efuse heap esp_bootloader_format esp_app_format esptool_py)
endif()
if(BOOTLOADER_BUILD)

View File

@@ -138,7 +138,7 @@ esp_err_t bootloader_flash_erase_range(uint32_t start_addr, uint32_t size)
#include "esp_flash_partitions.h"
#include "rom/spi_flash.h"
extern bool esp_tee_flash_check_prange_in_active_tee_part(const size_t paddr, const size_t len);
extern bool esp_tee_flash_check_paddr_in_active_tee_part(size_t paddr);
#endif
ESP_LOG_ATTR_TAG(TAG, "bootloader_flash");
@@ -524,7 +524,7 @@ esp_err_t bootloader_flash_write(size_t dest_addr, void *src, size_t size, bool
* by validating the address before proceeding.
*/
#if ESP_TEE_BUILD
bool addr_chk = esp_tee_flash_check_prange_in_active_tee_part(dest_addr, size);
bool addr_chk = esp_tee_flash_check_paddr_in_active_tee_part(dest_addr);
if (addr_chk) {
ESP_EARLY_LOGE(TAG, "bootloader_flash_write invalid dest_addr");
return ESP_FAIL;
@@ -578,7 +578,7 @@ esp_err_t bootloader_flash_erase_sector(size_t sector)
esp_err_t bootloader_flash_erase_range(uint32_t start_addr, uint32_t size)
{
#if ESP_TEE_BUILD
bool addr_chk = esp_tee_flash_check_prange_in_active_tee_part(start_addr, size);
bool addr_chk = esp_tee_flash_check_paddr_in_active_tee_part(start_addr);
if (addr_chk) {
return ESP_ERR_INVALID_ARG;
}

View File

@@ -38,7 +38,7 @@ __attribute__((weak)) void bootloader_clock_configure(void)
#if CONFIG_IDF_TARGET_ESP32
/* On ESP32 rev 0, switching to 80/160 MHz if clock was previously set to
* 240 MHz may cause the chip to lock up (see CPU-3.5 of the errata
* 240 MHz may cause the chip to lock up (see section 3.5 of the errata
* document). For rev. 0, switch to 240 instead if it has been enabled
* previously.
*/

View File

@@ -1,19 +1,17 @@
/*
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
#include "bootloader_random.h"
#include "esp_log.h"
#include "soc/syscon_reg.h"
#include "soc/rtc_cntl_reg.h"
#include "soc/apb_saradc_reg.h"
#include "soc/system_reg.h"
#include "esp_private/regi2c_ctrl.h"
#include "hal/adc_ll.h"
#include "hal/temperature_sensor_ll.h"
#include "esp_private/sar_periph_ctrl.h"
#define ADC_RNG_CLKM_DIV_NUM 15
#define ADC_RNG_CLKM_DIV_B 0
#define ADC_RNG_CLKM_DIV_A 0
#include "soc/regi2c_saradc.h"
void bootloader_random_enable(void)
{
@@ -21,57 +19,49 @@ void bootloader_random_enable(void)
REG_SET_FIELD(RTC_CNTL_SENSOR_CTRL_REG, RTC_CNTL_FORCE_XPD_SAR, 0x3);
SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_PU_M);
#ifndef BOOTLOADER_BUILD
sar_periph_ctrl_adc_reset();
#else
tsens_ll_reg_values_t saved_tsens_regs = {};
tsens_ll_backup_registers(&saved_tsens_regs);
_adc_ll_reset_register();
// Restore temperature sensor related register values after ADC reset
_temperature_sensor_ll_reset_module();
tsens_ll_restore_registers(&saved_tsens_regs);
#endif
// Bridging sar2 internal reference voltage
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC2_ENCAL_REF_ADDR, 1);
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_DTEST_RTC_ADDR, 0);
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_ENT_RTC_ADDR, 0);
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_ENT_TSENS_ADDR, 0);
_adc_ll_enable_bus_clock(true);
adc_ll_enable_func_clock(true);
adc_ll_digi_clk_sel(ADC_DIGI_CLK_SRC_APB);
adc_ll_digi_controller_clk_div(ADC_RNG_CLKM_DIV_NUM, ADC_RNG_CLKM_DIV_B, ADC_RNG_CLKM_DIV_A);
adc_ll_digi_set_power_manage(ADC_LL_POWER_SW_ON);
adc_ll_digi_set_fsm_time(ADC_LL_FSM_RSTB_WAIT_DEFAULT, ADC_LL_FSM_START_WAIT_DEFAULT,
ADC_LL_FSM_STANDBY_WAIT_DEFAULT);
// Enable SAR ADC2 internal channel to read adc2 ref voltage for additional entropy
SET_PERI_REG_MASK(SYSTEM_PERIP_CLK_EN0_REG, SYSTEM_APB_SARADC_CLK_EN_M);
CLEAR_PERI_REG_MASK(SYSTEM_PERIP_RST_EN0_REG, SYSTEM_APB_SARADC_RST_M);
REG_SET_FIELD(APB_SARADC_APB_ADC_CLKM_CONF_REG, APB_SARADC_CLK_SEL, 0x2);
SET_PERI_REG_MASK(APB_SARADC_APB_ADC_CLKM_CONF_REG, APB_SARADC_CLK_EN_M);
SET_PERI_REG_MASK(APB_SARADC_CTRL_REG, APB_SARADC_SAR_CLK_GATED_M);
REG_SET_FIELD(APB_SARADC_CTRL_REG, APB_SARADC_XPD_SAR_FORCE, 0x3);
REG_SET_FIELD(APB_SARADC_CTRL_REG, APB_SARADC_SAR_CLK_DIV, 1);
#ifndef BOOTLOADER_BUILD
regi2c_saradc_enable();
#else
regi2c_ctrl_ll_i2c_sar_periph_enable();
#endif
// enable analog i2c master clock for RNG runtime
ANALOG_CLOCK_ENABLE();
adc_ll_regi2c_init();
REG_SET_FIELD(APB_SARADC_FSM_WAIT_REG, APB_SARADC_RSTB_WAIT, 8);
REG_SET_FIELD(APB_SARADC_FSM_WAIT_REG, APB_SARADC_XPD_WAIT, 5);
REG_SET_FIELD(APB_SARADC_FSM_WAIT_REG, APB_SARADC_STANDBY_WAIT, 100);
adc_digi_pattern_config_t pattern_config = {};
pattern_config.unit = ADC_UNIT_2;
pattern_config.atten = ADC_ATTEN_DB_12;
pattern_config.channel = ADC_CHANNEL_1; //Use reserved channel 10 to get internal voltage
adc_ll_digi_set_pattern_table(ADC_UNIT_2, 0, pattern_config);
adc_ll_digi_set_pattern_table_len(ADC_UNIT_2, 1);
adc_ll_digi_dma_enable();
adc_ll_digi_set_clk_div(1);
adc_ll_digi_set_trigger_interval(100);
adc_ll_digi_trigger_enable();
SET_PERI_REG_MASK(APB_SARADC_CTRL_REG, APB_SARADC_SAR_PATT_P_CLEAR_M);
CLEAR_PERI_REG_MASK(APB_SARADC_CTRL_REG, APB_SARADC_SAR_PATT_P_CLEAR_M);
REG_SET_FIELD(APB_SARADC_CTRL_REG, APB_SARADC_SAR_PATT_LEN, 0);
REG_SET_FIELD(APB_SARADC_SAR_PATT_TAB1_REG, APB_SARADC_SAR_PATT_TAB1, 0x9cffff);// Set adc2 internal channel & atten
REG_SET_FIELD(APB_SARADC_SAR_PATT_TAB2_REG, APB_SARADC_SAR_PATT_TAB2, 0xffffff);
// Set ADC sampling frequency
REG_SET_FIELD(APB_SARADC_CTRL2_REG, APB_SARADC_TIMER_TARGET, 100);
REG_SET_FIELD(APB_SARADC_APB_ADC_CLKM_CONF_REG, APB_SARADC_CLKM_DIV_NUM, 15);
CLEAR_PERI_REG_MASK(APB_SARADC_CTRL2_REG,APB_SARADC_MEAS_NUM_LIMIT);
SET_PERI_REG_MASK(APB_SARADC_DMA_CONF_REG, APB_SARADC_APB_ADC_TRANS_M);
SET_PERI_REG_MASK(APB_SARADC_CTRL2_REG,APB_SARADC_TIMER_EN);
}
void bootloader_random_disable(void)
{
_adc_ll_enable_bus_clock(false);
adc_ll_digi_trigger_disable();
adc_ll_digi_reset_pattern_table();
adc_ll_regi2c_adc_deinit();
#ifndef BOOTLOADER_BUILD
regi2c_saradc_disable();
#endif
// disable analog i2c master clock
ANALOG_CLOCK_DISABLE();
/* Restore internal I2C bus state */
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC2_ENCAL_REF_ADDR, 0);
/* Restore SARADC to default mode */
CLEAR_PERI_REG_MASK(APB_SARADC_CTRL2_REG,APB_SARADC_TIMER_EN);
CLEAR_PERI_REG_MASK(APB_SARADC_DMA_CONF_REG, APB_SARADC_APB_ADC_TRANS_M);
REG_SET_FIELD(APB_SARADC_SAR_PATT_TAB1_REG, APB_SARADC_SAR_PATT_TAB1, 0xffffff);
REG_SET_FIELD(APB_SARADC_SAR_PATT_TAB2_REG, APB_SARADC_SAR_PATT_TAB2, 0xffffff);
CLEAR_PERI_REG_MASK(APB_SARADC_APB_ADC_CLKM_CONF_REG, APB_SARADC_CLK_EN_M);
REG_SET_FIELD(APB_SARADC_CTRL_REG, APB_SARADC_XPD_SAR_FORCE, 0);
REG_SET_FIELD(RTC_CNTL_SENSOR_CTRL_REG, RTC_CNTL_FORCE_XPD_SAR, 0);
}

View File

@@ -717,25 +717,7 @@ static void load_image(const esp_image_metadata_t *image_data)
*/
ESP_LOGI(TAG, "Checking flash encryption...");
bool flash_encryption_enabled = esp_flash_encrypt_state();
if (flash_encryption_enabled) {
#if BOOTLOADER_BUILD
/* Ensure security eFuses are burnt */
esp_efuse_batch_write_begin();
esp_err_t err = esp_flash_encryption_enable_secure_features();
if (err != ESP_OK) {
ESP_LOGE(TAG, "Error setting security eFuses (err=0x%x).", err);
esp_efuse_batch_write_cancel();
return;
}
err = esp_efuse_batch_write_commit();
if (err != ESP_OK) {
ESP_LOGE(TAG, "Error programming security eFuses (err=0x%x).", err);
return;
}
ESP_LOGI(TAG, "Security eFuses are burnt");
#endif // BOOTLOADER_BUILD
} else {
if (!flash_encryption_enabled) {
#ifdef CONFIG_SECURE_FLASH_REQUIRE_ALREADY_ENABLED
ESP_LOGE(TAG, "flash encryption is not enabled, and SECURE_FLASH_REQUIRE_ALREADY_ENABLED is set, refusing to boot.");
return;

View File

@@ -50,9 +50,6 @@ set(ble_mesh_v11_include_dirs
"esp_ble_mesh/v1.1/api/core/include"
"esp_ble_mesh/v1.1/api/models/include"
"esp_ble_mesh/v1.1/btc/include"
"esp_ble_mesh/v1.1/include"
"esp_ble_mesh/v1.1/dfu"
"esp_ble_mesh/v1.1/mbt"
)
if(CONFIG_IDF_DOC_BUILD)
@@ -634,13 +631,9 @@ if(CONFIG_BT_ENABLED)
"esp_ble_mesh/v1.1/api/core/esp_ble_mesh_sar_model_api.c"
"esp_ble_mesh/v1.1/api/core/esp_ble_mesh_srpl_model_api.c"
"esp_ble_mesh/v1.1/api/models/esp_ble_mesh_mbt_model_api.c"
"esp_ble_mesh/v1.1/api/models/esp_ble_mesh_dfu_model_api.c"
"esp_ble_mesh/v1.1/api/models/esp_ble_mesh_dfu_slot_api.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_agg_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_brc_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_df_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_dfu_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_dfu_slot.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_lcd_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_mbt_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_odp_model.c"
@@ -648,12 +641,6 @@ if(CONFIG_BT_ENABLED)
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_rpr_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_sar_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_srpl_model.c"
"esp_ble_mesh/v1.1/mbt/blob_srv.c"
"esp_ble_mesh/v1.1/mbt/blob_cli.c"
"esp_ble_mesh/v1.1/dfu/dfu_cli.c"
"esp_ble_mesh/v1.1/dfu/dfu_srv.c"
"esp_ble_mesh/v1.1/dfu/dfu_slot.c"
"esp_ble_mesh/v1.1/dfu/dfu_metadata.c"
"esp_ble_mesh/lib/ext.c")
if(CONFIG_BLE_MESH_SAR_ENHANCEMENT)
list(APPEND srcs "esp_ble_mesh/core/transport.enh.c")
@@ -767,7 +754,6 @@ if(CONFIG_BT_ENABLED)
host/nimble/nimble/nimble/host/util/include
host/nimble/nimble/nimble/host/store/ram/include
host/nimble/nimble/nimble/host/store/config/include
host/nimble/nimble/nimble/host/services/ras/include
)
list(APPEND srcs "host/nimble/nimble/nimble/transport/src/transport.c"
@@ -788,8 +774,6 @@ if(CONFIG_BT_ENABLED)
"host/nimble/nimble/nimble/host/services/hid/src/ble_svc_hid.c"
"host/nimble/nimble/nimble/host/services/sps/src/ble_svc_sps.c"
"host/nimble/nimble/nimble/host/services/cte/src/ble_svc_cte.c"
"host/nimble/nimble/nimble/host/services/ras/src/ble_svc_ras.c"
"host/nimble/nimble/nimble/host/src/ble_cs.c"
"host/nimble/nimble/nimble/host/src/ble_hs_conn.c"
"host/nimble/nimble/nimble/host/src/ble_store_util.c"
"host/nimble/nimble/nimble/host/src/ble_sm.c"

View File

@@ -255,9 +255,3 @@ config BT_BLE_LOG_UHCI_OUT_UART_IO_NUM_TX
default 0
help
IO number for UART TX port
config BT_LE_USED_MEM_STATISTICS_ENABLED
bool "Enable used memory statistics"
default n
help
Used in internal tests only. Enable used memory statistics.

View File

@@ -89,10 +89,6 @@
SPI_OUT_HCI_QUEUE_SIZE +\
SPI_OUT_MESH_QUEUE_SIZE)
#if SPI_OUT_LL_ENABLED && CONFIG_SOC_ESP_NIMBLE_CONTROLLER
#include "os/os_mbuf.h"
#endif /* SPI_OUT_LL_ENABLED && CONFIG_SOC_ESP_NIMBLE_CONTROLLER */
// Private typedefs
typedef struct {
// CRITICAL: 0 for available, 1 for need queue (ISR), 2 for in queue
@@ -160,7 +156,6 @@ enum {
LL_LOG_FLAG_ISR,
LL_LOG_FLAG_HCI,
LL_LOG_FLAG_RAW,
LL_LOG_FLAG_OMDATA,
LL_LOG_FLAG_HCI_UPSTREAM,
};
@@ -210,7 +205,7 @@ static inline void spi_out_log_cb_append_trans(spi_out_log_cb_t *log_cb);
static inline void spi_out_log_cb_flush_trans(spi_out_log_cb_t *log_cb);
static bool spi_out_log_cb_write(spi_out_log_cb_t *log_cb, const uint8_t *addr, uint16_t len,
const uint8_t *addr_append, uint16_t len_append, uint8_t source,
bool with_checksum, bool omdata);
bool with_checksum);
static void spi_out_log_cb_write_loss(spi_out_log_cb_t *log_cb);
static void spi_out_log_cb_dump(spi_out_log_cb_t *log_cb);
@@ -587,7 +582,7 @@ IRAM_ATTR static inline void spi_out_log_cb_flush_trans(spi_out_log_cb_t *log_cb
// Return value: Need append
IRAM_ATTR static bool spi_out_log_cb_write(spi_out_log_cb_t *log_cb, const uint8_t *addr, uint16_t len,
const uint8_t *addr_append, uint16_t len_append, uint8_t source,
bool with_checksum, bool omdata)
bool with_checksum)
{
spi_out_trans_cb_t *trans_cb = log_cb->trans_cb[log_cb->trans_cb_idx];
@@ -603,16 +598,7 @@ IRAM_ATTR static bool spi_out_log_cb_write(spi_out_log_cb_t *log_cb, const uint8
memcpy(buf, (const uint8_t *)&head, SPI_OUT_FRAME_HEAD_LEN);
memcpy(buf + SPI_OUT_FRAME_HEAD_LEN, addr, len);
if (len_append && addr_append) {
#if SPI_OUT_LL_ENABLED && CONFIG_SOC_ESP_NIMBLE_CONTROLLER
if (omdata) {
os_mbuf_copydata((struct os_mbuf *)addr_append, 0,
len_append, buf + SPI_OUT_FRAME_HEAD_LEN + len);
}
else
#endif /* SPI_OUT_LL_ENABLED && CONFIG_SOC_ESP_NIMBLE_CONTROLLER */
{
memcpy(buf + SPI_OUT_FRAME_HEAD_LEN + len, addr_append, len_append);
}
memcpy(buf + SPI_OUT_FRAME_HEAD_LEN + len, addr_append, len_append);
}
uint32_t checksum = 0;
@@ -642,7 +628,7 @@ IRAM_ATTR static void spi_out_log_cb_write_loss(spi_out_log_cb_t *log_cb)
.lost_bytes_cnt = log_cb->lost_bytes_cnt,
};
spi_out_log_cb_write(log_cb, (const uint8_t *)&payload, sizeof(loss_payload_t),
NULL, 0, BLE_LOG_SPI_OUT_SOURCE_LOSS, true, false);
NULL, 0, BLE_LOG_SPI_OUT_SOURCE_LOSS, true);
log_cb->lost_frame_cnt = 0;
log_cb->lost_bytes_cnt = 0;
@@ -770,9 +756,9 @@ static void spi_out_write_hex(spi_out_log_cb_t *log_cb, uint8_t source,
if (with_ts) {
uint32_t os_ts = pdTICKS_TO_MS(xTaskGetTickCount());
need_append |= spi_out_log_cb_write(log_cb, (const uint8_t *)&os_ts,
sizeof(uint32_t), addr, len, source, true, false);
sizeof(uint32_t), addr, len, source, true);
} else {
need_append |= spi_out_log_cb_write(log_cb, addr, len, NULL, 0, source, true, false);
need_append |= spi_out_log_cb_write(log_cb, addr, len, NULL, 0, source, true);
}
}
if (need_append) {
@@ -1171,12 +1157,11 @@ IRAM_ATTR void ble_log_spi_out_ll_write(uint32_t len, const uint8_t *addr, uint3
log_cb = ll_task_log_cb;
source = BLE_LOG_SPI_OUT_SOURCE_ESP;
}
bool omdata = flag & BIT(LL_LOG_FLAG_OMDATA);
bool need_append;
if (spi_out_log_cb_check_trans(log_cb, (uint16_t)(len + len_append), &need_append)) {
need_append |= spi_out_log_cb_write(log_cb, addr, (uint16_t)len, addr_append,
(uint16_t)len_append, source, true, omdata);
(uint16_t)len_append, source, true);
}
if (need_append) {
if (in_isr) {
@@ -1303,7 +1288,7 @@ IRAM_ATTR void ble_log_spi_out_le_audio_write(const uint8_t *addr, uint16_t len)
bool need_append;
if (spi_out_log_cb_check_trans(log_cb, len, &need_append)) {
need_append |= spi_out_log_cb_write(log_cb, addr, len, NULL, 0,
BLE_LOG_SPI_OUT_SOURCE_LE_AUDIO, false, false);
BLE_LOG_SPI_OUT_SOURCE_LE_AUDIO, false);
}
if (need_append) {
spi_out_log_cb_append_trans(log_cb);

View File

@@ -39,10 +39,6 @@
#define UHCI_OUT_LL_QUEUE_SIZE (3 * UHCI_OUT_PING_PONG_BUF_CNT)
#define UHCI_OUT_QUEUE_SIZE (UHCI_OUT_USER_QUEUE_SIZE + UHCI_OUT_LL_QUEUE_SIZE)
#if CONFIG_SOC_ESP_NIMBLE_CONTROLLER
#include "os/os_mbuf.h"
#endif /* CONFIG_SOC_ESP_NIMBLE_CONTROLLER */
// Private typedefs
typedef struct {
// This flag is for multithreading, must be a word, do not modify
@@ -99,8 +95,7 @@ enum {
LL_LOG_FLAG_ISR,
LL_LOG_FLAG_HCI,
LL_LOG_FLAG_RAW,
LL_LOG_FLAG_OMDATA,
LL_LOG_FLAG_HCI_UPSTREAM,
LL_LOG_FLAG_SYNC
};
enum {
@@ -141,7 +136,7 @@ static inline bool uhci_out_log_cb_check_trans(uhci_out_log_cb_t *log_cb, uint16
static inline void uhci_out_log_cb_append_trans(uhci_out_log_cb_t *log_cb);
static inline void uhci_out_log_cb_flush_trans(uhci_out_log_cb_t *log_cb);
static bool uhci_out_log_cb_write(uhci_out_log_cb_t *log_cb, const uint8_t *addr, uint16_t len,
const uint8_t *addr_append, uint16_t len_append, uint8_t source, bool omdata);
const uint8_t *addr_append, uint16_t len_append, uint8_t source);
static void uhci_out_log_cb_write_loss(uhci_out_log_cb_t *log_cb);
static void uhci_out_log_cb_dump(uhci_out_log_cb_t *log_cb);
@@ -323,7 +318,7 @@ IRAM_ATTR static inline void uhci_out_log_cb_flush_trans(uhci_out_log_cb_t *log_
// Return value: Need append
IRAM_ATTR static bool uhci_out_log_cb_write(uhci_out_log_cb_t *log_cb, const uint8_t *addr, uint16_t len,
const uint8_t *addr_append, uint16_t len_append, uint8_t source, bool omdata)
const uint8_t *addr_append, uint16_t len_append, uint8_t source)
{
uhci_out_trans_cb_t *trans_cb = log_cb->trans_cb[log_cb->trans_cb_idx];
@@ -339,16 +334,7 @@ IRAM_ATTR static bool uhci_out_log_cb_write(uhci_out_log_cb_t *log_cb, const uin
memcpy(buf, (const uint8_t *)&head, UHCI_OUT_FRAME_HEAD_LEN);
memcpy(buf + UHCI_OUT_FRAME_HEAD_LEN, addr, len);
if (len_append && addr_append) {
#if CONFIG_SOC_ESP_NIMBLE_CONTROLLER
if (omdata) {
os_mbuf_copydata((struct os_mbuf *)addr_append, 0,
len_append, buf + UHCI_OUT_FRAME_HEAD_LEN + len);
}
else
#endif /* CONFIG_SOC_ESP_NIMBLE_CONTROLLER */
{
memcpy(buf + UHCI_OUT_FRAME_HEAD_LEN + len, addr_append, len_append);
}
memcpy(buf + UHCI_OUT_FRAME_HEAD_LEN + len, addr_append, len_append);
}
uint32_t checksum = 0;
@@ -379,7 +365,7 @@ IRAM_ATTR static void uhci_out_log_cb_write_loss(uhci_out_log_cb_t *log_cb)
.lost_bytes_cnt = log_cb->lost_bytes_cnt,
};
uhci_out_log_cb_write(log_cb, (const uint8_t *)&payload, sizeof(loss_payload_t),
NULL, 0, BLE_LOG_UHCI_OUT_SOURCE_LOSS, false);
NULL, 0, BLE_LOG_UHCI_OUT_SOURCE_LOSS);
log_cb->lost_frame_cnt = 0;
log_cb->lost_bytes_cnt = 0;
@@ -690,13 +676,12 @@ IRAM_ATTR void ble_log_uhci_out_ll_write(uint32_t len, const uint8_t *addr, uint
log_cb = ll_task_log_cb;
source = BLE_LOG_UHCI_OUT_SOURCE_ESP;
}
bool omdata = flag & BIT(LL_LOG_FLAG_OMDATA);
bool need_append;
uint16_t frame_len = len + len_append + UHCI_OUT_FRAME_OVERHEAD;
if (uhci_out_log_cb_check_trans(log_cb, frame_len, &need_append)) {
need_append |= uhci_out_log_cb_write(log_cb, addr, len, addr_append,
len_append, source, omdata);
len_append, source);
}
ll_last_write_ts = in_isr?\

View File

@@ -12,10 +12,6 @@
#include "ble_log_lbm.h"
#include "ble_log_rt.h"
#if CONFIG_SOC_ESP_NIMBLE_CONTROLLER
#include "os/os_mbuf.h"
#endif /* CONFIG_SOC_ESP_NIMBLE_CONTROLLER */
/* VARIABLE */
BLE_LOG_STATIC volatile uint32_t lbm_ref_count = 0;
BLE_LOG_STATIC bool lbm_inited = false;
@@ -29,7 +25,7 @@ BLE_LOG_STATIC void ble_log_lbm_release(ble_log_lbm_t *lbm);
BLE_LOG_STATIC
void ble_log_lbm_write_trans(ble_log_prph_trans_t **trans, ble_log_src_t src_code,
const uint8_t *addr, uint16_t len,
const uint8_t *addr_append, uint16_t len_append, bool omdata);
const uint8_t *addr_append, uint16_t len_append);
#if CONFIG_BLE_LOG_ENH_STAT_ENABLED
BLE_LOG_STATIC void ble_log_stat_mgr_update(ble_log_src_t src_code, uint32_t len, bool lost);
#endif /* CONFIG_BLE_LOG_ENH_STAT_ENABLED */
@@ -88,7 +84,7 @@ void ble_log_lbm_release(ble_log_lbm_t *lbm)
BLE_LOG_IRAM_ATTR BLE_LOG_STATIC
void ble_log_lbm_write_trans(ble_log_prph_trans_t **trans, ble_log_src_t src_code,
const uint8_t *addr, uint16_t len,
const uint8_t *addr_append, uint16_t len_append, bool omdata)
const uint8_t *addr_append, uint16_t len_append)
{
/* Preparation before writing */
uint8_t *buf = (*trans)->buf + (*trans)->pos;
@@ -106,16 +102,7 @@ void ble_log_lbm_write_trans(ble_log_prph_trans_t **trans, ble_log_src_t src_cod
BLE_LOG_MEMCPY(buf + BLE_LOG_FRAME_HEAD_LEN, addr, len);
}
if (len_append) {
#if CONFIG_SOC_ESP_NIMBLE_CONTROLLER
if (omdata) {
os_mbuf_copydata((struct os_mbuf *)addr_append, 0,
len_append, buf + BLE_LOG_FRAME_HEAD_LEN + len);
}
else
#endif /* CONFIG_SOC_ESP_NIMBLE_CONTROLLER */
{
BLE_LOG_MEMCPY(buf + BLE_LOG_FRAME_HEAD_LEN + len, addr_append, len_append);
}
BLE_LOG_MEMCPY(buf + BLE_LOG_FRAME_HEAD_LEN + len, addr_append, len_append);
}
/* Data integrity check */
@@ -442,7 +429,7 @@ bool ble_log_write_hex(ble_log_src_t src_code, const uint8_t *addr, size_t len)
xTaskGetTickCountFromISR():
xTaskGetTickCount());
ble_log_lbm_write_trans(trans, src_code, (const uint8_t *)&os_ts,
sizeof(uint32_t), addr, len, false);
sizeof(uint32_t), addr, len);
/* Release */
ble_log_lbm_release(lbm);
@@ -480,7 +467,6 @@ void ble_log_write_hex_ll(uint32_t len, const uint8_t *addr,
src_code = BLE_LOG_SRC_LL_TASK;
use_ll_task = true;
}
bool omdata = flag & BIT(BLE_LOG_LL_FLAG_OMDATA);
if (!lbm_enabled) {
goto exit;
@@ -503,7 +489,7 @@ void ble_log_write_hex_ll(uint32_t len, const uint8_t *addr,
}
/* Write transport */
ble_log_lbm_write_trans(trans, src_code, addr, len, addr_append, len_append, omdata);
ble_log_lbm_write_trans(trans, src_code, addr, len, addr_append, len_append);
ble_log_lbm_release(lbm);
BLE_LOG_REF_COUNT_RELEASE(&lbm_ref_count);

View File

@@ -158,7 +158,6 @@ enum {
BLE_LOG_LL_FLAG_ISR,
BLE_LOG_LL_FLAG_HCI,
BLE_LOG_LL_FLAG_RAW,
BLE_LOG_LL_FLAG_OMDATA,
BLE_LOG_LL_FLAG_HCI_UPSTREAM,
};
#endif /* CONFIG_BLE_LOG_LL_ENABLED */

View File

@@ -89,7 +89,6 @@
#include "btc_ble_mesh_rpr_model.h"
#include "btc_ble_mesh_sar_model.h"
#include "btc_ble_mesh_srpl_model.h"
#include "btc_ble_mesh_dfu_model.h"
#endif /* CONFIG_BLE_MESH_V11_SUPPORT */
#endif /* #if CONFIG_BLE_MESH */
@@ -263,9 +262,6 @@ static const btc_func_t profile_tab[BTC_PID_NUM] = {
#if CONFIG_BLE_MESH_MBT_SRV
[BTC_PID_MBT_SERVER] = {btc_ble_mesh_mbt_server_call_handler, btc_ble_mesh_mbt_server_cb_handler },
#endif /* CONFIG_BLE_MESH_MBT_SRV */
#if CONFIG_BLE_MESH_DFU_CLI
[BTC_PID_DFU_CLIENT] = {btc_ble_mesh_dfu_client_call_handler, btc_ble_mesh_dfu_client_cb_handler},
#endif /* CONFIG_BLE_MESH_DFU_CLI */
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT || CONFIG_BLE_MESH_USE_BLE_50
[BTC_PID_BLE_MESH_BLE_COEX] = {btc_ble_mesh_ble_call_handler, btc_ble_mesh_ble_cb_handler },
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT || CONFIG_BLE_MESH_USE_BLE_50 */

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -106,10 +106,6 @@ typedef enum {
BTC_PID_TIME_SCENE_SERVER,
BTC_PID_MBT_CLIENT,
BTC_PID_MBT_SERVER,
BTC_PID_BLOB_CLIENT,
BTC_PID_BLOB_SERVER,
BTC_PID_DFU_CLIENT,
BTC_PID_DFU_SERVER,
BTC_PID_BLE_MESH_BLE_COEX,
#endif /* CONFIG_BLE_MESH */
#if (BLE_FEAT_ISO_EN == TRUE)

View File

@@ -141,9 +141,7 @@
#define LOG_LOCAL_LEVEL_MAPPING LOG_LOCAL_LEVEL
#endif
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#define BT_LOG_LEVEL_CHECK(LAYER, LEVEL) (MAX(LAYER##_INITIAL_TRACE_LEVEL, LOG_LOCAL_LEVEL_MAPPING) >= BT_TRACE_LEVEL_##LEVEL)

View File

@@ -1972,7 +1972,6 @@ esp_err_t esp_bt_controller_disable(void)
#endif
esp_phy_disable(PHY_MODEM_BT);
s_time_phy_rf_just_enabled = 0;
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED;
esp_unregister_shutdown_handler(bt_shutdown);

View File

@@ -458,12 +458,10 @@ config BT_LE_LL_DUP_SCAN_LIST_COUNT
config BT_LE_LL_SCA
int "BLE Sleep clock accuracy"
range 0 3000
range 0 500
default 60
help
Sleep clock accuracy of our device (in ppm)
The Bluetooth LE spec requires a Sleep Clock Accuracy (SCA) of < ±500 ppm.
This options allows for a larger value to enable the use of less accurate clock sources.
config BT_LE_LL_PEER_SCA_SET_ENABLE
bool "Enable to set constant peer SCA"

View File

@@ -575,7 +575,7 @@ struct ext_funcs_t ext_funcs_ro = {
._esp_intr_alloc = esp_intr_alloc_wrapper,
._esp_intr_free = esp_intr_free_wrapper,
._malloc = bt_osi_mem_malloc_internal,
._free = bt_osi_mem_free_internal,
._free = bt_osi_mem_free,
._task_create = task_create_wrapper,
._task_delete = task_delete_wrapper,
._osi_assert = osi_assert_wrapper,

View File

@@ -60,7 +60,6 @@
#include "esp_partition.h"
#include "hal/wdt_hal.h"
#endif // CONFIG_BT_CTRL_LE_LOG_STORAGE_EN
#include "esp_rom_gpio.h"
#if CONFIG_BT_ENABLED
/* Macro definition
@@ -2401,9 +2400,4 @@ static void * coex_schm_curr_phase_get_wrapper(void)
#endif
}
void btdm_gpio_matrix_out(uint32_t gpio, uint32_t signal_idx, bool out_inv, bool oen_inv)
{
esp_rom_gpio_connect_out_signal(gpio, signal_idx, out_inv, oen_inv);
}
#endif /* CONFIG_BT_ENABLED */

View File

@@ -511,12 +511,10 @@ config BT_LE_LL_DUP_SCAN_LIST_COUNT
config BT_LE_LL_SCA
int "BLE Sleep clock accuracy"
range 0 3000
range 0 500
default 60
help
Sleep clock accuracy of our device (in ppm)
The Bluetooth LE spec requires a Sleep Clock Accuracy (SCA) of < ±500 ppm.
This options allows for a larger value to enable the use of less accurate clock sources.
config BT_LE_LL_PEER_SCA_SET_ENABLE
bool "Enable to set constant peer SCA"

View File

@@ -537,7 +537,7 @@ struct ext_funcs_t ext_funcs_ro = {
._esp_intr_alloc = esp_intr_alloc_wrapper,
._esp_intr_free = esp_intr_free_wrapper,
._malloc = bt_osi_mem_malloc_internal,
._free = bt_osi_mem_free_internal,
._free = bt_osi_mem_free,
._task_create = task_create_wrapper,
._task_delete = task_delete_wrapper,
._osi_assert = osi_assert_wrapper,

View File

@@ -552,12 +552,10 @@ config BT_LE_LL_DUP_SCAN_LIST_COUNT
config BT_LE_LL_SCA
int "BLE Sleep clock accuracy"
range 0 3000
range 0 500
default 60
help
Sleep clock accuracy of our device (in ppm)
The Bluetooth LE spec requires a Sleep Clock Accuracy (SCA) of < ±500 ppm.
This options allows for a larger value to enable the use of less accurate clock sources.
config BT_LE_LL_PEER_SCA_SET_ENABLE
bool "Enable to set constant peer SCA"

View File

@@ -553,7 +553,7 @@ struct ext_funcs_t ext_funcs_ro = {
._esp_intr_alloc = esp_intr_alloc_wrapper,
._esp_intr_free = esp_intr_free_wrapper,
._malloc = bt_osi_mem_malloc_internal,
._free = bt_osi_mem_free_internal,
._free = bt_osi_mem_free,
._task_create = task_create_wrapper,
._task_delete = task_delete_wrapper,
._osi_assert = osi_assert_wrapper,

View File

@@ -546,12 +546,10 @@ config BT_LE_LL_DUP_SCAN_LIST_COUNT
config BT_LE_LL_SCA
int "BLE Sleep clock accuracy"
range 0 3000
range 0 500
default 60
help
Sleep clock accuracy of our device (in ppm)
The Bluetooth LE spec requires a Sleep Clock Accuracy (SCA) of < ±500 ppm.
This options allows for a larger value to enable the use of less accurate clock sources.
config BT_LE_LL_PEER_SCA_SET_ENABLE
bool "Enable to set constant peer SCA"

View File

@@ -545,7 +545,7 @@ struct ext_funcs_t ext_funcs_ro = {
._esp_intr_alloc = esp_intr_alloc_wrapper,
._esp_intr_free = esp_intr_free_wrapper,
._malloc = bt_osi_mem_malloc_internal,
._free = bt_osi_mem_free_internal,
._free = bt_osi_mem_free,
._task_create = task_create_wrapper,
._task_delete = task_delete_wrapper,
._osi_assert = osi_assert_wrapper,

View File

@@ -41,86 +41,6 @@ if BLE_MESH
help
This option to enable BLE Mesh using some BLE 5.0 APIs.
menuconfig BLE_MESH_EXT_ADV
bool "Enable extended advertising for BLE Mesh"
depends on BLE_MESH_USE_BLE_50
default n
help
Enable broadcasting of BLE Mesh messages using BLE 5.0 extended advertising.
This allows control of extended advertising parameters (e.g., PHY selection)
while maintaining standard BLE Mesh packet length.
config BLE_MESH_EXT_ADV_BUF_COUNT
int "Number of extended advertising buffers"
depends on BLE_MESH_EXT_ADV
range 6 256
default 60
help
Number of buffer slots allocated for extended advertising packets.
config BLE_MESH_EXT_RELAY_ADV_BUF_COUNT
int "Number of extended relay advertising buffers"
depends on BLE_MESH_EXT_ADV
depends on BLE_MESH_RELAY
range 0 256
default 60
help
Number of buffer slots allocated for extended advertising packets used in message relay.
menuconfig BLE_MESH_LONG_PACKET
bool "Enable non-standard long packet mode for BLE Mesh"
depends on BLE_MESH_EXT_ADV
default n
help
Enable extended-length advertising packets for BLE Mesh using BLE 5.0 extended advertising.
This overrides the standard BLE Mesh packet length limitations.
config BLE_MESH_LONG_PACKET_ADV_LEN
int "Maximum advertising payload length"
depends on BLE_MESH_LONG_PACKET
range 30 249
default 105
help
Maximum payload length for extended advertising packets (bytes).
Range: 30-249 bytes.
Default: 105.
Note: Maximum access payload = (LENGTH - 17) × SEGMENT_COUNT
- Transmission: Uses BLE_MESH_LONG_PACKET_TX_SEG_CNT
- Reception: Uses BLE_MESH_LONG_PACKET_RX_SEG_CNT
config BLE_MESH_LONG_PACKET_ADV_BUF_COUNT
int "Long packet advertising buffer count"
depends on BLE_MESH_LONG_PACKET
default 20
help
Number of advertising buffers allocated for long packet transmissions.
config BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT
int "Long packet relay buffer count"
depends on BLE_MESH_LONG_PACKET
depends on BLE_MESH_RELAY
default 20
help
Number of advertising buffers allocated for relay long packets.
config BLE_MESH_LONG_PACKET_TX_SEG_CNT
int "Maximum transmission segments per message"
depends on BLE_MESH_LONG_PACKET
range 1 BLE_MESH_TX_SEG_MAX if BLE_MESH_TX_SEG_MAX < BLE_MESH_LONG_PACKET_ADV_BUF_COUNT
range 1 BLE_MESH_LONG_PACKET_ADV_BUF_COUNT if BLE_MESH_TX_SEG_MAX >= BLE_MESH_LONG_PACKET_ADV_BUF_COUNT
default 20
help
Maximum number of segments for outgoing long packet messages.
Upper bound: min(BLE_MESH_TX_SEG_MAX, BLE_MESH_LONG_PACKET_ADV_BUF_COUNT)
config BLE_MESH_LONG_PACKET_RX_SEG_CNT
int "Maximum reception segments per message"
depends on BLE_MESH_LONG_PACKET
range 1 BLE_MESH_LONG_PACKET_ADV_BUF_COUNT
default 20
help
Maximum number of segments supported for receiving long packet messages.
config BLE_MESH_ADV_INST_ID
depends on BLE_MESH_USE_BLE_50
int "Extended adv instance for Mesh normal packets"
@@ -1644,13 +1564,11 @@ if BLE_MESH
Enable support for Lighting server models.
config BLE_MESH_MBT_CLI
bool "BLOB Transfer Client model(Deprecated)"
bool "BLOB Transfer Client model"
depends on BLE_MESH_V11_SUPPORT
default n
help
Enable support for BLOB Transfer Client model.
Warn: This version of the Mesh Binary Large Object Transfer Model will be deprecated,
and a new version will be released in the future.
if BLE_MESH_MBT_CLI
@@ -1665,212 +1583,11 @@ if BLE_MESH
endif # BLE_MESH_MBT_CLI
config BLE_MESH_MBT_SRV
bool "BLOB Transfer Server model(Deprecated)"
bool "BLOB Transfer Server model"
depends on BLE_MESH_V11_SUPPORT
default n
help
Enable support for BLOB Transfer Server model.
Warn: This version of the Mesh Binary Large Object Transfer Model will be deprecated,
and a new version will be released in the future.
menu "Binary Larger Object Transfer model"
config BLE_MESH_BLOB_SRV
bool "Support for BLOB Transfer Server model"
depends on BLE_MESH_V11_SUPPORT
help
Enable the Binary Large Object (BLOB) Transfer Server model.
if BLE_MESH_BLOB_SRV
config BLE_MESH_BLOB_SRV_PULL_REQ_COUNT
int "Number of chunks to request for each pull"
default 4
range 1 16
help
In Pull mode (Pull BLOB Transfer Mode), the BLOB Transfer Server
requests a fixed number of chunks from the Client. Use this option to
control the chunk count in the request. If the BLOB Transfer Server
is instantiated on a Low Power node, the pull request count will be
trimmed to not overflow the Friend queue.
config BLE_MESH_BLOB_SIZE_MAX
int "Largest BLOB size in bytes"
default 524288
range 1 3257617792
help
The maximum object size a BLOB Transfer Server can receive.
config BLE_MESH_BLOB_BLOCK_SIZE_MIN
int "Minimum block size"
default 4096
range 64 1048576 # 2^6 - 2^20
help
Minimum acceptable block size in a BLOB transfer. The transfer block
size will be some number that is a power of two, and is between block
size min and block size max. If no such number exists, a compile
time warning will be issued.
config BLE_MESH_BLOB_BLOCK_SIZE_MAX
int "Maximum block size"
default 4096
range BLE_MESH_BLOB_BLOCK_SIZE_MIN 1048576
help
Maximum acceptable block size in a BLOB transfer. The transfer block
size will be some number that is a power of two, and is between block
size min and block size max. If no such number exists, a compile
time warning will be issued.
config BLE_MESH_BLOB_REPORT_TIMEOUT
int "Partial Block Report interval in Pull mode"
default 10
range 1 31
help
The timer value that Pull BLOB Transfer Server uses to report missed chunks.
config BLE_MESH_RX_BLOB_CHUNK_SIZE
depends on !BLE_MESH_ALIGN_CHUNK_SIZE_TO_MAX_SEGMENT
int "BLOB Server chunk size"
default 8
range 8 377
help
Set the chunk size for the BLOB Server.
The actual maximum chunk size depends on how many segments are
possible and will be clamped to the max possible if set above.
see also: BLE_MESH_RX_SEG_MAX,
and the maximum SDU a node can receive.
endif # BLE_MESH_BLOB_SRV
config BLE_MESH_BLOB_CLI
bool "Support for BLOB Transfer Client model"
depends on BLE_MESH_V11_SUPPORT
help
Enable the Binary Large Object (BLOB) Transfer Client model.
if BLE_MESH_BLOB_CLI
config BLE_MESH_BLOB_CLI_BLOCK_RETRIES
int "Number of retries per block"
default 5
help
Controls the number of times the client will attempt to resend missing
chunks to the BLOB receivers for every block.
config BLE_MESH_TX_BLOB_CHUNK_SIZE
depends on !BLE_MESH_ALIGN_CHUNK_SIZE_TO_MAX_SEGMENT
int "BLOB Client chunk size"
default 8
range 1 377
help
Set the chunk size for the BLOB Client.
The actual maximum chunk size depends on how many segments are
possible and will be clamped to the max possible if set above.
see also: BLE_MESH_TX_SEG_MAX,
and the maximum SDU a node can receive.
config BLE_MESH_TX_BLOB_CHUNK_SEND_INTERVAL
int "BLOB Client chunk send interval"
default 0
range 0 2147483647
help
Set the interval in milliseconds in which chunks are sent during the BLOB transfer.
Note: Without a delay between each sent chunk, the network might become too busy with the
BLOB transfer for other communications to succeed.
Note: Timing restrictions, like the timeout base, should be considered or changed
accordingly when setting this interval. Otherwise, the interval might be too big for the
timeout settings and cause timeouts.
endif # BLE_MESH_BLOB_CLI
menu "BLOB models common configuration"
visible if BLE_MESH_BLOB_SRV || BLE_MESH_BLOB_CLI
config BLE_MESH_BLOB_CHUNK_COUNT_MAX
int "Maximum chunk count per block"
default 256
range 1 2992
help
A BLOB transfer contains several blocks. Each block is made up of
several chunks. This option controls the maximum chunk count per
block.
config BLE_MESH_ALIGN_CHUNK_SIZE_TO_MAX_SEGMENT
bool "Align chunk size to max segmented message size"
default y
endmenu #BLOB models common configuration
endmenu # Binary Larger Object Transfer model
menu "Device Firmware Update model"
config BLE_MESH_DFU_SRV
bool "Support for Firmware Update Server model"
depends on BLE_MESH_BLOB_SRV
help
Enable the Firmware Update Server model.
config BLE_MESH_DFU_CLI
bool "Support for Firmware Update Client model"
depends on BLE_MESH_BLOB_CLI
help
Enable the Firmware Update Client model.
menu "Firmware Update model configuration"
visible if BLE_MESH_DFU_SRV || BLE_MESH_DFU_CLI
config BLE_MESH_DFU_FWID_MAXLEN
int "DFU FWID max length"
default 16
range 0 106
help
This value defines the maximum length of an image's firmware ID.
config BLE_MESH_DFU_METADATA_MAXLEN
int "DFU metadata max length"
default 32
range 18 255 if BLE_MESH_DFU_METADATA
range 0 255
help
This value defines the maximum length of an image's metadata.
config BLE_MESH_DFU_METADATA
bool "Support for the default metadata format"
help
This option adds a set of functions that can be used to encode and decode a firmware
metadata using the format defined in the Bluetooth mesh DFU subsystem.
config BLE_MESH_DFU_URI_MAXLEN
int "DFU URI max length"
default 32
range 0 255
help
This value defines the maximum length of an image's URI, not including
a string terminator.
endmenu #Firmware Update model configuration
config BLE_MESH_DFU_SLOTS
bool "Firmware image slot manager"
default y if BLE_MESH_DFU_CLI
help
Enable the DFU image slot manager, for managing firmware distribution slots
for the Firmware Update Client model.
if BLE_MESH_DFU_SLOTS
config BLE_MESH_DFU_SLOT_CNT
int "Number of firmware image slots"
default 1
range 1 32767
help
This value defines the number of firmware slots the DFU image slot manager
can keep simultaneously.
endif #BLE_MESH_DFU_SLOTS
endmenu # Device Firmware Update model
endmenu #Support for BLE Mesh Client/Server models

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -30,55 +30,8 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model,
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
if (ctx) {
if (ctx->addr == ESP_BLE_MESH_ADDR_UNASSIGNED) {
BT_ERR("Invalid destination address 0x0000");
return ESP_ERR_INVALID_ARG;
}
if (ctx->enh.adv_cfg_used &&
ctx->enh.adv_cfg.channel_map & BIT(3)) {
BT_ERR("Invalid channel map 0x%04x: bit 3 is reserved", ctx->enh.adv_cfg.channel_map);
return ESP_ERR_INVALID_ARG;
}
#if CONFIG_BLE_MESH_EXT_ADV
if (ctx->enh.ext_adv_cfg_used) {
if (ctx->enh.ext_adv_cfg.primary_phy == ESP_BLE_MESH_ADV_PHY_CODED) {
BT_ERR("Primary phy can't be set to coded phy");
return ESP_ERR_INVALID_ARG;
}
if (ctx->enh.ext_adv_cfg.primary_phy == ESP_BLE_MESH_ADV_PHY_UNASSIGNED) {
ctx->enh.ext_adv_cfg.primary_phy = ESP_BLE_MESH_ADV_PHY_DEFAULT;
}
if (ctx->enh.ext_adv_cfg.secondary_phy == ESP_BLE_MESH_ADV_PHY_UNASSIGNED) {
ctx->enh.ext_adv_cfg.secondary_phy = ESP_BLE_MESH_ADV_PHY_DEFAULT;
}
}
#if CONFIG_BLE_MESH_LONG_PACKET
if (ctx->enh.long_pkt_cfg_used &&
(ctx->enh.long_pkt_cfg != ESP_BLE_MESH_LONG_PACKET_FORCE &&
ctx->enh.long_pkt_cfg != ESP_BLE_MESH_LONG_PACKET_PREFER)) {
BT_ERR("Invalid long packet configuration %d (expected FORCE=1 or PREFER=2)",
ctx->enh.long_pkt_cfg);
}
if (ctx->enh.long_pkt_cfg_used && (op_len + length + mic_len > ESP_BLE_MESH_EXT_SDU_MAX_LEN)) {
BT_ERR("The length(%d) exceeds the maximum length supported by the long packet", length);
return ESP_ERR_INVALID_ARG;
}
if (((!ctx->enh.long_pkt_cfg_used) && op_len + length + mic_len > MIN(ESP_BLE_MESH_SDU_MAX_LEN, ESP_BLE_MESH_TX_SDU_MAX))) {
BT_ERR("Too large data length %d", length);
return ESP_ERR_INVALID_ARG;
}
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
#endif /* CONFIG_BLE_MESH_EXT_ADV */
} // if (ctx)
if (op_len + length + mic_len > MIN(ESP_BLE_MESH_SDU_MAX_LEN, ESP_BLE_MESH_TX_SDU_MAX)) {
BT_ERR("Too large data length %d", length);
if (ctx && ctx->addr == ESP_BLE_MESH_ADDR_UNASSIGNED) {
BT_ERR("Invalid destination address 0x0000");
return ESP_ERR_INVALID_ARG;
}
@@ -117,6 +70,11 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model,
ESP_BLE_MESH_MIC_LONG : ESP_BLE_MESH_MIC_SHORT;
}
if (op_len + length + mic_len > MIN(ESP_BLE_MESH_SDU_MAX_LEN, ESP_BLE_MESH_TX_SDU_MAX)) {
BT_ERR("Too large data length %d", length);
return ESP_ERR_INVALID_ARG;
}
if (act == BTC_BLE_MESH_ACT_MODEL_PUBLISH) {
bt_mesh_model_msg_init(model->pub->msg, opcode);
net_buf_simple_add_mem(model->pub->msg, data, length);

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -20,12 +20,6 @@ extern "C" {
/*!< The maximum length of a BLE Mesh message, including Opcode, Payload and TransMIC */
#define ESP_BLE_MESH_SDU_MAX_LEN 384
#if CONFIG_BLE_MESH_LONG_PACKET
/* Extended SDU maximum length (included Opcode, Payload and TransMIC) calculation:
* SEGMENT_COUNT × (ADV_PAYLOAD_LEN - 17 bytes overhead)
* 17 bytes = 9 bytes mesh network header + 4 bytes transport overhead + 4 bytes NetMIC */
#define ESP_BLE_MESH_EXT_SDU_MAX_LEN (CONFIG_BLE_MESH_LONG_PACKET_TX_SEG_CNT * (CONFIG_BLE_MESH_LONG_PACKET_ADV_LEN - 17))
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
/*!< Length of a short Mesh MIC. */
#define ESP_BLE_MESH_MIC_SHORT 4
@@ -619,166 +613,6 @@ struct esp_ble_mesh_model {
*/
#define ESP_BLE_MESH_MODEL_NONE ((esp_ble_mesh_model_t []){})
#if CONFIG_BLE_MESH_USE_BLE_50
#define ESP_BLE_MESH_ADV_CHAN_UNASSIGNED (0)
#define ESP_BLE_MESH_ADV_CHAN_37 BIT(0)
#define ESP_BLE_MESH_ADV_CHAN_38 BIT(1)
#define ESP_BLE_MESH_ADV_CHAN_39 BIT(2)
#define ESP_BLE_MESH_DEFAULT_CHANNEL_MAP (ESP_BLE_MESH_ADV_CHAN_37| \
ESP_BLE_MESH_ADV_CHAN_38| \
ESP_BLE_MESH_ADV_CHAN_39)
#define ESP_BLE_MESH_ADV_PHY_UNASSIGNED (0)
#define ESP_BLE_MESH_ADV_PHY_1M (1)
#define ESP_BLE_MESH_ADV_PHY_2M (2)
#define ESP_BLE_MESH_ADV_PHY_CODED (3)
#define ESP_BLE_MESH_ADV_PHY_DEFAULT ESP_BLE_MESH_ADV_PHY_1M
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
/**
* Enhanced configuration for Mesh messages with legacy advertising
*/
typedef struct {
/**
* Advertising interval in milliseconds.
* If set to 0, the Mesh protocol stack's xmit parameters are used.
* If set to another value (e.g., 10), the advertising interval will be 10 ms.
*/
uint32_t adv_itvl;
/**
* Number of advertising per packet.
* If set to 0, the Mesh protocol stack's xmit parameters are used.
* If set to another value (e.g., 3), the number of advertising per packet will be 3.
*/
uint8_t adv_cnt;
/**
* Advertising channel map.
* If set to 0, the protocol stack uses default channels.
* If set to another value (e.g., ESP_BLE_MESH_ADV_CHAN_37),
* the advertising channel map will be 0x01, the advertising
* packet will only advertise on channel 37.
*/
uint8_t channel_map;
} esp_ble_mesh_adv_cfg_t;
#if CONFIG_BLE_MESH_EXT_ADV
/** Enhanced configuration for Mesh messages with extended advertising */
typedef struct {
/**
* Primary PHY for advertising (ESP_BLE_MESH_ADV_PHY_1M or
* ESP_BLE_MESH_ADV_PHY_CODED).
* When using coded PHY, receivers must use coded scanning.
*/
uint8_t primary_phy;
/**
* Secondary PHY for advertising (ESP_BLE_MESH_ADV_PHY_1M,
* ESP_BLE_MESH_ADV_PHY_2M, or ESP_BLE_MESH_ADV_PHY_CODED).
* When using coded PHY, receivers must use coded scanning.
*/
uint8_t secondary_phy;
/**
* Include TX power in advertising packets (0: disabled, 1: enabled).
* Allows receivers/relays to maintain original transmission power.
*/
uint8_t include_tx_power:1;
/** Transmission power level (in dBm) */
int8_t tx_power;
} esp_ble_mesh_ext_adv_cfg_t;
#endif /* CONFIG_BLE_MESH_EXT_ADV */
#if CONFIG_BLE_MESH_LONG_PACKET
/** Force this message to use long packet format */
#define ESP_BLE_MESH_LONG_PACKET_FORCE (1)
/**
* Whether to use the long packet mode will be chosen by the protocol stack,
* which currently makes the decision based on message length.
* Advertising using the standard BLE Mesh protocol when possible.
* Switch to long packet mode for advertising when the standard BLE
* Mesh protocol cannot be used.
*/
#define ESP_BLE_MESH_LONG_PACKET_PREFER (2)
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
/** Enhanced message advertising parameters */
typedef struct {
/**
* Use custom advertising parameters (0: disabled, 1: enabled).
* When enabled, `adv_cfg` parameters override stack defaults.
*/
uint8_t adv_cfg_used:1;
#if CONFIG_BLE_MESH_EXT_ADV
/**
* Use extended advertising parameters (0: disabled, 1: enabled).
* When enabled, `ext_adv_cfg` parameters override stack defaults.
*/
uint8_t ext_adv_cfg_used:1;
#endif /* CONFIG_BLE_MESH_EXT_ADV */
#if CONFIG_BLE_MESH_LONG_PACKET
/**
* Control long packet usage (0: disabled, 1: enabled).
* When disabled, the protocol stack cannot use long packets to
* send this message.
*/
uint8_t long_pkt_cfg_used:1;
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
/** Standard advertising parameters */
esp_ble_mesh_adv_cfg_t adv_cfg;
#if CONFIG_BLE_MESH_EXT_ADV
/** Extended advertising parameters */
esp_ble_mesh_ext_adv_cfg_t ext_adv_cfg;
#endif /* CONFIG_BLE_MESH_EXT_ADV */
#if CONFIG_BLE_MESH_LONG_PACKET
/**
* Long packet configuration:
* - ESP_BLE_MESH_LONG_PACKET_FORCE
* - ESP_BLE_MESH_LONG_PACKET_PREFER
*/
uint8_t long_pkt_cfg:2;
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
} esp_ble_mesh_msg_enh_params_t;
#define ESP_BLE_MESH_ADV_CFG_NULL ((esp_ble_mesh_adv_cfg_t){0})
#define ESP_BLE_MESH_EXT_ADV_CFG_NULL ((esp_ble_mesh_ext_adv_cfg_t){0})
#define ESP_BLE_MESH_ADV_CFG_DEFAULT \
((esp_ble_mesh_adv_cfg_t){\
.adv_itvl= 0, \
.adv_cnt = 0, \
.channel_map = ESP_BLE_MESH_DEFAULT_CHANNEL_MAP, \
})
#define ESP_BLE_MESH_EXT_ADV_CFG_DEFAULT \
((esp_ble_mesh_ext_adv_cfg_t){ \
.primary_phy = ESP_BLE_MESH_ADV_PHY_1M, \
.secondary_phy = ESP_BLE_MESH_ADV_PHY_1M, \
.tx_power = 0x7f, \
.include_tx_power = false,\
})
#if CONFIG_BLE_MESH_LONG_PACKET
#define ESP_BLE_MESH_LONG_PACKET_DEF_ENH_SET(ADV_CFG, EXT_ADV_CFG, LONG_PACKET_CFG) \
((esp_ble_mesh_msg_enh_params_t){ \
.adv_cfg_used = true,\
.adv_cfg = ADV_CFG, \
.ext_adv_cfg_used = true, \
.ext_adv_cfg = EXT_ADV_CFG, \
.long_pkt_cfg_used = true, \
.long_pkt_cfg = LONG_PACKET_CFG, \
})
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
/** Message sending context.
* This structure is associated with struct bt_mesh_msg_ctx in mesh_access.h
*/
@@ -830,9 +664,6 @@ typedef struct {
/** Indicate if the message is sent by a node server model, no need to be initialized before sending message */
bool srv_send __attribute__((deprecated));
/** Enhanced message advertising parameters */
esp_ble_mesh_msg_enh_params_t enh;
} esp_ble_mesh_msg_ctx_t;
/** Provisioning properties & capabilities.
@@ -1982,12 +1813,8 @@ typedef union {
#define ESP_BLE_MESH_MODEL_ID_LIGHT_LC_SRV 0x130f
#define ESP_BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV 0x1310
#define ESP_BLE_MESH_MODEL_ID_LIGHT_LC_CLI 0x1311
#define ESP_BLE_MESH_MODEL_ID_MBT_SRV 0x14fe
#define ESP_BLE_MESH_MODEL_ID_MBT_CLI 0x14ff
#define ESP_BLE_MESH_MODEL_ID_BLOB_SRV 0x1400
#define ESP_BLE_MESH_MODEL_ID_BLOB_CLI 0x1401
#define ESP_BLE_MESH_MODEL_ID_DFU_SRV 0x1402
#define ESP_BLE_MESH_MODEL_ID_DFU_CLI 0x1403
#define ESP_BLE_MESH_MODEL_ID_MBT_SRV 0x1400
#define ESP_BLE_MESH_MODEL_ID_MBT_CLI 0x1401
/**
* esp_ble_mesh_opcode_config_client_get_t belongs to esp_ble_mesh_opcode_t, this typedef is only

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -1410,23 +1410,6 @@ typedef bt_mesh_client_user_data_t bt_mesh_mbt_client_t;
extern const struct bt_mesh_model_op bt_mesh_mbt_cli_op[];
extern const struct bt_mesh_model_cb bt_mesh_mbt_cli_cb;
#endif /* CONFIG_BLE_MESH_MBT_CLI */
#if CONFIG_BLE_MESH_BLOB_SRV
extern const struct bt_mesh_model_op _bt_mesh_blob_srv_op[];
extern const struct bt_mesh_model_cb _bt_mesh_blob_srv_cb;
#endif /* CONFIG_BLE_MESH_BLOB_SRV */
#if CONFIG_BLE_MESH_BLOB_CLI
typedef bt_mesh_client_user_data_t bt_mesh_blob_client_t;
extern const struct bt_mesh_model_op _bt_mesh_blob_cli_op[];
extern const struct bt_mesh_model_cb _bt_mesh_blob_cli_cb;
#endif /* CONFIG_BLE_MESH_BLOB_CLI */
#if CONFIG_BLE_MESH_DFU_SRV
extern const struct bt_mesh_model_op _bt_mesh_dfu_srv_op[];
extern const struct bt_mesh_model_cb _bt_mesh_dfu_srv_cb;
#endif /* CONFIG_BLE_MESH_DFU_SRV */
#if CONFIG_BLE_MESH_DFU_CLI
extern const struct bt_mesh_model_op _bt_mesh_dfu_cli_op[];
extern const struct bt_mesh_model_cb _bt_mesh_dfu_cli_cb;
#endif /* CONFIG_BLE_MESH_DFU_CLI */
static void btc_ble_mesh_model_op_set(esp_ble_mesh_model_t *model)
{
@@ -2222,9 +2205,9 @@ static void btc_ble_mesh_model_op_set(esp_ble_mesh_model_t *model)
case BLE_MESH_MODEL_ID_MBT_CLI:
model->op = (esp_ble_mesh_model_op_t *)bt_mesh_mbt_cli_op;
model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_mbt_cli_cb;
bt_mesh_mbt_client_t *mbt_cli = (bt_mesh_mbt_client_t *)model->user_data;
if (mbt_cli) {
mbt_cli->publish_status = btc_ble_mesh_mbt_client_publish_callback;
bt_mesh_mbt_client_t *cli = (bt_mesh_mbt_client_t *)model->user_data;
if (cli) {
cli->publish_status = btc_ble_mesh_mbt_client_publish_callback;
}
break;
#endif /* CONFIG_BLE_MESH_MBT_CLI */
@@ -2237,43 +2220,6 @@ static void btc_ble_mesh_model_op_set(esp_ble_mesh_model_t *model)
}
break;
#endif /* CONFIG_BLE_MESH_MBT_SRV */
#if CONFIG_BLE_MESH_BLOB_CLI
case BLE_MESH_MODEL_ID_BLOB_CLI:
model->op = (esp_ble_mesh_model_op_t *)_bt_mesh_blob_cli_op;
model->cb = (esp_ble_mesh_model_cbs_t *)&_bt_mesh_blob_cli_cb;
bt_mesh_blob_client_t *blob_cli = (bt_mesh_blob_client_t *)model->user_data;
if (blob_cli) {
/* TBD: do we need publish callback for Blob Transfer Client model? */
}
break;
#endif /* CONFIG_BLE_MESH_BLOB_CLI */
#if CONFIG_BLE_MESH_BLOB_SRV
case BLE_MESH_MODEL_ID_BLOB_SRV:
model->op = (esp_ble_mesh_model_op_t *)_bt_mesh_blob_srv_op;
model->cb = (esp_ble_mesh_model_cbs_t *)&_bt_mesh_blob_srv_cb;
if (model->pub) {
model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
}
break;
#endif /* CONFIG_BLE_MESH_BLOB_SRV */
#if CONFIG_BLE_MESH_DFU_CLI
case BLE_MESH_MODEL_ID_DFU_CLI:
model->op = (esp_ble_mesh_model_op_t *)_bt_mesh_dfu_cli_op;
model->cb = (esp_ble_mesh_model_cbs_t *)&_bt_mesh_dfu_cli_cb;
if (model->pub) {
model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
}
break;
#endif /* CONFIG_BLE_MESH_DFU_CLI */
#if CONFIG_BLE_MESH_DFU_SRV
case BLE_MESH_MODEL_ID_DFU_SRV:
model->op = (esp_ble_mesh_model_op_t *)_bt_mesh_dfu_srv_op;
model->cb = (esp_ble_mesh_model_cbs_t *)&_bt_mesh_dfu_srv_cb;
if (model->pub) {
model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
}
break;
#endif /* CONFIG_BLE_MESH_DFU_SRV */
default:
goto set_vnd_op;
}
@@ -3004,8 +2950,6 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg)
.msg_timeout = arg->model_send.msg_timeout,
};
memcpy(&param.ctx.enh, &arg->model_send.ctx->enh, sizeof(bt_mesh_msg_enh_params_t));
err = bt_mesh_client_send_msg(&param, buf, arg->model_send.need_rsp,
btc_ble_mesh_client_model_timeout_cb);
bt_mesh_free_buf(buf);

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -32,27 +32,6 @@ static inline void btc_ble_mesh_set_client_common_param(esp_ble_mesh_client_comm
output->ctx.send_cred = input->ctx.send_cred;
output->ctx.send_tag = input->ctx.send_tag;
output->msg_timeout = input->msg_timeout;
if (input->ctx.enh.adv_cfg_used) {
output->ctx.enh.adv_cfg_used = input->ctx.enh.adv_cfg_used;
output->ctx.enh.adv_cfg.adv_cnt = input->ctx.enh.adv_cfg.adv_cnt;
output->ctx.enh.adv_cfg.adv_itvl = input->ctx.enh.adv_cfg.adv_itvl;
output->ctx.enh.adv_cfg.channel_map = input->ctx.enh.adv_cfg.channel_map;
}
#if CONFIG_BLE_MESH_EXT_ADV
if (input->ctx.enh.ext_adv_cfg_used) {
output->ctx.enh.ext_adv_cfg_used = input->ctx.enh.ext_adv_cfg_used;
output->ctx.enh.ext_adv_cfg.primary_phy = input->ctx.enh.ext_adv_cfg.primary_phy;
output->ctx.enh.ext_adv_cfg.secondary_phy = input->ctx.enh.ext_adv_cfg.secondary_phy;
output->ctx.enh.ext_adv_cfg.include_tx_power = input->ctx.enh.ext_adv_cfg.include_tx_power;
output->ctx.enh.ext_adv_cfg.tx_power = input->ctx.enh.ext_adv_cfg.tx_power;
}
#if CONFIG_BLE_MESH_LONG_PACKET
if (input->ctx.enh.long_pkt_cfg_used) {
output->ctx.enh.long_pkt_cfg_used = input->ctx.enh.long_pkt_cfg_used;
output->ctx.enh.long_pkt_cfg = input->ctx.enh.long_pkt_cfg;
}
#endif
#endif
}
}

View File

@@ -37,7 +37,7 @@ extern "C" {
#endif
#endif
#define BLE_MESH_ADV_TASK_STACK_SIZE (3072)
#define BLE_MESH_ADV_TASK_STACK_SIZE 3072
#define BLE_MESH_ADV_TASK_NAME "mesh_adv_task"
#define BLE_MESH_ADV_TASK_PRIO (configMAX_PRIORITIES - 5)

View File

@@ -1,6 +1,6 @@
/*
* SPDX-FileCopyrightText: 2016 Wind River Systems, Inc.
* SPDX-FileContributor: 2018-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -49,8 +49,6 @@ struct k_work;
*/
typedef void (*k_work_handler_t)(struct k_work *work);
typedef int32_t k_timeout_t;
struct k_work {
k_work_handler_t handler;
int index;
@@ -143,65 +141,6 @@ struct k_work {
*/
#define K_FOREVER (-1)
/**
* @brief Define for delayable work type.
*
* This macro maps the Zephyr delayable work type `k_work_delayable`
* to the ESP-IDF type `k_delayed_work`.
*/
#define k_work_delayable k_delayed_work
/**
* @brief Reschedule a delayable work item.
*
* This macro maps to `k_delayed_work_submit`, which cancels
* any existing pending submission of the work item and reschedules
* it with the new timeout delay.
*
* @param work Pointer to delayable work item.
* @param delay Timeout delay value.
* @return See implementation of `k_delayed_work_submit`.
*/
#define k_work_reschedule k_delayed_work_submit
/**
* @brief Schedule a delayable work item.
*
* This macro maps to `k_delayed_work_submit`,
* which schedules a work item to be processed
* after the specified timeout delay. If the work
* is already pending, the new delay is applied.
*
* @param work Pointer to delayable work item.
* @param delay Timeout delay value.
* @return See implementation of `k_delayed_work_submit`.
*/
#define k_work_schedule k_delayed_work_submit
/**
* @brief Cancel a delayable work item.
*
* This macro maps to `k_delayed_work_cancel`,
* which cancels a pending work submission
* associated with a delayable work item.
*
* @param work Pointer to delayable work item.
* @return See implementation of `k_delayed_work_cancel`.
*/
#define k_work_cancel_delayable k_delayed_work_cancel
/**
* @brief Initialize a delayable work item.
*
* This macro maps to `k_delayed_work_init`,
* which initializes a delayable work item with
* the provided handler function.
*
* @param work Pointer to delayable work item.
* @param handler Work item handler function.
*/
#define k_work_init_delayable k_delayed_work_init
/**
* @brief Get system uptime (32-bit version).
*
@@ -221,27 +160,6 @@ struct k_delayed_work {
struct k_work work;
};
#define _K_DELAYABLE_WORK_INITIALIZER(work_handler) { \
.work = { \
.handler = work_handler, \
}, \
}
/**
* @brief Convert a work item to its containing delayable work structure.
*
* This function uses container_of to derive the address of the containing
* k_work_delayable structure from the address of the embedded k_work structure.
*
* @param work Pointer to the embedded k_work structure within a k_work_delayable.
* @return Pointer to the containing k_work_delayable structure.
*/
static inline struct k_work_delayable *
k_work_delayable_from_work(struct k_work *work)
{
return CONTAINER_OF(work, struct k_work_delayable, work);
}
/**
* @brief Submit a delayed work item to the system workqueue.
*
@@ -291,21 +209,6 @@ int k_delayed_work_submit_periodic(struct k_delayed_work *work, int32_t period);
*/
int32_t k_delayed_work_remaining_get(struct k_delayed_work *work);
/**
* @brief Check if a delayable work item is pending execution.
*
* This function checks whether a delayable work item has been scheduled
* and is waiting to be processed. It returns true if the work item is in
* pending state (waiting for timeout expiration or being in work queue).
*
* @param dwork Pointer to delayable work item.
* @return true if work is pending, false otherwise.
*/
static inline bool k_work_delayable_is_pending(struct k_work_delayable *dwork)
{
return k_delayed_work_remaining_get(dwork);
}
/**
* @brief Submit a work item to the system workqueue.
*
@@ -364,45 +267,10 @@ int k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler);
* @return Current uptime.
*/
int64_t k_uptime_get(void);
int64_t k_uptime_delta(int64_t *reftime);
void bt_mesh_timer_init(void);
void bt_mesh_timer_deinit(void);
/**
* @brief Initialize a statically-defined work item.
*
* This macro can be used to initialize a statically-defined workqueue work
* item, prior to its first use. For example,
*
* @code static K_WORK_DEFINE(<work>, <work_handler>); @endcode
*
* @param work Symbol name for work item object
* @param work_handler Function to invoke each time work item is processed.
*/
#define K_WORK_DEFINE(work, work_handler) \
struct k_work work = _K_WORK_INITIALIZER(work_handler)
/**
* @brief Initialize a statically-defined delayable work item.
*
* This macro can be used to initialize a statically-defined delayable
* work item, prior to its first use. For example,
*
* @code static K_WORK_DELAYABLE_DEFINE(<dwork>, <work_handler>); @endcode
*
* Note that if the runtime dependencies support initialization with
* k_work_init_delayable() using that will eliminate the initialized
* object in ROM that is produced by this macro and copied in at
* system startup.
*
* @param work Symbol name for delayable work item object
* @param work_handler Function to invoke each time work item is processed.
*/
#define K_WORK_DELAYABLE_DEFINE(work, work_handler) \
struct k_delayed_work work \
= _K_DELAYABLE_WORK_INITIALIZER(work_handler)
#ifdef __cplusplus
}
#endif

View File

@@ -15,8 +15,6 @@
#define _BLE_MESH_UTILS_H_
#include <stddef.h>
#include <sys/cdefs.h>
#include <errno.h>
#include "esp_bit_defs.h"
#include "mesh/types.h"
#include "utils_loops.h"
@@ -96,81 +94,6 @@ extern "C" {
#define WB_DN(x) ROUND_DOWN(x, sizeof(void *))
#endif
/**
* @brief Whether @p ptr is an element of @p array
*
* This macro can be seen as a slightly stricter version of @ref PART_OF_ARRAY
* in that it also ensures that @p ptr is aligned to an array-element boundary
* of @p array.
*
* In C, passing a pointer as @p array causes a compile error.
*
* @param array the array in question
* @param ptr the pointer to check
*
* @return 1 if @p ptr is part of @p array, 0 otherwise
*/
#define IS_ARRAY_ELEMENT(array, ptr) \
((ptr) && POINTER_TO_UINT(array) <= POINTER_TO_UINT(ptr) && \
POINTER_TO_UINT(ptr) < POINTER_TO_UINT(&(array)[ARRAY_SIZE(array)]) && \
(POINTER_TO_UINT(ptr) - POINTER_TO_UINT(array)) % sizeof((array)[0]) == 0)
/**
* @brief Index of @p ptr within @p array
*
* With `CONFIG_ASSERT=y`, this macro will trigger a runtime assertion
* when @p ptr does not fall into the range of @p array or when @p ptr
* is not aligned to an array-element boundary of @p array.
*
* In C, passing a pointer as @p array causes a compile error.
*
* @param array the array in question
* @param ptr pointer to an element of @p array
*
* @return the array index of @p ptr within @p array, on success
*/
#define ARRAY_INDEX(array, ptr) \
({ \
__ASSERT_NO_MSG(IS_ARRAY_ELEMENT(array, ptr)); \
(__typeof__((array)[0]) *)(ptr) - (array); \
})
/**
* @brief Divide and round up.
*
* Example:
* @code{.c}
* DIV_ROUND_UP(1, 2); // 1
* DIV_ROUND_UP(3, 2); // 2
* @endcode
*
* @param n Numerator.
* @param d Denominator.
*
* @return The result of @p n / @p d, rounded up.
*/
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
/**
* @brief Divide and round to the nearest integer.
*
* Example:
* @code{.c}
* DIV_ROUND_CLOSEST(5, 2); // 3
* DIV_ROUND_CLOSEST(5, -2); // -3
* DIV_ROUND_CLOSEST(5, 3); // 2
* @endcode
*
* @param n Numerator.
* @param d Denominator.
*
* @return The result of @p n / @p d, rounded to the nearest integer.
*/
#define DIV_ROUND_CLOSEST(n, d) \
((((n) < 0) ^ ((d) < 0)) ? ((n) - ((d) / 2)) / (d) : \
((n) + ((d) / 2)) / (d))
#ifndef ceiling_fraction
#define ceiling_fraction(numerator, divider) \
(((numerator) + ((divider) - 1)) / (divider))
@@ -202,21 +125,6 @@ extern "C" {
#define BIT(n) (1UL << (n))
#endif
/**
* @brief Set or clear a bit depending on a boolean value
*
* The argument @p var is a variable whose value is written to as a
* side effect.
*
* @param var Variable to be altered
* @param bit Bit number
* @param set if 0, clears @p bit in @p var; any other value sets @p bit
*/
#ifndef WRITE_BIT
#define WRITE_BIT(var, bit, set) \
((var) = (set) ? ((var) | BIT(bit)) : ((var) & ~BIT(bit)))
#endif
#ifndef BIT_MASK
#define BIT_MASK(n) (BIT(n) - 1)
#endif
@@ -311,20 +219,6 @@ const char *bt_hex(const void *buf, size_t len);
void mem_rcopy(uint8_t *dst, uint8_t const *src, uint16_t len);
/**
* @brief Checks if a value is within range.
*
* @note @p val is evaluated twice.
*
* @param val Value to be checked.
* @param min Lower bound (inclusive).
* @param max Upper bound (inclusive).
*
* @retval true If value is within range
* @retval false If the value is not within range
*/
#define IN_RANGE(val, min, max) ((val) >= (min) && (val) <= (max))
#ifdef __cplusplus
}
#endif

View File

@@ -1,7 +1,7 @@
/*
* SPDX-FileCopyrightText: 2016 Intel Corporation
* SPDX-FileCopyrightText: 2016 Wind River Systems, Inc.
* SPDX-FileContributor: 2018-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -43,28 +43,6 @@ uint32_t k_uptime_get_32(void)
return (uint32_t)(esp_timer_get_time() / 1000);
}
/**
* @brief Get elapsed time.
*
* This routine computes the elapsed time between the current system uptime
* and an earlier reference time, in milliseconds.
*
* @param reftime Pointer to a reference time, which is updated to the current
* uptime upon return.
*
* @return Elapsed time.
*/
int64_t k_uptime_delta(int64_t *reftime)
{
int64_t uptime, delta;
uptime = k_uptime_get();
delta = uptime - *reftime;
*reftime = uptime;
return delta;
}
void bt_mesh_timer_init(void)
{
bm_alarm_hash_map = hash_map_new(BLE_MESH_ALARM_HASH_MAP_SIZE,

View File

@@ -2,7 +2,7 @@
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -29,15 +29,10 @@
#define BLE_MESH_SDU_MAX_LEN 384
/* Extended SDU maximum length (message length + TransMIC size) calculation:
* 32 segments maximum × (249 bytes max PDU - 17 bytes overhead)
* 17 bytes = 9 bytes mesh header + 4 bytes transport overhead + 4-byte NetMIC */
#define BLE_MESH_EXT_SDU_MAX_LEN (32*(249-17))
extern const struct bt_mesh_comp *comp_0;
static uint16_t dev_primary_addr;
static int model_send(const struct bt_mesh_model *model,
static int model_send(struct bt_mesh_model *model,
struct bt_mesh_net_tx *tx, bool implicit_bind,
struct net_buf_simple *msg,
const struct bt_mesh_send_cb *cb, void *cb_data);
@@ -300,7 +295,7 @@ static void mod_publish(struct k_work *work)
}
}
struct bt_mesh_elem *bt_mesh_model_elem(const struct bt_mesh_model *mod)
struct bt_mesh_elem *bt_mesh_model_elem(struct bt_mesh_model *mod)
{
return &comp_0->elem[mod->elem_idx];
}
@@ -548,31 +543,12 @@ struct bt_mesh_elem *bt_mesh_elem_find(uint16_t addr)
return NULL;
}
bool bt_mesh_has_addr(uint16_t addr)
{
uint16_t index;
if (BLE_MESH_ADDR_IS_UNICAST(addr)) {
return bt_mesh_elem_find(addr) != NULL;
}
for (index = 0; index < comp_0->elem_count; index++) {
struct bt_mesh_elem *elem = &comp_0->elem[index];
if (bt_mesh_elem_find_group(elem, addr)) {
return true;
}
}
return false;
}
uint8_t bt_mesh_elem_count(void)
{
return comp_0->elem_count;
}
static bool model_has_key(const struct bt_mesh_model *mod, uint16_t key)
static bool model_has_key(struct bt_mesh_model *mod, uint16_t key)
{
int i;
@@ -654,7 +630,7 @@ static int get_opcode(struct net_buf_simple *buf, uint32_t *opcode, bool pull_bu
if (pull_buf) {
*opcode = net_buf_simple_pull_u8(buf) << 16;
/* Using LE for the CID since the model layer is defined as
* little-endian in the mesh spec and using BLE_MESH_MODEL_OP_3
* little-endian in the mesh spec and using BT_MESH_MODEL_OP_3
* will declare the opcode in this way.
*/
*opcode |= net_buf_simple_pull_le16(buf);
@@ -812,7 +788,7 @@ void bt_mesh_model_msg_init(struct net_buf_simple *msg, uint32_t opcode)
case 3:
net_buf_simple_add_u8(msg, ((opcode >> 16) & 0xff));
/* Using LE for the CID since the model layer is defined as
* little-endian in the mesh spec and using BLE_MESH_MODEL_OP_3
* little-endian in the mesh spec and using BT_MESH_MODEL_OP_3
* will declare the opcode in this way.
*/
net_buf_simple_add_le16(msg, opcode & 0xffff);
@@ -970,7 +946,7 @@ void bt_mesh_choose_better_security_cred(struct bt_mesh_net_tx *tx)
}
#endif /* !CONFIG_BLE_MESH_V11_SUPPORT */
static int model_send(const struct bt_mesh_model *model,
static int model_send(struct bt_mesh_model *model,
struct bt_mesh_net_tx *tx, bool implicit_bind,
struct net_buf_simple *msg,
const struct bt_mesh_send_cb *cb, void *cb_data)
@@ -997,24 +973,10 @@ static int model_send(const struct bt_mesh_model *model,
return -EINVAL;
}
#if CONFIG_BLE_MESH_LONG_PACKET
if (msg->len > MIN(BLE_MESH_EXT_TX_SDU_MAX, BLE_MESH_EXT_SDU_MAX_LEN) - BLE_MESH_MIC_SHORT) {
BT_ERR("Too big ext message (len %d)", msg->len);
return -EMSGSIZE;
}
if ((msg->len <= MIN(BLE_MESH_EXT_TX_SDU_MAX, BLE_MESH_EXT_SDU_MAX_LEN) - BLE_MESH_MIC_SHORT) &&
(msg->len > MIN(BLE_MESH_TX_SDU_MAX, BLE_MESH_SDU_MAX_LEN) - BLE_MESH_MIC_SHORT) &&
!tx->ctx->enh.long_pkt_cfg_used) {
BT_ERR("Extended message length %d requires long packet mode, but long_pkt_cfg_used is false", msg->len);
return -EMSGSIZE;
}
#else
if (msg->len > MIN(BLE_MESH_TX_SDU_MAX, BLE_MESH_SDU_MAX_LEN) - BLE_MESH_MIC_SHORT) {
BT_ERR("Too big message (len %d)", msg->len);
return -EMSGSIZE;
}
#endif
if (!implicit_bind && !model_has_key(model, tx->ctx->app_idx)) {
BT_ERR("Model not bound to AppKey 0x%04x", tx->ctx->app_idx);
@@ -1060,7 +1022,7 @@ int bt_mesh_model_send_implicit(struct bt_mesh_model *model,
return model_send(model, &tx, implicit_bind, msg, cb, cb_data);
}
int bt_mesh_model_send(const struct bt_mesh_model *model,
int bt_mesh_model_send(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *msg,
const struct bt_mesh_send_cb *cb, void *cb_data)

View File

@@ -29,8 +29,6 @@ uint8_t bt_mesh_elem_count(void);
/* Find local element based on unicast or group address */
struct bt_mesh_elem *bt_mesh_elem_find(uint16_t addr);
bool bt_mesh_has_addr(uint16_t addr);
uint16_t *bt_mesh_model_find_group(struct bt_mesh_model *mod, uint16_t addr);
int bt_mesh_get_opcode(struct net_buf_simple *buf,

View File

@@ -2,7 +2,7 @@
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -60,7 +60,6 @@ static inline int adv_send(struct net_buf *buf)
void *cb_data = BLE_MESH_ADV(buf)->cb_data;
struct bt_mesh_adv_param param = {0};
uint16_t duration = 0U, adv_int = 0U;
uint8_t adv_cnt = 0;
struct bt_mesh_adv_data ad = {0};
int err = 0;
@@ -70,20 +69,10 @@ static inline int adv_send(struct net_buf *buf)
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
if (BLE_MESH_ADV(buf)->type != BLE_MESH_ADV_BLE) {
#endif
if (BLE_MESH_ADV(buf)->adv_itvl != BLE_MESH_ADV_ITVL_DEFAULT) {
adv_int = MAX(ADV_ITVL_MIN, BLE_MESH_ADV(buf)->adv_itvl);
} else {
adv_int = MAX(ADV_ITVL_MIN,
BLE_MESH_TRANSMIT_INT(BLE_MESH_ADV(buf)->xmit));
}
if (BLE_MESH_ADV(buf)->adv_cnt != BLE_MESH_ADV_CNT_DEFAULT) {
adv_cnt = BLE_MESH_ADV(buf)->adv_cnt;
} else {
adv_cnt = BLE_MESH_TRANSMIT_COUNT(BLE_MESH_ADV(buf)->xmit) + 1;
}
duration = adv_cnt * (adv_int + 10);
adv_int = MAX(ADV_ITVL_MIN,
BLE_MESH_TRANSMIT_INT(BLE_MESH_ADV(buf)->xmit));
duration = (BLE_MESH_TRANSMIT_COUNT(BLE_MESH_ADV(buf)->xmit) + 1) *
(adv_int + 10);
BT_DBG("count %u interval %ums duration %ums",
BLE_MESH_TRANSMIT_COUNT(BLE_MESH_ADV(buf)->xmit) + 1, adv_int,
@@ -97,38 +86,10 @@ static inline int adv_send(struct net_buf *buf)
param.interval_min = ADV_SCAN_UNIT(adv_int);
param.interval_max = param.interval_min;
if (BLE_MESH_ADV(buf)->channel_map) {
param.channel_map = BLE_MESH_ADV(buf)->channel_map;
} else {
param.channel_map = BLE_MESH_ADV_CHAN_DEFAULT;
}
#if CONFIG_BLE_MESH_USE_BLE_50
#if CONFIG_BLE_MESH_EXT_ADV
if (BLE_MESH_ADV(buf)->type == BLE_MESH_ADV_EXT_PROV ||
BLE_MESH_ADV(buf)->type == BLE_MESH_ADV_EXT_DATA ||
BLE_MESH_ADV(buf)->type == BLE_MESH_ADV_EXT_RELAY_DATA
#if CONFIG_BLE_MESH_LONG_PACKET
|| BLE_MESH_ADV(buf)->type == BLE_MESH_ADV_EXT_LONG_PROV
|| BLE_MESH_ADV(buf)->type == BLE_MESH_ADV_EXT_LONG_DATA
|| BLE_MESH_ADV(buf)->type == BLE_MESH_ADV_EXT_LONG_RELAY_DATA
#endif
) {
param.primary_phy = EXT_ADV(buf)->primary_phy;
param.secondary_phy = EXT_ADV(buf)->secondary_phy;
param.include_tx_power = EXT_ADV(buf)->include_tx_power;
param.tx_power = EXT_ADV(buf)->tx_power;
} else
#endif
{
param.primary_phy = BLE_MESH_ADV_PRI_PHY_DEFAULT;
param.secondary_phy = BLE_MESH_ADV_SEC_PHY_DEFAULT;
param.include_tx_power = BLE_MESH_TX_POWER_INCLUDE_DEFAULT;
param.tx_power = BLE_MESH_TX_POWER_DEFAULT;
}
param.adv_duration = duration;
param.adv_count = adv_cnt;
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
param.adv_count = BLE_MESH_TRANSMIT_COUNT(BLE_MESH_ADV(buf)->xmit) + 1;
#endif
#if CONFIG_BLE_MESH_PROXY_SOLIC_PDU_TX
if (BLE_MESH_ADV(buf)->type == BLE_MESH_ADV_PROXY_SOLIC) {
@@ -362,10 +323,6 @@ void bt_mesh_adv_update(void)
void bt_mesh_adv_init(void)
{
bt_mesh_adv_common_init();
adv_queue = bt_mesh_adv_queue_get();
assert(adv_queue && adv_queue->q.handle && adv_queue->send);
#if CONFIG_BLE_MESH_RELAY_ADV_BUF
bt_mesh_relay_adv_init();
@@ -374,6 +331,10 @@ void bt_mesh_adv_init(void)
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
bt_mesh_ble_adv_init();
#endif
bt_mesh_adv_common_init();
adv_queue = bt_mesh_adv_queue_get();
assert(adv_queue && adv_queue->q.handle && adv_queue->send);
#if CONFIG_BLE_MESH_RELAY_ADV_BUF && !CONFIG_BLE_MESH_SUPPORT_MULTI_ADV
QueueHandle_t relay_adv_handle =

View File

@@ -35,36 +35,6 @@ struct bt_mesh_adv_queue relay_adv_queue;
#endif
static bt_mesh_mutex_t adv_buf_alloc_lock;
#if CONFIG_BLE_MESH_EXT_ADV
NET_BUF_POOL_DEFINE(ext_adv_buf_pool, CONFIG_BLE_MESH_EXT_ADV_BUF_COUNT,
BLE_MESH_ADV_DATA_SIZE, BLE_MESH_ADV_USER_DATA_SIZE, NULL);
static bt_mesh_ext_adv_t ext_adv_pool[CONFIG_BLE_MESH_EXT_ADV_BUF_COUNT];
#if CONFIG_BLE_MESH_EXT_RELAY_ADV_BUF_COUNT
NET_BUF_POOL_DEFINE(ext_relay_adv_buf_pool, CONFIG_BLE_MESH_EXT_RELAY_ADV_BUF_COUNT,
BLE_MESH_ADV_DATA_SIZE, BLE_MESH_ADV_USER_DATA_SIZE, NULL);
static bt_mesh_ext_adv_t ext_relay_adv_pool[CONFIG_BLE_MESH_EXT_RELAY_ADV_BUF_COUNT];
#endif /* CONFIG_BLE_MESH_EXT_RELAY_ADV_BUF_COUNT */
#if CONFIG_BLE_MESH_LONG_PACKET
NET_BUF_POOL_DEFINE(ext_long_adv_buf_pool, CONFIG_BLE_MESH_LONG_PACKET_TX_SEG_CNT,
CONFIG_BLE_MESH_LONG_PACKET_ADV_LEN, BLE_MESH_ADV_USER_DATA_SIZE, NULL);
static bt_mesh_ext_adv_t ext_long_adv_pool[CONFIG_BLE_MESH_LONG_PACKET_TX_SEG_CNT];
#if CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT
NET_BUF_POOL_DEFINE(ext_long_relay_adv_buf_pool, CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT,
CONFIG_BLE_MESH_LONG_PACKET_ADV_LEN, BLE_MESH_ADV_USER_DATA_SIZE, NULL);
static bt_mesh_ext_adv_t ext_long_relay_adv_pool[CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT];
#endif /* CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT */
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
#endif /* CONFIG_BLE_MESH_EXT_ADV */
static inline void init_adv_with_defaults(struct bt_mesh_adv *adv,
enum bt_mesh_adv_type type)
{
memset(adv, 0, sizeof(struct bt_mesh_adv));
adv->type = type;
adv->adv_itvl = BLE_MESH_ADV_ITVL_DEFAULT;
adv->adv_cnt = BLE_MESH_ADV_CNT_DEFAULT;
adv->channel_map = BLE_MESH_ADV_CHAN_DEFAULT;
}
#if CONFIG_BLE_MESH_FRIEND
/* We reserve one extra buffer for each friendship, since we need to be able
@@ -78,10 +48,8 @@ NET_BUF_POOL_FIXED_DEFINE(friend_buf_pool, FRIEND_BUF_COUNT,
bt_mesh_friend_adv_t frnd_adv_pool[FRIEND_BUF_COUNT];
struct bt_mesh_adv *bt_mesh_frnd_adv_buf_get(int idx, enum bt_mesh_adv_type type)
struct bt_mesh_adv *bt_mesh_frnd_adv_buf_get(int idx)
{
memset(&frnd_adv_pool[idx].adv, 0, sizeof(struct bt_mesh_adv));
init_adv_with_defaults(&frnd_adv_pool[idx].adv, type);
frnd_adv_pool[idx].app_idx = BLE_MESH_KEY_UNUSED;
return &frnd_adv_pool[idx].adv;
}
@@ -186,58 +154,11 @@ int bt_mesh_adv_inst_deinit(enum bt_mesh_adv_inst_type inst_type)
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
struct bt_mesh_adv *adv_alloc(int id, enum bt_mesh_adv_type type)
struct bt_mesh_adv *adv_alloc(int id)
{
init_adv_with_defaults(&adv_pool[id], type);
return &adv_pool[id];
}
#if CONFIG_BLE_MESH_EXT_ADV
struct bt_mesh_adv *ext_adv_alloc(int id, enum bt_mesh_adv_type type)
{
init_adv_with_defaults(&ext_adv_pool[id].adv, type);
ext_adv_pool[id].primary_phy = BLE_MESH_ADV_PRI_PHY_DEFAULT;
ext_adv_pool[id].secondary_phy = BLE_MESH_ADV_SEC_PHY_DEFAULT;
ext_adv_pool[id].include_tx_power = BLE_MESH_TX_POWER_INCLUDE_DEFAULT;
ext_adv_pool[id].tx_power = BLE_MESH_TX_POWER_DEFAULT;
return &ext_adv_pool[id].adv;
}
#if CONFIG_BLE_MESH_EXT_RELAY_ADV_BUF_COUNT
struct bt_mesh_adv *ext_relay_adv_alloc(int id, enum bt_mesh_adv_type type)
{
init_adv_with_defaults(&ext_relay_adv_pool[id].adv, type);
ext_relay_adv_pool[id].primary_phy = BLE_MESH_ADV_PRI_PHY_DEFAULT;
ext_relay_adv_pool[id].secondary_phy = BLE_MESH_ADV_SEC_PHY_DEFAULT;
ext_relay_adv_pool[id].include_tx_power = BLE_MESH_TX_POWER_INCLUDE_DEFAULT;
ext_relay_adv_pool[id].tx_power = BLE_MESH_TX_POWER_DEFAULT;
return &ext_relay_adv_pool[id].adv;
}
#endif /* CONFIG_BLE_MESH_EXT_RELAY_ADV_BUF_COUNT */
#endif /* CONFIG_BLE_MESH_EXT_ADV */
#if CONFIG_BLE_MESH_LONG_PACKET
struct bt_mesh_adv *ext_long_adv_alloc(int id, enum bt_mesh_adv_type type)
{
init_adv_with_defaults(&ext_long_adv_pool[id].adv, type);
ext_long_adv_pool[id].primary_phy = BLE_MESH_ADV_PRI_PHY_DEFAULT;
ext_long_adv_pool[id].secondary_phy = BLE_MESH_ADV_SEC_PHY_DEFAULT;
ext_long_adv_pool[id].include_tx_power = BLE_MESH_TX_POWER_INCLUDE_DEFAULT;
ext_long_adv_pool[id].tx_power = BLE_MESH_TX_POWER_DEFAULT;
return &ext_long_adv_pool[id].adv;
}
#if CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT
struct bt_mesh_adv *ext_long_relay_adv_alloc(int id, enum bt_mesh_adv_type type)
{
init_adv_with_defaults(&ext_long_relay_adv_pool[id].adv, type);
ext_long_relay_adv_pool[id].primary_phy = BLE_MESH_ADV_PRI_PHY_DEFAULT;
ext_long_relay_adv_pool[id].secondary_phy = BLE_MESH_ADV_SEC_PHY_DEFAULT;
ext_long_relay_adv_pool[id].include_tx_power = BLE_MESH_TX_POWER_INCLUDE_DEFAULT;
ext_long_relay_adv_pool[id].tx_power = BLE_MESH_TX_POWER_DEFAULT;
return &ext_long_relay_adv_pool[id].adv;
}
#endif /* CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT */
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
struct bt_mesh_adv_type_manager *bt_mesh_adv_types_mgnt_get(enum bt_mesh_adv_type adv_type)
{
return &adv_types[adv_type];
@@ -436,8 +357,12 @@ struct net_buf *bt_mesh_adv_create_from_pool(enum bt_mesh_adv_type type,
BT_DBG("pool %p, buf_count %d, uinit_count %d, ref %d",
buf->pool, pool->buf_count, pool->uninit_count, buf->ref);
adv = adv_types[type].pool_allocator(net_buf_id(buf), type);
adv = adv_types[type].pool_allocator(net_buf_id(buf));
BLE_MESH_ADV(buf) = adv;
(void)memset(adv, 0, sizeof(*adv));
adv->type = type;
bt_mesh_r_mutex_unlock(&adv_buf_alloc_lock);
return buf;
}
@@ -551,10 +476,8 @@ bool bt_mesh_ignore_relay_packet(uint32_t timestamp)
return ((interval >= BLE_MESH_RELAY_TIME_INTERVAL) ? true : false);
}
static struct bt_mesh_adv *relay_adv_alloc(int id, enum bt_mesh_adv_type type)
static struct bt_mesh_adv *relay_adv_alloc(int id)
{
memset(&relay_adv_pool[id], 0, sizeof(struct bt_mesh_adv));
init_adv_with_defaults(&relay_adv_pool[id], type);
return &relay_adv_pool[id];
}
@@ -608,58 +531,21 @@ uint16_t bt_mesh_get_stored_relay_count(void)
return (uint16_t)uxQueueMessagesWaiting(relay_adv_queue.q.handle);
}
static ALWAYS_INLINE
uint16_t ble_mesh_relay_adv_buf_count_get(void)
{
uint16_t relay_adv_count = 2 + CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT;
#if CONFIG_BLE_MESH_EXT_ADV && CONFIG_BLE_MESH_RELAY
relay_adv_count += CONFIG_BLE_MESH_EXT_RELAY_ADV_BUF_COUNT;
#endif
#if CONFIG_BLE_MESH_LONG_PACKET && CONFIG_BLE_MESH_RELAY
relay_adv_count += CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT;
#endif
return relay_adv_count;
}
void bt_mesh_relay_adv_init(void)
{
bt_mesh_adv_queue_init(&relay_adv_queue, ble_mesh_relay_adv_buf_count_get(),
bt_mesh_adv_queue_init(&relay_adv_queue, CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT,
ble_mesh_relay_task_post);
bt_mesh_adv_type_init(BLE_MESH_ADV_RELAY_DATA, &relay_adv_queue,
&relay_adv_buf_pool, &relay_adv_alloc);
#if CONFIG_BLE_MESH_EXT_ADV
bt_mesh_adv_type_init(BLE_MESH_ADV_EXT_RELAY_DATA, &relay_adv_queue,
&ext_adv_buf_pool, &ext_relay_adv_alloc);
#if CONFIG_BLE_MESH_LONG_PACKET && CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT
bt_mesh_adv_type_init(BLE_MESH_ADV_EXT_LONG_RELAY_DATA, &relay_adv_queue,
&ext_long_relay_adv_buf_pool, ext_long_relay_adv_alloc);
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
#endif /* CONFIG_BLE_MESH_EXT_ADV */
#if CONFIG_BLE_MESH_USE_BLE_50
#if CONFIG_BLE_MESH_SEPARATE_RELAY_ADV_INSTANCE
bt_mesh_adv_inst_init(BLE_MESH_RELAY_ADV_INS,
CONFIG_BLE_MESH_RELAY_ADV_INST_ID);
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_RELAY_ADV_INS, BLE_MESH_ADV_RELAY_DATA);
#if CONFIG_BLE_MESH_EXT_ADV
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_RELAY_ADV_INS, BLE_MESH_ADV_EXT_RELAY_DATA);
#if CONFIG_BLE_MESH_LONG_PACKET
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_RELAY_ADV_INS, BLE_MESH_ADV_EXT_LONG_RELAY_DATA);
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
#endif /* CONFIG_BLE_MESH_EXT_ADV */
#else
#if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_RELAY_DATA);
#if CONFIG_BLE_MESH_EXT_ADV
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_RELAY_DATA);
#if CONFIG_BLE_MESH_LONG_PACKET
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_LONG_RELAY_DATA);
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
#endif /* CONFIG_BLE_MESH_EXT_ADV */
#endif /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */
#endif
#endif /* CONFIG_BLE_MESH_SEPARATE_RELAY_ADV_INSTANCE */
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
}
@@ -668,33 +554,14 @@ void bt_mesh_relay_adv_deinit(void)
{
bt_mesh_adv_queue_deinit(&relay_adv_queue);
bt_mesh_adv_type_deinit(BLE_MESH_ADV_RELAY_DATA);
#if CONFIG_BLE_MESH_EXT_ADV
bt_mesh_adv_type_deinit(BLE_MESH_ADV_EXT_RELAY_DATA);
#if CONFIG_BLE_MESH_LONG_PACKET
bt_mesh_adv_type_deinit(BLE_MESH_ADV_EXT_LONG_RELAY_DATA);
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
#endif
#if CONFIG_BLE_MESH_USE_BLE_50
#if CONFIG_BLE_MESH_SEPARATE_RELAY_ADV_INSTANCE
bt_mesh_adv_inst_supported_adv_type_rm(BLE_MESH_RELAY_ADV_INS, BLE_MESH_ADV_RELAY_DATA);
#if CONFIG_BLE_MESH_EXT_ADV
bt_mesh_adv_inst_supported_adv_type_rm(BLE_MESH_RELAY_ADV_INS, BLE_MESH_ADV_EXT_RELAY_DATA);
#if CONFIG_BLE_MESH_LONG_PACKET
bt_mesh_adv_inst_supported_adv_type_rm(BLE_MESH_RELAY_ADV_INS, BLE_MESH_ADV_EXT_LONG_RELAY_DATA);
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
#endif /* CONFIG_BLE_MESH_EXT_ADV */
bt_mesh_adv_inst_deinit(BLE_MESH_RELAY_ADV_INS);
#else
#if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV
bt_mesh_adv_inst_supported_adv_type_rm(BLE_MESH_ADV_INS, BLE_MESH_ADV_RELAY_DATA);
#if CONFIG_BLE_MESH_EXT_ADV
bt_mesh_adv_inst_supported_adv_type_rm(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_RELAY_DATA);
#if CONFIG_BLE_MESH_LONG_PACKET
bt_mesh_adv_inst_supported_adv_type_rm(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_LONG_RELAY_DATA);
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
#endif /* CONFIG_BLE_MESH_EXT_ADV */
#endif /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */
#endif
#endif /* CONFIG_BLE_MESH_SEPARATE_RELAY_ADV_INSTANCE */
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
bt_mesh_unref_buf_from_pool(&relay_adv_buf_pool);
@@ -730,33 +597,6 @@ void bt_mesh_frnd_adv_deinit(void)
}
#endif /* CONFIG_BLE_MESH_FRIEND */
static ALWAYS_INLINE
uint16_t ble_mesh_adv_buf_count_get(void)
{
uint16_t adv_count = 2 + CONFIG_BLE_MESH_ADV_BUF_COUNT;
#if CONFIG_BLE_MESH_EXT_ADV
adv_count += CONFIG_BLE_MESH_EXT_ADV_BUF_COUNT;
#if !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_RELAY
adv_count += CONFIG_BLE_MESH_EXT_RELAY_ADV_BUF_COUNT;
#endif
#endif
#if CONFIG_BLE_MESH_LONG_PACKET
adv_count += CONFIG_BLE_MESH_LONG_PACKET_ADV_BUF_COUNT;
#if !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_RELAY
adv_count += CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT;
#endif
#endif
#if (CONFIG_BLE_MESH_SUPPORT_BLE_ADV && \
!(CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE))
adv_count += CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT;
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
return adv_count;
}
void bt_mesh_adv_task_init(void adv_thread(void *p))
{
if (!adv_thread) {
@@ -785,7 +625,7 @@ void bt_mesh_adv_task_init(void adv_thread(void *p))
void bt_mesh_adv_common_init(void)
{
bt_mesh_r_mutex_create(&adv_buf_alloc_lock);
bt_mesh_adv_queue_init(&adv_queue, ble_mesh_adv_buf_count_get(), bt_mesh_task_post);
bt_mesh_adv_queue_init(&adv_queue, BLE_MESH_ADV_QUEUE_SIZE, bt_mesh_task_post);
bt_mesh_adv_type_init(BLE_MESH_ADV_PROV, &adv_queue, &adv_buf_pool, adv_alloc);
bt_mesh_adv_type_init(BLE_MESH_ADV_DATA, &adv_queue, &adv_buf_pool, adv_alloc);
bt_mesh_adv_type_init(BLE_MESH_ADV_BEACON, &adv_queue, &adv_buf_pool, adv_alloc);
@@ -796,21 +636,7 @@ void bt_mesh_adv_common_init(void)
#if CONFIG_BLE_MESH_USE_BLE_50
bt_mesh_adv_inst_init(BLE_MESH_ADV_INS, CONFIG_BLE_MESH_ADV_INST_ID);
#if CONFIG_BLE_MESH_EXT_ADV
bt_mesh_adv_type_init(BLE_MESH_ADV_EXT_PROV, &adv_queue, &ext_adv_buf_pool, ext_adv_alloc);
bt_mesh_adv_type_init(BLE_MESH_ADV_EXT_DATA, &adv_queue, &ext_adv_buf_pool, ext_adv_alloc);
#if !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_EXT_RELAY_ADV_BUF_COUNT
bt_mesh_adv_type_init(BLE_MESH_ADV_EXT_RELAY_DATA, &adv_queue, &ext_relay_adv_buf_pool, ext_relay_adv_alloc);
#endif
#if CONFIG_BLE_MESH_LONG_PACKET
bt_mesh_adv_type_init(BLE_MESH_ADV_EXT_LONG_PROV, &adv_queue, &ext_long_adv_buf_pool, ext_long_adv_alloc);
bt_mesh_adv_type_init(BLE_MESH_ADV_EXT_LONG_DATA, &adv_queue, &ext_long_adv_buf_pool, ext_long_adv_alloc);
#if !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT
bt_mesh_adv_type_init(BLE_MESH_ADV_EXT_LONG_RELAY_DATA, &adv_queue, &ext_long_relay_adv_buf_pool, ext_long_relay_adv_alloc);
#endif /* !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT */
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
#endif /* CONFIG_BLE_MESH_EXT_ADV */
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
#if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV
/**
@@ -825,21 +651,7 @@ void bt_mesh_adv_common_init(void)
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_DATA);
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_BEACON);
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_URI);
#if CONFIG_BLE_MESH_EXT_ADV
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_PROV);
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_DATA);
#if CONFIG_BLE_MESH_RELAY && !CONFIG_BLE_MESH_RELAY_ADV_BUF
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_RELAY_DATA);
#endif
#if CONFIG_BLE_MESH_LONG_PACKET
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_LONG_PROV);
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_LONG_DATA);
#if CONFIG_BLE_MESH_RELAY && !CONFIG_BLE_MESH_RELAY_ADV_BUF
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_LONG_RELAY_DATA);
#endif /* !CONFIG_BLE_MESH_RELAY_ADV_BUF */
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
#endif /* CONFIG_BLE_MESH_EXT_ADV */
#endif /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */
}
#if CONFIG_BLE_MESH_DEINIT
@@ -865,25 +677,6 @@ void bt_mesh_adv_common_deinit(void)
bt_mesh_adv_type_deinit(BLE_MESH_ADV_BEACON);
bt_mesh_adv_type_deinit(BLE_MESH_ADV_URI);
#if CONFIG_BLE_MESH_PROXY_SOLIC_PDU_TX
bt_mesh_adv_type_deinit(BLE_MESH_ADV_PROXY_SOLIC);
#endif
#if CONFIG_BLE_MESH_EXT_ADV
bt_mesh_adv_type_deinit(BLE_MESH_ADV_EXT_PROV);
bt_mesh_adv_type_deinit(BLE_MESH_ADV_EXT_DATA);
#if !CONFIG_BLE_MESH_RELAY_ADV_BUF
bt_mesh_adv_type_deinit(BLE_MESH_ADV_EXT_RELAY_DATA);
#endif
#if CONFIG_BLE_MESH_LONG_PACKET
bt_mesh_adv_type_deinit(BLE_MESH_ADV_EXT_LONG_PROV);
bt_mesh_adv_type_deinit(BLE_MESH_ADV_EXT_LONG_DATA);
#if !CONFIG_BLE_MESH_RELAY_ADV_BUF
bt_mesh_adv_type_deinit(BLE_MESH_ADV_EXT_LONG_RELAY_DATA);
#endif
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
#endif /* CONFIG_BLE_MESH_EXT_ADV */
bt_mesh_adv_queue_deinit(&adv_queue);
#if CONFIG_BLE_MESH_USE_BLE_50
bt_mesh_adv_inst_deinit(BLE_MESH_ADV_INS);

View File

@@ -2,7 +2,7 @@
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2024-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -48,6 +48,9 @@ extern "C" {
#define BLE_MESH_ADV_INS_UNUSED 0xFF
/* We reserve one queue item for bt_mesh_adv_update() */
#define BLE_MESH_ADV_QUEUE_SIZE (CONFIG_BLE_MESH_ADV_BUF_COUNT + 1)
struct bt_mesh_adv {
const struct bt_mesh_send_cb *cb;
void *cb_data;
@@ -57,23 +60,8 @@ struct bt_mesh_adv {
bt_mesh_atomic_t busy;
uint8_t xmit;
uint32_t adv_itvl;
uint8_t adv_cnt;
uint8_t channel_map;
};
#if CONFIG_BLE_MESH_USE_BLE_50
#define EXT_ADV(buf) CONTAINER_OF(BLE_MESH_ADV(buf), bt_mesh_ext_adv_t, adv)
typedef struct {
struct bt_mesh_adv adv;
uint8_t primary_phy;
uint8_t secondary_phy;
uint8_t include_tx_power:1;
int8_t tx_power;
} bt_mesh_ext_adv_t;
#endif
#if CONFIG_BLE_MESH_FRIEND
#define FRIEND_ADV(buf) CONTAINER_OF(BLE_MESH_ADV(buf), bt_mesh_friend_adv_t, adv)
@@ -122,6 +110,14 @@ typedef struct bt_mesh_msg {
uint32_t timestamp; /* Timestamp recorded when the relay packet is posted to queue */
} bt_mesh_msg_t;
typedef struct bt_mesh_adv *(*bt_mesh_pool_allocator_t)(int id);
typedef void (*bt_mesh_adv_queue_send_cb_t)(bt_mesh_msg_t *msg, uint32_t timeout, bool front);
struct bt_mesh_adv_queue {
bt_mesh_queue_t q;
bt_mesh_adv_queue_send_cb_t send;
};
struct bt_mesh_adv_inst {
uint8_t id;
#if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV
@@ -136,16 +132,6 @@ struct bt_mesh_adv_inst {
enum bt_mesh_adv_type {
BLE_MESH_ADV_PROV,
BLE_MESH_ADV_DATA,
#if CONFIG_BLE_MESH_EXT_ADV
BLE_MESH_ADV_EXT_PROV,
BLE_MESH_ADV_EXT_DATA,
BLE_MESH_ADV_EXT_RELAY_DATA,
#if CONFIG_BLE_MESH_LONG_PACKET
BLE_MESH_ADV_EXT_LONG_PROV,
BLE_MESH_ADV_EXT_LONG_DATA,
BLE_MESH_ADV_EXT_LONG_RELAY_DATA,
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
#endif /* CONFIG_BLE_MESH_EXT_ADV */
#if CONFIG_BLE_MESH_FRIEND
BLE_MESH_ADV_FRIEND,
#endif
@@ -169,20 +155,15 @@ typedef enum {
BLE_MESH_BUF_REF_MAX,
} bt_mesh_buf_ref_flag_t;
struct bt_mesh_adv_type_manager {
struct bt_mesh_adv_queue *adv_q;
struct net_buf_pool *pool;
bt_mesh_pool_allocator_t pool_allocator;
};
static const uint8_t adv_type[] = {
[BLE_MESH_ADV_PROV] = BLE_MESH_DATA_MESH_PROV,
[BLE_MESH_ADV_DATA] = BLE_MESH_DATA_MESH_MESSAGE,
#if CONFIG_BLE_MESH_EXT_ADV
[BLE_MESH_ADV_EXT_PROV] = BLE_MESH_DATA_MESH_PROV,
[BLE_MESH_ADV_EXT_RELAY_DATA] = BLE_MESH_DATA_MESH_MESSAGE,
[BLE_MESH_ADV_EXT_DATA] = BLE_MESH_DATA_MESH_MESSAGE,
#if CONFIG_BLE_MESH_LONG_PACKET
[BLE_MESH_ADV_EXT_LONG_PROV] = BLE_MESH_DATA_MESH_PROV,
[BLE_MESH_ADV_EXT_LONG_RELAY_DATA] = BLE_MESH_DATA_MESH_MESSAGE,
[BLE_MESH_ADV_EXT_LONG_DATA] = BLE_MESH_DATA_MESH_MESSAGE,
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
#endif /* CONFIG_BLE_MESH_EXT_ADV */
#if CONFIG_BLE_MESH_FRIEND
[BLE_MESH_ADV_FRIEND] = BLE_MESH_DATA_MESH_MESSAGE,
#endif
@@ -193,20 +174,6 @@ static const uint8_t adv_type[] = {
[BLE_MESH_ADV_URI] = BLE_MESH_DATA_URI,
};
typedef struct bt_mesh_adv *(*bt_mesh_pool_allocator_t)(int id, enum bt_mesh_adv_type type);
typedef void (*bt_mesh_adv_queue_send_cb_t)(bt_mesh_msg_t *msg, uint32_t timeout, bool front);
struct bt_mesh_adv_type_manager {
struct bt_mesh_adv_queue *adv_q;
struct net_buf_pool *pool;
bt_mesh_pool_allocator_t pool_allocator;
};
struct bt_mesh_adv_queue {
bt_mesh_queue_t q;
bt_mesh_adv_queue_send_cb_t send;
};
static inline TickType_t K_WAIT(int32_t val)
{
return (val == K_FOREVER) ? portMAX_DELAY : (val / portTICK_PERIOD_MS);
@@ -288,7 +255,7 @@ void bt_mesh_relay_adv_deinit(void);
#endif /* CONFIG_BLE_MESH_RELAY_ADV_BUF */
#if CONFIG_BLE_MESH_FRIEND
struct bt_mesh_adv *bt_mesh_frnd_adv_buf_get(int id, enum bt_mesh_adv_type type);
struct bt_mesh_adv *bt_mesh_frnd_adv_buf_get(int id);
struct net_buf_pool *bt_mesh_frnd_adv_pool_get(void);
void bt_mesh_frnd_adv_init(void);
#if CONFIG_BLE_MESH_DEINIT

View File

@@ -2,7 +2,7 @@
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -15,12 +15,8 @@
#include "mesh/buf.h"
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE
/* Use independent ble adv queue only if multi adv instance is used */
static struct bt_mesh_adv_queue ble_adv_queue;
static void bt_mesh_ble_task_post(bt_mesh_msg_t *msg, uint32_t timeout, bool front);
#endif
static struct bt_mesh_adv_queue *p_ble_adv_queue;
#define BLE_MESH_BLE_ADV_QUEUE_SIZE (CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT + 1)
/* length + advertising data + length + scan response data */
NET_BUF_POOL_DEFINE(ble_adv_buf_pool, CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT,
@@ -32,37 +28,34 @@ static struct bt_mesh_ble_adv_tx ble_adv_tx[CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT];
#define SEND_BLE_ADV_INFINITE 0xFFFF
static struct bt_mesh_adv *ble_adv_alloc(int id, enum bt_mesh_adv_type type)
static void bt_mesh_ble_task_post(bt_mesh_msg_t *msg, uint32_t timeout, bool front);
static struct bt_mesh_adv *ble_adv_alloc(int id)
{
memset(&ble_adv_pool[id], 0, sizeof(struct bt_mesh_adv));
ble_adv_pool[id].type = type;
return &ble_adv_pool[id];
}
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE
/* A separate post function is required only when using a separate queue */
static void bt_mesh_ble_task_post(bt_mesh_msg_t *msg, uint32_t timeout, bool front)
{
BT_DBG("%s", __func__);
if (p_ble_adv_queue->q.handle == NULL) {
if (ble_adv_queue.q.handle == NULL) {
BT_ERR("Invalid adv queue");
return;
}
if (front) {
if (xQueueSendToFront(p_ble_adv_queue->q.handle, msg, timeout) != pdTRUE) {
if (xQueueSendToFront(ble_adv_queue.q.handle, msg, timeout) != pdTRUE) {
BT_ERR("Failed to send item to adv queue front");
bt_mesh_unref_buf(msg);
}
} else {
if (xQueueSend(p_ble_adv_queue->q.handle, msg, timeout) != pdTRUE) {
if (xQueueSend(ble_adv_queue.q.handle, msg, timeout) != pdTRUE) {
BT_ERR("Failed to send item to adv queue back");
bt_mesh_unref_buf(msg);
}
}
}
#endif
static struct net_buf *bt_mesh_ble_adv_create(enum bt_mesh_adv_type type, int32_t timeout)
{
@@ -287,20 +280,10 @@ int bt_mesh_stop_ble_advertising(uint8_t index)
return 0;
}
struct bt_mesh_adv_queue *bt_mesh_ble_adv_queue_get(void)
{
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE
bt_mesh_adv_queue_init(&ble_adv_queue, CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT, bt_mesh_ble_task_post);
return &ble_adv_queue;
#else
return bt_mesh_adv_queue_get();
#endif
}
void bt_mesh_ble_adv_init(void)
{
p_ble_adv_queue = bt_mesh_ble_adv_queue_get();
bt_mesh_adv_type_init(BLE_MESH_ADV_BLE, p_ble_adv_queue, &ble_adv_buf_pool, ble_adv_alloc);
bt_mesh_adv_queue_init(&ble_adv_queue, CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT, bt_mesh_ble_task_post);
bt_mesh_adv_type_init(BLE_MESH_ADV_BLE, &ble_adv_queue, &ble_adv_buf_pool, ble_adv_alloc);
#if CONFIG_BLE_MESH_USE_BLE_50
#if CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE
bt_mesh_adv_inst_init(BLE_MESH_BLE_ADV_INS, CONFIG_BLE_MESH_BLE_ADV_INST_ID);
@@ -323,11 +306,7 @@ void bt_mesh_ble_adv_deinit(void)
bt_mesh_unref_buf_from_pool(&ble_adv_buf_pool);
memset(ble_adv_pool, 0, sizeof(ble_adv_pool));
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE
/* In other cases, ble_adv queue is an adv queue,
* so ble does not need to deinit separately */
bt_mesh_adv_queue_deinit(p_ble_adv_queue);
#endif
bt_mesh_adv_queue_deinit(&ble_adv_queue);
bt_mesh_adv_type_deinit(BLE_MESH_ADV_BLE);
#if CONFIG_BLE_MESH_USE_BLE_50
#if CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE

View File

@@ -1,7 +1,7 @@
/*
* SPDX-FileCopyrightText: 2017 Nordic Semiconductor ASA
* SPDX-FileCopyrightText: 2015-2016 Intel Corporation
* SPDX-FileContributor: 2018-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -240,19 +240,9 @@ void bt_mesh_ble_ext_adv_report(tBTM_BLE_EXT_ADV_REPORT *ext_adv_report)
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
}
#if CONFIG_BLE_MESH_LONG_PACKET
static struct {
struct bt_mesh_adv_report adv_rpt;
uint8_t adv_data_len;
uint8_t adv_data[2 + CONFIG_BLE_MESH_LONG_PACKET_ADV_LEN];
} adv_report_cache;
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
static bool bt_mesh_scan_result_process(tBTM_BLE_EXT_ADV_REPORT *ext_adv_report)
{
struct bt_mesh_adv_report adv_rpt = {0};
uint8_t *adv_data = NULL;
uint8_t adv_data_len = 0;
assert(ext_adv_report);
@@ -261,31 +251,23 @@ static bool bt_mesh_scan_result_process(tBTM_BLE_EXT_ADV_REPORT *ext_adv_report)
adv_rpt.primary_phy = ext_adv_report->primary_phy;
adv_rpt.secondary_phy = ext_adv_report->secondry_phy;
adv_rpt.rssi = ext_adv_report->rssi;
adv_rpt.tx_power = ext_adv_report->tx_power;
adv_data = ext_adv_report->adv_data;
adv_data_len = ext_adv_report->adv_data_len;
#if !CONFIG_BLE_MESH_EXT_ADV
if (!(ext_adv_report->event_type & BTM_BLE_ADV_LEGACY_MASK)) {
return false;
}
#endif
BT_DBG("Recv adv report type %04x", ext_adv_report->event_type);
if (ext_adv_report->adv_data_len > BLE_MESH_GAP_ADV_MAX_LEN) {
if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) {
return false;
}
BT_DBG("Recv adv report type %04x", ext_adv_report->event_type);
switch (ext_adv_report->event_type) {
case BLE_MESH_ADV_IND:
case BLE_MESH_ADV_DIRECT_IND:
case BLE_MESH_ADV_SCAN_IND:
case BLE_MESH_ADV_NONCONN_IND:
case BLE_MESH_ADV_SCAN_RSP:
#if CONFIG_BLE_MESH_EXT_ADV
case BLE_MESH_EXT_ADV_NONCONN_IND:
#endif
adv_rpt.adv_type = ext_adv_report->event_type;
break;
default:
@@ -293,51 +275,10 @@ static bool bt_mesh_scan_result_process(tBTM_BLE_EXT_ADV_REPORT *ext_adv_report)
break;
}
#if CONFIG_BLE_MESH_LONG_PACKET
switch (ext_adv_report->data_status) {
case BTM_BLE_EXT_ADV_DATA_COMPLETE:
if (adv_report_cache.adv_data_len) {
memcpy(adv_report_cache.adv_data + adv_report_cache.adv_data_len,
ext_adv_report->adv_data, ext_adv_report->adv_data_len);
adv_report_cache.adv_data_len += ext_adv_report->adv_data_len;
adv_data = adv_report_cache.adv_data;
adv_data_len = adv_report_cache.adv_data_len;
adv_report_cache.adv_data_len = 0;
}
break;
case BTM_BLE_EXT_ADV_DATA_INCOMPLETE:
if ((adv_report_cache.adv_data_len + ext_adv_report->adv_data_len) > BLE_MESH_GAP_ADV_MAX_LEN) {
adv_report_cache.adv_data_len = 0;
return false;
}
if (adv_report_cache.adv_data_len == 0) {
memcpy(&adv_report_cache.adv_rpt, &adv_rpt, sizeof(struct bt_mesh_adv_report));
}
memcpy(adv_report_cache.adv_data + adv_report_cache.adv_data_len,
ext_adv_report->adv_data, ext_adv_report->adv_data_len);
adv_report_cache.adv_data_len += ext_adv_report->adv_data_len;
/* To avoid discarding user's packets,
* it is assumed here that this packet
* is not mesh's packet */
return false;
case BTM_BLE_EXT_ADV_DATA_TRUNCATED:
if (adv_report_cache.adv_data_len) {
memset(&adv_report_cache, 0, sizeof(adv_report_cache));
}
return false;
default:
assert(0);
}
#else /* CONFIG_BLE_MESH_LONG_PACKET */
if (ext_adv_report->data_status != BTM_BLE_EXT_ADV_DATA_COMPLETE) {
return false;
}
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
if (bt_mesh_scan_dev_found_cb) {
net_buf_simple_init_with_data(&adv_rpt.adv_data, adv_data, adv_data_len);
net_buf_simple_init_with_data(&adv_rpt.adv_data, ext_adv_report->adv_data, ext_adv_report->adv_data_len);
bt_mesh_scan_dev_found_cb(&adv_rpt);
if (adv_rpt.adv_data.len != adv_data_len) {
if (adv_rpt.adv_data.len != ext_adv_report->adv_data_len) {
/* The advertising data has been processed by Mesh Protocol */
return true;
}
@@ -489,7 +430,7 @@ static int set_adv_data(uint16_t hci_op, const struct bt_mesh_adv_data *ad, size
for (i = 0; i < ad_len; i++) {
/* Check if ad fit in the remaining buffer */
if (param.len + ad[i].data_len + 2 > sizeof(param.data)) {
if (param.len + ad[i].data_len + 2 > 31) {
return -EINVAL;
}
@@ -652,11 +593,6 @@ static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARC
#endif
#if CONFIG_BLE_MESH_USE_BLE_50
static struct {
bool set;
tBTA_DM_BLE_GAP_EXT_ADV_PARAMS param;
} last_param[BLE_MESH_ADV_INS_TYPES_NUM];
int bt_le_ext_adv_start(const uint8_t inst_id,
const struct bt_mesh_adv_param *param,
const struct bt_mesh_adv_data *ad, size_t ad_len,
@@ -688,10 +624,11 @@ int bt_le_ext_adv_start(const uint8_t inst_id,
ext_adv_params.type = BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_SCAN;
} else {
if (param->primary_phy == BLE_MESH_ADV_PHY_1M &&
param->secondary_phy == BLE_MESH_ADV_PHY_1M &&
param->include_tx_power == false &&
ad->data_len <= 29) {
ext_adv_params.type = BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_NONCONN;
param->secondary_phy == BLE_MESH_ADV_PHY_1M) {
ext_adv_params.type = BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_NONCONN;
} else {
BT_ERR("Unsupported PHY: pri %d sec %d",param->primary_phy, param->secondary_phy);
return -EINVAL;
}
}
@@ -711,16 +648,12 @@ int bt_le_ext_adv_start(const uint8_t inst_id,
ext_adv_params.sid = inst_id;
ext_adv_params.max_skip = 0;
ext_adv_params.tx_power = param->tx_power;
ext_adv_params.tx_power = 0x7F;
ext_adv_params.scan_req_notif = false;
ext_adv_params.primary_phy = param->primary_phy;
ext_adv_params.secondary_phy = param->secondary_phy;
ext_adv_params.filter_policy = BLE_MESH_AP_SCAN_CONN_ALL;
ext_adv_params.channel_map = param->channel_map;
if (param->include_tx_power) {
ext_adv_params.type |= BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_INCLUDE_TX_PWR;
}
ext_adv_params.channel_map = BLE_MESH_ADV_CHNL_37 | BLE_MESH_ADV_CHNL_38 | BLE_MESH_ADV_CHNL_39;
interval = param->interval_min;
@@ -741,18 +674,8 @@ int bt_le_ext_adv_start(const uint8_t inst_id,
ext_adv_params.interval_min = interval;
ext_adv_params.interval_max = interval;
if (memcmp(&ext_adv_params, &last_param[inst_id].param, sizeof(tBTA_DM_BLE_GAP_EXT_ADV_PARAMS))) {
if (last_param[inst_id].set) {
BTA_DmBleGapExtAdvSetRemove(inst_id);
}
last_param[inst_id].set = true;
/* Check if we can start adv using BTM_BleSetAdvParamsStartAdvCheck */
BTA_DmBleGapExtAdvSetParams(inst_id, &ext_adv_params);
memcpy(&last_param[inst_id].param, &ext_adv_params, sizeof(tBTA_DM_BLE_GAP_EXT_ADV_PARAMS));
}
/* Check if we can start adv using BTM_BleSetAdvParamsStartAdvCheck */
BTA_DmBleGapExtAdvSetParams(inst_id, &ext_adv_params);
err = set_adv_data(BLE_MESH_HCI_OP_SET_ADV_DATA, inst_id, ad, ad_len);
if (err) {
@@ -800,6 +723,7 @@ int bt_le_adv_start(const struct bt_mesh_adv_param *param,
const struct bt_mesh_adv_data *sd, size_t sd_len)
{
tBTA_START_ADV_CMPL_CBACK *p_start_adv_cb = NULL;
tBTM_BLE_ADV_CHNL_MAP channel_map = 0U;
tBLE_ADDR_TYPE addr_type_own = 0U;
tBLE_BD_ADDR p_dir_bda = {0};
tBTM_BLE_AFP adv_fil_pol = 0U;
@@ -863,6 +787,7 @@ int bt_le_adv_start(const struct bt_mesh_adv_param *param,
addr_type_own = BLE_MESH_ADDR_PUBLIC;
#endif
channel_map = BLE_MESH_ADV_CHNL_37 | BLE_MESH_ADV_CHNL_38 | BLE_MESH_ADV_CHNL_39;
adv_fil_pol = BLE_MESH_AP_SCAN_CONN_ALL;
p_start_adv_cb = start_adv_completed_cb;
@@ -885,7 +810,7 @@ int bt_le_adv_start(const struct bt_mesh_adv_param *param,
BLE_MESH_BTM_CHECK_STATUS(
BTM_BleSetAdvParamsAll(interval, interval, adv_type,
addr_type_own, &p_dir_bda,
param->channel_map, adv_fil_pol, p_start_adv_cb));
channel_map, adv_fil_pol, p_start_adv_cb));
BLE_MESH_BTM_CHECK_STATUS(BTM_BleStartAdv());
#if BLE_MESH_DEV
@@ -929,6 +854,20 @@ int bt_mesh_ble_ext_adv_start(const uint8_t inst_id,
tBTA_DM_BLE_EXT_ADV ext_adv = {0};
struct bt_mesh_hci_cp_set_adv_data set = {0};
if (data && param->adv_type != BLE_MESH_ADV_DIRECT_IND &&
param->adv_type != BLE_MESH_ADV_DIRECT_IND_LOW_DUTY) {
if (data->adv_data_len) {
set.len = data->adv_data_len;
memcpy(set.data, data->adv_data, data->adv_data_len);
BTA_DmBleGapConfigExtAdvDataRaw(false, inst_id, set.len, set.data);
}
if (data->scan_rsp_data_len && param->adv_type != BLE_MESH_ADV_NONCONN_IND) {
set.len = data->scan_rsp_data_len;
memcpy(set.data, data->scan_rsp_data, data->scan_rsp_data_len);
BTA_DmBleGapConfigExtAdvDataRaw(true, inst_id, set.len, set.data);
}
}
switch (param->adv_type) {
case BLE_MESH_ADV_IND:
case BLE_MESH_ADV_DIRECT_IND:
@@ -952,7 +891,7 @@ int bt_mesh_ble_ext_adv_start(const uint8_t inst_id,
ext_adv_params.primary_phy = BLE_MESH_ADV_PHY_1M;
ext_adv_params.secondary_phy = BLE_MESH_ADV_PHY_1M;
ext_adv_params.filter_policy = BLE_MESH_AP_SCAN_CONN_ALL;
ext_adv_params.channel_map = BLE_MESH_ADV_CHAN_37 | BLE_MESH_ADV_CHAN_38 | BLE_MESH_ADV_CHAN_39;
ext_adv_params.channel_map = BLE_MESH_ADV_CHNL_37 | BLE_MESH_ADV_CHNL_38 | BLE_MESH_ADV_CHNL_39;
if (param->own_addr_type == BLE_MESH_ADDR_PUBLIC_ID ||
param->own_addr_type == BLE_MESH_ADDR_RANDOM_ID ||
@@ -969,20 +908,6 @@ int bt_mesh_ble_ext_adv_start(const uint8_t inst_id,
/* Check if we can start adv using BTM_BleSetAdvParamsStartAdvCheck */
BTA_DmBleGapExtAdvSetParams(inst_id, &ext_adv_params);
if (data && param->adv_type != BLE_MESH_ADV_DIRECT_IND &&
param->adv_type != BLE_MESH_ADV_DIRECT_IND_LOW_DUTY) {
if (data->adv_data_len) {
set.len = data->adv_data_len;
memcpy(set.data, data->adv_data, data->adv_data_len);
BTA_DmBleGapConfigExtAdvDataRaw(false, inst_id, set.len, set.data);
}
if (data->scan_rsp_data_len && param->adv_type != BLE_MESH_ADV_NONCONN_IND) {
set.len = data->scan_rsp_data_len;
memcpy(set.data, data->scan_rsp_data, data->scan_rsp_data_len);
BTA_DmBleGapConfigExtAdvDataRaw(true, inst_id, set.len, set.data);
}
}
BTA_DmBleGapExtAdvEnable(true, 1, &ext_adv);
#if !CONFIG_BLE_MESH_SUPPORT_MULTI_ADV
@@ -1014,7 +939,7 @@ int bt_mesh_ble_adv_start(const struct bt_mesh_ble_adv_param *param,
}
}
channel_map = BLE_MESH_ADV_CHAN_37 | BLE_MESH_ADV_CHAN_38 | BLE_MESH_ADV_CHAN_39;
channel_map = BLE_MESH_ADV_CHNL_37 | BLE_MESH_ADV_CHNL_38 | BLE_MESH_ADV_CHNL_39;
adv_fil_pol = BLE_MESH_AP_SCAN_CONN_ALL;
if (param->own_addr_type == BLE_MESH_ADDR_PUBLIC_ID ||
param->own_addr_type == BLE_MESH_ADDR_RANDOM_ID ||

View File

@@ -2,7 +2,7 @@
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -56,30 +56,13 @@ static inline int adv_send(struct bt_mesh_adv_inst *inst, uint16_t *adv_duration
void *cb_data = BLE_MESH_ADV(buf)->cb_data;
struct bt_mesh_adv_param param = {0};
uint16_t duration = 0U, adv_int = 0U;
uint8_t adv_cnt = 0;
struct bt_mesh_adv_data ad = {0};
int err = 0;
#if CONFIG_BLE_MESH_EXT_ADV
uint8_t is_ext_adv = false;
#endif
BT_DBG("type %u len %u: %s", BLE_MESH_ADV(buf)->type,
buf->len, bt_hex(buf->data, buf->len));
buf->len, bt_hex(buf->data, buf->len));
switch (BLE_MESH_ADV(buf)->type) {
#if CONFIG_BLE_MESH_EXT_ADV
case BLE_MESH_ADV_EXT_PROV:
case BLE_MESH_ADV_EXT_DATA:
case BLE_MESH_ADV_EXT_RELAY_DATA:
#if CONFIG_BLE_MESH_LONG_PACKET
case BLE_MESH_ADV_EXT_LONG_PROV:
case BLE_MESH_ADV_EXT_LONG_DATA:
case BLE_MESH_ADV_EXT_LONG_RELAY_DATA:
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
{
is_ext_adv = true;
}
#endif /* CONFIG_BLE_MESH_EXT_ADV */
case BLE_MESH_ADV_PROV:
case BLE_MESH_ADV_DATA:
#if CONFIG_BLE_MESH_FRIEND
@@ -93,38 +76,14 @@ static inline int adv_send(struct bt_mesh_adv_inst *inst, uint16_t *adv_duration
#endif
case BLE_MESH_ADV_BEACON:
case BLE_MESH_ADV_URI: {
#if CONFIG_BLE_MESH_EXT_ADV
if (is_ext_adv) {
param.primary_phy = EXT_ADV(buf)->primary_phy;
param.secondary_phy = EXT_ADV(buf)->secondary_phy;
param.include_tx_power = EXT_ADV(buf)->include_tx_power;
param.tx_power = EXT_ADV(buf)->tx_power;
} else
#endif
{
param.primary_phy = BLE_MESH_ADV_PRI_PHY_DEFAULT;
param.secondary_phy = BLE_MESH_ADV_SEC_PHY_DEFAULT;
param.include_tx_power = BLE_MESH_TX_POWER_INCLUDE_DEFAULT;
param.tx_power = BLE_MESH_TX_POWER_DEFAULT;
}
if (BLE_MESH_ADV(buf)->adv_itvl != BLE_MESH_ADV_ITVL_DEFAULT) {
adv_int = MAX(ADV_ITVL_MIN, BLE_MESH_ADV(buf)->adv_itvl);
} else {
adv_int = MAX(ADV_ITVL_MIN,
BLE_MESH_TRANSMIT_INT(BLE_MESH_ADV(buf)->xmit));
}
if (BLE_MESH_ADV(buf)->adv_cnt != BLE_MESH_ADV_CNT_DEFAULT) {
adv_cnt = BLE_MESH_ADV(buf)->adv_cnt;
} else {
adv_cnt = BLE_MESH_TRANSMIT_COUNT(BLE_MESH_ADV(buf)->xmit) + 1;
}
duration = adv_cnt * (adv_int + 10);
adv_int = MAX(ADV_ITVL_MIN,
BLE_MESH_TRANSMIT_INT(BLE_MESH_ADV(buf)->xmit));
duration = (BLE_MESH_TRANSMIT_COUNT(BLE_MESH_ADV(buf)->xmit) + 1) *
(adv_int + 10);
BT_DBG("count %u interval %ums duration %ums",
adv_cnt, adv_int, duration);
BLE_MESH_TRANSMIT_COUNT(BLE_MESH_ADV(buf)->xmit) + 1, adv_int,
duration);
ad.type = adv_type[BLE_MESH_ADV(buf)->type];
ad.data_len = buf->len;
@@ -135,13 +94,10 @@ static inline int adv_send(struct bt_mesh_adv_inst *inst, uint16_t *adv_duration
param.interval_max = param.interval_min;
param.adv_duration = duration;
param.adv_count = adv_cnt;
param.adv_count = BLE_MESH_TRANSMIT_COUNT(BLE_MESH_ADV(buf)->xmit) + 1;
if (BLE_MESH_ADV(buf)->channel_map) {
param.channel_map = BLE_MESH_ADV(buf)->channel_map;
} else {
param.channel_map = BLE_MESH_ADV_CHAN_DEFAULT;
}
param.primary_phy = BLE_MESH_ADV_PHY_1M;
param.secondary_phy = BLE_MESH_ADV_PHY_1M;
#if CONFIG_BLE_MESH_PROXY_SOLIC_PDU_TX
if (BLE_MESH_ADV(buf)->type == BLE_MESH_ADV_PROXY_SOLIC) {

View File

@@ -4,7 +4,7 @@
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -14,7 +14,6 @@
#include "mesh/config.h"
#include "mesh/buf.h"
#include "mesh/timer.h"
#include "sys/types.h"
/**
* @brief Bluetooth Mesh Access Layer
@@ -152,58 +151,8 @@ struct bt_mesh_elem {
#define BLE_MESH_MODEL_ID_LIGHT_LC_SRV 0x130f
#define BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV 0x1310
#define BLE_MESH_MODEL_ID_LIGHT_LC_CLI 0x1311
#define BLE_MESH_MODEL_ID_BLOB_SRV 0x1400
#define BLE_MESH_MODEL_ID_BLOB_CLI 0x1401
#define BLE_MESH_MODEL_ID_DFU_SRV 0x1402
#define BLE_MESH_MODEL_ID_DFU_CLI 0x1403
#define BLE_MESH_MODEL_ID_DFD_SRV 0x1404
#define BLE_MESH_MODEL_ID_DFD_CLI 0x1405
#define BLE_MESH_MODEL_ID_MBT_SRV BLE_MESH_MODEL_ID_BLOB_SRV
#define BLE_MESH_MODEL_ID_MBT_CLI BLE_MESH_MODEL_ID_BLOB_CLI
typedef struct {
uint32_t adv_itvl;
uint8_t adv_cnt;
uint8_t channel_map;
} ble_mesh_adv_cfg_t;
#if CONFIG_BLE_MESH_EXT_ADV
typedef struct {
uint8_t primary_phy;
uint8_t secondary_phy;
uint8_t include_tx_power:1;
int8_t tx_power;
} ble_mesh_ext_adv_cfg_t;
#endif /* CONFIG_BLE_MESH_EXT_ADV */
#if CONFIG_BLE_MESH_LONG_PACKET
#define BLE_MESH_LONG_PACKET_FORCE (1)
#define BLE_MESH_LONG_PACKET_PREFER (2)
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
typedef struct {
uint8_t adv_cfg_used : 1;
#if CONFIG_BLE_MESH_EXT_ADV
uint8_t ext_adv_cfg_used : 1;
#endif /* CONFIG_BLE_MESH_EXT_ADV */
#if CONFIG_BLE_MESH_LONG_PACKET
uint8_t long_pkt_cfg_used : 1;
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
ble_mesh_adv_cfg_t adv_cfg;
#if CONFIG_BLE_MESH_EXT_ADV
ble_mesh_ext_adv_cfg_t ext_adv_cfg;
#endif /* CONFIG_BLE_MESH_EXT_ADV */
#if CONFIG_BLE_MESH_LONG_PACKET
/**
* Long packets will be used for broadcasting
* only if this flag is set and the traditional
* packet length (380 bytes) cannot be used.
*/
uint8_t long_pkt_cfg : 2;
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
} bt_mesh_msg_enh_params_t;
#define BLE_MESH_MODEL_ID_MBT_SRV 0x1400
#define BLE_MESH_MODEL_ID_MBT_CLI 0x1401
/** Message sending context. */
struct bt_mesh_msg_ctx {
@@ -255,8 +204,6 @@ struct bt_mesh_msg_ctx {
/** Change by Espressif, if the message is sent by a server
* model. Not used for receiving message. */
bool srv_send __attribute__((deprecated));
bt_mesh_msg_enh_params_t enh;
};
struct bt_mesh_model_op {
@@ -528,8 +475,6 @@ struct bt_mesh_model_pub {
.update = _update, \
}
typedef ssize_t (*settings_read_cb)(void *cb_arg, void *data, size_t len);
/** Model callback functions. */
struct bt_mesh_model_cb {
/** @brief Model init callback.
@@ -623,7 +568,7 @@ void bt_mesh_model_msg_init(struct net_buf_simple *msg, uint32_t opcode);
*
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_model_send(const struct bt_mesh_model *model,
int bt_mesh_model_send(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *msg,
const struct bt_mesh_send_cb *cb,
@@ -652,7 +597,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model);
*
* @return Pointer to the element that the given model belongs to.
*/
struct bt_mesh_elem *bt_mesh_model_elem(const struct bt_mesh_model *mod);
struct bt_mesh_elem *bt_mesh_model_elem(struct bt_mesh_model *mod);
/** @brief Find a SIG model.
*

View File

@@ -1,7 +1,7 @@
/*
* SPDX-FileCopyrightText: 2017 Nordic Semiconductor ASA
* SPDX-FileCopyrightText: 2015-2017 Intel Corporation
* SPDX-FileContributor: 2018-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -77,17 +77,11 @@ extern "C" {
#endif
#endif /* CONFIG_BT_NIMBLE_ENABLED */
#if CONFIG_BLE_MESH_LONG_PACKET
#define BLE_MESH_GAP_ADV_MAX_LEN (2 + CONFIG_BLE_MESH_LONG_PACKET_ADV_LEN)
#else
#define BLE_MESH_GAP_ADV_MAX_LEN 31
#endif
#define BLE_MESH_GATT_DEF_MTU_SIZE 23
#if CONFIG_BLE_MESH_USE_BLE_50
#define BLE_MESH_TX_POWER_INCLUDE_DEFAULT false
#define BLE_MESH_TX_POWER_DEFAULT 0x7f
#define BLE_MESH_ADV_PHY_UNASSIGNED 0
#define BLE_MESH_ADV_PHY_1M 1
#define BLE_MESH_ADV_PHY_2M 2
@@ -97,8 +91,6 @@ extern "C" {
#define BLE_MESH_ADV_PHY_OPTION_PREFER_S8 2
#define BLE_MESH_ADV_PHY_OPTION_REQUIRE_S2 3
#define BLE_MESH_ADV_PHY_OPTION_REQUIRE_S8 4
#define BLE_MESH_ADV_PRI_PHY_DEFAULT BLE_MESH_ADV_PHY_1M
#define BLE_MESH_ADV_SEC_PHY_DEFAULT BLE_MESH_ADV_PHY_1M
#endif
/* BD ADDR types */
@@ -120,9 +112,6 @@ extern "C" {
#define BLE_MESH_ADV_SCAN_RSP 0x04
#else
/* Bluetooth Core Spec 6.0, Vol 4, Part E, 7.7.65.13 */
#if CONFIG_BLE_MESH_EXT_ADV
#define BLE_MESH_EXT_ADV_NONCONN_IND (0)
#endif
#define BLE_MESH_ADV_IND (0x13)
#define BLE_MESH_ADV_DIRECT_IND (0x15)
#define BLE_MESH_ADV_SCAN_IND (0x12)
@@ -131,15 +120,10 @@ extern "C" {
#define BLE_MESH_ADV_SCAN_RSP (0x1b)
#endif
#define BLE_MESH_ADV_ITVL_DEFAULT (0)
#define BLE_MESH_ADV_CNT_DEFAULT (0)
/* advertising channel map */
#define BLE_MESH_ADV_CHAN_UNASSIGNED (0)
#define BLE_MESH_ADV_CHAN_37 BIT(0)
#define BLE_MESH_ADV_CHAN_38 BIT(1)
#define BLE_MESH_ADV_CHAN_39 BIT(2)
#define BLE_MESH_ADV_CHAN_DEFAULT (BLE_MESH_ADV_CHAN_39|BLE_MESH_ADV_CHAN_38|BLE_MESH_ADV_CHAN_37)
#define BLE_MESH_ADV_CHNL_37 BIT(0)
#define BLE_MESH_ADV_CHNL_38 BIT(1)
#define BLE_MESH_ADV_CHNL_39 BIT(2)
/* Advertising filter policy */
#define BLE_MESH_AP_SCAN_CONN_ALL 0x00
@@ -488,8 +472,6 @@ struct bt_mesh_adv_param {
/** Maximum Advertising Interval (N * 0.625) */
uint16_t interval_max;
uint8_t channel_map;
#if CONFIG_BLE_MESH_USE_BLE_50
/** Maximum Advertising Duration (N * 0.625) */
uint16_t adv_duration;
@@ -502,10 +484,6 @@ struct bt_mesh_adv_param {
/** Advertising Secondary PHY */
uint8_t secondary_phy;
int8_t tx_power;
uint8_t include_tx_power : 1;
#endif
};
@@ -599,8 +577,6 @@ struct bt_mesh_adv_report {
/* Secondary advertising PHY */
uint8_t secondary_phy;
uint8_t tx_power;
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
};

View File

@@ -112,11 +112,7 @@ struct bt_mesh_hci_cp_set_adv_param {
#define BLE_MESH_HCI_OP_SET_ADV_DATA BLE_MESH_OP(BLE_MESH_OGF_LE, 0x0008)
struct bt_mesh_hci_cp_set_adv_data {
uint8_t len;
#if CONFIG_BLE_MESH_LONG_PACKET
uint8_t data[2 + CONFIG_BLE_MESH_LONG_PACKET_ADV_LEN];
#else
uint8_t data[31];
#endif
} __attribute__((packed));
#define BLE_MESH_HCI_OP_SET_SCAN_RSP_DATA BLE_MESH_OP(BLE_MESH_OGF_LE, 0x0009)

View File

@@ -2,7 +2,7 @@
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -27,6 +27,7 @@
#include "fast_prov.h"
#include "prov_node.h"
#include "test.h"
#include "fast_prov.h"
#include "proxy_client.h"
#include "proxy_server.h"
#include "pvnr_mgmt.h"
@@ -1673,27 +1674,7 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
*/
#if !CONFIG_BLE_MESH_RELAY_ADV_BUF
#if CONFIG_BLE_MESH_EXT_ADV
if (rx->ctx.enh.ext_adv_cfg_used) {
#if CONFIG_BLE_MESH_LONG_PACKET
if (rx->ctx.enh.long_pkt_cfg) {
buf = bt_mesh_adv_create(BLE_MESH_ADV_EXT_LONG_RELAY_DATA, K_NO_WAIT);
} else
#endif
{
buf = bt_mesh_adv_create(BLE_MESH_ADV_EXT_DATA, K_NO_WAIT);
}
if (buf) {
EXT_ADV(buf)->primary_phy = rx->ctx.enh.ext_adv_cfg.primary_phy;
EXT_ADV(buf)->secondary_phy = rx->ctx.enh.ext_adv_cfg.secondary_phy;
EXT_ADV(buf)->include_tx_power = rx->ctx.enh.ext_adv_cfg.include_tx_power;
EXT_ADV(buf)->tx_power = rx->ctx.enh.ext_adv_cfg.tx_power;
}
} else
#endif
{
buf = bt_mesh_adv_create(BLE_MESH_ADV_DATA, K_NO_WAIT);
}
buf = bt_mesh_adv_create(BLE_MESH_ADV_DATA, K_NO_WAIT);
#else
/* Check if the number of relay packets in queue is too large, if so
* use minimum relay retransmit value for later relay packets.
@@ -1701,27 +1682,7 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
if (bt_mesh_get_stored_relay_count() >= BLE_MESH_MAX_STORED_RELAY_COUNT) {
xmit = BLE_MESH_TRANSMIT(0, 20);
}
#if CONFIG_BLE_MESH_EXT_ADV
if (rx->ctx.enh.ext_adv_cfg_used) {
#if CONFIG_BLE_MESH_LONG_PACKET
if (rx->ctx.enh.long_pkt_cfg) {
buf = bt_mesh_adv_create(BLE_MESH_ADV_EXT_LONG_RELAY_DATA, K_NO_WAIT);
} else
#endif
{
buf = bt_mesh_adv_create(BLE_MESH_ADV_EXT_DATA, K_NO_WAIT);
}
if (buf) {
EXT_ADV(buf)->primary_phy = rx->ctx.enh.ext_adv_cfg.primary_phy;
EXT_ADV(buf)->secondary_phy = rx->ctx.enh.ext_adv_cfg.secondary_phy;
EXT_ADV(buf)->include_tx_power = rx->ctx.enh.ext_adv_cfg.include_tx_power;
EXT_ADV(buf)->tx_power = rx->ctx.enh.ext_adv_cfg.tx_power;
}
} else
#endif
{
buf = bt_mesh_relay_adv_create(BLE_MESH_ADV_RELAY_DATA, K_NO_WAIT);
}
buf = bt_mesh_relay_adv_create(BLE_MESH_ADV_RELAY_DATA, K_NO_WAIT);
#endif
if (!buf) {
@@ -1961,42 +1922,33 @@ void bt_mesh_generic_net_recv(struct net_buf_simple *data,
struct bt_mesh_net_rx *rx,
enum bt_mesh_net_if net_if)
{
NET_BUF_SIMPLE_DEFINE(buf, 29);
struct net_buf_simple_state state = {0};
struct net_buf_simple *buf = NULL;
if (data->len > (BLE_MESH_GAP_ADV_MAX_LEN - 2)) {
BT_ERR("Invalid net message length %d", data->len);
return;
}
assert(rx);
BT_DBG("rssi %d net_if %u", rx->ctx.recv_rssi, net_if);
if (!ready_to_recv()) {
return;
}
buf = bt_mesh_alloc_buf(data->len);
if (!buf) {
BT_ERR("Alloc net msg buffer failed");
if (bt_mesh_net_decode(data, net_if, rx, &buf)) {
return;
}
BT_DBG("rssi %d net_if %u", rx->ctx.recv_rssi, net_if);
if (bt_mesh_net_decode(data, net_if, rx, buf)) {
goto free_net_msg_buf;
}
if (ignore_net_msg(rx->ctx.addr, rx->ctx.recv_dst)) {
goto free_net_msg_buf;
return;
}
/* Save the state so the buffer can later be relayed */
net_buf_simple_save(buf, &state);
net_buf_simple_save(&buf, &state);
BT_BQB(BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_NODE | \
BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_NET,
"\nNetRecv: ctl: %d, src: %d, dst: %d, ttl: %d, data: 0x%s",
rx->ctl, rx->ctx.addr, rx->ctx.recv_dst, rx->ctx.recv_ttl,
bt_hex(buf->data + BLE_MESH_NET_HDR_LEN, buf->len - BLE_MESH_NET_HDR_LEN));
bt_hex(buf.data + BLE_MESH_NET_HDR_LEN, buf.len - BLE_MESH_NET_HDR_LEN));
/* If trying to handle a message with DST set to all-directed-forwarding-nodes,
* we need to make sure the directed forwarding functionality is enabled in the
@@ -2006,15 +1958,6 @@ void bt_mesh_generic_net_recv(struct net_buf_simple *data,
bt_mesh_fixed_direct_match(rx->sub, rx->ctx.recv_dst) ||
bt_mesh_elem_find(rx->ctx.recv_dst));
#if CONFIG_BLE_MESH_LONG_PACKET
/* It should be noted that if the length of buf
* is less than or equal to 29, it still may be the
* last segment for a long packet, But if the bit
* is set, it must be part of the long packet*/
rx->ctx.enh.long_pkt_cfg_used = (buf->len >= 29);
rx->ctx.enh.long_pkt_cfg = BLE_MESH_LONG_PACKET_FORCE;
#endif
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
#if CONFIG_BLE_MESH_PRB_SRV
bt_mesh_private_gatt_proxy_state_get() != BLE_MESH_PRIVATE_GATT_PROXY_ENABLED &&
@@ -2025,7 +1968,7 @@ void bt_mesh_generic_net_recv(struct net_buf_simple *data,
if (bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_DISABLED &&
!rx->local_match) {
BT_INFO("Proxy is disabled; ignoring message");
goto free_net_msg_buf;
return;
}
/* If the Directed Proxy Server receives a valid Network PDU from the Directed
@@ -2052,7 +1995,7 @@ void bt_mesh_generic_net_recv(struct net_buf_simple *data,
* credentials. Remove it from the message cache so that we accept
* it again in the future.
*/
if (bt_mesh_trans_recv(buf, rx) == -EAGAIN) {
if (bt_mesh_trans_recv(&buf, rx) == -EAGAIN) {
BT_WARN("Removing rejected message from Network Message Cache");
msg_cache[rx->msg_cache_idx].src = BLE_MESH_ADDR_UNASSIGNED;
/* Rewind the next index now that we're not using this entry */
@@ -2068,12 +2011,9 @@ void bt_mesh_generic_net_recv(struct net_buf_simple *data,
&& !rx->replay_msg
#endif
)) {
net_buf_simple_restore(buf, &state);
bt_mesh_net_relay(buf, rx);
net_buf_simple_restore(&buf, &state);
bt_mesh_net_relay(&buf, rx);
}
free_net_msg_buf:
bt_mesh_free(buf);
}
static void ivu_refresh(struct k_work *work)

View File

@@ -2,7 +2,7 @@
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -473,14 +473,6 @@ static inline void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi,
enum bt_mesh_net_if net_if)
{
struct bt_mesh_net_rx rx = { .ctx.recv_rssi = rssi };
#if CONFIG_BLE_MESH_EXT_ADV
rx.ctx.enh.adv_cfg_used = false;
rx.ctx.enh.ext_adv_cfg_used = false;
#if CONFIG_BLE_MESH_LONG_PACKET
rx.ctx.enh.long_pkt_cfg_used = (data->len >= 29);
rx.ctx.enh.long_pkt_cfg = BLE_MESH_LONG_PACKET_FORCE;
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
#endif /* CONFIG_BLE_MESH_EXT_ADV */
bt_mesh_generic_net_recv(data, &rx, net_if);
}

Some files were not shown because too many files have changed in this diff Show More