nu_etimer.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /**************************************************************************//**
  2. * @file etimer.h
  3. * @brief N9H30 series ETIMER driver header file
  4. *
  5. * @note
  6. * SPDX-License-Identifier: Apache-2.0
  7. * Copyright (C) 2018 Nuvoton Technology Corp. All rights reserved.
  8. *****************************************************************************/
  9. #ifndef __NU_ETIMER_H__
  10. #define __NU_ETIMER_H__
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. #include "N9H30.h"
  16. /** @addtogroup N9H30_Device_Driver N9H30 Device Driver
  17. @{
  18. */
  19. /** @addtogroup N9H30_ETIMER_Driver ETIMER Driver
  20. @{
  21. */
  22. /** @addtogroup N9H30_ETIMER_EXPORTED_CONSTANTS ETIMER Exported Constants
  23. @{
  24. */
  25. #define ETIMER_ONESHOT_MODE (0UL) /*!< Timer working in one shot mode */
  26. #define ETIMER_PERIODIC_MODE (1UL << 4) /*!< Timer working in periodic mode */
  27. #define ETIMER_TOGGLE_MODE (2UL << 4) /*!< Timer working in toggle mode */
  28. #define ETIMER_CONTINUOUS_MODE (3UL << 4) /*!< Timer working in continuous mode */
  29. #define ETIMER_CAPTURE_FREE_COUNTING_MODE (0UL) /*!< Free counting mode */
  30. #define ETIMER_CAPTURE_TRIGGER_COUNTING_MODE (1UL << 20) /*!< Trigger counting mode */
  31. #define ETIMER_CAPTURE_COUNTER_RESET_MODE (1UL << 17) /*!< Counter reset mode */
  32. #define ETIMER_CAPTURE_FALLING_EDGE (0UL) /*!< Falling edge trigger timer capture */
  33. #define ETIMER_CAPTURE_RISING_EDGE (1UL << 18) /*!< Rising edge trigger timer capture */
  34. #define ETIMER_CAPTURE_FALLING_THEN_RISING_EDGE (2UL << 18) /*!< Falling edge then rising edge trigger timer capture */
  35. #define ETIMER_CAPTURE_RISING_THEN_FALLING_EDGE (3UL << 18) /*!< Rising edge then falling edge trigger timer capture */
  36. #define ETIMER_TIMEOUT_TRIGGER (0UL) /*!< Timer timeout trigger other modules */
  37. #define ETIMER_CAPTURE_TRIGGER (1UL << 11) /*!< Timer capture trigger other modules */
  38. #define ETIMER_COUNTER_RISING_EDGE (1UL << 13) /*!< Counter increase on rising edge */
  39. #define ETIMER_COUNTER_FALLING_EDGE (0UL) /*!< Counter increase on falling edge */
  40. /*@}*/ /* end of group ETIMER_EXPORTED_CONSTANTS */
  41. /** @addtogroup N9H30_ETIMER_EXPORTED_FUNCTIONS ETIMER Exported Functions
  42. @{
  43. */
  44. /**
  45. * @brief This macro is used to set new Timer compared value
  46. * @param[in] timer ETIMER number. Range from 0 ~ 3
  47. * @param[in] u32Value Timer compare value. Valid values are between 2 to 0xFFFFFF
  48. * @return None
  49. * \hideinitializer
  50. */
  51. #define ETIMER_SET_CMP_VALUE(timer, u32Value) \
  52. do{\
  53. if((timer) == 0) {\
  54. outpw(REG_ETMR0_CMPR, u32Value);\
  55. } else if((timer) == 1) {\
  56. outpw(REG_ETMR1_CMPR, u32Value);\
  57. } else if((timer) == 2) {\
  58. outpw(REG_ETMR2_CMPR, u32Value);\
  59. } else {\
  60. outpw(REG_ETMR3_CMPR, u32Value);\
  61. }\
  62. }while(0)
  63. /**
  64. * @brief This macro is used to set new Timer prescale value
  65. * @param[in] timer ETIMER number. Range from 0 ~ 3
  66. * @param[in] u32Value Timer prescale value. Valid values are between 0 to 0xFF
  67. * @return None
  68. * @note Clock input is divided by (prescale + 1) before it is fed into timer
  69. * \hideinitializer
  70. */
  71. #define ETIMER_SET_PRESCALE_VALUE(timer, u32Value) \
  72. do{\
  73. if((timer) == 0) {\
  74. outpw(REG_ETMR0_PRECNT, u32Value);\
  75. } else if((timer) == 1) {\
  76. outpw(REG_ETMR1_PRECNT, u32Value);\
  77. } else if((timer) == 2) {\
  78. outpw(REG_ETMR2_PRECNT, u32Value);\
  79. } else {\
  80. outpw(REG_ETMR3_PRECNT, u32Value);\
  81. }\
  82. }while(0)
  83. /**
  84. * @brief Select Timer operating mode
  85. *
  86. * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
  87. * @param[in] u32OpMode Operation mode. Possible options are
  88. * - \ref ETIMER_ONESHOT_MODE
  89. * - \ref ETIMER_PERIODIC_MODE
  90. * - \ref ETIMER_TOGGLE_MODE
  91. * - \ref ETIMER_CONTINUOUS_MODE
  92. *
  93. * @return None
  94. * \hideinitializer
  95. */
  96. #define ETIMER_SET_OPMODE(timer, u32OpMode) \
  97. do{\
  98. if((timer) == 0) {\
  99. outpw(REG_ETMR0_CTL, (inpw(REG_ETMR0_CTL)&~0x30) | u32OpMode);\
  100. } else if((timer) == 1) {\
  101. outpw(REG_ETMR1_CTL, (inpw(REG_ETMR1_CTL)&~0x30) | u32OpMode);\
  102. } else if((timer) == 2) {\
  103. outpw(REG_ETMR2_CTL, (inpw(REG_ETMR2_CTL)&~0x30) | u32OpMode);\
  104. } else {\
  105. outpw(REG_ETMR3_CTL, (inpw(REG_ETMR3_CTL)&~0x30) | u32OpMode);\
  106. }\
  107. }while(0)
  108. /*
  109. * @brief This macro is used to check if specify Timer is inactive or active
  110. * @param[in] timer ETIMER number. Range from 0 ~ 3
  111. * @return timer is activate or inactivate
  112. * @retval 0 Timer 24-bit up counter is inactive
  113. * @retval 1 Timer 24-bit up counter is active
  114. * \hideinitializer
  115. */
  116. static __inline int ETIMER_Is_Active(UINT timer)
  117. {
  118. int reg;
  119. if (timer == 0)
  120. {
  121. reg = inpw(REG_ETMR0_CTL);
  122. }
  123. else if (timer == 1)
  124. {
  125. reg = inpw(REG_ETMR1_CTL);
  126. }
  127. else if (timer == 2)
  128. {
  129. reg = inpw(REG_ETMR2_CTL);
  130. }
  131. else
  132. {
  133. reg = inpw(REG_ETMR3_CTL);
  134. }
  135. return reg & 0x80 ? 1 : 0;
  136. }
  137. /**
  138. * @brief This function is used to start Timer counting
  139. * @param[in] timer ETIMER number. Range from 0 ~ 3
  140. * @return None
  141. */
  142. static __inline void ETIMER_Start(UINT timer)
  143. {
  144. if (timer == 0)
  145. {
  146. outpw(REG_ETMR0_CTL, inpw(REG_ETMR0_CTL) | 1);
  147. }
  148. else if (timer == 1)
  149. {
  150. outpw(REG_ETMR1_CTL, inpw(REG_ETMR1_CTL) | 1);
  151. }
  152. else if (timer == 2)
  153. {
  154. outpw(REG_ETMR2_CTL, inpw(REG_ETMR2_CTL) | 1);
  155. }
  156. else
  157. {
  158. outpw(REG_ETMR3_CTL, inpw(REG_ETMR3_CTL) | 1);
  159. }
  160. }
  161. /**
  162. * @brief This function is used to stop Timer counting
  163. * @param[in] timer ETIMER number. Range from 0 ~ 3
  164. * @return None
  165. */
  166. static __inline void ETIMER_Stop(UINT timer)
  167. {
  168. if (timer == 0)
  169. {
  170. outpw(REG_ETMR0_CTL, inpw(REG_ETMR0_CTL) & ~1);
  171. }
  172. else if (timer == 1)
  173. {
  174. outpw(REG_ETMR1_CTL, inpw(REG_ETMR1_CTL) & ~1);
  175. }
  176. else if (timer == 2)
  177. {
  178. outpw(REG_ETMR2_CTL, inpw(REG_ETMR2_CTL) & ~1);
  179. }
  180. else
  181. {
  182. outpw(REG_ETMR3_CTL, inpw(REG_ETMR3_CTL) & ~1);
  183. }
  184. }
  185. /**
  186. * @brief This function is used to enable the Timer wake-up function
  187. * @param[in] timer ETIMER number. Range from 0 ~ 3
  188. * @return None
  189. * @note To wake the system from power down mode, timer clock source must be ether LXT or LIRC
  190. */
  191. static __inline void ETIMER_EnableWakeup(UINT timer)
  192. {
  193. if (timer == 0)
  194. {
  195. outpw(REG_ETMR0_CTL, inpw(REG_ETMR0_CTL) | 4);
  196. }
  197. else if (timer == 1)
  198. {
  199. outpw(REG_ETMR1_CTL, inpw(REG_ETMR1_CTL) | 4);
  200. }
  201. else if (timer == 2)
  202. {
  203. outpw(REG_ETMR2_CTL, inpw(REG_ETMR2_CTL) | 4);
  204. }
  205. else
  206. {
  207. outpw(REG_ETMR3_CTL, inpw(REG_ETMR3_CTL) | 4);
  208. }
  209. }
  210. /**
  211. * @brief This function is used to disable the Timer wake-up function
  212. * @param[in] timer ETIMER number. Range from 0 ~ 3
  213. * @return None
  214. */
  215. static __inline void ETIMER_DisableWakeup(UINT timer)
  216. {
  217. if (timer == 0)
  218. {
  219. outpw(REG_ETMR0_CTL, inpw(REG_ETMR0_CTL) & ~4);
  220. }
  221. else if (timer == 1)
  222. {
  223. outpw(REG_ETMR1_CTL, inpw(REG_ETMR1_CTL) & ~4);
  224. }
  225. else if (timer == 2)
  226. {
  227. outpw(REG_ETMR2_CTL, inpw(REG_ETMR2_CTL) & ~4);
  228. }
  229. else
  230. {
  231. outpw(REG_ETMR3_CTL, inpw(REG_ETMR3_CTL) & ~4);
  232. }
  233. }
  234. /**
  235. * @brief This function is used to enable the capture pin detection de-bounce function.
  236. * @param[in] timer ETIMER number. Range from 0 ~ 3
  237. * @return None
  238. */
  239. static __inline void ETIMER_EnableCaptureDebounce(UINT timer)
  240. {
  241. if (timer == 0)
  242. {
  243. outpw(REG_ETMR0_CTL, inpw(REG_ETMR0_CTL) | 0x400000);
  244. }
  245. else if (timer == 1)
  246. {
  247. outpw(REG_ETMR1_CTL, inpw(REG_ETMR1_CTL) | 0x400000);
  248. }
  249. else if (timer == 2)
  250. {
  251. outpw(REG_ETMR2_CTL, inpw(REG_ETMR2_CTL) | 0x400000);
  252. }
  253. else
  254. {
  255. outpw(REG_ETMR3_CTL, inpw(REG_ETMR3_CTL) | 0x400000);
  256. }
  257. }
  258. /**
  259. * @brief This function is used to disable the capture pin detection de-bounce function.
  260. * @param[in] timer ETIMER number. Range from 0 ~ 3
  261. * @return None
  262. */
  263. static __inline void ETIMER_DisableCaptureDebounce(UINT timer)
  264. {
  265. if (timer == 0)
  266. {
  267. outpw(REG_ETMR0_CTL, inpw(REG_ETMR0_CTL) & ~0x400000);
  268. }
  269. else if (timer == 1)
  270. {
  271. outpw(REG_ETMR1_CTL, inpw(REG_ETMR1_CTL) & ~0x400000);
  272. }
  273. else if (timer == 2)
  274. {
  275. outpw(REG_ETMR2_CTL, inpw(REG_ETMR2_CTL) & ~0x400000);
  276. }
  277. else
  278. {
  279. outpw(REG_ETMR3_CTL, inpw(REG_ETMR3_CTL) & ~0x400000);
  280. }
  281. }
  282. /**
  283. * @brief This function is used to enable the Timer time-out interrupt function.
  284. * @param[in] timer ETIMER number. Range from 0 ~ 3
  285. * @return None
  286. */
  287. static __inline void ETIMER_EnableInt(UINT timer)
  288. {
  289. if (timer == 0)
  290. {
  291. outpw(REG_ETMR0_IER, inpw(REG_ETMR0_IER) | 1);
  292. }
  293. else if (timer == 1)
  294. {
  295. outpw(REG_ETMR1_IER, inpw(REG_ETMR1_IER) | 1);
  296. }
  297. else if (timer == 2)
  298. {
  299. outpw(REG_ETMR2_IER, inpw(REG_ETMR2_IER) | 1);
  300. }
  301. else
  302. {
  303. outpw(REG_ETMR3_IER, inpw(REG_ETMR3_IER) | 1);
  304. }
  305. }
  306. /**
  307. * @brief This function is used to disable the Timer time-out interrupt function.
  308. * @param[in] timer ETIMER number. Range from 0 ~ 3
  309. * @return None
  310. */
  311. static __inline void ETIMER_DisableInt(UINT timer)
  312. {
  313. if (timer == 0)
  314. {
  315. outpw(REG_ETMR0_IER, inpw(REG_ETMR0_IER) & ~1);
  316. }
  317. else if (timer == 1)
  318. {
  319. outpw(REG_ETMR1_IER, inpw(REG_ETMR1_IER) & ~1);
  320. }
  321. else if (timer == 2)
  322. {
  323. outpw(REG_ETMR2_IER, inpw(REG_ETMR2_IER) & ~1);
  324. }
  325. else
  326. {
  327. outpw(REG_ETMR3_IER, inpw(REG_ETMR3_IER) & ~1);
  328. }
  329. }
  330. /**
  331. * @brief This function is used to enable the Timer capture trigger interrupt function.
  332. * @param[in] timer ETIMER number. Range from 0 ~ 3
  333. * @return None
  334. */
  335. static __inline void ETIMER_EnableCaptureInt(UINT timer)
  336. {
  337. if (timer == 0)
  338. {
  339. outpw(REG_ETMR0_IER, inpw(REG_ETMR0_IER) | 2);
  340. }
  341. else if (timer == 1)
  342. {
  343. outpw(REG_ETMR1_IER, inpw(REG_ETMR1_IER) | 2);
  344. }
  345. else if (timer == 2)
  346. {
  347. outpw(REG_ETMR2_IER, inpw(REG_ETMR2_IER) | 2);
  348. }
  349. else
  350. {
  351. outpw(REG_ETMR3_IER, inpw(REG_ETMR3_IER) | 2);
  352. }
  353. }
  354. /**
  355. * @brief This function is used to disable the Timer capture trigger interrupt function.
  356. * @param[in] timer ETIMER number. Range from 0 ~ 3
  357. * @return None
  358. */
  359. static __inline void ETIMER_DisableCaptureInt(UINT timer)
  360. {
  361. if (timer == 0)
  362. {
  363. outpw(REG_ETMR0_IER, inpw(REG_ETMR0_IER) & ~2);
  364. }
  365. else if (timer == 1)
  366. {
  367. outpw(REG_ETMR1_IER, inpw(REG_ETMR1_IER) & ~2);
  368. }
  369. else if (timer == 2)
  370. {
  371. outpw(REG_ETMR2_IER, inpw(REG_ETMR2_IER) & ~2);
  372. }
  373. else
  374. {
  375. outpw(REG_ETMR3_IER, inpw(REG_ETMR3_IER) & ~2);
  376. }
  377. }
  378. /**
  379. * @brief This function indicates Timer time-out interrupt occurred or not.
  380. * @param[in] timer ETIMER number. Range from 0 ~ 3
  381. * @return Timer time-out interrupt occurred or not
  382. * @retval 0 Timer time-out interrupt did not occur
  383. * @retval 1 Timer time-out interrupt occurred
  384. */
  385. static __inline UINT ETIMER_GetIntFlag(UINT timer)
  386. {
  387. int reg;
  388. if (timer == 0)
  389. {
  390. reg = inpw(REG_ETMR0_ISR);
  391. }
  392. else if (timer == 1)
  393. {
  394. reg = inpw(REG_ETMR1_ISR);
  395. }
  396. else if (timer == 2)
  397. {
  398. reg = inpw(REG_ETMR2_ISR);
  399. }
  400. else
  401. {
  402. reg = inpw(REG_ETMR3_ISR);
  403. }
  404. return reg & 1;
  405. }
  406. /**
  407. * @brief This function clears the Timer time-out interrupt flag.
  408. * @param[in] timer ETIMER number. Range from 0 ~ 3
  409. * @return None
  410. */
  411. static __inline void ETIMER_ClearIntFlag(UINT timer)
  412. {
  413. if (timer == 0)
  414. {
  415. outpw(REG_ETMR0_ISR, 1);
  416. }
  417. else if (timer == 1)
  418. {
  419. outpw(REG_ETMR1_ISR, 1);
  420. }
  421. else if (timer == 2)
  422. {
  423. outpw(REG_ETMR2_ISR, 1);
  424. }
  425. else
  426. {
  427. outpw(REG_ETMR3_ISR, 1);
  428. }
  429. }
  430. /**
  431. * @brief This function indicates Timer capture interrupt occurred or not.
  432. * @param[in] timer ETIMER number. Range from 0 ~ 3
  433. * @return Timer capture interrupt occurred or not
  434. * @retval 0 Timer capture interrupt did not occur
  435. * @retval 1 Timer capture interrupt occurred
  436. */
  437. static __inline UINT ETIMER_GetCaptureIntFlag(UINT timer)
  438. {
  439. int reg;
  440. if (timer == 0)
  441. {
  442. reg = inpw(REG_ETMR0_ISR);
  443. }
  444. else if (timer == 1)
  445. {
  446. reg = inpw(REG_ETMR1_ISR);
  447. }
  448. else if (timer == 2)
  449. {
  450. reg = inpw(REG_ETMR2_ISR);
  451. }
  452. else
  453. {
  454. reg = inpw(REG_ETMR3_ISR);
  455. }
  456. return (reg & 2) >> 1;
  457. }
  458. /**
  459. * @brief This function clears the Timer capture interrupt flag.
  460. * @param[in] timer ETIMER number. Range from 0 ~ 3
  461. * @return None
  462. */
  463. static __inline void ETIMER_ClearCaptureIntFlag(UINT timer)
  464. {
  465. if (timer == 0)
  466. {
  467. outpw(REG_ETMR0_ISR, 2);
  468. }
  469. else if (timer == 1)
  470. {
  471. outpw(REG_ETMR1_ISR, 2);
  472. }
  473. else if (timer == 2)
  474. {
  475. outpw(REG_ETMR2_ISR, 2);
  476. }
  477. else
  478. {
  479. outpw(REG_ETMR3_ISR, 2);
  480. }
  481. }
  482. /**
  483. * @brief This function gets the Timer capture falling edge flag.
  484. * @param[in] timer ETIMER number. Range from 0 ~ 5
  485. * @return None
  486. */
  487. static __inline UINT8 ETIMER_GetCaptureFallingEdgeFlag(UINT timer)
  488. {
  489. UINT ret;
  490. if (timer == 0)
  491. {
  492. ret = inpw(REG_ETMR0_ISR);
  493. }
  494. else if (timer == 1)
  495. {
  496. ret = inpw(REG_ETMR1_ISR);
  497. }
  498. else if (timer == 2)
  499. {
  500. ret = inpw(REG_ETMR2_ISR);
  501. }
  502. else
  503. {
  504. ret = inpw(REG_ETMR3_ISR);
  505. }
  506. return (ret & (1 << 6)) >> 6;
  507. }
  508. /*
  509. * @brief This function indicates Timer has waked up system or not.
  510. * @param[in] timer ETIMER number. Range from 0 ~ 3
  511. * @return Timer has waked up system or not
  512. * @retval 0 Timer did not wake up system
  513. * @retval 1 Timer wake up system
  514. */
  515. static __inline UINT ETIMER_GetWakeupFlag(UINT timer)
  516. {
  517. int reg;
  518. if (timer == 0)
  519. {
  520. reg = inpw(REG_ETMR0_ISR);
  521. }
  522. else if (timer == 1)
  523. {
  524. reg = inpw(REG_ETMR1_ISR);
  525. }
  526. else if (timer == 2)
  527. {
  528. reg = inpw(REG_ETMR2_ISR);
  529. }
  530. else
  531. {
  532. reg = inpw(REG_ETMR3_ISR);
  533. }
  534. return (reg & 0x10) >> 4;
  535. }
  536. /**
  537. * @brief This function clears the Timer wakeup interrupt flag.
  538. * @param[in] timer ETIMER number. Range from 0 ~ 3
  539. * @return None
  540. */
  541. static __inline void ETIMER_ClearWakeupFlag(UINT timer)
  542. {
  543. if (timer == 0)
  544. {
  545. outpw(REG_ETMR0_ISR, 0x10);
  546. }
  547. else if (timer == 1)
  548. {
  549. outpw(REG_ETMR1_ISR, 0x10);
  550. }
  551. else if (timer == 2)
  552. {
  553. outpw(REG_ETMR2_ISR, 0x10);
  554. }
  555. else
  556. {
  557. outpw(REG_ETMR3_ISR, 0x10);
  558. }
  559. }
  560. /**
  561. * @brief This function gets the Timer compare value.
  562. * @param[in] timer ETIMER number. Range from 0 ~ 5
  563. * @return Timer compare data value
  564. */
  565. static __inline UINT ETIMER_GetCompareData(UINT timer)
  566. {
  567. if (timer == 0)
  568. {
  569. return inpw(REG_ETMR0_CMPR);
  570. }
  571. else if (timer == 1)
  572. {
  573. return inpw(REG_ETMR1_CMPR);
  574. }
  575. else if (timer == 2)
  576. {
  577. return inpw(REG_ETMR2_CMPR);
  578. }
  579. else
  580. {
  581. return inpw(REG_ETMR3_CMPR);
  582. }
  583. }
  584. /**
  585. * @brief This function gets the Timer capture data.
  586. * @param[in] timer ETIMER number. Range from 0 ~ 3
  587. * @return Timer capture data value
  588. */
  589. static __inline UINT ETIMER_GetCaptureData(UINT timer)
  590. {
  591. if (timer == 0)
  592. {
  593. return inpw(REG_ETMR0_TCAP);
  594. }
  595. else if (timer == 1)
  596. {
  597. return inpw(REG_ETMR1_TCAP);
  598. }
  599. else if (timer == 2)
  600. {
  601. return inpw(REG_ETMR2_TCAP);
  602. }
  603. else
  604. {
  605. return inpw(REG_ETMR3_TCAP);
  606. }
  607. }
  608. /**
  609. * @brief This function reports the current timer counter value.
  610. * @param[in] timer ETIMER number. Range from 0 ~ 3
  611. * @return Timer counter value
  612. */
  613. static __inline UINT ETIMER_GetCounter(UINT timer)
  614. {
  615. if (timer == 0)
  616. {
  617. return inpw(REG_ETMR0_DR);
  618. }
  619. else if (timer == 1)
  620. {
  621. return inpw(REG_ETMR1_DR);
  622. }
  623. else if (timer == 2)
  624. {
  625. return inpw(REG_ETMR2_DR);
  626. }
  627. else
  628. {
  629. return inpw(REG_ETMR3_DR);
  630. }
  631. }
  632. static __inline UINT ETIMER_ClearCounter(UINT timer)
  633. {
  634. if (timer == 0)
  635. {
  636. return outpw(REG_ETMR0_DR, 0);
  637. }
  638. else if (timer == 1)
  639. {
  640. return outpw(REG_ETMR1_DR, 0);
  641. }
  642. else if (timer == 2)
  643. {
  644. return outpw(REG_ETMR2_DR, 0);
  645. }
  646. else
  647. {
  648. return outpw(REG_ETMR3_DR, 0);
  649. }
  650. }
  651. UINT ETIMER_Open(UINT timer, UINT u32Mode, UINT u32Freq);
  652. void ETIMER_Close(UINT timer);
  653. void ETIMER_Delay(UINT timer, UINT u32Usec);
  654. void ETIMER_EnableCapture(UINT timer, UINT u32CapMode, UINT u32Edge);
  655. void ETIMER_DisableCapture(UINT timer);
  656. UINT ETIMER_GetModuleClock(UINT timer);
  657. /*@}*/ /* end of group N9H30_ETIMER_EXPORTED_FUNCTIONS */
  658. /*@}*/ /* end of group N9H30_ETIMER_Driver */
  659. /*@}*/ /* end of group N9H30_Device_Driver */
  660. #ifdef __cplusplus
  661. }
  662. #endif
  663. #endif //__NU_ETIMER_H__
  664. /*** (C) COPYRIGHT 2018 Nuvoton Technology Corp. ***/