99#include "freertos/FreeRTOS.h"
1010#include "freertos/task.h"
1111#include "unity.h"
12+ #include "soc/soc_caps.h"
13+ #include "soc/pcnt_periph.h"
14+ #include "hal/pcnt_ll.h"
1215#include "driver/pulse_cnt.h"
1316#include "driver/gpio.h"
14- #include "soc/soc_caps.h"
1517#include "esp_attr.h"
1618#include "test_pulse_cnt_board.h"
17- #include "hal/pcnt_ll.h"
1819
1920TEST_CASE ("pcnt_unit_install_uninstall" , "[pcnt]" )
2021{
@@ -23,21 +24,21 @@ TEST_CASE("pcnt_unit_install_uninstall", "[pcnt]")
2324 .high_limit = 100 ,
2425 .intr_priority = 0 ,
2526 };
26- pcnt_unit_handle_t units [SOC_PCNT_UNITS_PER_GROUP ];
27+ pcnt_unit_handle_t units [SOC_PCNT_ATTR ( UNITS_PER_INST ) ];
2728 int count_value = 0 ;
2829
2930 printf ("install pcnt units and check initial count\r\n" );
30- for (int i = 0 ; i < SOC_PCNT_UNITS_PER_GROUP - 1 ; i ++ ) {
31+ for (int i = 0 ; i < SOC_PCNT_ATTR ( UNITS_PER_INST ) - 1 ; i ++ ) {
3132 TEST_ESP_OK (pcnt_new_unit (& unit_config , & units [i ]));
3233 TEST_ESP_OK (pcnt_unit_get_count (units [i ], & count_value ));
3334 TEST_ASSERT_EQUAL (0 , count_value );
3435 }
3536
3637 // unit with a different interrupt priority
3738 unit_config .intr_priority = 3 ;
38- TEST_ESP_ERR (ESP_ERR_INVALID_STATE , pcnt_new_unit (& unit_config , & units [SOC_PCNT_UNITS_PER_GROUP - 1 ]));
39+ TEST_ESP_ERR (ESP_ERR_INVALID_STATE , pcnt_new_unit (& unit_config , & units [SOC_PCNT_ATTR ( UNITS_PER_INST ) - 1 ]));
3940 unit_config .intr_priority = 0 ;
40- TEST_ESP_OK (pcnt_new_unit (& unit_config , & units [SOC_PCNT_UNITS_PER_GROUP - 1 ]));
41+ TEST_ESP_OK (pcnt_new_unit (& unit_config , & units [SOC_PCNT_ATTR ( UNITS_PER_INST ) - 1 ]));
4142
4243 // no more free pcnt units
4344 TEST_ASSERT_EQUAL (ESP_ERR_NOT_FOUND , pcnt_new_unit (& unit_config , & units [0 ]));
@@ -46,7 +47,7 @@ TEST_CASE("pcnt_unit_install_uninstall", "[pcnt]")
4647 pcnt_glitch_filter_config_t filter_config = {
4748 .max_glitch_ns = 1000 ,
4849 };
49- for (int i = 0 ; i < SOC_PCNT_UNITS_PER_GROUP ; i ++ ) {
50+ for (int i = 0 ; i < SOC_PCNT_ATTR ( UNITS_PER_INST ) ; i ++ ) {
5051 TEST_ESP_OK (pcnt_unit_set_glitch_filter (units [i ], & filter_config ));
5152 }
5253 // invalid glitch configuration
@@ -56,30 +57,30 @@ TEST_CASE("pcnt_unit_install_uninstall", "[pcnt]")
5657 .on_reach = NULL ,
5758 };
5859 printf ("enable pcnt units\r\n" );
59- for (int i = 0 ; i < SOC_PCNT_UNITS_PER_GROUP ; i ++ ) {
60+ for (int i = 0 ; i < SOC_PCNT_ATTR ( UNITS_PER_INST ) ; i ++ ) {
6061 TEST_ESP_OK (pcnt_unit_register_event_callbacks (units [i ], & cbs , NULL ));
6162 TEST_ESP_OK (pcnt_unit_enable (units [i ]));
6263 }
6364
6465 printf ("start pcnt units\r\n" );
65- for (int i = 0 ; i < SOC_PCNT_UNITS_PER_GROUP ; i ++ ) {
66+ for (int i = 0 ; i < SOC_PCNT_ATTR ( UNITS_PER_INST ) ; i ++ ) {
6667 TEST_ESP_OK (pcnt_unit_start (units [i ]));
6768 }
6869
6970 printf ("stop pcnt units\r\n" );
70- for (int i = 0 ; i < SOC_PCNT_UNITS_PER_GROUP ; i ++ ) {
71+ for (int i = 0 ; i < SOC_PCNT_ATTR ( UNITS_PER_INST ) ; i ++ ) {
7172 TEST_ESP_OK (pcnt_unit_stop (units [i ]));
7273 }
7374
7475 // can't uninstall unit before disable it
7576 TEST_ASSERT_EQUAL (ESP_ERR_INVALID_STATE , pcnt_del_unit (units [0 ]));
7677 printf ("disable pcnt units\r\n" );
77- for (int i = 0 ; i < SOC_PCNT_UNITS_PER_GROUP ; i ++ ) {
78+ for (int i = 0 ; i < SOC_PCNT_ATTR ( UNITS_PER_INST ) ; i ++ ) {
7879 TEST_ESP_OK (pcnt_unit_disable (units [i ]));
7980 }
8081
8182 printf ("uninstall pcnt units\r\n" );
82- for (int i = 0 ; i < SOC_PCNT_UNITS_PER_GROUP ; i ++ ) {
83+ for (int i = 0 ; i < SOC_PCNT_ATTR ( UNITS_PER_INST ) ; i ++ ) {
8384 TEST_ESP_OK (pcnt_del_unit (units [i ]));
8485 }
8586}
@@ -96,17 +97,17 @@ TEST_CASE("pcnt_channel_install_uninstall", "[pcnt]")
9697 .edge_gpio_num = TEST_PCNT_GPIO_A , // only detect edge signal in this case
9798 .level_gpio_num = -1 ,
9899 };
99- pcnt_unit_handle_t units [SOC_PCNT_UNITS_PER_GROUP ];
100- pcnt_channel_handle_t chans [SOC_PCNT_UNITS_PER_GROUP ][ SOC_PCNT_CHANNELS_PER_UNIT ];
100+ pcnt_unit_handle_t units [SOC_PCNT_ATTR ( UNITS_PER_INST ) ];
101+ pcnt_channel_handle_t chans [SOC_PCNT_ATTR ( UNITS_PER_INST )][ SOC_PCNT_ATTR ( CHANS_PER_UNIT ) ];
101102
102103 printf ("install pcnt units\r\n" );
103- for (int i = 0 ; i < SOC_PCNT_UNITS_PER_GROUP ; i ++ ) {
104+ for (int i = 0 ; i < SOC_PCNT_ATTR ( UNITS_PER_INST ) ; i ++ ) {
104105 TEST_ESP_OK (pcnt_new_unit (& unit_config , & units [i ]));
105106 }
106107
107108 printf ("install pcnt channels\r\n" );
108- for (int i = 0 ; i < SOC_PCNT_UNITS_PER_GROUP ; i ++ ) {
109- for (int j = 0 ; j < SOC_PCNT_CHANNELS_PER_UNIT ; j ++ ) {
109+ for (int i = 0 ; i < SOC_PCNT_ATTR ( UNITS_PER_INST ) ; i ++ ) {
110+ for (int j = 0 ; j < SOC_PCNT_ATTR ( CHANS_PER_UNIT ) ; j ++ ) {
110111 TEST_ESP_OK (pcnt_new_channel (units [i ], & chan_config , & chans [i ][j ]));
111112 TEST_ESP_OK (pcnt_channel_set_edge_action (chans [i ][j ], PCNT_CHANNEL_EDGE_ACTION_INCREASE , PCNT_CHANNEL_EDGE_ACTION_HOLD ));
112113 TEST_ESP_OK (pcnt_channel_set_level_action (chans [i ][j ], PCNT_CHANNEL_LEVEL_ACTION_KEEP , PCNT_CHANNEL_LEVEL_ACTION_KEEP ));
@@ -117,55 +118,55 @@ TEST_CASE("pcnt_channel_install_uninstall", "[pcnt]")
117118
118119 printf ("start units\r\n" );
119120 int count_value = 0 ;
120- for (int i = 0 ; i < SOC_PCNT_UNITS_PER_GROUP ; i ++ ) {
121+ for (int i = 0 ; i < SOC_PCNT_ATTR ( UNITS_PER_INST ) ; i ++ ) {
121122 // start unit
122123 TEST_ESP_OK (pcnt_unit_start (units [i ]));
123124 // trigger 10 rising edge on GPIO0
124125 test_gpio_simulate_rising_edge (TEST_PCNT_GPIO_A , 10 );
125126 TEST_ESP_OK (pcnt_unit_get_count (units [i ], & count_value ));
126127 // each channel increases to the same unit counter
127- TEST_ASSERT_EQUAL (10 * SOC_PCNT_CHANNELS_PER_UNIT , count_value );
128+ TEST_ASSERT_EQUAL (10 * SOC_PCNT_ATTR ( CHANS_PER_UNIT ) , count_value );
128129 }
129130
130131 printf ("clear counts\r\n" );
131- for (int i = 0 ; i < SOC_PCNT_UNITS_PER_GROUP ; i ++ ) {
132+ for (int i = 0 ; i < SOC_PCNT_ATTR ( UNITS_PER_INST ) ; i ++ ) {
132133 TEST_ESP_OK (pcnt_unit_clear_count (units [i ]));
133134 TEST_ESP_OK (pcnt_unit_get_count (units [i ], & count_value ));
134135 TEST_ASSERT_EQUAL (0 , count_value );
135136 }
136137
137138 printf ("stop unit\r\n" );
138- for (int i = 0 ; i < SOC_PCNT_UNITS_PER_GROUP ; i ++ ) {
139+ for (int i = 0 ; i < SOC_PCNT_ATTR ( UNITS_PER_INST ) ; i ++ ) {
139140 // stop unit
140141 TEST_ESP_OK (pcnt_unit_stop (units [i ]));
141142 }
142143
143144 // trigger 10 rising edge on GPIO0 shouldn't increase the counter
144145 test_gpio_simulate_rising_edge (TEST_PCNT_GPIO_A , 10 );
145- for (int i = 0 ; i < SOC_PCNT_UNITS_PER_GROUP ; i ++ ) {
146+ for (int i = 0 ; i < SOC_PCNT_ATTR ( UNITS_PER_INST ) ; i ++ ) {
146147 TEST_ESP_OK (pcnt_unit_get_count (units [i ], & count_value ));
147148 TEST_ASSERT_EQUAL (0 , count_value );
148149 }
149150
150151 printf ("restart units\r\n" );
151- for (int i = 0 ; i < SOC_PCNT_UNITS_PER_GROUP ; i ++ ) {
152+ for (int i = 0 ; i < SOC_PCNT_ATTR ( UNITS_PER_INST ) ; i ++ ) {
152153 // start unit
153154 TEST_ESP_OK (pcnt_unit_start (units [i ]));
154155 // trigger 10 rising edge on GPIO
155156 test_gpio_simulate_rising_edge (TEST_PCNT_GPIO_A , 10 );
156157 TEST_ESP_OK (pcnt_unit_get_count (units [i ], & count_value ));
157158 // each channel increases to the same unit counter
158- TEST_ASSERT_EQUAL (10 * SOC_PCNT_CHANNELS_PER_UNIT , count_value );
159+ TEST_ASSERT_EQUAL (10 * SOC_PCNT_ATTR ( CHANS_PER_UNIT ) , count_value );
159160 }
160161
161162 printf ("uninstall channels and units\r\n" );
162- for (int i = 0 ; i < SOC_PCNT_UNITS_PER_GROUP ; i ++ ) {
163+ for (int i = 0 ; i < SOC_PCNT_ATTR ( UNITS_PER_INST ) ; i ++ ) {
163164 // stop unit
164165 TEST_ESP_OK (pcnt_unit_stop (units [i ]));
165166 TEST_ESP_OK (pcnt_unit_disable (units [i ]));
166167 // can't uninstall unit when channel is still alive
167168 TEST_ASSERT_EQUAL (ESP_ERR_INVALID_STATE , pcnt_del_unit (units [i ]));
168- for (int j = 0 ; j < SOC_PCNT_CHANNELS_PER_UNIT ; j ++ ) {
169+ for (int j = 0 ; j < SOC_PCNT_ATTR ( CHANS_PER_UNIT ) ; j ++ ) {
169170 TEST_ESP_OK (pcnt_del_channel (chans [i ][j ]));
170171 }
171172 TEST_ESP_OK (pcnt_del_unit (units [i ]));
0 commit comments