pcnt.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include "esp_log.h"
  14. #include "esp_intr_alloc.h"
  15. #include "driver/pcnt.h"
  16. #include "driver/periph_ctrl.h"
  17. #define PCNT_CHANNEL_ERR_STR "PCNT CHANNEL ERROR"
  18. #define PCNT_UNIT_ERR_STR "PCNT UNIT ERROR"
  19. #define PCNT_GPIO_ERR_STR "PCNT GPIO NUM ERROR"
  20. #define PCNT_ADDRESS_ERR_STR "PCNT ADDRESS ERROR"
  21. #define PCNT_PARAM_ERR_STR "PCNT PARAM ERROR"
  22. #define PCNT_COUNT_MODE_ERR_STR "PCNT COUNTER MODE ERROR"
  23. #define PCNT_CTRL_MODE_ERR_STR "PCNT CTRL MODE ERROR"
  24. #define PCNT_EVT_TYPE_ERR_STR "PCNT value type error"
  25. #define PCNT_ENTER_CRITICAL(mux) portENTER_CRITICAL(mux)
  26. #define PCNT_EXIT_CRITICAL(mux) portEXIT_CRITICAL(mux)
  27. #define PCNT_CHECK(a, str, ret_val) \
  28. if (!(a)) { \
  29. ESP_LOGE(PCNT_TAG,"%s(%d): %s", __FUNCTION__, __LINE__, str); \
  30. return (ret_val); \
  31. }
  32. typedef struct{
  33. void(*fn)(void *args); /*!< isr function */
  34. void* args; /*!< isr function args */
  35. } pcnt_isr_func_t;
  36. static pcnt_isr_func_t *pcnt_isr_func = NULL;
  37. static pcnt_isr_handle_t pcnt_isr_service = NULL;
  38. static portMUX_TYPE pcnt_spinlock = portMUX_INITIALIZER_UNLOCKED;
  39. static const char* PCNT_TAG = "pcnt";
  40. esp_err_t pcnt_unit_config(const pcnt_config_t *pcnt_config)
  41. {
  42. uint8_t unit = pcnt_config->unit;
  43. uint8_t channel = pcnt_config->channel;
  44. int input_io = pcnt_config->pulse_gpio_num;
  45. int ctrl_io = pcnt_config->ctrl_gpio_num;
  46. PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  47. PCNT_CHECK(channel < PCNT_CHANNEL_MAX, PCNT_CHANNEL_ERR_STR, ESP_ERR_INVALID_ARG);
  48. PCNT_CHECK(input_io < 0 || (GPIO_IS_VALID_GPIO(input_io) && (input_io != ctrl_io)), "PCNT pluse input io error", ESP_ERR_INVALID_ARG);
  49. PCNT_CHECK(ctrl_io < 0 || GPIO_IS_VALID_GPIO(ctrl_io), "PCNT ctrl io error", ESP_ERR_INVALID_ARG);
  50. PCNT_CHECK((pcnt_config->pos_mode < PCNT_COUNT_MAX) && (pcnt_config->neg_mode < PCNT_COUNT_MAX), PCNT_COUNT_MODE_ERR_STR, ESP_ERR_INVALID_ARG);
  51. PCNT_CHECK((pcnt_config->hctrl_mode < PCNT_MODE_MAX) && (pcnt_config->lctrl_mode < PCNT_MODE_MAX), PCNT_CTRL_MODE_ERR_STR, ESP_ERR_INVALID_ARG);
  52. /*Enalbe hardware module*/
  53. periph_module_enable(PERIPH_PCNT_MODULE);
  54. /*Set counter range*/
  55. pcnt_set_event_value(unit, PCNT_EVT_H_LIM, pcnt_config->counter_h_lim);
  56. pcnt_set_event_value(unit, PCNT_EVT_L_LIM, pcnt_config->counter_l_lim);
  57. /*Default value after reboot is positive, we disable these events like others*/
  58. pcnt_event_disable(unit, PCNT_EVT_H_LIM);
  59. pcnt_event_disable(unit, PCNT_EVT_L_LIM);
  60. pcnt_event_disable(unit, PCNT_EVT_ZERO);
  61. pcnt_filter_disable(unit);
  62. /*set pulse input and control mode*/
  63. pcnt_set_mode(unit, channel, pcnt_config->pos_mode, pcnt_config->neg_mode, pcnt_config->hctrl_mode, pcnt_config->lctrl_mode);
  64. /*Set pulse input and control pins*/
  65. pcnt_set_pin(unit, channel, input_io, ctrl_io);
  66. return ESP_OK;
  67. }
  68. esp_err_t pcnt_set_mode(pcnt_unit_t unit, pcnt_channel_t channel, pcnt_count_mode_t pos_mode, pcnt_count_mode_t neg_mode, pcnt_ctrl_mode_t hctrl_mode, pcnt_ctrl_mode_t lctrl_mode)
  69. {
  70. PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  71. PCNT_CHECK(channel < PCNT_CHANNEL_MAX, PCNT_CHANNEL_ERR_STR, ESP_ERR_INVALID_ARG);
  72. PCNT_CHECK((pos_mode < PCNT_COUNT_MAX) && (neg_mode < PCNT_COUNT_MAX), PCNT_COUNT_MODE_ERR_STR, ESP_ERR_INVALID_ARG);
  73. PCNT_CHECK((hctrl_mode < PCNT_MODE_MAX) && (lctrl_mode < PCNT_MODE_MAX), PCNT_CTRL_MODE_ERR_STR, ESP_ERR_INVALID_ARG);
  74. if(channel == 0) {
  75. PCNT.conf_unit[unit].conf0.ch0_pos_mode = pos_mode;
  76. PCNT.conf_unit[unit].conf0.ch0_neg_mode = neg_mode;
  77. PCNT.conf_unit[unit].conf0.ch0_hctrl_mode = hctrl_mode;
  78. PCNT.conf_unit[unit].conf0.ch0_lctrl_mode = lctrl_mode;
  79. } else {
  80. PCNT.conf_unit[unit].conf0.ch1_pos_mode = pos_mode;
  81. PCNT.conf_unit[unit].conf0.ch1_neg_mode = neg_mode;
  82. PCNT.conf_unit[unit].conf0.ch1_hctrl_mode = hctrl_mode;
  83. PCNT.conf_unit[unit].conf0.ch1_lctrl_mode = lctrl_mode;
  84. }
  85. return ESP_OK;
  86. }
  87. esp_err_t pcnt_set_pin(pcnt_unit_t unit, pcnt_channel_t channel, int pulse_io, int ctrl_io)
  88. {
  89. PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  90. PCNT_CHECK(channel < PCNT_CHANNEL_MAX, PCNT_CHANNEL_ERR_STR, ESP_ERR_INVALID_ARG);
  91. PCNT_CHECK(GPIO_IS_VALID_GPIO(pulse_io) || pulse_io < 0, PCNT_GPIO_ERR_STR, ESP_ERR_INVALID_ARG);
  92. PCNT_CHECK(GPIO_IS_VALID_GPIO(ctrl_io) || ctrl_io < 0, PCNT_GPIO_ERR_STR, ESP_ERR_INVALID_ARG);
  93. int sig_base = (channel == 0) ? PCNT_SIG_CH0_IN0_IDX : PCNT_SIG_CH1_IN0_IDX;
  94. int ctrl_base = (channel == 0) ? PCNT_CTRL_CH0_IN0_IDX : PCNT_CTRL_CH1_IN0_IDX;
  95. if (unit > 4) {
  96. sig_base += 12; // GPIO matrix assignments have a gap between units 4 & 5
  97. ctrl_base += 12;
  98. }
  99. int input_sig_index = sig_base + (4 * unit);
  100. int ctrl_sig_index = ctrl_base + (4 * unit);
  101. if(pulse_io >= 0) {
  102. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pulse_io], PIN_FUNC_GPIO);
  103. gpio_set_direction(pulse_io, GPIO_MODE_INPUT);
  104. gpio_set_pull_mode(pulse_io, GPIO_PULLUP_ONLY);
  105. gpio_matrix_in(pulse_io, input_sig_index, 0);
  106. }
  107. if(ctrl_io >= 0) {
  108. PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[ctrl_io], PIN_FUNC_GPIO);
  109. gpio_set_direction(ctrl_io, GPIO_MODE_INPUT);
  110. gpio_set_pull_mode(ctrl_io, GPIO_PULLUP_ONLY);
  111. gpio_matrix_in(ctrl_io, ctrl_sig_index, 0);
  112. }
  113. return ESP_OK;
  114. }
  115. esp_err_t pcnt_get_counter_value(pcnt_unit_t pcnt_unit, int16_t* count)
  116. {
  117. PCNT_CHECK(pcnt_unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  118. PCNT_CHECK(count != NULL, PCNT_ADDRESS_ERR_STR, ESP_ERR_INVALID_ARG);
  119. *count = (int16_t) PCNT.cnt_unit[pcnt_unit].cnt_val;
  120. return ESP_OK;
  121. }
  122. esp_err_t pcnt_counter_pause(pcnt_unit_t pcnt_unit)
  123. {
  124. PCNT_CHECK(pcnt_unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  125. PCNT_ENTER_CRITICAL(&pcnt_spinlock);
  126. PCNT.ctrl.val |= BIT(PCNT_CNT_PAUSE_U0_S + (pcnt_unit * 2));
  127. PCNT_EXIT_CRITICAL(&pcnt_spinlock);
  128. return ESP_OK;
  129. }
  130. esp_err_t pcnt_counter_resume(pcnt_unit_t pcnt_unit)
  131. {
  132. PCNT_CHECK(pcnt_unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  133. PCNT_ENTER_CRITICAL(&pcnt_spinlock);
  134. PCNT.ctrl.val &= (~(BIT(PCNT_CNT_PAUSE_U0_S + (pcnt_unit * 2))));
  135. PCNT_EXIT_CRITICAL(&pcnt_spinlock);
  136. return ESP_OK;
  137. }
  138. esp_err_t pcnt_counter_clear(pcnt_unit_t pcnt_unit)
  139. {
  140. PCNT_CHECK(pcnt_unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  141. PCNT_ENTER_CRITICAL(&pcnt_spinlock);
  142. uint32_t reset_bit = BIT(PCNT_PLUS_CNT_RST_U0_S + (pcnt_unit * 2));
  143. PCNT.ctrl.val |= reset_bit;
  144. PCNT.ctrl.val &= ~reset_bit;
  145. PCNT_EXIT_CRITICAL(&pcnt_spinlock);
  146. return ESP_OK;
  147. }
  148. esp_err_t pcnt_intr_enable(pcnt_unit_t pcnt_unit)
  149. {
  150. PCNT_CHECK(pcnt_unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  151. PCNT_ENTER_CRITICAL(&pcnt_spinlock);
  152. PCNT.int_ena.val |= BIT(PCNT_CNT_THR_EVENT_U0_INT_ENA_S + pcnt_unit);
  153. PCNT_EXIT_CRITICAL(&pcnt_spinlock);
  154. return ESP_OK;
  155. }
  156. esp_err_t pcnt_intr_disable(pcnt_unit_t pcnt_unit)
  157. {
  158. PCNT_CHECK(pcnt_unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  159. PCNT_ENTER_CRITICAL(&pcnt_spinlock);
  160. PCNT.int_ena.val &= (~(BIT(PCNT_CNT_THR_EVENT_U0_INT_ENA_S + pcnt_unit)));
  161. PCNT_EXIT_CRITICAL(&pcnt_spinlock);
  162. return ESP_OK;
  163. }
  164. esp_err_t pcnt_event_enable(pcnt_unit_t unit, pcnt_evt_type_t evt_type)
  165. {
  166. PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  167. PCNT_CHECK(evt_type < PCNT_EVT_MAX, PCNT_EVT_TYPE_ERR_STR, ESP_ERR_INVALID_ARG);
  168. if(evt_type == PCNT_EVT_L_LIM) {
  169. PCNT.conf_unit[unit].conf0.thr_l_lim_en = 1;
  170. } else if(evt_type == PCNT_EVT_H_LIM) {
  171. PCNT.conf_unit[unit].conf0.thr_h_lim_en = 1;
  172. } else if(evt_type == PCNT_EVT_THRES_0) {
  173. PCNT.conf_unit[unit].conf0.thr_thres0_en = 1;
  174. } else if(evt_type == PCNT_EVT_THRES_1) {
  175. PCNT.conf_unit[unit].conf0.thr_thres1_en = 1;
  176. } else if(evt_type == PCNT_EVT_ZERO) {
  177. PCNT.conf_unit[unit].conf0.thr_zero_en = 1;
  178. }
  179. return ESP_OK;
  180. }
  181. esp_err_t pcnt_event_disable(pcnt_unit_t unit, pcnt_evt_type_t evt_type)
  182. {
  183. PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  184. PCNT_CHECK(evt_type < PCNT_EVT_MAX, PCNT_EVT_TYPE_ERR_STR, ESP_ERR_INVALID_ARG);
  185. if(evt_type == PCNT_EVT_L_LIM) {
  186. PCNT.conf_unit[unit].conf0.thr_l_lim_en = 0;
  187. } else if(evt_type == PCNT_EVT_H_LIM) {
  188. PCNT.conf_unit[unit].conf0.thr_h_lim_en = 0;
  189. } else if(evt_type == PCNT_EVT_THRES_0) {
  190. PCNT.conf_unit[unit].conf0.thr_thres0_en = 0;
  191. } else if(evt_type == PCNT_EVT_THRES_1) {
  192. PCNT.conf_unit[unit].conf0.thr_thres1_en = 0;
  193. } else if(evt_type == PCNT_EVT_ZERO) {
  194. PCNT.conf_unit[unit].conf0.thr_zero_en = 0;
  195. }
  196. return ESP_OK;
  197. }
  198. esp_err_t pcnt_set_event_value(pcnt_unit_t unit, pcnt_evt_type_t evt_type, int16_t value)
  199. {
  200. PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  201. PCNT_CHECK(evt_type < PCNT_EVT_MAX, PCNT_EVT_TYPE_ERR_STR, ESP_ERR_INVALID_ARG);
  202. if(evt_type == PCNT_EVT_L_LIM) {
  203. PCNT.conf_unit[unit].conf2.cnt_l_lim = value;
  204. } else if(evt_type == PCNT_EVT_H_LIM) {
  205. PCNT.conf_unit[unit].conf2.cnt_h_lim = value;
  206. } else if(evt_type == PCNT_EVT_THRES_0) {
  207. PCNT.conf_unit[unit].conf1.cnt_thres0 = value;
  208. } else if(evt_type == PCNT_EVT_THRES_1) {
  209. PCNT.conf_unit[unit].conf1.cnt_thres1 = value;
  210. }
  211. return ESP_OK;
  212. }
  213. esp_err_t pcnt_get_event_value(pcnt_unit_t unit, pcnt_evt_type_t evt_type, int16_t *value)
  214. {
  215. PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  216. PCNT_CHECK(evt_type < PCNT_EVT_MAX, PCNT_EVT_TYPE_ERR_STR, ESP_ERR_INVALID_ARG);
  217. PCNT_CHECK(value != NULL, PCNT_ADDRESS_ERR_STR, ESP_ERR_INVALID_ARG);
  218. if(evt_type == PCNT_EVT_L_LIM) {
  219. *value = (int16_t) PCNT.conf_unit[unit].conf2.cnt_l_lim;
  220. } else if(evt_type == PCNT_EVT_H_LIM) {
  221. *value = (int16_t) PCNT.conf_unit[unit].conf2.cnt_h_lim;
  222. } else if(evt_type == PCNT_EVT_THRES_0) {
  223. *value = (int16_t) PCNT.conf_unit[unit].conf1.cnt_thres0;
  224. } else if(evt_type == PCNT_EVT_THRES_1) {
  225. *value = (int16_t) PCNT.conf_unit[unit].conf1.cnt_thres1;
  226. } else {
  227. *value = 0;
  228. }
  229. return ESP_OK;
  230. }
  231. esp_err_t pcnt_set_filter_value(pcnt_unit_t unit, uint16_t filter_val)
  232. {
  233. PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  234. PCNT_CHECK(filter_val < 1024, PCNT_PARAM_ERR_STR, ESP_ERR_INVALID_ARG);
  235. PCNT.conf_unit[unit].conf0.filter_thres = filter_val;
  236. return ESP_OK;
  237. }
  238. esp_err_t pcnt_get_filter_value(pcnt_unit_t unit, uint16_t *filter_val)
  239. {
  240. PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  241. PCNT_CHECK(filter_val != NULL, PCNT_ADDRESS_ERR_STR, ESP_ERR_INVALID_ARG);
  242. *filter_val = PCNT.conf_unit[unit].conf0.filter_thres;
  243. return ESP_OK;
  244. }
  245. esp_err_t pcnt_filter_enable(pcnt_unit_t unit)
  246. {
  247. PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  248. PCNT.conf_unit[unit].conf0.filter_en = 1;
  249. return ESP_OK;
  250. }
  251. esp_err_t pcnt_filter_disable(pcnt_unit_t unit)
  252. {
  253. PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
  254. PCNT.conf_unit[unit].conf0.filter_en = 0;
  255. return ESP_OK;
  256. }
  257. esp_err_t pcnt_isr_register(void (*fun)(void*), void * arg, int intr_alloc_flags, pcnt_isr_handle_t *handle)
  258. {
  259. PCNT_CHECK(fun != NULL, PCNT_ADDRESS_ERR_STR, ESP_ERR_INVALID_ARG);
  260. return esp_intr_alloc(ETS_PCNT_INTR_SOURCE, intr_alloc_flags, fun, arg, handle);
  261. }
  262. // pcnt interrupt service
  263. static void IRAM_ATTR pcnt_intr_service(void* arg)
  264. {
  265. uint32_t intr_status = PCNT.int_st.val;
  266. for (int unit = 0; unit < PCNT_UNIT_MAX; unit++) {
  267. if (intr_status & (BIT(unit))) {
  268. if (pcnt_isr_func[unit].fn != NULL) {
  269. (pcnt_isr_func[unit].fn)(pcnt_isr_func[unit].args);
  270. }
  271. PCNT.int_clr.val = BIT(unit);
  272. }
  273. }
  274. }
  275. esp_err_t pcnt_isr_handler_add(pcnt_unit_t unit, void(*isr_handler)(void *), void *args)
  276. {
  277. PCNT_CHECK(pcnt_isr_func != NULL, "ISR service is not installed, call pcnt_install_isr_service() first", ESP_ERR_INVALID_STATE);
  278. PCNT_CHECK(unit < PCNT_UNIT_MAX, "PCNT unit error", ESP_ERR_INVALID_ARG);
  279. PCNT_ENTER_CRITICAL(&pcnt_spinlock);
  280. pcnt_intr_disable(unit);
  281. if (pcnt_isr_func) {
  282. pcnt_isr_func[unit].fn = isr_handler;
  283. pcnt_isr_func[unit].args = args;
  284. }
  285. pcnt_intr_enable(unit);
  286. PCNT_EXIT_CRITICAL(&pcnt_spinlock);
  287. return ESP_OK;
  288. }
  289. esp_err_t pcnt_isr_handler_remove(pcnt_unit_t unit)
  290. {
  291. PCNT_CHECK(pcnt_isr_func != NULL, "ISR service is not installed", ESP_ERR_INVALID_STATE);
  292. PCNT_CHECK(unit < PCNT_UNIT_MAX, "PCNT unit error", ESP_ERR_INVALID_ARG);
  293. PCNT_ENTER_CRITICAL(&pcnt_spinlock);
  294. pcnt_intr_disable(unit);
  295. if (pcnt_isr_func) {
  296. pcnt_isr_func[unit].fn = NULL;
  297. pcnt_isr_func[unit].args = NULL;
  298. }
  299. PCNT_EXIT_CRITICAL(&pcnt_spinlock);
  300. return ESP_OK;
  301. }
  302. esp_err_t pcnt_isr_service_install(int intr_alloc_flags)
  303. {
  304. PCNT_CHECK(pcnt_isr_func == NULL, "ISR service already installed", ESP_ERR_INVALID_STATE);
  305. PCNT_ENTER_CRITICAL(&pcnt_spinlock);
  306. esp_err_t ret = ESP_FAIL;
  307. pcnt_isr_func = (pcnt_isr_func_t*) calloc(PCNT_UNIT_MAX, sizeof(pcnt_isr_func_t));
  308. if (pcnt_isr_func == NULL) {
  309. ret = ESP_ERR_NO_MEM;
  310. } else {
  311. ret = pcnt_isr_register(pcnt_intr_service, NULL, intr_alloc_flags, &pcnt_isr_service);
  312. }
  313. PCNT_EXIT_CRITICAL(&pcnt_spinlock);
  314. return ret;
  315. }
  316. void pcnt_isr_service_uninstall(void)
  317. {
  318. if (pcnt_isr_func == NULL) {
  319. return;
  320. }
  321. PCNT_ENTER_CRITICAL(&pcnt_spinlock);
  322. esp_intr_free(pcnt_isr_service);
  323. free(pcnt_isr_func);
  324. pcnt_isr_func = NULL;
  325. pcnt_isr_service = NULL;
  326. PCNT_EXIT_CRITICAL(&pcnt_spinlock);
  327. }