InPlay API
hal_counter.h
1 
12 #ifndef HAL_COUNTER_H
13 #define HAL_COUNTER_H
14 
23 #include "./hal/hal_power.h"
24 
25 #include "in_mmap.h"
26 #include <stdint.h>
27 //#define APB_CLOCK 32000000
28 
29 #define CNT0_BASE (0)
30 #define CNT1_BASE (0x100)
31 #define CNT2_BASE (0x200)
32 #define CNT3_BASE (0x300)
33 
34 #define CNT_CAPTURE_SHIFTIN_MODE 0x0
35 #define CNT_WAVEFORM_SHITOUT_MODE 0x1
36 #define CNT_COUNT_MODE 0x0
37 #define CNT_SHIFT_MODE 0x2
38 #define CNT_SWITCH_DISABLE 0x0
39 #define CNT_SWITCH_ENABLE 0x4
40 
41 #define CNT_CAPTURE_MODE (CNT_CAPTURE_SHIFTIN_MODE | CNT_COUNT_MODE)
42 #define CNT_WAVAFORM_MODE (CNT_WAVEFORM_SHITOUT_MODE | CNT_COUNT_MODE)
43 #define CNT_SHIFTIN_MODE (CNT_CAPTURE_SHIFTIN_MODE | CNT_SHIFT_MODE)
44 #define CNT_SHIFTOUT_MODE (CNT_WAVEFORM_SHITOUT_MODE | CNT_SHIFT_MODE)
45 
46 //enable_c0
47 #define CNT_ENABLE 0x1UL
48 #define CNT_CLK_INV_ENABLE 0x1000UL
49 #define CNT_CLK_ENABLE 0x2000UL
50 #define CNT_CLK_DIV8 0
51 #define CNT_CLK_DIV4 1
52 #define CNT_CLK_DIV2 2
53 #define CNT_CLK_32K 3
54 #define CNT_EXT_CLK0 4
55 #define CNT_EXT_CLK1 5
56 #define CNT_EXT_CLK2 6
57 
58 /* For count0, clk0 is count1, clk1 is count2, clk2 is count3.
59  For count1, clk0 is count0, clk1 is count2, clk2 is count3 */
60 #define CNT_COUNTER_CLK0 7
61 #define CNT_COUNTER_CLK1 8
62 #define CNT_COUNTER_CLK2 9
63 
64 //src_sel_start_c0
65 #define CNT_EXT_DIN_A 1
66 #define CNT_EXT_DIN_B 2
67 #define CNT_GLOBAL_START_TRIGGER 3
68 #define CNT_SINGLE_START_TRIGGER 4
69 #define CNT_GLOBAL_STOP_TRIGGER 5
70 #define CNT_SINGLE_STOP_TRIGGER 6
71 #define CNT_INNER_DIN0 11
72 #define CNT_INNER_DIN1 12
73 #define CNT_INNER_DIN2 13
74 #define CNT_INNER_DIN3 14
75 #define CNT_START_SIGNLE_SHIFT 0
76 #define CNT_STOP_SIGNLE_SHIFT 8
77 #define CNT_DIN0_SHIFT 16
78 #define CNT_DIN1_SHIFT 24
79 #define CNT_RISING_EDGE 0
80 #define CNT_FALLING_EDGE 0x10UL
81 #define CNT_BOTH_EDGE 0x20UL
82 
83 //ctrl_snap_c0 reverse
84 #define CNT_SNAP_SHADOW_MASK 0x1UL
85 #define CNT_SNAP_CAPTURE_A_MASK 0x2UL
86 #define CNT_SNAP_CAPTURE_B_MASK 0x4UL
87 #define CNT_SNAP_SHIFTIN_DATA_MASK 0x8UL
88 #define CNT_SNAP_CLEAR_MASK 0x10000UL
89 
90 //TARGET_REG_CTRL
91 #define CNT_A2_KEEP_VALUE 0x1UL
92 #define CNT_A2_RESET_VALUE 0x0UL
93 #define CNT_A2_STOP_COUNTER 0x2UL
94 #define CNT_A2_RESTART_COUNTER 0x0UL
95 #define CNT_B2_KEEP_VALUE 0x4UL
96 #define CNT_B2_RESET_VALUE 0x0UL
97 #define CNT_B2_STOP_COUNTER 0x8UL
98 #define CNT_B2_RESTART_COUNTER 0x0UL
99 #define CNT_DOUT_A_RESET_VALUE_SHIFT 4
100 #define CNT_DOUT_B_RESET_VALUE_SHIFT 5
101 
102 //ir_dout_bypass_c0
103 #define CNT_OUT_BYPASS_A 0x10000UL //Bypass pin A operation(AND, OR and NOT)
104 #define CNT_OUT_BYPASS_B 0x20000UL //Bypass pin B operation(AND, OR and NOT)
105 #define CNT_OPT_A_AND 0x0
106 #define CNT_OPT_A_OR 0x1
107 #define CNT_OPT_A_XOR 0x2
108 #define CNT_OPT_B_AND 0x0
109 #define CNT_OPT_B_OR 0x10
110 #define CNT_OPT_B_XOR 0x20
111 
112 //ir_din_bypass_c0
113 #define CNT_IN_BYPASS_A 0x1UL
114 #define CNT_IN_BYPASS_B 0x2UL
115 
116 //shiftmode_point_en_c0
117 #define CNT_SHIFTMODE_POINT_EN 0x10000
118 
119 //waveform_mode_automatic_c0
120 #define CNT_WAVEFORM_SHIFTOUT_CNT_SHIFT 0
121 #define CNT_CAPTURE_SHIFTIN_CNT_SHIFT 8
122 #define CNT_WAVEFORM_SHIFTOUT_AUTO_ENABLE 0x10000UL
123 #define CNT_CAPTURE_SHIFTIN_AUTO_ENABLE 0x1000000UL
124 
125 //interrupt
126 #define CNT0_SHIFT 0
127 #define CNT1_SHIFT 8
128 #define CNT2_SHIFT 16
129 #define CNT3_SHIFT 24
130 #define CNT_A_UPDATE 1
131 #define CNT_B_UPDATE 0x2
132 #define CNT_OVERFLOW 0x4
133 #define CNT_SHIFTIN_COMPLETE 0x8
134 #define CNT_SHIFTOUT_COMPLETE 0x10
135 #define CNT_WAVEFORM_STOP 0x20 //counter value reach a2 or b2
136 #define CNT_SHIFTIN_CAPTURE_END 0x40 //need enable auto switch
137 #define CNT_SHIFTOUT_WAVEFORM_END 0x80 //need enable auto swtich
138 
139 //reset_ctrl_4
140 #define CNT_RESET_CNT0 0x00000010UL
141 #define CNT_RESET_CNT1 0x00000020UL
142 #define CNT_RESET_CNT2 0x00000040UL
143 #define CNT_RESET_CNT3 0x00000080UL
144 
145 //mux sel
146 #define CNT0_BUS_B 0x1
147 #define CNT1_BUS_B 0x2
148 #define CNT2_BUS_B 0x4
149 #define CNT3_BUS_B 0x8
150 
151 
152 /* flip bit with mask */
153 #define FLIP_BIT(val, mask) \
154  do { \
155  uint32_t _tmp = (~val) & mask; \
156  val &= ~mask; \
157  val |= _tmp; \
158  } while (0)
159 #define DUMP_REG(reg, base) PRINTD(DBG_TRACE, #reg " %08x (%x)\n", RD_WORD(reg + base), base)
160 enum cnt_id {
161  CNT0_ID = 0,
162  CNT1_ID,
163  CNT2_ID,
164  CNT3_ID,
165  CNT_MAX_ID,
166 };
167 
168 
171  CNT0_PIN_A = 0,
172  CNT0_PIN_B,
173  CNT1_PIN_A,
174  CNT1_PIN_B,
175  CNT2_PIN_A,
176  CNT2_PIN_B,
177  CNT3_PIN_A,
178  CNT3_PIN_B,
179  CNT_MAX_PIN,
180 };
181 
182 enum cnt_error {
183  CNT_ERR_OK = 0,
184  CNT_ERR_INVALID_PARAM = -1,
185  CNT_ERR_TIMEOUT = -2,
186 };
187 typedef struct {
188  int clk_div; /*<When use XO, clk can be 16000000, 8000000, 4000000. When use RC, clk can be 8000000, 4000000, 2000000.
189  CNT_CLK_DIV8 0 ///Root clock divide 8
190  CNT_CLK_DIV4 1 ///Root clock divide 4
191  CNT_CLK_DIV2 2 ///Root clock divide 2*/
192  int prio;
193  void *arg;
194  void (*cb)(void *arg, uint32_t status);
195 } cnt_init_t;
196 typedef struct {
197  uint32_t base;
198  void (*cb)(void *arg, uint32_t status);
199  void* arg;
200  uint32_t clk;
201  char id;
202  char clk_div;
203  char used;
204  char prio;
205 #if CFG_PM_EN
206  int resume;
207  int power_state;
208  struct pm_module pmd;
209 #endif
210 
211 } cnt_dev_t;
212 
213 typedef void (*CNT_ISR_FUN)(void*, uint32_t);
214 
215 static INLINE void cnt_enable_clk(uint32_t base)
216 {
217  uint32_t reg = RD_WORD(COUNTER_ALL_APB_REG_ENABLE_C0 + base);
218  reg |= CNT_CLK_ENABLE;
219  WR_WORD(COUNTER_ALL_APB_REG_ENABLE_C0 + base, reg);
220 }
221 static INLINE void cnt_disable_clk(uint32_t base)
222 {
223  uint32_t reg = RD_WORD(COUNTER_ALL_APB_REG_ENABLE_C0 + base);
224  reg &= ~CNT_CLK_ENABLE;
225  WR_WORD(COUNTER_ALL_APB_REG_ENABLE_C0 + base, reg);
226 }
227 static INLINE void cnt_set_clk(uint32_t base, uint32_t val)
228 {
229  uint32_t reg = RD_WORD(COUNTER_ALL_APB_REG_ENABLE_C0 + base);
230  reg |= val << 8;
231  WR_WORD(COUNTER_ALL_APB_REG_ENABLE_C0 + base, reg);
232 }
233 
234 static INLINE void cnt_set_mode(uint32_t base, uint32_t mode)
235 {
236  WR_WORD(COUNTER_ALL_APB_REG_MODE_SEL_C0 + base, mode);
237 }
238 static INLINE void cnt_set_src_edge(uint32_t base, uint32_t src_edge)
239 {
240  WR_WORD(COUNTER_ALL_APB_REG_SRC_SEL_EDGE_C0 + base, src_edge);
241 }
242 static INLINE void cnt_set_target_ctrl(uint32_t base, uint32_t ctrl)
243 {
244  WR_WORD(COUNTER_ALL_APB_REG_TARGET_REG_CTRL_C0 + base, ctrl);
245 }
246 static INLINE void cnt_set_soft_trigger(uint32_t base, uint32_t trigger)
247 {
248  WR_WORD(COUNTER_ALL_APB_REG_SOFT_TRIGGER_CTRL_C0 + base, trigger);
249 }
250 static INLINE void cnt_set_target_a(uint32_t base, uint32_t a0, uint32_t a1, uint32_t a2)
251 {
252  WR_WORD(COUNTER_ALL_APB_REG_TARGET_REG_A0_C0 + base, a0);
253  WR_WORD(COUNTER_ALL_APB_REG_TARGET_REG_A1_C0 + base, a1);
254  WR_WORD(COUNTER_ALL_APB_REG_TARGET_REG_A2_C0 + base, a2);
255 }
256 static INLINE void cnt_set_target_b(uint32_t base, uint32_t b0, uint32_t b1, uint32_t b2)
257 {
258  WR_WORD(COUNTER_ALL_APB_REG_TARGET_REG_B0_C0 + base, b0);
259  WR_WORD(COUNTER_ALL_APB_REG_TARGET_REG_B1_C0 + base, b1);
260  WR_WORD(COUNTER_ALL_APB_REG_TARGET_REG_B2_C0 + base, b2);
261 }
262 static INLINE void cnt_set_out_bypass(uint32_t base, uint32_t val)
263 {
264  WR_WORD(COUNTER_ALL_APB_REG_IR_DOUT_BYPASS_C0 + base, val);
265 }
266 static INLINE void cnt_set_in_bypass(uint32_t base, uint32_t val)
267 {
268  WR_WORD(COUNTER_ALL_APB_REG_IR_DIN_BYPASS_C0 + base, val);
269 }
270 static INLINE void cnt_set_input_mux(uint32_t base, uint32_t val)
271 {
272  WR_WORD(COUNTER_ALL_APB_REG_MUX_SEL_C0 + base, val);
273 }
274 static INLINE void cnt_set_shiftmode_ctrl(uint32_t base, uint32_t val)
275 {
276  WR_WORD(COUNTER_ALL_APB_REG_SHIFTMODE_CTRL_C0 + base, val);
277 }
278 
279 /* shiftin n bits*/
280 static INLINE void cnt_set_shiftin_bit_num(uint32_t base, uint32_t n)
281 {
282  WR_WORD(COUNTER_ALL_APB_REG_SHIFTIN_DATA_CTRL_BITCNTS_C0 + base, n);
283 }
284 
285 /* enable and sample point*/
286 static INLINE void cnt_set_shiftmode_point_en(uint32_t base, uint32_t val)
287 {
288  WR_WORD(COUNTER_ALL_APB_REG_SHIFTMODE_POINT_EN_C0 + base, val);
289 }
290 
291 static INLINE void cnt_set_one_bit_count(uint32_t base, uint32_t val)
292 {
293  WR_WORD(COUNTER_ALL_APB_REG_SWITCH_MODE_ONEBIT_CNTS_C0 + base, val);
294 }
295 
296 static INLINE void cnt_set_one_cycle_value(uint32_t base, uint32_t val)
297 {
298  WR_WORD(COUNTER_ALL_APB_REG_IR_DIN_ONECYCLE_VALUE_A_C0 + base, val);
299 }
300 static INLINE void cnt_config_switch_mode(uint32_t base, uint32_t val)
301 {
302  WR_WORD(COUNTER_ALL_APB_REG_WAVEFORM_MODE_AUTOMATIC_C0 + base, val);
303 }
304 
305 static INLINE uint32_t cnt_get_shiftin_update(uint32_t base)
306 {
307  return RD_WORD(COUNTER_ALL_APB_REG_SHIFTIN_DATABITS_UPDATED_C0 + base);
308 }
309 
310 static INLINE uint32_t cnt_get_shiftin_data(uint32_t base)
311 {
312  return RD_WORD(COUNTER_ALL_APB_REG_SHIFTIN_DATA_C0 + base);
313 }
314 /* shiftout n bits, start from zero*/
315 static INLINE void cnt_set_shiftout_bit_num(uint32_t base, uint32_t n)
316 {
317  WR_WORD(COUNTER_ALL_APB_REG_SHIFTOUT_DATA_CTRL_BITCNTS_C0 + base, n);
318 }
319 static INLINE void cnt_set_shiftout_data(uint32_t base, uint32_t val)
320 {
321  WR_WORD(COUNTER_ALL_APB_REG_SHIFTOUT_DATA_C0 + base, val);
322 }
323 static INLINE void cnt_set_shiftout_data_valid(uint32_t base, uint32_t val)
324 {
325  WR_WORD(COUNTER_ALL_APB_REG_SHIFTOUT_DATA_VALID_C0 + base, val);
326 }
327 
328 static INLINE uint32_t cnt_get_shadow_reg(uint32_t base)
329 {
330  return RD_WORD(COUNTER_ALL_APB_REG_SHADOW_REG_C0 + base);
331 }
332 static INLINE uint32_t cnt_get_capture_reg_a0(uint32_t base)
333 {
334  return RD_WORD(COUNTER_ALL_APB_REG_CAPTURE_REG_A0_C0 + base);
335 }
336 static INLINE uint32_t cnt_get_capture_reg_a1(uint32_t base)
337 {
338  return RD_WORD(COUNTER_ALL_APB_REG_CAPTURE_REG_A1_C0 + base);
339 }
340 static INLINE uint32_t cnt_get_capture_reg_a2(uint32_t base)
341 {
342  return RD_WORD(COUNTER_ALL_APB_REG_CAPTURE_REG_A2_C0 + base);
343 }
344 static INLINE uint32_t cnt_get_capture_reg_b0(uint32_t base)
345 {
346  return RD_WORD(COUNTER_ALL_APB_REG_CAPTURE_REG_B0_C0 + base);
347 }
348 static INLINE uint32_t cnt_get_capture_reg_b1(uint32_t base)
349 {
350  return RD_WORD(COUNTER_ALL_APB_REG_CAPTURE_REG_B1_C0 + base);
351 }
352 static INLINE uint32_t cnt_get_capture_reg_b2(uint32_t base)
353 {
354  return RD_WORD(COUNTER_ALL_APB_REG_CAPTURE_REG_B2_C0 + base);
355 }
356 static INLINE uint32_t cnt_get_capture_status(uint32_t base)
357 {
358  return RD_WORD(COUNTER_ALL_APB_REG_CAPTURE_REG_STATUS_C0 + base);
359 }
360 static INLINE void cnt_set_capture_overflow(uint32_t base, uint32_t val)
361 {
362  WR_WORD(COUNTER_ALL_APB_REG_CAPTURE_REG_OVERFLOW_CTRL_C0 + base, val);
363 }
364 static INLINE uint32_t cnt_get_din_mux()
365 {
366  return RD_WORD(COUNTER_ALL_APB_REG_DIN_MUX_SEL);
367 }
368 static INLINE uint32_t cnt_get_dout_mux()
369 {
370  return RD_WORD(COUNTER_ALL_APB_REG_DOUT_MUX_SEL);
371 }
372 static INLINE void cnt_set_din_mux(uint32_t val)
373 {
374  WR_WORD(COUNTER_ALL_APB_REG_DIN_MUX_SEL, val);
375 }
376 static INLINE void cnt_set_dout_mux(uint32_t val)
377 {
378  WR_WORD(COUNTER_ALL_APB_REG_DOUT_MUX_SEL, val);
379 }
380 static INLINE void cnt_set_dout_enable_ctrl(uint32_t base, uint32_t val)
381 {
382  WR_WORD(COUNTER_ALL_APB_REG_DOUT_ENABLE_CTRL + base, val);
383 }
384 static INLINE uint32_t cnt_get_dout_enable_ctrl(uint32_t base)
385 {
386  return RD_WORD(COUNTER_ALL_APB_REG_DOUT_ENABLE_CTRL + base);
387 }
388 static INLINE void cnt_enable(uint32_t base)
389 {
390  uint32_t reg = RD_WORD(COUNTER_ALL_APB_REG_ENABLE_C0 + base);
391 
392  reg |= CNT_ENABLE;
393  WR_WORD(COUNTER_ALL_APB_REG_ENABLE_C0 + base, reg);
394 }
395 static INLINE void cnt_disable(uint32_t base)
396 {
397  uint32_t reg = RD_WORD(COUNTER_ALL_APB_REG_ENABLE_C0 + base);
398  reg &= ~CNT_ENABLE;
399  WR_WORD(COUNTER_ALL_APB_REG_ENABLE_C0 + base, reg);
400 }
401 static INLINE void cnt_trigger_start(uint32_t base)
402 {
403  //unsigned int reg = RD_WORD(COUNTER_ALL_APB_REG_SINGLE_START_TRIGGER_C0 + base);
404  WR_WORD(COUNTER_ALL_APB_REG_SINGLE_START_TRIGGER_C0 + base, 1);
405  WR_WORD(COUNTER_ALL_APB_REG_SINGLE_START_TRIGGER_C0 + base, 0);
406 }
407 static INLINE void cnt_trigger_stop(uint32_t base)
408 {
409  //unsigned int reg = RD_WORD(COUNTER_ALL_APB_REG_SINGLE_STOP_TRIGGER_C0 + base);
410  WR_WORD(COUNTER_ALL_APB_REG_SINGLE_STOP_TRIGGER_C0 + base, 1);
411  WR_WORD(COUNTER_ALL_APB_REG_SINGLE_STOP_TRIGGER_C0 + base, 0);
412 }
413 static INLINE void cnt_trigger_clear(uint32_t base) // clear to 0x0
414 {
415  //unsigned int reg = RD_WORD(COUNTER_ALL_APB_REG_SINGLE_START_TRIGGER_C0 + base);
416  WR_WORD(COUNTER_ALL_APB_REG_SINGLE_CLEAR_TRIGGER_C0 + base, 1);
417  WR_WORD(COUNTER_ALL_APB_REG_SINGLE_CLEAR_TRIGGER_C0 + base, 0);
418 }
419 static INLINE void cnt_trigger_reset(uint32_t base) // equal to stop + clear
420 {
421  //unsigned int reg = RD_WORD(COUNTER_ALL_APB_REG_SINGLE_STOP_TRIGGER_C0 + base);
422  WR_WORD(COUNTER_ALL_APB_REG_SINGLE_RESET_TRIGGER_C0 + base, 1);
423  WR_WORD(COUNTER_ALL_APB_REG_SINGLE_RESET_TRIGGER_C0 + base, 0);
424 }
425 static INLINE void cnt_set_snap_ctrl(uint32_t base, uint32_t mask)
426 {
427  uint32_t snap = RD_WORD(COUNTER_ALL_APB_REG_CTRL_SNAP_C0 + base);
428  FLIP_BIT(snap, mask);
429  WR_WORD(COUNTER_ALL_APB_REG_CTRL_SNAP_C0 + base, snap);
430 }
431 static INLINE void cnt_reset(int id)
432 {
433  uint32_t reg;
434  reg = RD_WORD(GLOBAL_REG_RESET_CTRL_4);
435  uint32_t mask = 0x1UL << (4 + id);
436  reg &= ~mask;
437  WR_WORD(GLOBAL_REG_RESET_CTRL_4, reg);
438 
439  /* need 2 nop at least. */
440  __NOP();
441  __NOP();
442  __NOP();
443  __NOP();
444  __NOP();
445 
446  WR_WORD(GLOBAL_REG_RESET_CTRL_4, reg | mask);
447 }
448 
449 static INLINE void cnt_reset_pclk(void)
450 {
451  uint32_t reg;
452  reg = RD_WORD(GLOBAL_REG_RESET_CTRL_5);
453 
454  reg &= ~GLOBAL_REG_RESET_CTRL_5_CTL_RESET_5_D0_COUNTER_TOP_PCLK_RSTN_REG;
455  WR_WORD(GLOBAL_REG_RESET_CTRL_4, reg);
456 
457  reg |= GLOBAL_REG_RESET_CTRL_5_CTL_RESET_5_D0_COUNTER_TOP_PCLK_RSTN_REG;
458  WR_WORD(GLOBAL_REG_RESET_CTRL_4, reg);
459 }
460 static INLINE uint32_t cnt_snap_status(uint32_t base)
461 {
462  return RD_WORD(COUNTER_ALL_APB_REG_SNAP_STATUS_C0 + base);
463 }
464 static INLINE uint32_t cnt_intr_status(void)
465 {
466  return RD_WORD(COUNTER_ALL_APB_REG_INTR_STATUS);
467 }
468 static INLINE uint32_t cnt_intr_mask_status(void)
469 {
470  return RD_WORD(COUNTER_ALL_APB_REG_INTR_MASK_STATUS);
471 }
472 static INLINE void cnt_intr_clear(uint32_t val)
473 {
474  WR_WORD(COUNTER_ALL_APB_REG_INTR_CLR, val);
475 }
476 static INLINE void cnt_intr_set(uint32_t val)
477 {
478  WR_WORD(COUNTER_ALL_APB_REG_INTR_SET, val);
479 }
480 static INLINE void cnt_intr_mask_set(uint32_t val)
481 {
482  WR_WORD(COUNTER_ALL_APB_REG_INTR_MASK_SET, val);
483 }
484 static INLINE void cnt_intr_mask_clear(uint32_t val)
485 {
486  WR_WORD(COUNTER_ALL_APB_REG_INTR_MASK_CLR, val);
487 }
488 
489 static INLINE void cnt_intr_sw_reset()
490 {
491  WR_WORD(COUNTER_ALL_APB_REG_INTR_SRESET, 1);
492  WR_WORD(COUNTER_ALL_APB_REG_INTR_SRESET, 0);
493 }
494 static INLINE void cnt_trigger_global_start(void)
495 {
496  WR_WORD(COUNTER_ALL_APB_REG_GLOBAL_START_TRIGGER, 1);
497  WR_WORD(COUNTER_ALL_APB_REG_GLOBAL_START_TRIGGER, 0);
498 }
499 static INLINE void cnt_trigger_global_stop(void)
500 {
501  WR_WORD(COUNTER_ALL_APB_REG_GLOBAL_STOP_TRIGGER, 1);
502  WR_WORD(COUNTER_ALL_APB_REG_GLOBAL_STOP_TRIGGER, 0);
503 }
504 static INLINE void cnt_trigger_global_clear(void) // clear to 0x0
505 {
506  WR_WORD(COUNTER_ALL_APB_REG_GLOBAL_CLEAR_TRIGGER, 1);
507  WR_WORD(COUNTER_ALL_APB_REG_GLOBAL_CLEAR_TRIGGER, 0);
508 }
509 static INLINE void cnt_trigger_global_reset(void) // equal to stop + clear
510 {
511  WR_WORD(COUNTER_ALL_APB_REG_GLOBAL_RESET_TRIGGER, 1);
512  WR_WORD(COUNTER_ALL_APB_REG_GLOBAL_RESET_TRIGGER, 0);
513 }
514 void cnt_resume(cnt_dev_t *pd);
515 
522 cnt_dev_t* hal_cnt_open(int id, cnt_init_t *init);
523 
528 void hal_cnt_close(cnt_dev_t* dev);
529 
536 int hal_cnt_sync(cnt_dev_t* dev, uint32_t mask);
537 
543 int hal_cnt_intr_mask(cnt_dev_t* dev);
544 
550 int hal_cnt_intr_unmask(cnt_dev_t* dev);
551 
559 int hal_cnt_pin_mux_en(int port, int pin, int en);
560 
568 int hal_cnt_internal_din_pinmux(int inner_pin, int ext_port, int ext_pin);
569 
577 int hal_cnt_internal_dout_pinmux(int inner_pin, int ext_port, int ext_pin);
578 
584 int hal_cnt_enable(cnt_dev_t* dev);
585 
591 int hal_cnt_disable(cnt_dev_t* dev);
592 
598 uint32_t hal_cnt_get_clk(cnt_dev_t* dev);
599 
606 int hal_cnt_pin_chk(int port, int pin);
607 
615 void hal_cnt_set_handler(cnt_dev_t* dev, CNT_ISR_FUN fun, void* arg);
617 
618 
619 #endif
int hal_cnt_pin_chk(int port, int pin)
Check counter pinmux.
int hal_cnt_enable(cnt_dev_t *dev)
Enable counter.
int hal_cnt_internal_dout_pinmux(int inner_pin, int ext_port, int ext_pin)
Set dout pin mux.
int hal_cnt_sync(cnt_dev_t *dev, uint32_t mask)
Synchronize status registers manually. Will block until register finish update.
uint32_t hal_cnt_get_clk(cnt_dev_t *dev)
Get counter clock frequency.
cnt_int_pin
Counter internal pin.
Definition: hal_counter.h:170
void hal_cnt_close(cnt_dev_t *dev)
Close counter device.
int hal_cnt_intr_unmask(cnt_dev_t *dev)
Set interrupt unmask.
int hal_cnt_intr_mask(cnt_dev_t *dev)
Set interrupt mask.
cnt_dev_t * hal_cnt_open(int id, cnt_init_t *init)
Open counter device.
int hal_cnt_pin_mux_en(int port, int pin, int en)
Set pin mux.
int hal_cnt_internal_din_pinmux(int inner_pin, int ext_port, int ext_pin)
Set din pin mux.
int hal_cnt_disable(cnt_dev_t *dev)
Disable counter.
void hal_cnt_set_handler(cnt_dev_t *dev, CNT_ISR_FUN fun, void *arg)
Set ISR handler.