mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'feature/tsens_etm' into 'master'
feature(temperature sensor): Temperature sensor ETM support. Closes IDF-6357 See merge request espressif/esp-idf!28880
This commit is contained in:
commit
0f03434119
@ -3,6 +3,9 @@ set(priv_req efuse)
|
||||
set(public_include "include")
|
||||
if(CONFIG_SOC_TEMP_SENSOR_SUPPORTED)
|
||||
list(APPEND srcs "src/temperature_sensor.c")
|
||||
if(CONFIG_SOC_TEMPERATURE_SENSOR_SUPPORT_ETM)
|
||||
list(APPEND srcs "src/temperature_sensor_etm.c")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
idf_component_register(SRCS ${srcs}
|
||||
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_etm.h"
|
||||
#include "driver/temperature_sensor.h"
|
||||
#include "hal/temperature_sensor_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Temperature Sensor ETM event configuration
|
||||
*/
|
||||
typedef struct {
|
||||
temperature_sensor_etm_event_type_t event_type; /*!< Temperature Sensor ETM event type */
|
||||
} temperature_sensor_etm_event_config_t;
|
||||
|
||||
/**
|
||||
* @brief Get the ETM event for Temperature Sensor
|
||||
*
|
||||
* @note The created ETM event object can be deleted later by calling `esp_etm_del_event`
|
||||
*
|
||||
* @param[in] tsens Temperature Sensor handle, allocated by `temperature_sensor_install()`
|
||||
* @param[in] config Temperature Sensor ETM event configuration
|
||||
* @param[out] out_event Returned ETM event handle
|
||||
* @return
|
||||
* - ESP_OK: Get ETM event successfully
|
||||
* - ESP_ERR_INVALID_ARG: Get ETM event failed because of invalid argument
|
||||
* - ESP_FAIL: Get ETM event failed because of other error
|
||||
*/
|
||||
esp_err_t temperature_sensor_new_etm_event(temperature_sensor_handle_t tsens, const temperature_sensor_etm_event_config_t *config, esp_etm_event_handle_t *out_event);
|
||||
|
||||
/**
|
||||
* @brief Temperature Sensor ETM task configuration
|
||||
*/
|
||||
typedef struct {
|
||||
temperature_sensor_etm_task_type_t task_type; /*!< Temperature Sensor ETM task type */
|
||||
} temperature_sensor_etm_task_config_t;
|
||||
|
||||
/**
|
||||
* @brief Get the ETM task for Temperature Sensor
|
||||
*
|
||||
* @note The created ETM task object can be deleted later by calling `esp_etm_del_task`
|
||||
*
|
||||
* @param[in] tsens Temperature Sensor, allocated by `temperature_sensor_install()`
|
||||
* @param[in] config Temperature Sensor ETM task configuration
|
||||
* @param[out] out_task Returned ETM task handle
|
||||
* @return
|
||||
* - ESP_OK: Get ETM task successfully
|
||||
* - ESP_ERR_INVALID_ARG: Get ETM task failed because of invalid argument
|
||||
* - ESP_FAIL: Get ETM task failed because of other error
|
||||
*/
|
||||
esp_err_t temperature_sensor_new_etm_task(temperature_sensor_handle_t tsens, const temperature_sensor_etm_task_config_t *config, esp_etm_task_handle_t *out_task);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -103,9 +103,12 @@ esp_err_t temperature_sensor_install(const temperature_sensor_config_t *tsens_co
|
||||
ESP_RETURN_ON_FALSE((s_tsens_attribute_copy == NULL), ESP_ERR_INVALID_STATE, TAG, "Already installed");
|
||||
temperature_sensor_handle_t tsens = NULL;
|
||||
tsens = (temperature_sensor_obj_t *) heap_caps_calloc(1, sizeof(temperature_sensor_obj_t), MALLOC_CAP_DEFAULT);
|
||||
ESP_GOTO_ON_FALSE(tsens != NULL, ESP_ERR_NO_MEM, err, TAG, "no mem for temp sensor");
|
||||
ESP_RETURN_ON_FALSE((tsens != NULL), ESP_ERR_NO_MEM, TAG, "no mem for temp sensor");
|
||||
tsens->clk_src = tsens_config->clk_src;
|
||||
|
||||
temperature_sensor_power_acquire();
|
||||
temperature_sensor_ll_clk_sel(tsens->clk_src);
|
||||
|
||||
ESP_GOTO_ON_ERROR(temperature_sensor_attribute_table_sort(), err, TAG, "Table sort failed");
|
||||
ESP_GOTO_ON_ERROR(temperature_sensor_choose_best_range(tsens, tsens_config), err, TAG, "Cannot select the correct range");
|
||||
|
||||
@ -140,6 +143,7 @@ esp_err_t temperature_sensor_uninstall(temperature_sensor_handle_t tsens)
|
||||
ESP_RETURN_ON_ERROR(esp_intr_free(tsens->temp_sensor_isr_handle), TAG, "uninstall interrupt service failed");
|
||||
}
|
||||
#endif // SOC_TEMPERATURE_SENSOR_INTR_SUPPORT
|
||||
temperature_sensor_power_release();
|
||||
|
||||
free(tsens);
|
||||
return ESP_OK;
|
||||
@ -175,8 +179,6 @@ esp_err_t temperature_sensor_enable(temperature_sensor_handle_t tsens)
|
||||
temperature_sensor_ll_sample_enable(true);
|
||||
#endif // SOC_TEMPERATURE_SENSOR_INTR_SUPPORT
|
||||
|
||||
temperature_sensor_ll_clk_sel(tsens->clk_src);
|
||||
temperature_sensor_power_acquire();
|
||||
// After enabling/reseting the temperature sensor,
|
||||
// the output value gradually approaches the true temperature
|
||||
// value as the measurement time increases. 300us is recommended.
|
||||
@ -190,7 +192,6 @@ esp_err_t temperature_sensor_disable(temperature_sensor_handle_t tsens)
|
||||
ESP_RETURN_ON_FALSE(tsens, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
|
||||
ESP_RETURN_ON_FALSE(tsens->fsm == TEMP_SENSOR_FSM_ENABLE, ESP_ERR_INVALID_STATE, TAG, "tsens not enabled yet");
|
||||
|
||||
temperature_sensor_power_release();
|
||||
#if SOC_TEMPERATURE_SENSOR_INTR_SUPPORT
|
||||
temperature_sensor_ll_wakeup_enable(false);
|
||||
temperature_sensor_ll_sample_enable(false);
|
||||
|
96
components/esp_driver_tsens/src/temperature_sensor_etm.c
Normal file
96
components/esp_driver_tsens/src/temperature_sensor_etm.c
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_etm.h"
|
||||
#include "esp_check.h"
|
||||
#include "esp_private/etm_interface.h"
|
||||
#include "hal/temperature_sensor_ll.h"
|
||||
#include "driver/temperature_sensor_etm.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#if CONFIG_ETM_ENABLE_DEBUG_LOG
|
||||
// The local log level must be defined before including esp_log.h
|
||||
// Set the maximum log level for this source file
|
||||
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
|
||||
#endif
|
||||
#include "esp_log.h"
|
||||
|
||||
#define ETM_MEM_ALLOC_CAPS MALLOC_CAP_DEFAULT
|
||||
|
||||
static const char *TAG = "tsens-etm";
|
||||
|
||||
static esp_err_t temperature_sensor_del_etm_event(esp_etm_event_t *event)
|
||||
{
|
||||
free(event);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t temperature_sensor_del_etm_task(esp_etm_task_t *task)
|
||||
{
|
||||
free(task);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t temperature_sensor_new_etm_event(temperature_sensor_handle_t tsens, const temperature_sensor_etm_event_config_t *config, esp_etm_event_handle_t *out_event)
|
||||
{
|
||||
#if CONFIG_ETM_ENABLE_DEBUG_LOG
|
||||
esp_log_level_set(TAG, ESP_LOG_DEBUG);
|
||||
#endif
|
||||
esp_etm_event_t *event = NULL;
|
||||
esp_err_t ret = ESP_OK;
|
||||
ESP_GOTO_ON_FALSE(tsens && config && out_event, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument");
|
||||
ESP_GOTO_ON_FALSE(config->event_type < TEMPERATURE_SENSOR_EVENT_MAX, ESP_ERR_INVALID_ARG, err, TAG, "invalid event type");
|
||||
event = heap_caps_calloc(1, sizeof(esp_etm_event_t), ETM_MEM_ALLOC_CAPS);
|
||||
ESP_GOTO_ON_FALSE(event, ESP_ERR_NO_MEM, err, TAG, "no memory for ETM event");
|
||||
|
||||
uint32_t event_id = TEMPERATURE_SENSOR_LL_ETM_EVENT_TABLE(config->event_type);
|
||||
ESP_GOTO_ON_FALSE(event_id != 0, ESP_ERR_NOT_SUPPORTED, err, TAG, "not supported event type");
|
||||
|
||||
// fill the ETM event object
|
||||
event->event_id = event_id;
|
||||
event->trig_periph = ETM_TRIG_PERIPH_TSENS;
|
||||
event->del = temperature_sensor_del_etm_event;
|
||||
ESP_LOGD(TAG, "new event @%p, event_id=%"PRIu32, event, event_id);
|
||||
*out_event = event;
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
if (event) {
|
||||
temperature_sensor_del_etm_event(event);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t temperature_sensor_new_etm_task(temperature_sensor_handle_t tsens, const temperature_sensor_etm_task_config_t *config, esp_etm_task_handle_t *out_task)
|
||||
{
|
||||
#if CONFIG_ETM_ENABLE_DEBUG_LOG
|
||||
esp_log_level_set(TAG, ESP_LOG_DEBUG);
|
||||
#endif
|
||||
esp_etm_task_t *task = NULL;
|
||||
esp_err_t ret = ESP_OK;
|
||||
ESP_GOTO_ON_FALSE(tsens && config && out_task, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument");
|
||||
ESP_GOTO_ON_FALSE(config->task_type < TEMPERATURE_SENSOR_TASK_MAX, ESP_ERR_INVALID_ARG, err, TAG, "invalid task type");
|
||||
task = heap_caps_calloc(1, sizeof(esp_etm_task_t), ETM_MEM_ALLOC_CAPS);
|
||||
ESP_GOTO_ON_FALSE(task, ESP_ERR_NO_MEM, err, TAG, "no memory for ETM task");
|
||||
|
||||
uint32_t task_id = TEMPERATURE_SENSOR_LL_ETM_TASK_TABLE(config->task_type);
|
||||
ESP_GOTO_ON_FALSE(task_id != 0, ESP_ERR_NOT_SUPPORTED, err, TAG, "not supported task type");
|
||||
|
||||
// fill the ETM task object
|
||||
task->task_id = task_id;
|
||||
task->trig_periph = ETM_TRIG_PERIPH_TSENS;
|
||||
task->del = temperature_sensor_del_etm_task;
|
||||
ESP_LOGD(TAG, "new task @%p, task_id=%"PRIu32, task, task_id);
|
||||
*out_task = task;
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
if (task) {
|
||||
temperature_sensor_del_etm_task(task);
|
||||
}
|
||||
return ret;
|
||||
}
|
@ -2,8 +2,12 @@ set(srcs "test_app_main.c"
|
||||
"test_temperature_sensor.c"
|
||||
"test_temperature_phy.c")
|
||||
|
||||
if(CONFIG_SOC_TEMPERATURE_SENSOR_SUPPORT_ETM)
|
||||
list(APPEND srcs "test_temperature_etm.c")
|
||||
endif()
|
||||
|
||||
# In order for the cases defined by `TEST_CASE` to be linked into the final elf,
|
||||
# the component can be registered as WHOLE_ARCHIVE
|
||||
idf_component_register(SRCS ${srcs}
|
||||
PRIV_REQUIRES unity esp_wifi test_utils nvs_flash esp_driver_tsens
|
||||
PRIV_REQUIRES unity esp_wifi test_utils nvs_flash esp_driver_tsens esp_driver_gpio
|
||||
WHOLE_ARCHIVE)
|
||||
|
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include "unity.h"
|
||||
#include "unity_test_utils.h"
|
||||
#include "esp_attr.h"
|
||||
#include "driver/gpio_etm.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/temperature_sensor_etm.h"
|
||||
#include "driver/temperature_sensor.h"
|
||||
#include "soc/soc_etm_struct.h"
|
||||
|
||||
// To run this example, you need a facility that can make the temperature change
|
||||
// on board. Like a heat gun.
|
||||
// Then after the temperature meet the threshold, you can see the gpio level changes
|
||||
// from 0 to 1 on logic analyzer or oscilloscope.
|
||||
TEST_CASE("temperature sensor alarm cause gpio pull up", "[etm]")
|
||||
{
|
||||
const uint32_t output_gpio = 5;
|
||||
// temperature sensor alarm ---> ETM channel A ---> GPIO level to high
|
||||
printf("allocate etm channel\r\n");
|
||||
esp_etm_channel_config_t etm_config = {};
|
||||
esp_etm_channel_handle_t etm_channel_a;
|
||||
TEST_ESP_OK(esp_etm_new_channel(&etm_config, &etm_channel_a));
|
||||
|
||||
printf("allocate GPIO etm task\r\n");
|
||||
esp_etm_task_handle_t gpio_task = NULL;
|
||||
gpio_etm_task_config_t gpio_task_config = {
|
||||
.action = GPIO_ETM_TASK_ACTION_SET,
|
||||
};
|
||||
TEST_ESP_OK(gpio_new_etm_task(&gpio_task_config, &gpio_task));
|
||||
// set gpio number for the gpio etm primitives
|
||||
TEST_ESP_OK(gpio_etm_task_add_gpio(gpio_task, output_gpio));
|
||||
|
||||
printf("initialize gpio\r\n");
|
||||
gpio_set_level(output_gpio, 0);
|
||||
gpio_config_t task_gpio_config = {
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pin_bit_mask = 1ULL << output_gpio,
|
||||
};
|
||||
TEST_ESP_OK(gpio_config(&task_gpio_config));
|
||||
|
||||
float tsens_out;
|
||||
temperature_sensor_config_t temp_sensor = TEMPERATURE_SENSOR_CONFIG_DEFAULT(10, 50);
|
||||
temperature_sensor_handle_t temp_handle = NULL;
|
||||
TEST_ESP_OK(temperature_sensor_install(&temp_sensor, &temp_handle));
|
||||
|
||||
temperature_sensor_abs_threshold_config_t threshold_cfg = {
|
||||
.high_threshold = 50,
|
||||
.low_threshold = -10,
|
||||
};
|
||||
TEST_ESP_OK(temperature_sensor_set_absolute_threshold(temp_handle, &threshold_cfg));
|
||||
TEST_ESP_OK(temperature_sensor_enable(temp_handle));
|
||||
printf("Temperature sensor started\n");
|
||||
|
||||
temperature_sensor_etm_event_config_t tsens_etm_event = {
|
||||
.event_type = TEMPERATURE_SENSOR_EVENT_OVER_LIMIT,
|
||||
};
|
||||
|
||||
esp_etm_event_handle_t tsens_evt;
|
||||
|
||||
TEST_ESP_OK(temperature_sensor_new_etm_event(temp_handle, &tsens_etm_event, &tsens_evt));
|
||||
|
||||
printf("connect event and task to the channel\r\n");
|
||||
TEST_ESP_OK(esp_etm_channel_connect(etm_channel_a, tsens_evt, gpio_task));
|
||||
|
||||
printf("enable etm channel\r\n");
|
||||
TEST_ESP_OK(esp_etm_channel_enable(etm_channel_a));
|
||||
|
||||
uint32_t cnt = 20;
|
||||
while (cnt--) {
|
||||
TEST_ESP_OK(temperature_sensor_get_celsius(temp_handle, &tsens_out));
|
||||
printf("Temperature out celsius %f°C\n", tsens_out);
|
||||
vTaskDelay(100);
|
||||
}
|
||||
|
||||
TEST_ESP_OK(temperature_sensor_disable(temp_handle));
|
||||
TEST_ESP_OK(temperature_sensor_uninstall(temp_handle));
|
||||
// delete etm primitives
|
||||
TEST_ESP_OK(gpio_etm_task_rm_gpio(gpio_task, output_gpio));
|
||||
TEST_ESP_OK(esp_etm_del_task(gpio_task));
|
||||
TEST_ESP_OK(esp_etm_del_event(tsens_evt));
|
||||
TEST_ESP_OK(esp_etm_channel_disable(etm_channel_a));
|
||||
TEST_ESP_OK(esp_etm_del_channel(etm_channel_a));
|
||||
}
|
@ -26,6 +26,7 @@ typedef enum {
|
||||
ETM_TRIG_PERIPH_SYSTIMER, /*!< ETM trigger source: Systimer */
|
||||
ETM_TRIG_PERIPH_MCPWM, /*!< ETM trigger source: MCPWM */
|
||||
ETM_TRIG_PERIPH_ANA_CMPR, /*!< ETM trigger source: Analog Comparator */
|
||||
ETM_TRIG_PERIPH_TSENS, /*!< ETM trigger source: Temperature Sensor */
|
||||
} etm_trigger_peripheral_t;
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -25,6 +25,7 @@
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/pcr_struct.h"
|
||||
#include "soc/interrupts.h"
|
||||
#include "soc/soc_etm_source.h"
|
||||
#include "hal/temperature_sensor_types.h"
|
||||
#include "hal/assert.h"
|
||||
#include "hal/misc.h"
|
||||
@ -41,6 +42,17 @@ extern "C" {
|
||||
|
||||
#define TEMPERATURE_SENSOR_LL_INTR_MASK APB_SARADC_APB_SARADC_TSENS_INT_ST
|
||||
|
||||
#define TEMPERATURE_SENSOR_LL_ETM_EVENT_TABLE(event) \
|
||||
(uint32_t [TEMPERATURE_SENSOR_EVENT_MAX]){ \
|
||||
[TEMPERATURE_SENSOR_EVENT_OVER_LIMIT] = TMPSNSR_EVT_OVER_LIMIT, \
|
||||
}[event]
|
||||
|
||||
#define TEMPERATURE_SENSOR_LL_ETM_TASK_TABLE(task) \
|
||||
(uint32_t [TEMPERATURE_SENSOR_TASK_MAX]){ \
|
||||
[TEMPERATURE_SENSOR_TASK_START] = TMPSNSR_TASK_START_SAMPLE, \
|
||||
[TEMPERATURE_SENSOR_TASK_STOP] = TMPSNSR_TASK_STOP_SAMPLE, \
|
||||
}[task]
|
||||
|
||||
typedef enum {
|
||||
TEMPERATURE_SENSOR_LL_WAKE_ABSOLUTE = 0,
|
||||
TEMPERATURE_SENSOR_LL_WAKE_DELTA = 1,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -24,6 +24,7 @@
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/pcr_struct.h"
|
||||
#include "soc/interrupts.h"
|
||||
#include "soc/soc_etm_source.h"
|
||||
#include "hal/temperature_sensor_types.h"
|
||||
#include "hal/assert.h"
|
||||
#include "hal/misc.h"
|
||||
@ -40,6 +41,17 @@ extern "C" {
|
||||
|
||||
#define TEMPERATURE_SENSOR_LL_INTR_MASK APB_SARADC_APB_SARADC_TSENS_INT_ST
|
||||
|
||||
#define TEMPERATURE_SENSOR_LL_ETM_EVENT_TABLE(event) \
|
||||
(uint32_t [TEMPERATURE_SENSOR_EVENT_MAX]){ \
|
||||
[TEMPERATURE_SENSOR_EVENT_OVER_LIMIT] = TMPSNSR_EVT_OVER_LIMIT, \
|
||||
}[event]
|
||||
|
||||
#define TEMPERATURE_SENSOR_LL_ETM_TASK_TABLE(task) \
|
||||
(uint32_t [TEMPERATURE_SENSOR_TASK_MAX]){ \
|
||||
[TEMPERATURE_SENSOR_TASK_START] = TMPSNSR_TASK_START_SAMPLE, \
|
||||
[TEMPERATURE_SENSOR_TASK_STOP] = TMPSNSR_TASK_STOP_SAMPLE, \
|
||||
}[task]
|
||||
|
||||
typedef enum {
|
||||
TEMPERATURE_SENSOR_LL_WAKE_ABSOLUTE = 0,
|
||||
TEMPERATURE_SENSOR_LL_WAKE_DELTA = 1,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -24,6 +24,7 @@
|
||||
#include "soc/soc.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/interrupts.h"
|
||||
#include "soc/soc_etm_source.h"
|
||||
#include "hal/temperature_sensor_types.h"
|
||||
#include "hal/assert.h"
|
||||
#include "hal/misc.h"
|
||||
@ -40,6 +41,17 @@ extern "C" {
|
||||
|
||||
#define TEMPERATURE_SENSOR_LL_INTR_MASK TSENS_COCPU_TSENS_WAKE_INT_ST
|
||||
|
||||
#define TEMPERATURE_SENSOR_LL_ETM_EVENT_TABLE(event) \
|
||||
(uint32_t [TEMPERATURE_SENSOR_EVENT_MAX]){ \
|
||||
[TEMPERATURE_SENSOR_EVENT_OVER_LIMIT] = TMPSNSR_EVT_OVER_LIMIT, \
|
||||
}[event]
|
||||
|
||||
#define TEMPERATURE_SENSOR_LL_ETM_TASK_TABLE(task) \
|
||||
(uint32_t [TEMPERATURE_SENSOR_TASK_MAX]){ \
|
||||
[TEMPERATURE_SENSOR_TASK_START] = TMPSNSR_TASK_START_SAMPLE, \
|
||||
[TEMPERATURE_SENSOR_TASK_STOP] = TMPSNSR_TASK_STOP_SAMPLE, \
|
||||
}[task]
|
||||
|
||||
typedef enum {
|
||||
TEMPERATURE_SENSOR_LL_WAKE_ABSOLUTE = 0,
|
||||
TEMPERATURE_SENSOR_LL_WAKE_DELTA = 1,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -22,6 +22,23 @@ typedef soc_periph_temperature_sensor_clk_src_t temperature_sensor_clk_src_t;
|
||||
typedef int temperature_sensor_clk_src_t;
|
||||
#endif // SOC_TEMP_SENSOR_SUPPORTED
|
||||
|
||||
/**
|
||||
* @brief temperature sensor event types enum
|
||||
*/
|
||||
typedef enum {
|
||||
TEMPERATURE_SENSOR_EVENT_OVER_LIMIT, /*!< Temperature sensor over limit event */
|
||||
TEMPERATURE_SENSOR_EVENT_MAX, /*!< Maximum number of temperature sensor events */
|
||||
} temperature_sensor_etm_event_type_t;
|
||||
|
||||
/**
|
||||
* @brief temperature sensor task types enum
|
||||
*/
|
||||
typedef enum {
|
||||
TEMPERATURE_SENSOR_TASK_START, /*!< Temperature sensor start task */
|
||||
TEMPERATURE_SENSOR_TASK_STOP, /*!< Temperature sensor stop task */
|
||||
TEMPERATURE_SENSOR_TASK_MAX, /*!< Maximum number of temperature sensor tasks */
|
||||
} temperature_sensor_etm_task_type_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1335,6 +1335,10 @@ config SOC_TEMPERATURE_SENSOR_INTR_SUPPORT
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TEMPERATURE_SENSOR_SUPPORT_ETM
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_WIFI_HW_TSF
|
||||
bool
|
||||
default y
|
||||
|
@ -536,6 +536,7 @@
|
||||
#define SOC_TEMPERATURE_SENSOR_SUPPORT_FAST_RC (1)
|
||||
#define SOC_TEMPERATURE_SENSOR_SUPPORT_XTAL (1)
|
||||
#define SOC_TEMPERATURE_SENSOR_INTR_SUPPORT (1)
|
||||
#define SOC_TEMPERATURE_SENSOR_SUPPORT_ETM (1)
|
||||
|
||||
/*------------------------------------ WI-FI CAPS ------------------------------------*/
|
||||
#define SOC_WIFI_HW_TSF (1) /*!< Support hardware TSF */
|
||||
|
@ -1299,6 +1299,10 @@ config SOC_TEMPERATURE_SENSOR_INTR_SUPPORT
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TEMPERATURE_SENSOR_SUPPORT_ETM
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_BLE_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
|
@ -515,6 +515,7 @@
|
||||
#define SOC_TEMPERATURE_SENSOR_SUPPORT_FAST_RC (1)
|
||||
#define SOC_TEMPERATURE_SENSOR_SUPPORT_XTAL (1)
|
||||
#define SOC_TEMPERATURE_SENSOR_INTR_SUPPORT (1)
|
||||
#define SOC_TEMPERATURE_SENSOR_SUPPORT_ETM (1)
|
||||
|
||||
/*---------------------------------- Bluetooth CAPS ----------------------------------*/
|
||||
#define SOC_BLE_SUPPORTED (1) /*!< Support Bluetooth Low Energy hardware */
|
||||
|
@ -1403,6 +1403,10 @@ config SOC_TSENS_IS_INDEPENDENT_FROM_ADC
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TEMPERATURE_SENSOR_SUPPORT_ETM
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_MEM_TCM_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
|
@ -592,6 +592,7 @@
|
||||
#define SOC_TEMPERATURE_SENSOR_LP_PLL_SUPPORT (1)
|
||||
#define SOC_TEMPERATURE_SENSOR_INTR_SUPPORT (1)
|
||||
#define SOC_TSENS_IS_INDEPENDENT_FROM_ADC (1) /*!< Temperature sensor is a separate module, not share regs with ADC */
|
||||
#define SOC_TEMPERATURE_SENSOR_SUPPORT_ETM (1)
|
||||
|
||||
/*-------------------------- Memory CAPS --------------------------*/
|
||||
#define SOC_MEM_TCM_SUPPORTED (1)
|
||||
|
@ -143,6 +143,7 @@ INPUT = \
|
||||
$(PROJECT_PATH)/components/esp_driver_spi/include/driver/spi_slave_hd.h \
|
||||
$(PROJECT_PATH)/components/esp_driver_spi/include/driver/spi_slave.h \
|
||||
$(PROJECT_PATH)/components/esp_driver_tsens/include/driver/temperature_sensor.h \
|
||||
$(PROJECT_PATH)/components/esp_driver_tsens/include/driver/temperature_sensor_etm.h \
|
||||
$(PROJECT_PATH)/components/esp_driver_uart/include/driver/uart.h \
|
||||
$(PROJECT_PATH)/components/esp_driver_uart/include/driver/uart_vfs.h \
|
||||
$(PROJECT_PATH)/components/esp_eth/include/esp_eth_com.h \
|
||||
@ -251,6 +252,7 @@ INPUT = \
|
||||
$(PROJECT_PATH)/components/hal/include/hal/sdm_types.h \
|
||||
$(PROJECT_PATH)/components/hal/include/hal/spi_flash_types.h \
|
||||
$(PROJECT_PATH)/components/hal/include/hal/spi_types.h \
|
||||
$(PROJECT_PATH)/components/hal/include/hal/temperature_sensor_types.h \
|
||||
$(PROJECT_PATH)/components/hal/include/hal/timer_types.h \
|
||||
$(PROJECT_PATH)/components/hal/include/hal/touch_sensor_types.h \
|
||||
$(PROJECT_PATH)/components/hal/include/hal/twai_types.h \
|
||||
|
@ -71,6 +71,7 @@ Other Peripheral Events
|
||||
:SOC_GDMA_SUPPORT_ETM: - Refer to :doc:`/api-reference/system/async_memcpy` for how to get the ETM event handle from async memcpy.
|
||||
:SOC_MCPWM_SUPPORT_ETM: - Refer to :doc:`/api-reference/peripherals/mcpwm` for how to get the ETM event handle from MCPWM.
|
||||
:SOC_ANA_CMPR_SUPPORT_ETM: - Refer to :doc:`/api-reference/peripherals/ana_cmpr` for how to get the ETM event handle from analog comparator.
|
||||
:SOC_TEMPERATURE_SENSOR_SUPPORT_ETM: - Refer to :doc:`/api-reference/peripherals/temp_sensor` for how to get the ETM event handle from temperature sensor.
|
||||
|
||||
.. _etm-task:
|
||||
|
||||
@ -96,6 +97,7 @@ Other Peripheral Tasks
|
||||
.. list::
|
||||
|
||||
:SOC_TIMER_SUPPORT_ETM: - Refer to :doc:`GPTimer </api-reference/peripherals/gptimer>` for how to get the ETM task handle from GPTimer.
|
||||
:SOC_TEMPERATURE_SENSOR_SUPPORT_ETM: - Refer to :doc:`/api-reference/peripherals/temp_sensor` for how to get the ETM task handle from temperature sensor.
|
||||
|
||||
.. _etm-channel-control:
|
||||
|
||||
|
@ -46,6 +46,7 @@ The description of the temperature sensor functionality is divided into the foll
|
||||
- :ref:`temp-power-management` - covers how the temperature sensor is affected when changing power mode (e.g., Light-sleep mode).
|
||||
:SOC_TEMPERATURE_SENSOR_INTR_SUPPORT: - :ref:`temp-iram-safe` - describes tips on how to make the temperature sensor interrupt work better along with a disabled cache.
|
||||
- :ref:`temp-thread-safety` - covers how to make the driver to be thread-safe.
|
||||
:SOC_TEMPERATURE_SENSOR_SUPPORT_ETM: - :ref:`temperature-sensor-etm-event-and-task` - describes what the events and tasks can be connected to the ETM channel.
|
||||
|
||||
.. _temp-resource-allocation:
|
||||
|
||||
@ -180,6 +181,21 @@ Thread Safety
|
||||
|
||||
In the temperature sensor driver, we do not add any protection to ensure the thread safety, because typically this driver is only supposed to be used in one task. If you have to use this driver in different tasks, please add extra locks to protect it.
|
||||
|
||||
.. only:: SOC_TEMPERATURE_SENSOR_SUPPORT_ETM
|
||||
|
||||
.. _temperature-sensor-etm-event-and-task:
|
||||
|
||||
ETM Event and Task
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Temperature Sensor is able to generate events that can interact with the :doc:`ETM </api-reference/peripherals/etm>` module. The supported events are listed in the :cpp:type:`temperature_sensor_etm_event_type_t`. You can call :cpp:func:`temperature_sensor_new_etm_event` to get the corresponding ETM event handle. The supported tasks are listed in the :cpp:type:`temperature_sensor_etm_task_type_t`. You can call :cpp:func:`temperature_sensor_new_etm_task` to get the corresponding ETM event handle.
|
||||
|
||||
.. note::
|
||||
|
||||
- :cpp:enumerator:`TEMPERATURE_SENSOR_EVENT_OVER_LIMIT` for :cpp:member:`temperature_sensor_etm_event_type_t::event_type` depends on what kind of threshold you set first. If you set the absolute threshold by :cpp:func:`temperature_sensor_set_absolute_threshold`, then the :cpp:enumerator:`TEMPERATURE_SENSOR_EVENT_OVER_LIMIT` refers to absolute threshold. Likewise, if you set the delta threshold by :cpp:func:`temperature_sensor_set_delta_threshold`, then the :cpp:enumerator:`TEMPERATURE_SENSOR_EVENT_OVER_LIMIT` refers to delta threshold.
|
||||
|
||||
For how to connect the event and task to an ETM channel, please refer to the :doc:`ETM </api-reference/peripherals/etm>` documentation.
|
||||
|
||||
Unexpected Behaviors
|
||||
--------------------
|
||||
|
||||
@ -202,3 +218,8 @@ API Reference
|
||||
----------------------------------
|
||||
|
||||
.. include-build-file:: inc/temperature_sensor.inc
|
||||
.. include-build-file:: inc/temperature_sensor_types.inc
|
||||
|
||||
.. only:: SOC_TEMPERATURE_SENSOR_SUPPORT_ETM
|
||||
|
||||
.. include-build-file:: inc/temperature_sensor_etm.inc
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user