gd32f3x0_timer.h 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. /*!
  2. \file gd32f3x0_timer.h
  3. \brief definitions for the TIMER
  4. */
  5. /*
  6. Copyright (C) 2017 GigaDevice
  7. 2017-06-06, V1.0.0, firmware for GD32F3x0
  8. */
  9. #ifndef GD32F3X0_TIMER_H
  10. #define GD32F3X0_TIMER_H
  11. #include "gd32f3x0.h"
  12. /* TIMERx(x=0,1,2,5,13..16) definitions */
  13. #define TIMER0 (TIMER_BASE + 0x00012C00U)
  14. #define TIMER1 (TIMER_BASE + 0x00000000U)
  15. #define TIMER2 (TIMER_BASE + 0x00000400U)
  16. #ifdef GD32F350
  17. #define TIMER5 (TIMER_BASE + 0x00001000U)
  18. #endif
  19. #define TIMER13 (TIMER_BASE + 0x00002000U)
  20. #define TIMER14 (TIMER_BASE + 0x00014000U)
  21. #define TIMER15 (TIMER_BASE + 0x00014400U)
  22. #define TIMER16 (TIMER_BASE + 0x00014800U)
  23. /* registers definitions */
  24. #define TIMER_CTL0(timerx) REG32((timerx) + 0x00U) /*!< TIMER control register 0 */
  25. #define TIMER_CTL1(timerx) REG32((timerx) + 0x04U) /*!< TIMER control register 1 */
  26. #define TIMER_SMCFG(timerx) REG32((timerx) + 0x08U) /*!< TIMER slave mode configuration register */
  27. #define TIMER_DMAINTEN(timerx) REG32((timerx) + 0x0CU) /*!< TIMER DMA and interrupt enable register */
  28. #define TIMER_INTF(timerx) REG32((timerx) + 0x10U) /*!< TIMER interrupt flag register */
  29. #define TIMER_SWEVG(timerx) REG32((timerx) + 0x14U) /*!< TIMER software event generation register */
  30. #define TIMER_CHCTL0(timerx) REG32((timerx) + 0x18U) /*!< TIMER channel control register 0 */
  31. #define TIMER_CHCTL1(timerx) REG32((timerx) + 0x1CU) /*!< TIMER channel control register 1 */
  32. #define TIMER_CHCTL2(timerx) REG32((timerx) + 0x20U) /*!< TIMER channel control register 2 */
  33. #define TIMER_CNT(timerx) REG32((timerx) + 0x24U) /*!< TIMER counter register */
  34. #define TIMER_PSC(timerx) REG32((timerx) + 0x28U) /*!< TIMER prescaler register */
  35. #define TIMER_CAR(timerx) REG32((timerx) + 0x2CU) /*!< TIMER counter auto reload register */
  36. #define TIMER_CREP(timerx) REG32((timerx) + 0x30U) /*!< TIMER counter repetition register */
  37. #define TIMER_CH0CV(timerx) REG32((timerx) + 0x34U) /*!< TIMER channel 0 capture/compare value register */
  38. #define TIMER_CH1CV(timerx) REG32((timerx) + 0x38U) /*!< TIMER channel 1 capture/compare value register */
  39. #define TIMER_CH2CV(timerx) REG32((timerx) + 0x3CU) /*!< TIMER channel 2 capture/compare value register */
  40. #define TIMER_CH3CV(timerx) REG32((timerx) + 0x40U) /*!< TIMER channel 3 capture/compare value register */
  41. #define TIMER_CCHP(timerx) REG32((timerx) + 0x44U) /*!< TIMER complementary channel protection register */
  42. #define TIMER_DMACFG(timerx) REG32((timerx) + 0x48U) /*!< TIMER DMA configuration register */
  43. #define TIMER_DMATB(timerx) REG32((timerx) + 0x4CU) /*!< TIMER DMA transfer buffer register */
  44. #define TIMER_IRMP(timerx) REG32((timerx) + 0x50U) /*!< TIMER channel input remap register */
  45. #define TIMER_CFG(timerx) REG32((timerx) + 0xFCU) /*!< TIMER configuration register */
  46. /* bits definitions */
  47. /* TIMER_CTL0 */
  48. #define TIMER_CTL0_CEN BIT(0) /*!< TIMER counter enable */
  49. #define TIMER_CTL0_UPDIS BIT(1) /*!< update disable */
  50. #define TIMER_CTL0_UPS BIT(2) /*!< update source */
  51. #define TIMER_CTL0_SPM BIT(3) /*!< single pulse mode */
  52. #define TIMER_CTL0_DIR BIT(4) /*!< timer counter direction */
  53. #define TIMER_CTL0_CAM BITS(5,6) /*!< center-aligned mode selection */
  54. #define TIMER_CTL0_ARSE BIT(7) /*!< auto-reload shadow enable */
  55. #define TIMER_CTL0_CKDIV BITS(8,9) /*!< clock division */
  56. /* TIMER_CTL1 */
  57. #define TIMER_CTL1_CCSE BIT(0) /*!< commutation control shadow enable */
  58. #define TIMER_CTL1_CCUC BIT(2) /*!< commutation control shadow register update control */
  59. #define TIMER_CTL1_DMAS BIT(3) /*!< DMA request source selection */
  60. #define TIMER_CTL1_MMC BITS(4,6) /*!< master mode control */
  61. #define TIMER_CTL1_TI0S BIT(7) /*!< channel 0 trigger input selection(hall mode selection) */
  62. #define TIMER_CTL1_ISO0 BIT(8) /*!< idle state of channel 0 output */
  63. #define TIMER_CTL1_ISO0N BIT(9) /*!< idle state of channel 0 complementary output */
  64. #define TIMER_CTL1_ISO1 BIT(10) /*!< idle state of channel 1 output */
  65. #define TIMER_CTL1_ISO1N BIT(11) /*!< idle state of channel 1 complementary output */
  66. #define TIMER_CTL1_ISO2 BIT(12) /*!< idle state of channel 2 output */
  67. #define TIMER_CTL1_ISO2N BIT(13) /*!< idle state of channel 2 complementary output */
  68. #define TIMER_CTL1_ISO3 BIT(14) /*!< idle state of channel 3 output */
  69. /* TIMER_SMCFG */
  70. #define TIMER_SMCFG_SMC BITS(0,2) /*!< slave mode control */
  71. #define TIMER_SMCFG_OCRC BIT(3) /*!< OCPRE clear source selection */
  72. #define TIMER_SMCFG_TRGS BITS(4,6) /*!< trigger selection */
  73. #define TIMER_SMCFG_MSM BIT(7) /*!< master-slave mode */
  74. #define TIMER_SMCFG_ETFC BITS(8,11) /*!< external trigger filter control */
  75. #define TIMER_SMCFG_ETPSC BITS(12,13) /*!< external trigger prescaler */
  76. #define TIMER_SMCFG_SMC1 BIT(14) /*!< part of SMC for enable external clock mode 1 */
  77. #define TIMER_SMCFG_ETP BIT(15) /*!< external trigger polarity */
  78. /* TIMER_DMAINTEN */
  79. #define TIMER_DMAINTEN_UPIE BIT(0) /*!< update interrupt enable */
  80. #define TIMER_DMAINTEN_CH0IE BIT(1) /*!< channel 0 interrupt enable */
  81. #define TIMER_DMAINTEN_CH1IE BIT(2) /*!< channel 1 interrupt enable */
  82. #define TIMER_DMAINTEN_CH2IE BIT(3) /*!< channel 2 interrupt enable */
  83. #define TIMER_DMAINTEN_CH3IE BIT(4) /*!< channel 3 interrupt enable */
  84. #define TIMER_DMAINTEN_CMTIE BIT(5) /*!< commutation DMA request enable */
  85. #define TIMER_DMAINTEN_TRGIE BIT(6) /*!< trigger interrupt enable */
  86. #define TIMER_DMAINTEN_BRKIE BIT(7) /*!< break interrupt enable */
  87. #define TIMER_DMAINTEN_UPDEN BIT(8) /*!< update DMA request enable */
  88. #define TIMER_DMAINTEN_CH0DEN BIT(9) /*!< channel 0 DMA request enable */
  89. #define TIMER_DMAINTEN_CH1DEN BIT(10) /*!< channel 1 DMA request enable */
  90. #define TIMER_DMAINTEN_CH2DEN BIT(11) /*!< channel 2 DMA request enable */
  91. #define TIMER_DMAINTEN_CH3DEN BIT(12) /*!< channel 3 DMA request enable */
  92. #define TIMER_DMAINTEN_CMTDEN BIT(13) /*!< channel control update DMA request enable */
  93. #define TIMER_DMAINTEN_TRGDEN BIT(14) /*!< trigger DMA request enable */
  94. /* TIMER_INTF */
  95. #define TIMER_INTF_UPIF BIT(0) /*!< update interrupt flag */
  96. #define TIMER_INTF_CH0IF BIT(1) /*!< channel 0 interrupt flag */
  97. #define TIMER_INTF_CH1IF BIT(2) /*!< channel 1 interrupt flag */
  98. #define TIMER_INTF_CH2IF BIT(3) /*!< channel 2 interrupt flag */
  99. #define TIMER_INTF_CH3IF BIT(4) /*!< channel 3 interrupt flag */
  100. #define TIMER_INTF_CMTIF BIT(5) /*!< channel commutation interrupt flag */
  101. #define TIMER_INTF_TRGIF BIT(6) /*!< trigger interrupt flag */
  102. #define TIMER_INTF_BRKIF BIT(7) /*!< break interrupt flag */
  103. #define TIMER_INTF_CH0OF BIT(9) /*!< channel 0 overcapture flag */
  104. #define TIMER_INTF_CH1OF BIT(10) /*!< channel 1 overcapture flag */
  105. #define TIMER_INTF_CH2OF BIT(11) /*!< channel 2 overcapture flag */
  106. #define TIMER_INTF_CH3OF BIT(12) /*!< channel 3 overcapture flag */
  107. /* TIMER_SWEVG */
  108. #define TIMER_SWEVG_UPG BIT(0) /*!< update event generate */
  109. #define TIMER_SWEVG_CH0G BIT(1) /*!< channel 0 capture or compare event generation */
  110. #define TIMER_SWEVG_CH1G BIT(2) /*!< channel 1 capture or compare event generation */
  111. #define TIMER_SWEVG_CH2G BIT(3) /*!< channel 2 capture or compare event generation */
  112. #define TIMER_SWEVG_CH3G BIT(4) /*!< channel 3 capture or compare event generation */
  113. #define TIMER_SWEVG_CMTG BIT(5) /*!< channel commutation event generation */
  114. #define TIMER_SWEVG_TRGG BIT(6) /*!< trigger event generation */
  115. #define TIMER_SWEVG_BRKG BIT(7) /*!< break event generation */
  116. /* TIMER_CHCTL0 */
  117. /* output compare mode */
  118. #define TIMER_CHCTL0_CH0MS BITS(0,1) /*!< channel 0 mode selection */
  119. #define TIMER_CHCTL0_CH0COMFEN BIT(2) /*!< channel 0 output compare fast enable */
  120. #define TIMER_CHCTL0_CH0COMSEN BIT(3) /*!< channel 0 output compare shadow enable */
  121. #define TIMER_CHCTL0_CH0COMCTL BITS(4,6) /*!< channel 0 output compare mode */
  122. #define TIMER_CHCTL0_CH0COMCEN BIT(7) /*!< channel 0 output compare clear enable */
  123. #define TIMER_CHCTL0_CH1MS BITS(8,9) /*!< channel 1 mode selection */
  124. #define TIMER_CHCTL0_CH1COMFEN BIT(10) /*!< channel 1 output compare fast enable */
  125. #define TIMER_CHCTL0_CH1COMSEN BIT(11) /*!< channel 1 output compare shadow enable */
  126. #define TIMER_CHCTL0_CH1COMCTL BITS(12,14) /*!< channel 1 output compare mode */
  127. #define TIMER_CHCTL0_CH1COMCEN BIT(15) /*!< channel 1 output compare clear enable */
  128. /* input capture mode */
  129. #define TIMER_CHCTL0_CH0CAPPSC BITS(2,3) /*!< channel 0 input capture prescaler */
  130. #define TIMER_CHCTL0_CH0CAPFLT BITS(4,7) /*!< channel 0 input capture filter control */
  131. #define TIMER_CHCTL0_CH1CAPPSC BITS(10,11) /*!< channel 1 input capture prescaler */
  132. #define TIMER_CHCTL0_CH1CAPFLT BITS(12,15) /*!< channel 1 input capture filter control */
  133. /* TIMER_CHCTL1 */
  134. /* output compare mode */
  135. #define TIMER_CHCTL1_CH2MS BITS(0,1) /*!< channel 2 mode selection */
  136. #define TIMER_CHCTL1_CH2COMFEN BIT(2) /*!< channel 2 output compare fast enable */
  137. #define TIMER_CHCTL1_CH2COMSEN BIT(3) /*!< channel 2 output compare shadow enable */
  138. #define TIMER_CHCTL1_CH2COMCTL BITS(4,6) /*!< channel 2 output compare mode */
  139. #define TIMER_CHCTL1_CH2COMCEN BIT(7) /*!< channel 2 output compare clear enable */
  140. #define TIMER_CHCTL1_CH3MS BITS(8,9) /*!< channel 3 mode selection */
  141. #define TIMER_CHCTL1_CH3COMFEN BIT(10) /*!< channel 3 output compare fast enable */
  142. #define TIMER_CHCTL1_CH3COMSEN BIT(11) /*!< channel 3 output compare shadow enable */
  143. #define TIMER_CHCTL1_CH3COMCTL BITS(12,14) /*!< channel 3 output compare mode */
  144. #define TIMER_CHCTL1_CH3COMCEN BIT(15) /*!< channel 3 output compare clear enable */
  145. /* input capture mode */
  146. #define TIMER_CHCTL1_CH2CAPPSC BITS(2,3) /*!< channel 2 input capture prescaler */
  147. #define TIMER_CHCTL1_CH2CAPFLT BITS(4,7) /*!< channel 2 input capture filter control */
  148. #define TIMER_CHCTL1_CH3CAPPSC BITS(10,11) /*!< channel 3 input capture prescaler */
  149. #define TIMER_CHCTL1_CH3CAPFLT BITS(12,15) /*!< channel 3 input capture filter control */
  150. /* TIMER_CHCTL2 */
  151. #define TIMER_CHCTL2_CH0EN BIT(0) /*!< channel 0 enable */
  152. #define TIMER_CHCTL2_CH0P BIT(1) /*!< channel 0 polarity */
  153. #define TIMER_CHCTL2_CH0NEN BIT(2) /*!< channel 0 complementary output enable */
  154. #define TIMER_CHCTL2_CH0NP BIT(3) /*!< channel 0 complementary output polarity */
  155. #define TIMER_CHCTL2_CH1EN BIT(4) /*!< channel 1 enable */
  156. #define TIMER_CHCTL2_CH1P BIT(5) /*!< channel 1 polarity */
  157. #define TIMER_CHCTL2_CH1NEN BIT(6) /*!< channel 1 complementary output enable */
  158. #define TIMER_CHCTL2_CH1NP BIT(7) /*!< channel 1 complementary output polarity */
  159. #define TIMER_CHCTL2_CH2EN BIT(8) /*!< channel 2 enable */
  160. #define TIMER_CHCTL2_CH2P BIT(9) /*!< channel 2 polarity */
  161. #define TIMER_CHCTL2_CH2NEN BIT(10) /*!< channel 2 complementary output enable */
  162. #define TIMER_CHCTL2_CH2NP BIT(11) /*!< channel 2 complementary output polarity */
  163. #define TIMER_CHCTL2_CH3EN BIT(12) /*!< channel 3 enable */
  164. #define TIMER_CHCTL2_CH3P BIT(13) /*!< channel 3 polarity */
  165. #define TIMER_CHCTL2_CH3NP BIT(15) /*!< channel 3 complementary output polarity */
  166. /* TIMER_CNT */
  167. #define TIMER_CNT_CNT16 BITS(0,15) /*!< 16 bit timer counter */
  168. #define TIMER_CNT_CNT32 BITS(0,31) /*!< 32 bit(TIMER1) timer counter */
  169. /* TIMER_PSC */
  170. #define TIMER_PSC_PSC BITS(0,15) /*!< prescaler value of the counter clock */
  171. /* TIMER_CAR */
  172. #define TIMER_CAR_CARL16 BITS(0,15) /*!< 16 bit counter auto reload value */
  173. #define TIMER_CAR_CARL32 BITS(0,31) /*!< 32 bit(TIMER1) counter auto reload value */
  174. /* TIMER_CREP */
  175. #define TIMER_CREP_CREP BITS(0,7) /*!< counter repetition value */
  176. /* TIMER_CH0CV */
  177. #define TIMER_CH0CV_CH0VAL16 BITS(0,15) /*!< 16 bit capture/compare value of channel 0 */
  178. #define TIMER_CH0CV_CH0VAL32 BITS(0,31) /*!< 32 bit(TIMER1) capture/compare value of channel 0 */
  179. /* TIMER_CH1CV */
  180. #define TIMER_CH1CV_CH1VAL16 BITS(0,15) /*!< 16 bit capture/compare value of channel 1 */
  181. #define TIMER_CH1CV_CH1VAL32 BITS(0,31) /*!< 32 bit(TIMER1) capture/compare value of channel 1 */
  182. /* TIMER_CH2CV */
  183. #define TIMER_CH2CV_CH2VAL16 BITS(0,15) /*!< 16 bit capture/compare value of channel 2 */
  184. #define TIMER_CH2CV_CH2VAL32 BITS(0,31) /*!< 32 bit(TIMER1) capture/compare value of channel 2 */
  185. /* TIMER_CH3CV */
  186. #define TIMER_CH3CV_CH3VAL16 BITS(0,15) /*!< 16 bit capture/compare value of channel 3 */
  187. #define TIMER_CH3CV_CH3VAL32 BITS(0,31) /*!< 32 bit(TIMER1) capture/compare value of channel 3 */
  188. /* TIMER_CCHP */
  189. #define TIMER_CCHP_DTCFG BITS(0,7) /*!< dead time configure */
  190. #define TIMER_CCHP_PROT BITS(8,9) /*!< complementary register protect control */
  191. #define TIMER_CCHP_IOS BIT(10) /*!< idle mode off-state configure */
  192. #define TIMER_CCHP_ROS BIT(11) /*!< run mode off-state configure */
  193. #define TIMER_CCHP_BRKEN BIT(12) /*!< break enable */
  194. #define TIMER_CCHP_BRKP BIT(13) /*!< break polarity */
  195. #define TIMER_CCHP_OAEN BIT(14) /*!< output automatic enable */
  196. #define TIMER_CCHP_POEN BIT(15) /*!< primary output enable */
  197. /* TIMER_DMACFG */
  198. #define TIMER_DMACFG_DMATA BITS(0,4) /*!< DMA transfer access start address */
  199. #define TIMER_DMACFG_DMATC BITS(8,12) /*!< DMA transfer count */
  200. /* TIMER_DMATB */
  201. #define TIMER_DMATB_DMATB BITS(0,15) /*!< DMA transfer buffer address */
  202. /* TIMER_IRMP */
  203. #define TIMER13_IRMP_CI0_RMP BITS(0,1) /*!< TIMER13 channel 0 input remap */
  204. /* TIMER_CFG */
  205. #define TIMER_CFG_OUTSEL BIT(0) /*!< the output value selection */
  206. #define TIMER_CFG_CHVSEL BIT(1) /*!< write CHxVAL register selection */
  207. /* constants definitions */
  208. /* TIMER init parameter struct definitions*/
  209. typedef struct
  210. {
  211. uint16_t prescaler; /*!< prescaler value */
  212. uint16_t alignedmode; /*!< aligned mode */
  213. uint16_t counterdirection; /*!< counter direction */
  214. uint32_t period; /*!< period value */
  215. uint16_t clockdivision; /*!< clock division value */
  216. uint8_t repetitioncounter; /*!< the counter repetition value */
  217. }timer_parameter_struct;
  218. /* break parameter struct definitions*/
  219. typedef struct
  220. {
  221. uint16_t runoffstate; /*!< run mode off-state */
  222. uint32_t ideloffstate; /*!< idle mode off-state */
  223. uint16_t deadtime; /*!< dead time */
  224. uint16_t breakpolarity; /*!< break polarity */
  225. uint16_t outputautostate; /*!< output automatic enable */
  226. uint16_t protectmode; /*!< complementary register protect control */
  227. uint16_t breakstate; /*!< break enable */
  228. }timer_break_parameter_struct;
  229. /* channel output parameter struct definitions */
  230. typedef struct
  231. {
  232. uint32_t outputstate; /*!< channel output state */
  233. uint16_t outputnstate; /*!< channel complementary output state */
  234. uint16_t ocpolarity; /*!< channel output polarity */
  235. uint16_t ocnpolarity; /*!< channel complementary output polarity */
  236. uint16_t ocidlestate; /*!< idle state of channel output */
  237. uint16_t ocnidlestate; /*!< idle state of channel complementary output */
  238. }timer_oc_parameter_struct;
  239. /* channel input parameter struct definitions */
  240. typedef struct
  241. {
  242. uint16_t icpolarity; /*!< channel input polarity */
  243. uint16_t icselection; /*!< channel input mode selection */
  244. uint16_t icprescaler; /*!< channel input capture prescaler */
  245. uint16_t icfilter; /*!< channel input capture filter control */
  246. }timer_ic_parameter_struct;
  247. /* TIMER interrupt enable or disable */
  248. #define TIMER_INT_UP TIMER_DMAINTEN_UPIE /*!< update interrupt */
  249. #define TIMER_INT_CH0 TIMER_DMAINTEN_CH0IE /*!< channel 0 interrupt */
  250. #define TIMER_INT_CH1 TIMER_DMAINTEN_CH1IE /*!< channel 1 interrupt */
  251. #define TIMER_INT_CH2 TIMER_DMAINTEN_CH2IE /*!< channel 2 interrupt */
  252. #define TIMER_INT_CH3 TIMER_DMAINTEN_CH3IE /*!< channel 3 interrupt */
  253. #define TIMER_INT_CMT TIMER_DMAINTEN_CMTIE /*!< channel commutation interrupt flag */
  254. #define TIMER_INT_TRG TIMER_DMAINTEN_TRGIE /*!< trigger interrupt */
  255. #define TIMER_INT_BRK TIMER_DMAINTEN_BRKIE /*!< break interrupt */
  256. /* TIMER flag */
  257. #define TIMER_FLAG_UP TIMER_INTF_UPIF /*!< update flag */
  258. #define TIMER_FLAG_CH0 TIMER_INTF_CH0IF /*!< channel 0 flag */
  259. #define TIMER_FLAG_CH1 TIMER_INTF_CH1IF /*!< channel 1 flag */
  260. #define TIMER_FLAG_CH2 TIMER_INTF_CH2IF /*!< channel 2 flag */
  261. #define TIMER_FLAG_CH3 TIMER_INTF_CH3IF /*!< channel 3 flag */
  262. #define TIMER_FLAG_CMT TIMER_INTF_CMTIF /*!< channel commutation flag */
  263. #define TIMER_FLAG_TRG TIMER_INTF_TRGIF /*!< trigger flag */
  264. #define TIMER_FLAG_BRK TIMER_INTF_BRKIF /*!< break flag */
  265. #define TIMER_FLAG_CH0O TIMER_INTF_CH0OF /*!< channel 0 overcapture flag */
  266. #define TIMER_FLAG_CH1O TIMER_INTF_CH1OF /*!< channel 1 overcapture flag */
  267. #define TIMER_FLAG_CH2O TIMER_INTF_CH2OF /*!< channel 2 overcapture flag */
  268. #define TIMER_FLAG_CH3O TIMER_INTF_CH3OF /*!< channel 3 overcapture flag */
  269. /* TIMER interrupt flag */
  270. #define TIMER_INT_FLAG_UP TIMER_INTF_UPIF /*!< update interrupt flag */
  271. #define TIMER_INT_FLAG_CH0 TIMER_INTF_CH0IF /*!< channel 0 interrupt flag */
  272. #define TIMER_INT_FLAG_CH1 TIMER_INTF_CH1IF /*!< channel 1 interrupt flag */
  273. #define TIMER_INT_FLAG_CH2 TIMER_INTF_CH2IF /*!< channel 2 interrupt flag */
  274. #define TIMER_INT_FLAG_CH3 TIMER_INTF_CH3IF /*!< channel 3 interrupt flag */
  275. #define TIMER_INT_FLAG_CMT TIMER_INTF_CMTIF /*!< channel commutation interrupt flag */
  276. #define TIMER_INT_FLAG_TRG TIMER_INTF_TRGIF /*!< trigger interrupt flag */
  277. #define TIMER_INT_FLAG_BRK TIMER_INTF_BRKIF
  278. /* TIMER DMA source enable */
  279. #define TIMER_DMA_UPD ((uint16_t)0x0100U) /*!< update DMA enable */
  280. #define TIMER_DMA_CH0D ((uint16_t)0x0200U) /*!< channel 0 DMA enable */
  281. #define TIMER_DMA_CH1D ((uint16_t)0x0400U) /*!< channel 1 DMA enable */
  282. #define TIMER_DMA_CH2D ((uint16_t)0x0800U) /*!< channel 2 DMA enable */
  283. #define TIMER_DMA_CH3D ((uint16_t)0x1000U) /*!< channel 3 DMA enable */
  284. #define TIMER_DMA_CMTD ((uint16_t)0x2000U) /*!< commutation DMA request enable */
  285. #define TIMER_DMA_TRGD ((uint16_t)0x4000U) /*!< trigger DMA enable */
  286. /* channel DMA request source selection */
  287. #define TIMER_DMAREQUEST_UPDATEEVENT ((uint8_t)0x00U) /*!< DMA request of channel y is sent when update event occurs */
  288. #define TIMER_DMAREQUEST_CHANNELEVENT ((uint8_t)0x01U) /*!< DMA request of channel y is sent when channel y event occurs */
  289. /* DMA access base address */
  290. #define DMACFG_DMATA(regval) (BITS(0, 4) & ((uint32_t)(regval) << 0U))
  291. #define TIMER_DMACFG_DMATA_CTL0 DMACFG_DMATA(0) /*!< DMA transfer address is TIMER_CTL0 */
  292. #define TIMER_DMACFG_DMATA_CTL1 DMACFG_DMATA(1) /*!< DMA transfer address is TIMER_CTL1 */
  293. #define TIMER_DMACFG_DMATA_SMCFG DMACFG_DMATA(2) /*!< DMA transfer address is TIMER_SMCFG */
  294. #define TIMER_DMACFG_DMATA_DMAINTEN DMACFG_DMATA(3) /*!< DMA transfer address is TIMER_DMAINTEN */
  295. #define TIMER_DMACFG_DMATA_INTF DMACFG_DMATA(4) /*!< DMA transfer address is TIMER_INTF */
  296. #define TIMER_DMACFG_DMATA_SWEVG DMACFG_DMATA(5) /*!< DMA transfer address is TIMER_SWEVG */
  297. #define TIMER_DMACFG_DMATA_CHCTL0 DMACFG_DMATA(6) /*!< DMA transfer address is TIMER_CHCTL0 */
  298. #define TIMER_DMACFG_DMATA_CHCTL1 DMACFG_DMATA(7) /*!< DMA transfer address is TIMER_CHCTL1 */
  299. #define TIMER_DMACFG_DMATA_CHCTL2 DMACFG_DMATA(8) /*!< DMA transfer address is TIMER_CHCTL2 */
  300. #define TIMER_DMACFG_DMATA_CNT DMACFG_DMATA(9) /*!< DMA transfer address is TIMER_CNT */
  301. #define TIMER_DMACFG_DMATA_PSC DMACFG_DMATA(10) /*!< DMA transfer address is TIMER_PSC */
  302. #define TIMER_DMACFG_DMATA_CAR DMACFG_DMATA(11) /*!< DMA transfer address is TIMER_CAR */
  303. #define TIMER_DMACFG_DMATA_CREP DMACFG_DMATA(12) /*!< DMA transfer address is TIMER_CREP */
  304. #define TIMER_DMACFG_DMATA_CH0CV DMACFG_DMATA(13) /*!< DMA transfer address is TIMER_CH0CV */
  305. #define TIMER_DMACFG_DMATA_CH1CV DMACFG_DMATA(14) /*!< DMA transfer address is TIMER_CH1CV */
  306. #define TIMER_DMACFG_DMATA_CH2CV DMACFG_DMATA(15) /*!< DMA transfer address is TIMER_CH2CV */
  307. #define TIMER_DMACFG_DMATA_CH3CV DMACFG_DMATA(16) /*!< DMA transfer address is TIMER_CH3CV */
  308. #define TIMER_DMACFG_DMATA_CCHP DMACFG_DMATA(17) /*!< DMA transfer address is TIMER_CCHP */
  309. #define TIMER_DMACFG_DMATA_DMACFG DMACFG_DMATA(18) /*!< DMA transfer address is TIMER_DMACFG */
  310. #define TIMER_DMACFG_DMATA_DMATB DMACFG_DMATA(19) /*!< DMA transfer address is TIMER_DMATB */
  311. /* DMA access burst length */
  312. #define DMACFG_DMATC(regval) (BITS(8, 12) & ((uint32_t)(regval) << 8U))
  313. #define TIMER_DMACFG_DMATC_1TRANSFER DMACFG_DMATC(0) /*!< DMA transfer 1 time */
  314. #define TIMER_DMACFG_DMATC_2TRANSFER DMACFG_DMATC(1) /*!< DMA transfer 2 times */
  315. #define TIMER_DMACFG_DMATC_3TRANSFER DMACFG_DMATC(2) /*!< DMA transfer 3 times */
  316. #define TIMER_DMACFG_DMATC_4TRANSFER DMACFG_DMATC(3) /*!< DMA transfer 4 times */
  317. #define TIMER_DMACFG_DMATC_5TRANSFER DMACFG_DMATC(4) /*!< DMA transfer 5 times */
  318. #define TIMER_DMACFG_DMATC_6TRANSFER DMACFG_DMATC(5) /*!< DMA transfer 6 times */
  319. #define TIMER_DMACFG_DMATC_7TRANSFER DMACFG_DMATC(6) /*!< DMA transfer 7 times */
  320. #define TIMER_DMACFG_DMATC_8TRANSFER DMACFG_DMATC(7) /*!< DMA transfer 8 times */
  321. #define TIMER_DMACFG_DMATC_9TRANSFER DMACFG_DMATC(8) /*!< DMA transfer 9 times */
  322. #define TIMER_DMACFG_DMATC_10TRANSFER DMACFG_DMATC(9) /*!< DMA transfer 10 times */
  323. #define TIMER_DMACFG_DMATC_11TRANSFER DMACFG_DMATC(10) /*!< DMA transfer 11 times */
  324. #define TIMER_DMACFG_DMATC_12TRANSFER DMACFG_DMATC(11) /*!< DMA transfer 12 times */
  325. #define TIMER_DMACFG_DMATC_13TRANSFER DMACFG_DMATC(12) /*!< DMA transfer 13 times */
  326. #define TIMER_DMACFG_DMATC_14TRANSFER DMACFG_DMATC(13) /*!< DMA transfer 14 times */
  327. #define TIMER_DMACFG_DMATC_15TRANSFER DMACFG_DMATC(14) /*!< DMA transfer 15 times */
  328. #define TIMER_DMACFG_DMATC_16TRANSFER DMACFG_DMATC(15) /*!< DMA transfer 16 times */
  329. #define TIMER_DMACFG_DMATC_17TRANSFER DMACFG_DMATC(16) /*!< DMA transfer 17 times */
  330. #define TIMER_DMACFG_DMATC_18TRANSFER DMACFG_DMATC(17) /*!< DMA transfer 18 times */
  331. /* TIMER software event generation source */
  332. #define TIMER_EVENT_SRC_UPG ((uint16_t)0x0001U) /*!< update event generation */
  333. #define TIMER_EVENT_SRC_CH0G ((uint16_t)0x0002U) /*!< channel 0 capture or compare event generation */
  334. #define TIMER_EVENT_SRC_CH1G ((uint16_t)0x0004U) /*!< channel 1 capture or compare event generation */
  335. #define TIMER_EVENT_SRC_CH2G ((uint16_t)0x0008U) /*!< channel 2 capture or compare event generation */
  336. #define TIMER_EVENT_SRC_CH3G ((uint16_t)0x0010U) /*!< channel 3 capture or compare event generation */
  337. #define TIMER_EVENT_SRC_CMTG ((uint16_t)0x0020U) /*!< channel commutation event generation */
  338. #define TIMER_EVENT_SRC_TRGG ((uint16_t)0x0040U) /*!< trigger event generation */
  339. #define TIMER_EVENT_SRC_BRKG ((uint16_t)0x0080U) /*!< break event generation */
  340. /* center-aligned mode selection */
  341. #define CTL0_CAM(regval) ((uint16_t)(BITS(5, 6) & ((uint32_t)(regval) << 5U)))
  342. #define TIMER_COUNTER_EDGE CTL0_CAM(0) /*!< edge-aligned mode */
  343. #define TIMER_COUNTER_CENTER_DOWN CTL0_CAM(1) /*!< center-aligned and counting down assert mode */
  344. #define TIMER_COUNTER_CENTER_UP CTL0_CAM(2) /*!< center-aligned and counting up assert mode */
  345. #define TIMER_COUNTER_CENTER_BOTH CTL0_CAM(3) /*!< center-aligned and counting up/down assert mode */
  346. /* TIMER prescaler reload mode */
  347. #define TIMER_PSC_RELOAD_NOW ((uint8_t)0x00U) /*!< the prescaler is loaded right now */
  348. #define TIMER_PSC_RELOAD_UPDATE ((uint8_t)0x01U) /*!< the prescaler is loaded at the next update event */
  349. /* count direction */
  350. #define TIMER_COUNTER_UP ((uint16_t)0x0000U) /*!< counter up direction */
  351. #define TIMER_COUNTER_DOWN ((uint16_t)0x0010U) /*!< counter down direction */
  352. /* specify division ratio between TIMER clock and dead-time and sampling clock */
  353. #define CTL0_CKDIV(regval) ((uint16_t)(BITS(8, 9) & ((uint32_t)(regval) << 8U)))
  354. #define TIMER_CKDIV_DIV1 CTL0_CKDIV(0) /*!< clock division value is 1, fDTS=fTIMER_CK */
  355. #define TIMER_CKDIV_DIV2 CTL0_CKDIV(1) /*!< clock division value is 2, fDTS= fTIMER_CK/2 */
  356. #define TIMER_CKDIV_DIV4 CTL0_CKDIV(2) /*!< clock division value is 4, fDTS= fTIMER_CK/4 */
  357. /* single pulse mode */
  358. #define TIMER_SP_MODE_SINGLE ((uint8_t)0x00U) /*!< single pulse mode */
  359. #define TIMER_SP_MODE_REPETITIVE ((uint8_t)0x01U) /*!< repetitive pulse mode */
  360. /* update source */
  361. #define TIMER_UPDATE_SRC_REGULAR ((uint8_t)0x00U) /*!< update generate only by counter overflow/underflow */
  362. #define TIMER_UPDATE_SRC_GLOBAL ((uint8_t)0x01U) /*!< update generate by setting of UPG bit or the counter overflow/underflow,or the slave mode controller trigger */
  363. /* run mode off-state configure */
  364. #define TIMER_ROS_STATE_ENABLE ((uint32_t)0x00000800U) /*!< when POEN bit is set, the channel output signals (CHx_O/CHx_ON) are enabled, with relationship to CHxEN/CHxNEN bits */
  365. #define TIMER_ROS_STATE_DISABLE ((uint32_t)0x00000000U) /*!< when POEN bit is set, the channel output signals (CHx_O/CHx_ON) are disabled */
  366. /* idle mode off-state configure */
  367. #define TIMER_IOS_STATE_ENABLE ((uint16_t)0x0400U) /*!< when POEN bit is reset, he channel output signals (CHx_O/CHx_ON) are enabled, with relationship to CHxEN/CHxNEN bits */
  368. #define TIMER_IOS_STATE_DISABLE ((uint16_t)0x0000U) /*!< when POEN bit is reset, the channel output signals (CHx_O/CHx_ON) are disabled */
  369. /* break input polarity */
  370. #define TIMER_BREAK_POLARITY_LOW ((uint16_t)0x0000U) /*!< break input polarity is low */
  371. #define TIMER_BREAK_POLARITY_HIGH ((uint16_t)0x2000U) /*!< break input polarity is high */
  372. /* output automatic enable */
  373. #define TIMER_OUTAUTO_ENABLE ((uint16_t)0x4000U) /*!< output automatic enable */
  374. #define TIMER_OUTAUTO_DISABLE ((uint16_t)0x0000U) /*!< output automatic disable */
  375. /* complementary register protect control */
  376. #define CCHP_PROT(regval) ((uint16_t)(BITS(8, 9) & ((uint32_t)(regval) << 8U)))
  377. #define TIMER_CCHP_PROT_OFF CCHP_PROT(0) /*!< protect disable */
  378. #define TIMER_CCHP_PROT_0 CCHP_PROT(1) /*!< PROT mode 0 */
  379. #define TIMER_CCHP_PROT_1 CCHP_PROT(2) /*!< PROT mode 1 */
  380. #define TIMER_CCHP_PROT_2 CCHP_PROT(3) /*!< PROT mode 2 */
  381. /* break input enable */
  382. #define TIMER_BREAK_ENABLE ((uint16_t)0x1000U) /*!< break input enable */
  383. #define TIMER_BREAK_DISABLE ((uint16_t)0x0000U) /*!< break input disable */
  384. /* TIMER channel y(y=0,1,2,3) */
  385. #define TIMER_CH_0 ((uint16_t)0x0000U) /*!< TIMER channel 0(TIMERx(x=0..2,13..16)) */
  386. #define TIMER_CH_1 ((uint16_t)0x0001U) /*!< TIMER channel 1(TIMERx(x=0..2,14)) */
  387. #define TIMER_CH_2 ((uint16_t)0x0002U) /*!< TIMER channel 2(TIMERx(x=0..2)) */
  388. #define TIMER_CH_3 ((uint16_t)0x0003U) /*!< TIMER channel 3(TIMERx(x=0..2)) */
  389. /* channel enable state*/
  390. #define TIMER_CCX_ENABLE ((uint32_t)0x00000001U) /*!< channel enable */
  391. #define TIMER_CCX_DISABLE ((uint32_t)0x00000000U) /*!< channel disable */
  392. /* channel complementary output enable state*/
  393. #define TIMER_CCXN_ENABLE ((uint16_t)0x0004U) /*!< channel complementary enable */
  394. #define TIMER_CCXN_DISABLE ((uint16_t)0x0000U) /*!< channel complementary disable */
  395. /* channel output polarity */
  396. #define TIMER_OC_POLARITY_HIGH ((uint16_t)0x0000U) /*!< channel output polarity is high */
  397. #define TIMER_OC_POLARITY_LOW ((uint16_t)0x0002U) /*!< channel output polarity is low */
  398. /* channel complementary output polarity */
  399. #define TIMER_OCN_POLARITY_HIGH ((uint16_t)0x0000U) /*!< channel complementary output polarity is high */
  400. #define TIMER_OCN_POLARITY_LOW ((uint16_t)0x0008U) /*!< channel complementary output polarity is low */
  401. /* idle state of channel output */
  402. #define TIMER_OC_IDLE_STATE_HIGH ((uint16_t)0x0100) /*!< idle state of channel output is high */
  403. #define TIMER_OC_IDLE_STATE_LOW ((uint16_t)0x0000) /*!< idle state of channel output is low */
  404. /* idle state of channel complementary output */
  405. #define TIMER_OCN_IDLE_STATE_HIGH ((uint16_t)0x0200U) /*!< idle state of channel complementary output is high */
  406. #define TIMER_OCN_IDLE_STATE_LOW ((uint16_t)0x0000U) /*!< idle state of channel complementary output is low */
  407. /* channel output compare mode */
  408. #define TIMER_OC_MODE_TIMING ((uint16_t)0x0000U) /*!< timing mode */
  409. #define TIMER_OC_MODE_ACTIVE ((uint16_t)0x0010U) /*!< active mode */
  410. #define TIMER_OC_MODE_INACTIVE ((uint16_t)0x0020U) /*!< inactive mode */
  411. #define TIMER_OC_MODE_TOGGLE ((uint16_t)0x0030U) /*!< toggle mode */
  412. #define TIMER_OC_MODE_LOW ((uint16_t)0x0040U) /*!< force low mode */
  413. #define TIMER_OC_MODE_HIGH ((uint16_t)0x0050U) /*!< force high mode */
  414. #define TIMER_OC_MODE_PWM0 ((uint16_t)0x0060U) /*!< PWM0 mode */
  415. #define TIMER_OC_MODE_PWM1 ((uint16_t)0x0070U) /*!< PWM1 mode*/
  416. /* channel output compare shadow enable */
  417. #define TIMER_OC_SHADOW_ENABLE ((uint16_t)0x0008U) /*!< channel output shadow state enable */
  418. #define TIMER_OC_SHADOW_DISABLE ((uint16_t)0x0000U) /*!< channel output shadow state disable */
  419. /* channel output compare fast enable */
  420. #define TIMER_OC_FAST_ENABLE ((uint16_t)0x0004) /*!< channel output fast function enable */
  421. #define TIMER_OC_FAST_DISABLE ((uint16_t)0x0000) /*!< channel output fast function disable */
  422. /* channel output compare clear enable */
  423. #define TIMER_OC_CLEAR_ENABLE ((uint16_t)0x0080U) /*!< channel output clear function enable */
  424. #define TIMER_OC_CLEAR_DISABLE ((uint16_t)0x0000U) /*!< channel output clear function disable */
  425. /* channel control shadow register update control */
  426. #define TIMER_UPDATECTL_CCU ((uint8_t)0x00U) /*!< the shadow registers update by when CMTG bit is set */
  427. #define TIMER_UPDATECTL_CCUTRI ((uint8_t)0x01U) /*!< the shadow registers update by when CMTG bit is set or an rising edge of TRGI occurs */
  428. /* channel input capture polarity */
  429. #define TIMER_IC_POLARITY_RISING ((uint16_t)0x0000U) /*!< input capture rising edge */
  430. #define TIMER_IC_POLARITY_FALLING ((uint16_t)0x0002U) /*!< input capture falling edge */
  431. #define TIMER_IC_POLARITY_BOTH_EDGE ((uint16_t)0x000AU) /*!< input capture both edge */
  432. /* timer input capture selection */
  433. #define TIMER_IC_SELECTION_DIRECTTI ((uint16_t)0x0001U) /*!< channel y is configured as input and icy is mapped on CIy */
  434. #define TIMER_IC_SELECTION_INDIRECTTI ((uint16_t)0x0002U) /*!< channel y is configured as input and icy is mapped on opposite input */
  435. #define TIMER_IC_SELECTION_ITS ((uint16_t)0x0003U) /*!< channel y is configured as input and icy is mapped on ITS */
  436. /* channel input capture prescaler */
  437. #define TIMER_IC_PSC_DIV1 ((uint16_t)0x0000U) /*!< no prescaler */
  438. #define TIMER_IC_PSC_DIV2 ((uint16_t)0x0004U) /*!< divided by 2 */
  439. #define TIMER_IC_PSC_DIV4 ((uint16_t)0x0008U) /*!< divided by 4*/
  440. #define TIMER_IC_PSC_DIV8 ((uint16_t)0x000CU) /*!< divided by 8 */
  441. /* trigger selection */
  442. #define SMCFG_TRGSEL(regval) (BITS(4, 6) & ((uint32_t)(regval) << 4U))
  443. #define TIMER_SMCFG_TRGSEL_ITI0 SMCFG_TRGSEL(0) /*!< internal trigger 0 */
  444. #define TIMER_SMCFG_TRGSEL_ITI1 SMCFG_TRGSEL(1) /*!< internal trigger 1 */
  445. #define TIMER_SMCFG_TRGSEL_ITI2 SMCFG_TRGSEL(2) /*!< internal trigger 2 */
  446. #define TIMER_SMCFG_TRGSEL_ITI3 SMCFG_TRGSEL(3) /*!< internal trigger 3 */
  447. #define TIMER_SMCFG_TRGSEL_CI0F_ED SMCFG_TRGSEL(4) /*!< TI0 Edge Detector */
  448. #define TIMER_SMCFG_TRGSEL_CI0FE0 SMCFG_TRGSEL(5) /*!< filtered TIMER input 0 */
  449. #define TIMER_SMCFG_TRGSEL_CI1FE1 SMCFG_TRGSEL(6) /*!< filtered TIMER input 1 */
  450. #define TIMER_SMCFG_TRGSEL_ETIFP SMCFG_TRGSEL(7) /*!< external trigger */
  451. /* master mode control */
  452. #define CTL1_MMC(regval) (BITS(4, 6) & ((uint32_t)(regval) << 4U))
  453. #define TIMER_TRI_OUT_SRC_RESET CTL1_MMC(0) /*!< the UPG bit as trigger output */
  454. #define TIMER_TRI_OUT_SRC_ENABLE CTL1_MMC(1) /*!< the counter enable signal TIMER_CTL0_CEN as trigger output */
  455. #define TIMER_TRI_OUT_SRC_UPDATE CTL1_MMC(2) /*!< update event as trigger output */
  456. #define TIMER_TRI_OUT_SRC_CC0 CTL1_MMC(3) /*!< a capture or a compare match occurred in channal0 as trigger output TRGO */
  457. #define TIMER_TRI_OUT_SRC_O0CPRE CTL1_MMC(4) /*!< O0CPRE as trigger output */
  458. #define TIMER_TRI_OUT_SRC_O1CPRE CTL1_MMC(5) /*!< O1CPRE as trigger output */
  459. #define TIMER_TRI_OUT_SRC_O2CPRE CTL1_MMC(6) /*!< O2CPRE as trigger output */
  460. #define TIMER_TRI_OUT_SRC_O3CPRE CTL1_MMC(7) /*!< O3CPRE as trigger output */
  461. /* slave mode control */
  462. #define SMCFG_SMC(regval) (BITS(0, 2) & ((uint32_t)(regval) << 0U))
  463. #define TIMER_SLAVE_MODE_DISABLE SMCFG_SMC(0) /*!< slave mode disable */
  464. #define TIMER_ENCODER_MODE0 SMCFG_SMC(1) /*!< encoder mode 0 */
  465. #define TIMER_ENCODER_MODE1 SMCFG_SMC(2) /*!< encoder mode 1 */
  466. #define TIMER_ENCODER_MODE2 SMCFG_SMC(3) /*!< encoder mode 2 */
  467. #define TIMER_SLAVE_MODE_RESTART SMCFG_SMC(4) /*!< restart mode */
  468. #define TIMER_SLAVE_MODE_PAUSE SMCFG_SMC(5) /*!< pause mode */
  469. #define TIMER_SLAVE_MODE_EVENT SMCFG_SMC(6) /*!< event mode */
  470. #define TIMER_SLAVE_MODE_EXTERNAL0 SMCFG_SMC(7) /*!< external clock mode 0 */
  471. /* OCPRE clear source selection */
  472. #define TIMER_OCPRE_CLEAR_SOURCE_CLR ((uint8_t)0x00U) /*!< OCPRE_CLR_INT is connected to the OCPRE_CLR input */
  473. #define TIMER_OCPRE_CLEAR_SOURCE_ETIF ((uint8_t)0x01U) /*!< OCPRE_CLR_INT is connected to ETIF */
  474. /* master slave mode selection */
  475. #define TIMER_MASTER_SLAVE_MODE_ENABLE ((uint8_t)0x00U) /*!< master slave mode enable */
  476. #define TIMER_MASTER_SLAVE_MODE_DISABLE ((uint8_t)0x01U) /*!< master slave mode disable */
  477. /* external trigger prescaler */
  478. #define SMCFG_ETPSC(regval) (BITS(12, 13) & ((uint32_t)(regval) << 12U))
  479. #define TIMER_EXT_TRI_PSC_OFF SMCFG_ETPSC(0) /*!< no divided */
  480. #define TIMER_EXT_TRI_PSC_DIV2 SMCFG_ETPSC(1) /*!< divided by 2 */
  481. #define TIMER_EXT_TRI_PSC_DIV4 SMCFG_ETPSC(2) /*!< divided by 4 */
  482. #define TIMER_EXT_TRI_PSC_DIV8 SMCFG_ETPSC(3) /*!< divided by 8 */
  483. /* external trigger polarity */
  484. #define TIMER_ETP_FALLING TIMER_SMCFG_ETP /*!< active low or falling edge active */
  485. #define TIMER_ETP_RISING ((uint32_t)0x00000000U) /*!< active high or rising edge active */
  486. /* channel 0 trigger input selection */
  487. #define TIMER_HALLINTERFACE_ENABLE ((uint8_t)0x00U) /*!< TIMER hall sensor mode enable */
  488. #define TIMER_HALLINTERFACE_DISABLE ((uint8_t)0x01U) /*!< TIMER hall sensor mode disable */
  489. /* timerx(x=0,1,2,13,14,15,16) write cc register selection */
  490. #define TIMER_CCSEL_DISABLE ((uint16_t)0x0000U) /*!< write CC register selection disable */
  491. #define TIMER_CCSEL_ENABLE ((uint16_t)0x0002U) /*!< write CC register selection enable */
  492. /* the output value selection */
  493. #define TIMER_OUTSEL_DISABLE ((uint16_t)0x0000U) /*!< output value selection disable */
  494. #define TIMER_OUTSEL_ENABLE ((uint16_t)0x0001U) /*!< output value selection enable */
  495. /* timer13 channel 0 input remap */
  496. #define TIMER13_IRMP(regval) (BITS(0, 1) & ((uint32_t)(regval) << 0U))
  497. #define TIMER13_CI0_RMP_GPIO TIMER13_IRMP(0) /*!< timer13 channel 0 input is connected to GPIO(TIMER13_CH0) */
  498. #define TIMER13_CI0_RMP_RTCCLK TIMER13_IRMP(1) /*!< timer13 channel 0 input is connected to the RTCCLK */
  499. #define TIMER13_CI0_RMP_HXTAL_DIV32 TIMER13_IRMP(2) /*!< timer13 channel 0 input is connected to HXTAL/32 clock */
  500. #define TIMER13_CI0_RMP_CKOUTSEL TIMER13_IRMP(3) /*!< timer13 channel 0 input is connected to CKOUTSEL */
  501. /* function declarations */
  502. /* TIMER timebase*/
  503. /* deinit a TIMER */
  504. void timer_deinit(uint32_t timer_periph);
  505. /* initialize TIMER counter */
  506. void timer_init(uint32_t timer_periph, timer_parameter_struct* initpara);
  507. /* enable a TIMER */
  508. void timer_enable(uint32_t timer_periph);
  509. /* disable a TIMER */
  510. void timer_disable(uint32_t timer_periph);
  511. /* enable the auto reload shadow function */
  512. void timer_auto_reload_shadow_enable(uint32_t timer_periph);
  513. /* disable the auto reload shadow function */
  514. void timer_auto_reload_shadow_disable(uint32_t timer_periph);
  515. /* enable the update event */
  516. void timer_update_event_enable(uint32_t timer_periph);
  517. /* disable the update event */
  518. void timer_update_event_disable(uint32_t timer_periph);
  519. /* set TIMER counter alignment mode */
  520. void timer_counter_alignment(uint32_t timer_periph, uint16_t aligned);
  521. /* set TIMER counter up direction */
  522. void timer_counter_up_direction(uint32_t timer_periph);
  523. /* set TIMER counter down direction */
  524. void timer_counter_down_direction(uint32_t timer_periph);
  525. /* configure TIMER prescaler */
  526. void timer_prescaler_config(uint32_t timer_periph, uint16_t prescaler, uint8_t pscreload);
  527. /* configure TIMER repetition register value */
  528. void timer_repetition_value_config(uint32_t timer_periph, uint16_t repetition);
  529. /* configure TIMER autoreload register value */
  530. void timer_autoreload_value_config(uint32_t timer_periph, uint32_t autoreload);
  531. /* configure TIMER counter register value */
  532. void timer_counter_value_config(uint32_t timer_periph , uint32_t counter);
  533. /* read TIMER counter value */
  534. uint32_t timer_counter_read(uint32_t timer_periph);
  535. /* read TIMER prescaler value */
  536. uint16_t timer_prescaler_read(uint32_t timer_periph);
  537. /* configure TIMER single pulse mode */
  538. void timer_single_pulse_mode_config(uint32_t timer_periph, uint8_t spmode);
  539. /* configure TIMER update source */
  540. void timer_update_source_config(uint32_t timer_periph, uint8_t update);
  541. /* OCPRE clear source selection */
  542. void timer_ocpre_clear_source_config(uint32_t timer_periph, uint8_t ocpreclear);
  543. /* TIMER interrupt and flag*/
  544. /* enable the TIMER interrupt */
  545. void timer_interrupt_enable(uint32_t timer_periph, uint32_t interrupt);
  546. /* disable the TIMER interrupt */
  547. void timer_interrupt_disable(uint32_t timer_periph, uint32_t interrupt);
  548. /* get timer interrupt flag */
  549. FlagStatus timer_interrupt_flag_get(uint32_t timer_periph, uint32_t interrupt);
  550. /* clear TIMER interrupt flag */
  551. void timer_interrupt_flag_clear(uint32_t timer_periph, uint32_t interrupt);
  552. /* get TIMER flags */
  553. FlagStatus timer_flag_get(uint32_t timer_periph, uint32_t flag);
  554. /* clear TIMER flags */
  555. void timer_flag_clear(uint32_t timer_periph, uint32_t flag);
  556. /* timer DMA and event*/
  557. /* enable the TIMER DMA */
  558. void timer_dma_enable(uint32_t timer_periph, uint16_t dma);
  559. /* disable the TIMER DMA */
  560. void timer_dma_disable(uint32_t timer_periph, uint16_t dma);
  561. /* channel DMA request source selection */
  562. void timer_channel_dma_request_source_select(uint32_t timer_periph, uint8_t dma_request);
  563. /* configure the TIMER DMA transfer */
  564. void timer_dma_transfer_config(uint32_t timer_periph,uint32_t dma_baseaddr, uint32_t dma_lenth);
  565. /* software generate events */
  566. void timer_event_software_generate(uint32_t timer_periph, uint16_t event);
  567. /* timer channel complementary protection */
  568. /* configure TIMER break function */
  569. void timer_break_config(uint32_t timer_periph, timer_break_parameter_struct* breakpara);
  570. /* enable TIMER break function */
  571. void timer_break_enable(uint32_t timer_periph);
  572. /* disable TIMER break function */
  573. void timer_break_disable(uint32_t timer_periph);
  574. /* enable TIMER output automatic function */
  575. void timer_automatic_output_enable(uint32_t timer_periph);
  576. /* disable TIMER output automatic function */
  577. void timer_automatic_output_disable(uint32_t timer_periph);
  578. /* configure TIMER primary output function */
  579. void timer_primary_output_config(uint32_t timer_periph, ControlStatus newvalue);
  580. /* channel capture/compare control shadow register enable */
  581. void timer_channel_control_shadow_config(uint32_t timer_periph, ControlStatus newvalue);
  582. /* configure TIMER channel control shadow register update control */
  583. void timer_channel_control_shadow_update_config(uint32_t timer_periph, uint8_t ccuctl);
  584. /* TIMER channel output */
  585. /* configure TIMER channel output function */
  586. void timer_channel_output_config(uint32_t timer_periph,uint16_t channel, timer_oc_parameter_struct* ocpara);
  587. /* configure TIMER channel output compare mode */
  588. void timer_channel_output_mode_config(uint32_t timer_periph, uint16_t channel,uint16_t ocmode);
  589. /* configure TIMER channel output pulse value */
  590. void timer_channel_output_pulse_value_config(uint32_t timer_periph, uint16_t channel, uint32_t pulse);
  591. /* configure TIMER channel output shadow function */
  592. void timer_channel_output_shadow_config(uint32_t timer_periph, uint16_t channel, uint16_t ocshadow);
  593. /* configure TIMER channel output fast function */
  594. void timer_channel_output_fast_config(uint32_t timer_periph, uint16_t channel, uint16_t ocfast);
  595. /* configure TIMER channel output clear function */
  596. void timer_channel_output_clear_config(uint32_t timer_periph,uint16_t channel,uint16_t occlear);
  597. /* configure TIMER channel output polarity */
  598. void timer_channel_output_polarity_config(uint32_t timer_periph, uint16_t channel, uint16_t ocpolarity);
  599. /* configure TIMER channel complementary output polarity */
  600. void timer_channel_complementary_output_polarity_config(uint32_t timer_periph, uint16_t channel, uint16_t ocnpolarity);
  601. /* configure TIMER channel enable state */
  602. void timer_channel_output_state_config(uint32_t timer_periph, uint16_t channel, uint32_t state);
  603. /* configure TIMER channel complementary output enable state */
  604. void timer_channel_complementary_output_state_config(uint32_t timer_periph, uint16_t channel, uint16_t ocnstate);
  605. /* TIMER channel input */
  606. /* configure TIMER input capture parameter */
  607. void timer_input_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct* icpara);
  608. /* configure TIMER channel input capture prescaler value */
  609. void timer_channel_input_capture_prescaler_config(uint32_t timer_periph, uint16_t channel, uint16_t prescaler);
  610. /* read TIMER channel capture compare register value */
  611. uint32_t timer_channel_capture_value_register_read(uint32_t timer_periph, uint16_t channel);
  612. /* configure TIMER input pwm capture function */
  613. void timer_input_pwm_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct* icpwm);
  614. /* configure TIMER hall sensor mode */
  615. void timer_hall_mode_config(uint32_t timer_periph, uint8_t hallmode);
  616. /* TIMER master and slave */
  617. /* select TIMER input trigger source */
  618. void timer_input_trigger_source_select(uint32_t timer_periph, uint32_t intrigger);
  619. /* select TIMER master mode output trigger source */
  620. void timer_master_output_trigger_source_select(uint32_t timer_periph, uint32_t outrigger);
  621. /* select TIMER slave mode */
  622. void timer_slave_mode_select(uint32_t timer_periph,uint32_t slavemode);
  623. /* configure TIMER master slave mode */
  624. void timer_master_slave_mode_config(uint32_t timer_periph, uint8_t masterslave);
  625. /* configure TIMER external trigger input */
  626. void timer_external_trigger_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t expolarity, uint32_t extfilter);
  627. /* configure TIMER quadrature decoder mode */
  628. void timer_quadrature_decoder_mode_config(uint32_t timer_periph, uint32_t decomode, uint16_t ic0polarity, uint16_t ic1polarity);
  629. /* configure TIMER internal clock mode */
  630. void timer_internal_clock_config(uint32_t timer_periph);
  631. /* configure TIMER the internal trigger as external clock input */
  632. void timer_internal_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t intrigger);
  633. /* configure TIMER the external trigger as external clock input */
  634. void timer_external_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t extrigger, uint16_t expolarity,uint32_t extfilter);
  635. /* configure TIMER the external clock mode 0 */
  636. void timer_external_clock_mode0_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t expolarity, uint32_t extfilter);
  637. /* configure TIMER the external clock mode 1 */
  638. void timer_external_clock_mode1_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t expolarity, uint32_t extfilter);
  639. /* disable TIMER the external clock mode 1 */
  640. void timer_external_clock_mode1_disable(uint32_t timer_periph);
  641. /* configure TIMER channel remap function */
  642. void timer_channel_remap_config(uint32_t timer_periph,uint32_t remap);
  643. /* TIMER configure */
  644. /* configure TIMER write CHxVAL register selection */
  645. void timer_write_cc_register_config(uint32_t timer_periph, uint16_t ccsel);
  646. /* configure TIMER output value selection */
  647. void timer_output_value_selection_config(uint32_t timer_periph, uint16_t outsel);
  648. #endif /* GD32F3X0_TIMER_H */