2022-01-02 03:14:17 -05:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2022-08-06 02:52:22 -04:00
|
|
|
#include <inttypes.h>
|
2022-01-02 03:14:17 -05:00
|
|
|
#include "unity.h"
|
2022-08-06 02:52:22 -04:00
|
|
|
#include "unity_test_utils.h"
|
|
|
|
#include "esp_attr.h"
|
2022-01-02 03:14:17 -05:00
|
|
|
#include "driver/gptimer.h"
|
|
|
|
|
|
|
|
static bool IRAM_ATTR on_gptimer_alarm_cb(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_ctx)
|
|
|
|
{
|
2022-08-06 02:52:22 -04:00
|
|
|
uint32_t *alarm_counts = (uint32_t *)user_ctx;
|
|
|
|
(*alarm_counts)++;
|
2022-01-02 03:14:17 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-06 02:52:22 -04:00
|
|
|
static void IRAM_ATTR test_delay_post_cache_disable(void *args)
|
2022-01-02 03:14:17 -05:00
|
|
|
{
|
2022-08-06 02:52:22 -04:00
|
|
|
esp_rom_delay_us(1000);
|
2022-01-02 03:14:17 -05:00
|
|
|
}
|
|
|
|
|
2022-08-06 02:52:22 -04:00
|
|
|
TEST_CASE("gptimer_interrupt_iram_safe", "[gptimer]")
|
2022-01-02 03:14:17 -05:00
|
|
|
{
|
|
|
|
gptimer_handle_t gptimer = NULL;
|
|
|
|
gptimer_config_t timer_config = {
|
2022-04-13 01:12:30 -04:00
|
|
|
.clk_src = GPTIMER_CLK_SRC_DEFAULT,
|
2022-01-02 03:14:17 -05:00
|
|
|
.direction = GPTIMER_COUNT_UP,
|
2022-08-06 02:52:22 -04:00
|
|
|
.resolution_hz = 1 * 1000 * 1000, // 1MHz, 1 tick = 1us
|
2022-01-02 03:14:17 -05:00
|
|
|
};
|
|
|
|
TEST_ESP_OK(gptimer_new_timer(&timer_config, &gptimer));
|
|
|
|
gptimer_event_callbacks_t cbs = {
|
|
|
|
.on_alarm = on_gptimer_alarm_cb,
|
|
|
|
};
|
2022-08-06 02:52:22 -04:00
|
|
|
uint32_t alarm_counts = 0;
|
|
|
|
TEST_ESP_OK(gptimer_register_event_callbacks(gptimer, &cbs, &alarm_counts));
|
2022-01-02 03:14:17 -05:00
|
|
|
gptimer_alarm_config_t alarm_config = {
|
|
|
|
.reload_count = 0,
|
2022-08-06 02:52:22 -04:00
|
|
|
.alarm_count = 100, // 100us per alarm event
|
2022-01-02 03:14:17 -05:00
|
|
|
.flags.auto_reload_on_alarm = true,
|
|
|
|
};
|
|
|
|
TEST_ESP_OK(gptimer_set_alarm_action(gptimer, &alarm_config));
|
2022-04-23 06:59:38 -04:00
|
|
|
TEST_ESP_OK(gptimer_enable(gptimer));
|
2022-01-02 03:14:17 -05:00
|
|
|
TEST_ESP_OK(gptimer_start(gptimer));
|
|
|
|
|
2022-08-06 02:52:22 -04:00
|
|
|
vTaskDelay(pdMS_TO_TICKS(10));
|
|
|
|
|
|
|
|
printf("disable flash cache and check the alarm events are still in working\r\n");
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
unity_utils_run_cache_disable_stub(test_delay_post_cache_disable, NULL);
|
|
|
|
}
|
|
|
|
printf("alarm counts: %"PRIu32"\r\n", alarm_counts);
|
|
|
|
TEST_ASSERT_GREATER_THAN(150, alarm_counts);
|
|
|
|
|
2022-01-02 03:14:17 -05:00
|
|
|
// delete gptimer
|
|
|
|
TEST_ESP_OK(gptimer_stop(gptimer));
|
2022-04-23 06:59:38 -04:00
|
|
|
TEST_ESP_OK(gptimer_disable(gptimer));
|
2022-01-02 03:14:17 -05:00
|
|
|
TEST_ESP_OK(gptimer_del_timer(gptimer));
|
|
|
|
}
|