2019-10-14 22:32:31 -04:00
|
|
|
#include <esp_types.h>
|
|
|
|
#include <stdio.h>
|
2020-11-05 23:03:21 -05:00
|
|
|
#include "sdkconfig.h"
|
2019-10-14 22:32:31 -04:00
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
#include "freertos/semphr.h"
|
|
|
|
#include "freertos/queue.h"
|
|
|
|
#include "esp_intr_alloc.h"
|
|
|
|
#include "unity.h"
|
|
|
|
#include "soc/cpu.h"
|
|
|
|
#include "test_utils.h"
|
2020-11-05 23:03:21 -05:00
|
|
|
#if CONFIG_IDF_TARGET_ARCH_XTENSA
|
|
|
|
#include "xtensa/hal.h"
|
|
|
|
#include "freertos/xtensa_api.h"
|
|
|
|
#define TEST_SET_INT_MASK(mask) xt_set_intset(mask)
|
|
|
|
#define TEST_CLR_INT_MASK(mask) xt_set_intclear(mask)
|
|
|
|
#elif CONFIG_IDF_TARGET_ARCH_RISCV
|
|
|
|
#include "riscv/interrupt.h"
|
|
|
|
#define TEST_SET_INT_MASK(mask) esprv_intc_int_enable(mask)
|
|
|
|
#define TEST_CLR_INT_MASK(mask) esprv_intc_int_disable(mask)
|
|
|
|
#endif
|
|
|
|
|
2021-11-26 04:03:47 -05:00
|
|
|
#ifndef __riscv // TODO: IDF-4416
|
2019-10-14 22:32:31 -04:00
|
|
|
|
2019-10-24 15:49:59 -04:00
|
|
|
#define SW_ISR_LEVEL_1 7
|
2019-10-16 10:21:52 -04:00
|
|
|
|
2019-10-24 15:49:59 -04:00
|
|
|
static SemaphoreHandle_t sync;
|
2019-10-14 22:32:31 -04:00
|
|
|
static SemaphoreHandle_t end_sema;
|
2019-11-26 12:49:08 -05:00
|
|
|
static uint32_t cycle_before_trigger;
|
|
|
|
static uint32_t cycle_before_exit;
|
|
|
|
static uint32_t delta_enter_cycles = 0;
|
|
|
|
static uint32_t delta_exit_cycles = 0;
|
2019-10-14 22:32:31 -04:00
|
|
|
|
2020-08-04 15:16:33 -04:00
|
|
|
static void software_isr_using_parameter_vportyield(void *arg) {
|
2019-10-24 15:49:59 -04:00
|
|
|
(void)arg;
|
|
|
|
BaseType_t yield;
|
|
|
|
delta_enter_cycles += portGET_RUN_TIME_COUNTER_VALUE() - cycle_before_trigger;
|
2020-11-05 23:03:21 -05:00
|
|
|
TEST_CLR_INT_MASK(1 << SW_ISR_LEVEL_1);
|
2019-10-24 15:49:59 -04:00
|
|
|
|
|
|
|
xSemaphoreGiveFromISR(sync, &yield);
|
2020-07-29 14:04:47 -04:00
|
|
|
portYIELD_FROM_ISR(yield);
|
2019-10-24 15:49:59 -04:00
|
|
|
|
|
|
|
cycle_before_exit = portGET_RUN_TIME_COUNTER_VALUE();
|
2019-10-14 22:32:31 -04:00
|
|
|
}
|
|
|
|
|
2020-08-04 15:16:33 -04:00
|
|
|
static void software_isr_using_no_argument_vportyield(void *arg) {
|
2019-10-24 15:49:59 -04:00
|
|
|
(void)arg;
|
2020-08-04 15:16:33 -04:00
|
|
|
BaseType_t yield;
|
|
|
|
delta_enter_cycles += portGET_RUN_TIME_COUNTER_VALUE() - cycle_before_trigger;
|
2020-11-10 02:40:01 -05:00
|
|
|
|
2020-11-05 23:03:21 -05:00
|
|
|
TEST_CLR_INT_MASK(1 << SW_ISR_LEVEL_1);
|
2020-08-04 15:16:33 -04:00
|
|
|
|
|
|
|
xSemaphoreGiveFromISR(sync, &yield);
|
|
|
|
if(yield) {
|
|
|
|
portYIELD_FROM_ISR();
|
|
|
|
}
|
|
|
|
cycle_before_exit = portGET_RUN_TIME_COUNTER_VALUE();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_task(void *arg) {
|
|
|
|
(void) arg;
|
2019-10-14 22:32:31 -04:00
|
|
|
|
2019-10-24 15:49:59 -04:00
|
|
|
for(int i = 0;i < 10000; i++) {
|
|
|
|
cycle_before_trigger = portGET_RUN_TIME_COUNTER_VALUE();
|
2020-11-05 23:03:21 -05:00
|
|
|
TEST_SET_INT_MASK(1 << SW_ISR_LEVEL_1);
|
2019-10-24 15:49:59 -04:00
|
|
|
xSemaphoreTake(sync, portMAX_DELAY);
|
|
|
|
delta_exit_cycles += portGET_RUN_TIME_COUNTER_VALUE() - cycle_before_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
delta_enter_cycles /= 10000;
|
|
|
|
delta_exit_cycles /= 10000;
|
2019-10-14 22:32:31 -04:00
|
|
|
|
|
|
|
xSemaphoreGive(end_sema);
|
|
|
|
vTaskDelete(NULL);
|
|
|
|
}
|
|
|
|
|
2020-08-04 15:16:33 -04:00
|
|
|
TEST_CASE("isr latency test vport-yield-from-isr with no parameter", "[freertos] [ignore]")
|
2019-10-14 22:32:31 -04:00
|
|
|
{
|
2020-08-04 15:16:33 -04:00
|
|
|
intr_handle_t handle;
|
|
|
|
esp_err_t err = esp_intr_alloc(ETS_INTERNAL_SW0_INTR_SOURCE, ESP_INTR_FLAG_LEVEL1, &software_isr_using_no_argument_vportyield, NULL, &handle);
|
|
|
|
TEST_ASSERT_EQUAL_HEX32(ESP_OK, err);
|
|
|
|
|
2019-10-24 15:49:59 -04:00
|
|
|
sync = xSemaphoreCreateBinary();
|
|
|
|
TEST_ASSERT(sync != NULL);
|
2019-10-14 22:32:31 -04:00
|
|
|
end_sema = xSemaphoreCreateBinary();
|
|
|
|
TEST_ASSERT(end_sema != NULL);
|
2019-10-24 16:36:37 -04:00
|
|
|
xTaskCreatePinnedToCore(test_task, "tst" , 4096, NULL, configMAX_PRIORITIES - 1, NULL, 0);
|
2020-08-04 15:16:33 -04:00
|
|
|
vTaskDelay(100);
|
2020-11-10 02:40:01 -05:00
|
|
|
BaseType_t result = xSemaphoreTake(end_sema, portMAX_DELAY);
|
2019-10-14 22:32:31 -04:00
|
|
|
TEST_ASSERT_EQUAL_HEX32(pdTRUE, result);
|
2019-10-24 15:49:59 -04:00
|
|
|
TEST_PERFORMANCE_LESS_THAN(ISR_ENTER_CYCLES, "%d cycles" ,delta_enter_cycles);
|
|
|
|
TEST_PERFORMANCE_LESS_THAN(ISR_EXIT_CYCLES, "%d cycles" ,delta_exit_cycles);
|
2020-08-04 15:16:33 -04:00
|
|
|
|
|
|
|
esp_intr_free(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("isr latency test vport-yield-from-isr with parameter", "[freertos][ignore]")
|
|
|
|
{
|
|
|
|
intr_handle_t handle;
|
|
|
|
esp_err_t err = esp_intr_alloc(ETS_INTERNAL_SW0_INTR_SOURCE, ESP_INTR_FLAG_LEVEL1, &software_isr_using_parameter_vportyield, NULL, &handle);
|
|
|
|
TEST_ASSERT_EQUAL_HEX32(ESP_OK, err);
|
|
|
|
|
|
|
|
sync = xSemaphoreCreateBinary();
|
|
|
|
TEST_ASSERT(sync != NULL);
|
|
|
|
end_sema = xSemaphoreCreateBinary();
|
|
|
|
TEST_ASSERT(end_sema != NULL);
|
|
|
|
xTaskCreatePinnedToCore(test_task, "tst" , 4096, NULL, configMAX_PRIORITIES - 1, NULL, 0);
|
2020-11-10 02:40:01 -05:00
|
|
|
BaseType_t result = xSemaphoreTake(end_sema, portMAX_DELAY);
|
2020-08-04 15:16:33 -04:00
|
|
|
TEST_ASSERT_EQUAL_HEX32(pdTRUE, result);
|
|
|
|
TEST_PERFORMANCE_LESS_THAN(ISR_ENTER_CYCLES, "%d cycles" ,delta_enter_cycles);
|
|
|
|
TEST_PERFORMANCE_LESS_THAN(ISR_EXIT_CYCLES, "%d cycles" ,delta_exit_cycles);
|
|
|
|
|
|
|
|
esp_intr_free(handle);
|
|
|
|
}
|
2020-11-05 23:03:21 -05:00
|
|
|
|
2021-11-26 04:03:47 -05:00
|
|
|
#endif // __riscv
|