Procházet zdrojové kódy

Merge branch 'bugfix/fix_driver_ut_pcnt' into 'master'

bugfix(pcnt): fix driver ut pcnt

See merge request espressif/esp-idf!6891
Michael (XIAO Xufeng) před 6 roky
rodič
revize
7f8c827326

+ 15 - 1
components/driver/include/driver/pcnt.h

@@ -179,6 +179,20 @@ esp_err_t pcnt_set_event_value(pcnt_unit_t unit, pcnt_evt_type_t evt_type, int16
  */
 esp_err_t pcnt_get_event_value(pcnt_unit_t unit, pcnt_evt_type_t evt_type, int16_t *value);
 
+/**
+ * @brief Unregister PCNT interrupt handler (registered by pcnt_isr_register), the handler is an ISR.
+ *        The handler will be attached to the same CPU core that this function is running on.
+ *        If the interrupt service is registered by pcnt_isr_service_install, please call pcnt_isr_service_uninstall instead
+ *
+ * @param handle handle to unregister the ISR service.
+ *
+ * @return
+ *     - ESP_OK Success
+ *     - ESP_ERR_NOT_FOUND Can not find the interrupt that matches the flags.
+ *     - ESP_ERR_INVALID_ARG Function pointer error.
+ */
+esp_err_t pcnt_isr_unregister(pcnt_isr_handle_t handle);
+
 /**
  * @brief Register PCNT interrupt handler, the handler is an ISR.
  *        The handler will be attached to the same CPU core that this function is running on.
@@ -189,7 +203,7 @@ esp_err_t pcnt_get_event_value(pcnt_unit_t unit, pcnt_evt_type_t evt_type, int16
  * @param intr_alloc_flags Flags used to allocate the interrupt. One or multiple (ORred)
  *        ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info.
  * @param handle Pointer to return handle. If non-NULL, a handle for the interrupt will
- *        be returned here. Calling esp_intr_free to unregister this ISR service if needed,
+ *        be returned here. Calling pcnt_isr_unregister to unregister this ISR service if needed,
  *        but only if the handle is not NULL.
  *
  * @return

+ 23 - 12
components/driver/pcnt.c

@@ -297,7 +297,6 @@ static inline esp_err_t _pcnt_isr_service_install(pcnt_port_t pcnt_port, int int
 {
     PCNT_OBJ_CHECK(pcnt_port);
     PCNT_CHECK(pcnt_isr_func == NULL, "ISR service already installed", ESP_ERR_INVALID_STATE);
-    PCNT_ENTER_CRITICAL(&pcnt_spinlock);
     esp_err_t ret = ESP_FAIL;
     pcnt_isr_func = (pcnt_isr_func_t *) calloc(PCNT_UNIT_MAX, sizeof(pcnt_isr_func_t));
 
@@ -305,28 +304,27 @@ static inline esp_err_t _pcnt_isr_service_install(pcnt_port_t pcnt_port, int int
         ret = ESP_ERR_NO_MEM;
     } else {
         ret = pcnt_isr_register(pcnt_intr_service, (void *)pcnt_port, intr_alloc_flags, &pcnt_isr_service);
+        if (ret != ESP_OK) {
+            ESP_LOGE(TAG, "pcnt isr registration failed, maybe you need `pcnt_isr_unregister` to unregister your isr");
+            free(pcnt_isr_func);
+            pcnt_isr_func = NULL;
+        }
     }
 
-    PCNT_EXIT_CRITICAL(&pcnt_spinlock);
     return ret;
 }
 
 static inline esp_err_t _pcnt_isr_service_uninstall(pcnt_port_t pcnt_port)
 {
     PCNT_OBJ_CHECK(pcnt_port);
-
-    if (pcnt_isr_func == NULL) {
-        return ESP_FAIL;
-    }
-
-    PCNT_ENTER_CRITICAL(&pcnt_spinlock);
-    esp_intr_free(pcnt_isr_service);
+    PCNT_CHECK(pcnt_isr_func != NULL, "ISR Service not installed yet.", ESP_ERR_INVALID_STATE);
+    esp_err_t ret = ESP_FAIL;
+    ret = pcnt_isr_unregister(pcnt_isr_service);
     free(pcnt_isr_func);
     pcnt_isr_func = NULL;
     pcnt_isr_service = NULL;
-    PCNT_EXIT_CRITICAL(&pcnt_spinlock);
 
-    return ESP_OK;
+    return ret;
 }
 
 static inline esp_err_t _pcnt_unit_config(pcnt_port_t pcnt_port, const pcnt_config_t *pcnt_config)
@@ -485,10 +483,23 @@ esp_err_t pcnt_filter_disable(pcnt_unit_t unit)
     return _pcnt_filter_disable(PCNT_PORT_0, unit);
 }
 
+esp_err_t pcnt_isr_unregister(pcnt_isr_handle_t handle)
+{
+    esp_err_t ret = ESP_FAIL;
+    PCNT_ENTER_CRITICAL(&pcnt_spinlock);
+    ret = esp_intr_free(handle);
+    PCNT_EXIT_CRITICAL(&pcnt_spinlock);
+    return ret;
+}
+
 esp_err_t pcnt_isr_register(void (*fun)(void *), void *arg, int intr_alloc_flags, pcnt_isr_handle_t *handle)
 {
+    esp_err_t ret = ESP_FAIL;
     PCNT_CHECK(fun != NULL, PCNT_ADDRESS_ERR_STR, ESP_ERR_INVALID_ARG);
-    return esp_intr_alloc(ETS_PCNT_INTR_SOURCE, intr_alloc_flags, fun, arg, handle);
+    PCNT_ENTER_CRITICAL(&pcnt_spinlock);
+    ret = esp_intr_alloc(ETS_PCNT_INTR_SOURCE, intr_alloc_flags, fun, arg, handle);
+    PCNT_EXIT_CRITICAL(&pcnt_spinlock);
+    return ret;
 }
 
 esp_err_t pcnt_isr_handler_add(pcnt_unit_t unit, void(*isr_handler)(void *), void *args)

+ 61 - 45
components/driver/test/test_pcnt.c

@@ -1,8 +1,9 @@
 /**
  * this case is used for test PCNT
  * prepare job for test environment UT_T1_PCNT:
+ * We use internal signals instead of external wiring, but please keep the following IO connections, or connect nothing to prevent the signal from being disturbed.
  *  1. prepare one ESP-WROOM-32 board and connect it to PC.
- *  2. connect GPIO18 with GPIO4
+ *  2. connect GPIO21 with GPIO4
  *  3. GPIO5 connect to 3.3v
  *  4. GPIO19 connect to GND
  *  5. logic analyzer will help too if possible
@@ -22,18 +23,18 @@
 #include "soc/gpio_periph.h"
 #include "unity.h"
 
-#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2)
-
-#define PULSE_IO 18
+#define PULSE_IO 21
 #define PCNT_INPUT_IO 4
-#define PCNT_CTRL_FLOATING_IO 5
+#define PCNT_CTRL_VCC_IO 5
 #define PCNT_CTRL_GND_IO 19
 #define HIGHEST_LIMIT 10
 #define LOWEST_LIMIT 0
 #define MAX_THRESHOLD 5
 #define MIN_THRESHOLD 0
+#define PCNT_CTRL_HIGH_LEVEL 1
+#define PCNT_CTRL_LOW_LEVEL 0
 
-static xQueueHandle pcnt_evt_queue;
+static xQueueHandle pcnt_evt_queue = NULL;
 
 typedef struct {
     int zero_times;
@@ -44,6 +45,15 @@ typedef struct {
     int filter_time;
 } event_times;
 
+static void pcnt_test_io_config(int ctrl_level)
+{
+    // Connect internal signals using IO matrix.
+    gpio_set_direction(PULSE_IO, GPIO_MODE_INPUT_OUTPUT);
+    gpio_matrix_out(PULSE_IO, LEDC_LS_SIG_OUT1_IDX, 0, 0); // LEDC_TIMER_1, LEDC_LOW_SPEED_MODE
+    gpio_matrix_in(PULSE_IO, PCNT_SIG_CH0_IN0_IDX, 0); // PCNT_UNIT_0, PCNT_CHANNEL_0
+    gpio_matrix_in(ctrl_level ? GPIO_FUNC_IN_HIGH: GPIO_FUNC_IN_LOW, PCNT_CTRL_CH0_IN0_IDX, 0); // PCNT_UNIT_0, PCNT_CHANNEL_0
+}
+
 /* use LEDC to produce pulse for PCNT
  * the frequency of LEDC is 1000, so every second will get 1000 count values
  * the PCNT count the LEDC pulse
@@ -51,7 +61,7 @@ typedef struct {
 static void produce_pulse(void)
 {
     ledc_timer_config_t ledc_timer = {
-        .speed_mode = LEDC_HIGH_SPEED_MODE,
+        .speed_mode = LEDC_LOW_SPEED_MODE,
         .timer_num  = LEDC_TIMER_1,
         .duty_resolution = LEDC_TIMER_10_BIT,
         .freq_hz = 1,
@@ -60,7 +70,7 @@ static void produce_pulse(void)
     ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
 
     ledc_channel_config_t ledc_channel = {
-        .speed_mode = LEDC_HIGH_SPEED_MODE,
+        .speed_mode = LEDC_LOW_SPEED_MODE,
         .channel = LEDC_CHANNEL_1,
         .timer_sel = LEDC_TIMER_1,
         .intr_type = LEDC_INTR_DISABLE,
@@ -102,23 +112,23 @@ static void event_calculate(event_times* event)
             event->filter_time++;
             TEST_ESP_OK(pcnt_get_counter_value(PCNT_UNIT_0, &test_counter));
             printf("Current counter value :%d\n", test_counter);
-            if (status & PCNT_STATUS_THRES1_M) {
+            if (status & PCNT_EVT_THRES_1) {
                 printf("THRES1 EVT\n");
                 event->h_threshold++;
             }
-            if (status & PCNT_STATUS_THRES0_M) {
+            if (status & PCNT_EVT_THRES_0) {
                 printf("THRES0 EVT\n");
                 event->l_threshold++;
             }
-            if (status & PCNT_STATUS_L_LIM_M) {
+            if (status & PCNT_EVT_L_LIM) {
                 printf("L_LIM EVT\n");
                 event->l_limit++;
             }
-            if (status & PCNT_STATUS_H_LIM_M) {
+            if (status & PCNT_EVT_H_LIM) {
                 printf("H_LIM EVT\n");
                 event->h_limit++;
             }
-            if (status & PCNT_STATUS_ZERO_M) {
+            if (status & PCNT_EVT_ZERO) {
                 printf("ZERO EVT\n");
                 event->zero_times++;
             }
@@ -157,7 +167,7 @@ static void count_mode_test(gpio_num_t ctl_io)
     int16_t test_counter;
     //produce pulse, 100HZ
     ledc_timer_config_t ledc_timer = {
-        .speed_mode = LEDC_HIGH_SPEED_MODE,
+        .speed_mode = LEDC_LOW_SPEED_MODE,
         .timer_num  = LEDC_TIMER_1,
         .duty_resolution = LEDC_TIMER_10_BIT,
         .freq_hz = 100,
@@ -166,7 +176,7 @@ static void count_mode_test(gpio_num_t ctl_io)
     ledc_timer_config(&ledc_timer);
 
     ledc_channel_config_t ledc_channel = {
-        .speed_mode = LEDC_HIGH_SPEED_MODE,
+        .speed_mode = LEDC_LOW_SPEED_MODE,
         .channel = LEDC_CHANNEL_1,
         .timer_sel = LEDC_TIMER_1,
         .intr_type = LEDC_INTR_DISABLE,
@@ -189,10 +199,11 @@ static void count_mode_test(gpio_num_t ctl_io)
         .counter_l_lim = -101,
     };
     TEST_ESP_OK(pcnt_unit_config(&pcnt_config));
+    pcnt_test_io_config((ctl_io == PCNT_CTRL_VCC_IO) ? PCNT_CTRL_HIGH_LEVEL : PCNT_CTRL_LOW_LEVEL);
     int16_t result1[8] = {100, -100, 0, -100, 100, 100, 0, 100};
     int16_t result2[8] = {100, -100, 0, 100, -100, -100, 100, 0};
     int16_t *result;
-    if (gpio_get_level(pcnt_config.ctrl_gpio_num)) {
+    if (ctl_io == PCNT_CTRL_VCC_IO) {
         result = result1;
     } else {
         result = result2;
@@ -296,11 +307,11 @@ static void count_mode_test(gpio_num_t ctl_io)
 }
 
 // test PCNT basic configuration
-TEST_CASE("PCNT test config", "[pcnt][test_env=UT_T1_PCNT]")
+TEST_CASE("PCNT test config", "[pcnt]")
 {
     pcnt_config_t pcnt_config = {
         .pulse_gpio_num = PCNT_INPUT_IO,
-        .ctrl_gpio_num = PCNT_CTRL_FLOATING_IO,
+        .ctrl_gpio_num = PCNT_CTRL_VCC_IO,
         .channel = PCNT_CHANNEL_0,
         .unit = PCNT_UNIT_0,
         .pos_mode = PCNT_COUNT_INC,
@@ -314,11 +325,11 @@ TEST_CASE("PCNT test config", "[pcnt][test_env=UT_T1_PCNT]")
     pcnt_config_t temp_pcnt_config = pcnt_config;
     TEST_ESP_OK(pcnt_unit_config(&pcnt_config));
 
-    // test 8 units, from 0-7
+    // test PCNT_UNIT_MAX units, from 0-(PCNT_UNIT_MAX-1)
     pcnt_config = temp_pcnt_config;
     pcnt_config.unit = PCNT_UNIT_MAX;
     TEST_ASSERT_NOT_NULL((void *)pcnt_unit_config(&pcnt_config));
-    for (int i = 0; i <= 7; i++) {
+    for (int i = 0; i < PCNT_UNIT_MAX; i++) {
         pcnt_config.unit = i;
         TEST_ESP_OK(pcnt_unit_config(&pcnt_config));
     }
@@ -332,7 +343,7 @@ TEST_CASE("PCNT test config", "[pcnt][test_env=UT_T1_PCNT]")
     TEST_ESP_OK(pcnt_unit_config(&pcnt_config));
 
     pcnt_config = temp_pcnt_config;
-    pcnt_config.pulse_gpio_num = 41;
+    pcnt_config.pulse_gpio_num = GPIO_NUM_MAX + 1;
     TEST_ASSERT_NOT_NULL((void *)pcnt_unit_config(&pcnt_config));
 
     // test pulse_gpio_num and ctrl_gpio_num is the same
@@ -359,7 +370,7 @@ TEST_CASE("PCNT test config", "[pcnt][test_env=UT_T1_PCNT]")
  * 2. resume counter
  * 3. clear counter
  * 4. check the counter value*/
-TEST_CASE("PCNT basic function test", "[pcnt][test_env=UT_T1_PCNT]")
+TEST_CASE("PCNT basic function test", "[pcnt]")
 {
     int16_t test_counter;
     int16_t time = 0;
@@ -368,7 +379,7 @@ TEST_CASE("PCNT basic function test", "[pcnt][test_env=UT_T1_PCNT]")
     int temp_value = 0;
     pcnt_config_t pcnt_config = {
         .pulse_gpio_num = PCNT_INPUT_IO,
-        .ctrl_gpio_num = PCNT_CTRL_FLOATING_IO,
+        .ctrl_gpio_num = PCNT_CTRL_VCC_IO,
         .channel = PCNT_CHANNEL_0,
         .unit = PCNT_UNIT_0,
         .pos_mode = PCNT_COUNT_INC,
@@ -382,6 +393,7 @@ TEST_CASE("PCNT basic function test", "[pcnt][test_env=UT_T1_PCNT]")
 
     // use LEDC to produce the pulse, then the PCNT to count it
     produce_pulse();
+    pcnt_test_io_config(PCNT_CTRL_HIGH_LEVEL);
 
     // initialize first, the initail value should be 0
     TEST_ESP_OK(pcnt_counter_pause(PCNT_UNIT_0));
@@ -424,7 +436,7 @@ TEST_CASE("PCNT basic function test", "[pcnt][test_env=UT_T1_PCNT]")
             vTaskDelay(1000 / portTICK_RATE_MS);
             TEST_ESP_OK(pcnt_get_counter_value(PCNT_UNIT_0, &test_counter));
             printf("RESUME: %d\n", test_counter);
-            TEST_ASSERT_EQUAL_INT16(test_counter, (gpio_get_level(PCNT_CTRL_FLOATING_IO) > 0) ? (1) : -1);
+            TEST_ASSERT_EQUAL_INT16(test_counter, 1);
             resume_count++;
         }
         time++;
@@ -447,12 +459,11 @@ TEST_CASE("PCNT basic function test", "[pcnt][test_env=UT_T1_PCNT]")
  *   4. PCNT_EVT_H_LIM
  *   5. PCNT_EVT_L_LIM
  * */
-// set it ignore: need to debug
-TEST_CASE("PCNT interrupt method test(control IO is high)", "[pcnt][test_env=UT_T1_PCNT][timeout=120][ignore]")
+TEST_CASE("PCNT interrupt method test(control IO is high)", "[pcnt][timeout=120]")
 {
     pcnt_config_t config = {
         .pulse_gpio_num = PCNT_INPUT_IO,
-        .ctrl_gpio_num = PCNT_CTRL_FLOATING_IO,
+        .ctrl_gpio_num = PCNT_CTRL_VCC_IO,
         .channel = PCNT_CHANNEL_0,
         .unit = PCNT_UNIT_0,
         .pos_mode = PCNT_COUNT_INC,
@@ -464,6 +475,7 @@ TEST_CASE("PCNT interrupt method test(control IO is high)", "[pcnt][test_env=UT_
     };
     TEST_ESP_OK(pcnt_unit_config(&config));
     produce_pulse();
+    pcnt_test_io_config(PCNT_CTRL_HIGH_LEVEL);
 
     event_times event = {
         .zero_times = 0,
@@ -485,16 +497,17 @@ TEST_CASE("PCNT interrupt method test(control IO is high)", "[pcnt][test_env=UT_
     TEST_ESP_OK(pcnt_event_enable(PCNT_UNIT_0, PCNT_EVT_H_LIM));  // when arrive to max limit trigger
     TEST_ESP_OK(pcnt_event_enable(PCNT_UNIT_0, PCNT_EVT_L_LIM));  // when arrive to minimum limit trigger
 
-    // to initialize for PCNT
+    // initialize first, the initail value should be 0
     TEST_ESP_OK(pcnt_counter_pause(PCNT_UNIT_0));
     TEST_ESP_OK(pcnt_counter_clear(PCNT_UNIT_0));
 
-    TEST_ESP_OK(pcnt_isr_register(pcnt_intr_handler, NULL, 0, NULL));
+    pcnt_evt_queue = xQueueCreate(10, sizeof(uint32_t));
+
+    pcnt_isr_handle_t pcnt_isr_service;
+    TEST_ESP_OK(pcnt_isr_register(pcnt_intr_handler, NULL, 0, &pcnt_isr_service));
     TEST_ESP_OK(pcnt_intr_enable(PCNT_UNIT_0));
     TEST_ESP_OK(pcnt_counter_resume(PCNT_UNIT_0));
 
-    pcnt_evt_queue = xQueueCreate(10, sizeof(uint32_t));
-
     // test event
     event_calculate(&event);
     TEST_ASSERT_INT_WITHIN(2, event.h_threshold, 2);
@@ -537,15 +550,16 @@ TEST_CASE("PCNT interrupt method test(control IO is high)", "[pcnt][test_env=UT_
     TEST_ASSERT_INT_WITHIN(2, event.h_threshold, 5);
     TEST_ASSERT_INT_WITHIN(2, event.l_threshold, 4);
     TEST_ASSERT(event.l_limit == 0);
-    TEST_ASSERT_INT_WITHIN(2, event.h_limit, 6);
+    TEST_ASSERT_INT_WITHIN(3, event.h_limit, 6);
     TEST_ASSERT_INT_WITHIN(2, event.zero_times, 4);
     TEST_ASSERT_INT_WITHIN(3, event.filter_time, 14);
 
-    pcnt_isr_service_uninstall();
+    // Because this test uses its own ISR, we need to release it with `pcnt_isr_unregister` instead of `pcnt_isr_service_uninstall`
+    TEST_ESP_OK(pcnt_isr_unregister(pcnt_isr_service));
+    vQueueDelete(pcnt_evt_queue);
 }
 
-// set it ignore: need to debug
-TEST_CASE("PCNT interrupt method test(control IO is low)", "[pcnt][test_env=UT_T1_PCNT][timeout=120][ignore]")
+TEST_CASE("PCNT interrupt method test(control IO is low)", "[pcnt][timeout=120]")
 {
     pcnt_config_t config = {
         .pulse_gpio_num = PCNT_INPUT_IO,
@@ -559,9 +573,9 @@ TEST_CASE("PCNT interrupt method test(control IO is low)", "[pcnt][test_env=UT_T
         .counter_h_lim = 0,
         .counter_l_lim = -5,
     };
-
     TEST_ESP_OK(pcnt_unit_config(&config));
     produce_pulse();
+    pcnt_test_io_config(PCNT_CTRL_LOW_LEVEL);
 
     event_times event = {
         .zero_times = 0,
@@ -587,12 +601,13 @@ TEST_CASE("PCNT interrupt method test(control IO is low)", "[pcnt][test_env=UT_T
     TEST_ESP_OK(pcnt_counter_pause(PCNT_UNIT_0));
     TEST_ESP_OK(pcnt_counter_clear(PCNT_UNIT_0));
 
-    TEST_ESP_OK(pcnt_isr_register(pcnt_intr_handler, NULL, 0, NULL));
+    pcnt_evt_queue = xQueueCreate(10, sizeof(uint32_t));
+    
+    pcnt_isr_handle_t pcnt_isr_service;
+    TEST_ESP_OK(pcnt_isr_register(pcnt_intr_handler, NULL, 0, &pcnt_isr_service));
     TEST_ESP_OK(pcnt_intr_enable(PCNT_UNIT_0));
     TEST_ESP_OK(pcnt_counter_resume(PCNT_UNIT_0));
 
-    pcnt_evt_queue = xQueueCreate(10, sizeof(uint32_t));
-
     // test event
     event_calculate(&event);
     TEST_ASSERT_INT_WITHIN(2, event.h_threshold, 1);
@@ -616,6 +631,7 @@ TEST_CASE("PCNT interrupt method test(control IO is low)", "[pcnt][test_env=UT_T
 
     // enable the intr
     pcnt_unit_config(&config);
+    pcnt_test_io_config(PCNT_CTRL_LOW_LEVEL);
     TEST_ESP_OK(pcnt_intr_enable(PCNT_UNIT_0));
     TEST_ESP_OK(pcnt_counter_pause(PCNT_UNIT_0));
     TEST_ESP_OK(pcnt_counter_clear(PCNT_UNIT_0));
@@ -640,15 +656,15 @@ TEST_CASE("PCNT interrupt method test(control IO is low)", "[pcnt][test_env=UT_T
     TEST_ASSERT_INT_WITHIN(2, event.zero_times, 2);
     TEST_ASSERT_INT_WITHIN(2, event.filter_time, 8);
 
-    pcnt_isr_service_uninstall();
+    // Because this test uses its own ISR, we need to release it with `pcnt_isr_unregister` instead of `pcnt_isr_service_uninstall`
+    TEST_ESP_OK(pcnt_isr_unregister(pcnt_isr_service));
+    vQueueDelete(pcnt_evt_queue);
 }
 
-TEST_CASE("PCNT counting mode test", "[pcnt][test_env=UT_T1_PCNT]")
+TEST_CASE("PCNT counting mode test", "[pcnt]")
 {
     printf("PCNT mode test for positive count\n");
-    count_mode_test(PCNT_CTRL_FLOATING_IO);
+    count_mode_test(PCNT_CTRL_VCC_IO);
     printf("PCNT mode test for negative count\n");
     count_mode_test(PCNT_CTRL_GND_IO);
-}
-
-#endif
+}

+ 19 - 2
components/soc/include/hal/pcnt_types.h

@@ -18,15 +18,32 @@
 extern "C" {
 #endif
 
+#define PCNT_PIN_NOT_USED     (-1)  /*!< When selected for a pin, this pin will not be used */
+
 /**
  * @brief PCNT port number, the max port number is (PCNT_PORT_MAX - 1).
  */
-typedef int pcnt_port_t;
+typedef enum {
+    PCNT_PORT_0 = 0,                 /*!< PCNT port 0 */
+    PCNT_PORT_MAX,                   /*!< PCNT port max */
+} pcnt_port_t;
 
 /**
  * @brief Selection of all available PCNT units
  */
-typedef int pcnt_unit_t;
+typedef enum {
+    PCNT_UNIT_0 = 0,                 /*!< PCNT unit 0 */
+    PCNT_UNIT_1 = 1,                 /*!< PCNT unit 1 */
+    PCNT_UNIT_2 = 2,                 /*!< PCNT unit 2 */
+    PCNT_UNIT_3 = 3,                 /*!< PCNT unit 3 */
+#if SOC_PCNT_UNIT_NUM > 4
+    PCNT_UNIT_4 = 4,                 /*!< PCNT unit 4 */
+    PCNT_UNIT_5 = 5,                 /*!< PCNT unit 5 */
+    PCNT_UNIT_6 = 6,                 /*!< PCNT unit 6 */
+    PCNT_UNIT_7 = 7,                 /*!< PCNT unit 7 */
+#endif
+    PCNT_UNIT_MAX,
+} pcnt_unit_t; 
 
 /**
  * @brief Selection of available modes that determine the counter's action depending on the state of the control signal's input GPIO

+ 2 - 15
components/soc/soc/esp32/include/soc/pcnt_caps.h

@@ -19,21 +19,8 @@ extern "C" {
 #endif
 
 // ESP32 have 1 PCNT peripheral
-#define PCNT_PORT_0            (0) /*!< PCNT port 0 */
-#define PCNT_PORT_MAX          (1) /*!< PCNT port max */
-#define SOC_PCNT_NUM           (PCNT_PORT_MAX)
-
-#define PCNT_PIN_NOT_USED     (-1)  /*!< When selected for a pin, this pin will not be used */
-
-#define PCNT_UNIT_0   (0)   /*!< PCNT unit 0 */
-#define PCNT_UNIT_1   (1)   /*!< PCNT unit 1 */
-#define PCNT_UNIT_2   (2)   /*!< PCNT unit 2 */
-#define PCNT_UNIT_3   (3)   /*!< PCNT unit 3 */
-#define PCNT_UNIT_4   (4)   /*!< PCNT unit 4 */
-#define PCNT_UNIT_5   (5)   /*!< PCNT unit 5 */
-#define PCNT_UNIT_6   (6)   /*!< PCNT unit 6 */
-#define PCNT_UNIT_7   (7)   /*!< PCNT unit 7 */
-#define PCNT_UNIT_MAX (8)
+#define SOC_PCNT_PORT_NUM      (1)
+#define SOC_PCNT_UNIT_NUM      (8)
 
 #ifdef __cplusplus
 }

+ 2 - 12
components/soc/soc/esp32s2/include/soc/pcnt_caps.h

@@ -19,18 +19,8 @@ extern "C" {
 #endif
 
 // ESP32-S2 have 1 PCNT peripheral
-#define PCNT_PORT_0            (0) /*!< PCNT port 0 */
-#define PCNT_PORT_MAX          (1) /*!< PCNT port max */
-#define SOC_PCNT_NUM           (PCNT_PORT_MAX)
-
-#define PCNT_PIN_NOT_USED     (-1)  /*!< When selected for a pin, this pin will not be used */
-
-// ESP32-S2 only have 4 unit
-#define PCNT_UNIT_0   (0)   /*!< PCNT unit 0 */
-#define PCNT_UNIT_1   (1)   /*!< PCNT unit 1 */
-#define PCNT_UNIT_2   (2)   /*!< PCNT unit 2 */
-#define PCNT_UNIT_3   (3)   /*!< PCNT unit 3 */
-#define PCNT_UNIT_MAX (4)
+#define SOC_PCNT_PORT_NUM      (1)
+#define SOC_PCNT_UNIT_NUM      (4) // ESP32-S2 only have 4 unit
 
 #ifdef __cplusplus
 }

+ 0 - 7
tools/ci/config/target-test.yml

@@ -384,13 +384,6 @@ UT_008:
     - UT_T1_GPIO
     - psram
 
-UT_010:
-  extends: .unit_test_template
-  tags:
-    - ESP32_IDF
-    - UT_T1_PCNT
-    - psram
-
 UT_012:
   extends: .unit_test_template
   tags: