mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-26 20:53:11 +00:00
Merge branch 'feature/temperature_intr' into 'master'
temperature sensor: Add high/low value threshold interrupt support Closes IDF-5786 See merge request espressif/esp-idf!22331
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -8,6 +8,11 @@
|
||||
#include "esp_log.h"
|
||||
#include "unity.h"
|
||||
#include "driver/temperature_sensor.h"
|
||||
#include "esp_attr.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "unity_test_utils_cache.h"
|
||||
|
||||
TEST_CASE("Temperature_sensor_driver_workflow_test", "[temperature_sensor]")
|
||||
{
|
||||
@@ -79,3 +84,64 @@ TEST_CASE("Double Start-Stop test", "[temperature_sensor]")
|
||||
TEST_ESP_OK(temperature_sensor_disable(temp_handle));
|
||||
TEST_ESP_OK(temperature_sensor_uninstall(temp_handle));
|
||||
}
|
||||
|
||||
#if SOC_TEMPERATURE_SENSOR_INTR_SUPPORT
|
||||
|
||||
IRAM_ATTR static bool temp_sensor_cbs_test(temperature_sensor_handle_t tsens, const temperature_sensor_threshold_event_data_t *edata, void *user_data)
|
||||
{
|
||||
uint8_t *times = (uint8_t*)user_data;
|
||||
ESP_DRAM_LOGI("tsens", "Temperature value is higher or lower than threshold, restart...\n\n");
|
||||
(*times)++;
|
||||
return false;
|
||||
}
|
||||
|
||||
#if CONFIG_TEMP_SENSOR_ISR_IRAM_SAFE
|
||||
static void IRAM_ATTR test_delay_post_cache_disable(void *args)
|
||||
{
|
||||
esp_rom_delay_us(1000);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("Temperature sensor callback test", "[temperature_sensor]")
|
||||
{
|
||||
printf("Initializing Temperature sensor\n");
|
||||
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_event_callbacks_t cbs = {
|
||||
.on_threshold = temp_sensor_cbs_test,
|
||||
};
|
||||
|
||||
temperature_sensor_abs_threshold_config_t threshold_cfg = {
|
||||
.high_threshold = 50,
|
||||
.low_threshold = -10,
|
||||
};
|
||||
uint8_t temperature_alarm = 0;
|
||||
uint8_t cnt = 10;
|
||||
TEST_ESP_OK(temperature_sensor_set_absolute_threshold(temp_handle, &threshold_cfg));
|
||||
temperature_sensor_register_callbacks(temp_handle, &cbs, &temperature_alarm);
|
||||
|
||||
TEST_ESP_OK(temperature_sensor_enable(temp_handle));
|
||||
#if CONFIG_TEMP_SENSOR_ISR_IRAM_SAFE
|
||||
printf("disable flash cache and check if we can still get temperature intr\r\n");
|
||||
for (int i = 0; i < 100; i++) {
|
||||
unity_utils_run_cache_disable_stub(test_delay_post_cache_disable, NULL);
|
||||
}
|
||||
#endif
|
||||
while (cnt--) {
|
||||
ESP_ERROR_CHECK(temperature_sensor_get_celsius(temp_handle, &tsens_out));
|
||||
printf("Temperature out celsius %f°C\n", tsens_out);
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
|
||||
TEST_ESP_OK(temperature_sensor_disable(temp_handle));
|
||||
TEST_ESP_OK(temperature_sensor_uninstall(temp_handle));
|
||||
printf("temperature alarm is %d\n", temperature_alarm);
|
||||
// Note that on CI runner there is no way to heat the board to trigger such an interrupt.
|
||||
// But locally test should be notice that alarm must be larger than 0.
|
||||
TEST_ASSERT_GREATER_OR_EQUAL(0, temperature_alarm);
|
||||
}
|
||||
|
||||
#endif // SOC_TEMPERATURE_SENSOR_INTR_SUPPORT
|
||||
|
||||
@@ -16,6 +16,14 @@ from pytest_embedded import Dut
|
||||
'release',
|
||||
], indirect=True)
|
||||
def test_temperature_sensor_driver(dut: Dut) -> None:
|
||||
dut.expect('Press ENTER to see the list of tests')
|
||||
dut.write('*')
|
||||
dut.expect_unity_test_output(timeout=120)
|
||||
dut.run_all_single_board_cases()
|
||||
|
||||
|
||||
@pytest.mark.esp32c6
|
||||
@pytest.mark.esp32h2
|
||||
@pytest.mark.generic
|
||||
@pytest.mark.parametrize('config', [
|
||||
'iram_safe',
|
||||
], indirect=True)
|
||||
def test_temperature_sensor_cbs(dut: Dut) -> None:
|
||||
dut.run_all_single_board_cases()
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
CONFIG_COMPILER_DUMP_RTL_FILES=y
|
||||
CONFIG_TEMP_SENSOR_ISR_IRAM_SAFE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_NONE=y
|
||||
# silent the error check, as the error string are stored in rodata, causing RTL check failure
|
||||
CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT=y
|
||||
# place non-ISR FreeRTOS functions in Flash
|
||||
CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y
|
||||
Reference in New Issue
Block a user