hc32_ll_tmra.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /**
  2. *******************************************************************************
  3. * @file hc32_ll_tmra.h
  4. * @brief This file contains all the functions prototypes of the TMRA(TimerA)
  5. * driver library.
  6. @verbatim
  7. Change Logs:
  8. Date Author Notes
  9. 2022-12-31 CDT First version
  10. @endverbatim
  11. *******************************************************************************
  12. * Copyright (C) 2022, Xiaohua Semiconductor Co., Ltd. All rights reserved.
  13. *
  14. * This software component is licensed by XHSC under BSD 3-Clause license
  15. * (the "License"); You may not use this file except in compliance with the
  16. * License. You may obtain a copy of the License at:
  17. * opensource.org/licenses/BSD-3-Clause
  18. *
  19. *******************************************************************************
  20. */
  21. #ifndef __HC32_LL_TMRA_H__
  22. #define __HC32_LL_TMRA_H__
  23. /* C binding of definitions if building with C++ compiler */
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. /*******************************************************************************
  29. * Include files
  30. ******************************************************************************/
  31. #include "hc32_ll_def.h"
  32. #include "hc32f4xx.h"
  33. #include "hc32f4xx_conf.h"
  34. /**
  35. * @addtogroup LL_Driver
  36. * @{
  37. */
  38. /**
  39. * @addtogroup LL_TMRA
  40. * @{
  41. */
  42. #if (LL_TMRA_ENABLE == DDL_ON)
  43. /*******************************************************************************
  44. * Global type definitions ('typedef')
  45. ******************************************************************************/
  46. /**
  47. * @defgroup TMRA_Global_Types TMRA Global Types
  48. * @{
  49. */
  50. /**
  51. * @brief TMRA initialization structure.
  52. */
  53. typedef struct {
  54. uint8_t u8CountSrc; /*!< Specifies the count source of TMRA.
  55. This parameter can be a value of @ref TMRA_Count_Src */
  56. union {
  57. struct {
  58. uint16_t u16ClockDiv; /*!< Specifies the divider of software clock source.
  59. This parameter can be a value of @ref TMRA_Clock_Divider */
  60. uint16_t u16CountMode; /*!< Specifies count mode.
  61. This parameter can be a value of @ref TMRA_Count_Mode */
  62. uint16_t u16CountDir; /*!< Specifies count direction.
  63. This parameter can be a value of @ref TMRA_Count_Dir */
  64. } sw_count;
  65. struct {
  66. uint16_t u16CountUpCond; /*!< Hardware count up condition.
  67. This parameter can be a value of @ref TMRA_Hard_Count_Up_Condition */
  68. uint16_t u16CountDownCond; /*!< Hardware count down condition.
  69. This parameter can be a value of @ref TMRA_Hard_Count_Down_Condition */
  70. uint16_t u16Reserved; /*!< Reserved, for future use. */
  71. } hw_count;
  72. };
  73. uint32_t u32PeriodValue; /*!< Specifies the period reference value.
  74. This parameter can be a number between 0U and 0xFFFFU, inclusive. */
  75. uint16_t u16CountReload; /*!< Continue counting or stop when counter overflow/underflow.
  76. This parameter can be a value of @ref TMRA_Count_Reload_En */
  77. } stc_tmra_init_t;
  78. /**
  79. * @brief TMRA PWM configuration structure.
  80. */
  81. typedef struct {
  82. uint32_t u32CompareValue; /*!< Specifies compare value of the TMRA channel.
  83. This parameter can be a number between:
  84. 0UL and 0xFFFFFFFFUL for 32-bit TimerA units.
  85. 0UL and 0xFFFFUL for 16-bit TimerA units. */
  86. uint16_t u16StartPolarity; /*!< Specifies the polarity when the counter start counting.
  87. This parameter can be a value of @ref TMRA_PWM_Polarity
  88. NOTE: CAN NOT be specified as TMRA_PWM_LOW or TMRA_PWM_HIGH when
  89. sw_count.u16ClockDiv of @ref stc_tmra_init_t is NOT specified
  90. as @ref TMRA_CLK_DIV1 */
  91. uint16_t u16StopPolarity; /*!< Specifies the polarity when the counter stop counting.
  92. This parameter can be a value of @ref TMRA_PWM_Polarity */
  93. uint16_t u16CompareMatchPolarity; /*!< Specifies the polarity when the counter matches the compare register.
  94. This parameter can be a value of @ref TMRA_PWM_Polarity */
  95. uint16_t u16PeriodMatchPolarity; /*!< Specifies the polarity when the counter matches the period register.
  96. This parameter can be a value of @ref TMRA_PWM_Polarity */
  97. } stc_tmra_pwm_init_t;
  98. /**
  99. * @}
  100. */
  101. /*******************************************************************************
  102. * Global pre-processor symbols/macros ('#define')
  103. ******************************************************************************/
  104. /**
  105. * @defgroup TMRA_Global_Macros TMRA Global Macros
  106. * @{
  107. */
  108. /**
  109. * @defgroup TMRA_Count_Src TMRA Count Source
  110. * @{
  111. */
  112. #define TMRA_CNT_SRC_SW (0U) /*!< Clock source is PCLK. */
  113. #define TMRA_CNT_SRC_HW (1U) /*!< Clock source is from external pin or peripheral event. */
  114. /**
  115. * @}
  116. */
  117. /**
  118. * @defgroup TMRA_Channel TMRA Channel
  119. * @{
  120. */
  121. #define TMRA_CH1 (0U) /*!< Channel 1 of TMRA. */
  122. #define TMRA_CH2 (1U) /*!< Channel 2 of TMRA. */
  123. #define TMRA_CH3 (2U) /*!< Channel 3 of TMRA. */
  124. #define TMRA_CH4 (3U) /*!< Channel 4 of TMRA. */
  125. #define TMRA_CH5 (4U) /*!< Channel 5 of TMRA. */
  126. #define TMRA_CH6 (5U) /*!< Channel 6 of TMRA. */
  127. #define TMRA_CH7 (6U) /*!< Channel 7 of TMRA. */
  128. #define TMRA_CH8 (7U) /*!< Channel 8 of TMRA. */
  129. /**
  130. * @}
  131. */
  132. /**
  133. * @defgroup TMRA_Count_Dir TMRA Count Direction
  134. * @{
  135. */
  136. #define TMRA_DIR_DOWN (0x0U) /*!< TMRA count down. */
  137. #define TMRA_DIR_UP (TMRA_BCSTR_DIR) /*!< TMRA count up. */
  138. /**
  139. * @}
  140. */
  141. /**
  142. * @defgroup TMRA_Count_Mode TMRA Count Mode
  143. * @{
  144. */
  145. #define TMRA_MD_SAWTOOTH (0x0U) /*!< Count mode is sawtooth wave. */
  146. #define TMRA_MD_TRIANGLE (TMRA_BCSTR_MODE) /*!< Count mode is triangle wave. */
  147. /**
  148. * @}
  149. */
  150. /**
  151. * @defgroup TMRA_Function_Mode TMRA TMRA Function Mode
  152. * @{
  153. */
  154. #define TMRA_FUNC_CMP (0x0U) /*!< Function mode of TMRA channel is ouput compare. */
  155. #define TMRA_FUNC_CAPT (TMRA_CCONR_CAPMD) /*!< Function mode of TMRA channel is input capture. */
  156. /**
  157. * @}
  158. */
  159. /**
  160. * @defgroup TMRA_Count_Reload_En TMRA Count Reload
  161. * @{
  162. */
  163. #define TMRA_CNT_RELOAD_DISABLE (TMRA_BCSTR_OVSTP) /*!< Stop when counter overflow/underflow. */
  164. #define TMRA_CNT_RELOAD_ENABLE (0U) /*!< When counter overflow/underflow, counter reload to continue counting. */
  165. /**
  166. * @}
  167. */
  168. /**
  169. * @defgroup TMRA_Clock_Divider TMRA Clock Divider
  170. * @{
  171. */
  172. #define TMRA_CLK_DIV1 (0x0U) /*!< The clock source of TMRA is PCLK. */
  173. #define TMRA_CLK_DIV2 (0x1U << TMRA_BCSTR_CKDIV_POS) /*!< The clock source of TMRA is PCLK / 2. */
  174. #define TMRA_CLK_DIV4 (0x2U << TMRA_BCSTR_CKDIV_POS) /*!< The clock source of TMRA is PCLK / 4. */
  175. #define TMRA_CLK_DIV8 (0x3U << TMRA_BCSTR_CKDIV_POS) /*!< The clock source of TMRA is PCLK / 8. */
  176. #define TMRA_CLK_DIV16 (0x4U << TMRA_BCSTR_CKDIV_POS) /*!< The clock source of TMRA is PCLK / 16. */
  177. #define TMRA_CLK_DIV32 (0x5U << TMRA_BCSTR_CKDIV_POS) /*!< The clock source of TMRA is PCLK / 32. */
  178. #define TMRA_CLK_DIV64 (0x6U << TMRA_BCSTR_CKDIV_POS) /*!< The clock source of TMRA is PCLK / 64. */
  179. #define TMRA_CLK_DIV128 (0x7U << TMRA_BCSTR_CKDIV_POS) /*!< The clock source of TMRA is PCLK / 128. */
  180. #define TMRA_CLK_DIV256 (0x8U << TMRA_BCSTR_CKDIV_POS) /*!< The clock source of TMRA is PCLK / 256. */
  181. #define TMRA_CLK_DIV512 (0x9U << TMRA_BCSTR_CKDIV_POS) /*!< The clock source of TMRA is PCLK / 512. */
  182. #define TMRA_CLK_DIV1024 (0xAU << TMRA_BCSTR_CKDIV_POS) /*!< The clock source of TMRA is PCLK / 1024. */
  183. /**
  184. * @}
  185. */
  186. /**
  187. * @defgroup TMRA_Filter_Pin TMRA Pin With Filter
  188. * @{
  189. */
  190. #define TMRA_PIN_TRIG (0U) /*!< Pin TIMA_<t>_TRIG. */
  191. #define TMRA_PIN_CLKA (1U) /*!< Pin TIMA_<t>_CLKA. */
  192. #define TMRA_PIN_CLKB (2U) /*!< Pin TIMA_<t>_CLKB. */
  193. #define TMRA_PIN_PWM1 (3U) /*!< Pin TIMA_<t>_PWM1. */
  194. #define TMRA_PIN_PWM2 (4U) /*!< Pin TIMA_<t>_PWM2. */
  195. #define TMRA_PIN_PWM3 (5U) /*!< Pin TIMA_<t>_PWM3. */
  196. #define TMRA_PIN_PWM4 (6U) /*!< Pin TIMA_<t>_PWM4. */
  197. #define TMRA_PIN_PWM5 (7U) /*!< Pin TIMA_<t>_PWM5. */
  198. #define TMRA_PIN_PWM6 (8U) /*!< Pin TIMA_<t>_PWM6. */
  199. #define TMRA_PIN_PWM7 (9U) /*!< Pin TIMA_<t>_PWM7. */
  200. #define TMRA_PIN_PWM8 (10U) /*!< Pin TIMA_<t>_PWM8. */
  201. /**
  202. * @}
  203. */
  204. /**
  205. * @defgroup TMRA_Hard_Count_Up_Condition TMRA Hardware Count Up Condition
  206. * @note Symmetric units: unit 1 and 2; unit 3 and 4; ...; unit 11 and 12.
  207. * @{
  208. */
  209. #define TMRA_CNT_UP_COND_INVD (0U) /*!< TMRA hardware count up condition is INVALID. */
  210. #define TMRA_CNT_UP_COND_CLKA_LOW_CLKB_RISING (TMRA_HCUPR_HCUP0) /*!< When CLKA is low, a rising edge is sampled on CLKB, the counter register counts up. */
  211. #define TMRA_CNT_UP_COND_CLKA_LOW_CLKB_FALLING (TMRA_HCUPR_HCUP1) /*!< When CLKA is low, a falling edge is sampled on CLKB, the counter register counts up. */
  212. #define TMRA_CNT_UP_COND_CLKA_HIGH_CLKB_RISING (TMRA_HCUPR_HCUP2) /*!< When CLKA is high, a rising edge is sampled on CLKB, the counter register counts up. */
  213. #define TMRA_CNT_UP_COND_CLKA_HIGH_CLKB_FALLING (TMRA_HCUPR_HCUP3) /*!< When CLKA is high, a falling edge is sampled on CLKB, the counter register counts up. */
  214. #define TMRA_CNT_UP_COND_CLKB_LOW_CLKA_RISING (TMRA_HCUPR_HCUP4) /*!< When CLKB is low, a rising edge is sampled on CLKA, the counter register counts up. */
  215. #define TMRA_CNT_UP_COND_CLKB_LOW_CLKA_FALLING (TMRA_HCUPR_HCUP5) /*!< When CLKB is low, a falling edge is sampled on CLKA, the counter register counts up. */
  216. #define TMRA_CNT_UP_COND_CLKB_HIGH_CLKA_RISING (TMRA_HCUPR_HCUP6) /*!< When CLKB is high, a rising edge is sampled on CLKA, the counter register counts up. */
  217. #define TMRA_CNT_UP_COND_CLKB_HIGH_CLKA_FALLING (TMRA_HCUPR_HCUP7) /*!< When CLKB is high, a falling edge is sampled on CLKA, the counter register counts up. */
  218. #define TMRA_CNT_UP_COND_TRIG_RISING (TMRA_HCUPR_HCUP8) /*!< When a rising edge occurred on TRIG, the counter register counts up. */
  219. #define TMRA_CNT_UP_COND_TRIG_FALLING (TMRA_HCUPR_HCUP9) /*!< When a falling edge occurred on TRIG, the counter register counts up. */
  220. #define TMRA_CNT_UP_COND_EVT (TMRA_HCUPR_HCUP10) /*!< When the event specified by TMRA_HTSSR occurred, the counter register counts up. */
  221. #define TMRA_CNT_UP_COND_SYM_OVF (TMRA_HCUPR_HCUP11) /*!< When the symmetric unit overflow, the counter register counts up. */
  222. #define TMRA_CNT_UP_COND_SYM_UDF (TMRA_HCUPR_HCUP12) /*!< When the symmetric unit underflow, the counter register counts up. */
  223. #define TMRA_CNT_UP_COND_ALL (0x1FFFU)
  224. /**
  225. * @}
  226. */
  227. /**
  228. * @defgroup TMRA_Hard_Count_Down_Condition TMRA Hardware Count Down Condition
  229. * @note Symmetric units: unit 1 and 2; unit 3 and 4; ...; unit 11 and 12.
  230. * @{
  231. */
  232. #define TMRA_CNT_DOWN_COND_INVD (0U) /*!< TMRA hardware count down condition is INVALID. */
  233. #define TMRA_CNT_DOWN_COND_CLKA_LOW_CLKB_RISING (TMRA_HCDOR_HCDO0) /*!< When CLKA is low, a rising edge is sampled on CLKB, the counter register counts down. */
  234. #define TMRA_CNT_DOWN_COND_CLKA_LOW_CLKB_FALLING (TMRA_HCDOR_HCDO1) /*!< When CLKA is low, a falling edge is sampled on CLKB, the counter register counts down. */
  235. #define TMRA_CNT_DOWN_COND_CLKA_HIGH_CLKB_RISING (TMRA_HCDOR_HCDO2) /*!< When CLKA is high, a rising edge is sampled on CLKB, the counter register counts down. */
  236. #define TMRA_CNT_DOWN_COND_CLKA_HIGH_CLKB_FALLING (TMRA_HCDOR_HCDO3) /*!< When CLKA is high, a falling edge is sampled on CLKB, the counter register counts down. */
  237. #define TMRA_CNT_DOWN_COND_CLKB_LOW_CLKA_RISING (TMRA_HCDOR_HCDO4) /*!< When CLKB is low, a rising edge is sampled on CLKA, the counter register counts down. */
  238. #define TMRA_CNT_DOWN_COND_CLKB_LOW_CLKA_FALLING (TMRA_HCDOR_HCDO5) /*!< When CLKB is low, a falling edge is sampled on CLKA, the counter register counts down. */
  239. #define TMRA_CNT_DOWN_COND_CLKB_HIGH_CLKA_RISING (TMRA_HCDOR_HCDO6) /*!< When CLKB is high, a rising edge is sampled on CLKA, the counter register counts down. */
  240. #define TMRA_CNT_DOWN_COND_CLKB_HIGH_CLKA_FALLING (TMRA_HCDOR_HCDO7) /*!< When CLKB is high, a falling edge is sampled on CLKA, the counter register counts down. */
  241. #define TMRA_CNT_DOWN_COND_TRIG_RISING (TMRA_HCDOR_HCDO8) /*!< When a rising edge occurred on TRIG, the counter register counts down. */
  242. #define TMRA_CNT_DOWN_COND_TRIG_FALLING (TMRA_HCDOR_HCDO9) /*!< When a falling edge occurred on TRIG, the counter register counts down. */
  243. #define TMRA_CNT_DOWN_COND_EVT (TMRA_HCDOR_HCDO10) /*!< When the event specified by TMRA_HTSSR occurred, the counter register counts down. */
  244. #define TMRA_CNT_DOWN_COND_SYM_OVF (TMRA_HCDOR_HCDO11) /*!< When the symmetric unit overflow, the counter register counts down. */
  245. #define TMRA_CNT_DOWN_COND_SYM_UDF (TMRA_HCDOR_HCDO12) /*!< When the symmetric unit underflow, the counter register counts down. */
  246. #define TMRA_CNT_DOWN_COND_ALL (0x1FFFU)
  247. /**
  248. * @}
  249. */
  250. /**
  251. * @defgroup TMRA_Interrupt_Type TMRA Interrupt Type
  252. * @{
  253. */
  254. #define TMRA_INT_OVF (1UL << 12U) /*!< The interrupt of counting overflow. */
  255. #define TMRA_INT_UDF (1UL << 13U) /*!< The interrupt of counting underflow. */
  256. #define TMRA_INT_CMP_CH1 (1UL << 16U) /*!< The interrupt of compare-match of channel 1. */
  257. #define TMRA_INT_CMP_CH2 (1UL << 17U) /*!< The interrupt of compare-match of channel 2. */
  258. #define TMRA_INT_CMP_CH3 (1UL << 18U) /*!< The interrupt of compare-match of channel 3. */
  259. #define TMRA_INT_CMP_CH4 (1UL << 19U) /*!< The interrupt of compare-match of channel 4. */
  260. #define TMRA_INT_CMP_CH5 (1UL << 20U) /*!< The interrupt of compare-match of channel 5. */
  261. #define TMRA_INT_CMP_CH6 (1UL << 21U) /*!< The interrupt of compare-match of channel 6. */
  262. #define TMRA_INT_CMP_CH7 (1UL << 22U) /*!< The interrupt of compare-match of channel 7. */
  263. #define TMRA_INT_CMP_CH8 (1UL << 23U) /*!< The interrupt of compare-match of channel 8. */
  264. #define TMRA_INT_ALL (0xFF3000UL)
  265. /**
  266. * @}
  267. */
  268. /**
  269. * @defgroup TMRA_Event_Type TMRA Event Type
  270. * @{
  271. */
  272. #define TMRA_EVT_CMP_CH1 (TMRA_ECONR_ETEN1) /*!< The event of compare-match of channel 1. */
  273. #define TMRA_EVT_CMP_CH2 (TMRA_ECONR_ETEN2) /*!< The event of compare-match of channel 2. */
  274. #define TMRA_EVT_CMP_CH3 (TMRA_ECONR_ETEN3) /*!< The event of compare-match of channel 3. */
  275. #define TMRA_EVT_CMP_CH4 (TMRA_ECONR_ETEN4) /*!< The event of compare-match of channel 4. */
  276. #define TMRA_EVT_CMP_CH5 (TMRA_ECONR_ETEN5) /*!< The event of compare-match of channel 5. */
  277. #define TMRA_EVT_CMP_CH6 (TMRA_ECONR_ETEN6) /*!< The event of compare-match of channel 6. */
  278. #define TMRA_EVT_CMP_CH7 (TMRA_ECONR_ETEN7) /*!< The event of compare-match of channel 7. */
  279. #define TMRA_EVT_CMP_CH8 (TMRA_ECONR_ETEN8) /*!< The event of compare-match of channel 8. */
  280. #define TMRA_EVT_ALL (TMRA_EVT_CMP_CH1 | TMRA_EVT_CMP_CH2 | TMRA_EVT_CMP_CH3 | \
  281. TMRA_EVT_CMP_CH4 | TMRA_EVT_CMP_CH5 | TMRA_EVT_CMP_CH6 | \
  282. TMRA_EVT_CMP_CH7 | TMRA_EVT_CMP_CH8)
  283. /**
  284. * @}
  285. */
  286. /**
  287. * @defgroup TMRA_Status_Flag TMRA Status Flag
  288. * @{
  289. */
  290. #define TMRA_FLAG_OVF (1UL << 14U) /*!< The flag of counting overflow. */
  291. #define TMRA_FLAG_UDF (1UL << 15U) /*!< The flag of counting underflow. */
  292. #define TMRA_FLAG_CMP_CH1 (1UL << 16U) /*!< The flag of compare-match of channel 1. */
  293. #define TMRA_FLAG_CMP_CH2 (1UL << 17U) /*!< The flag of compare-match of channel 2. */
  294. #define TMRA_FLAG_CMP_CH3 (1UL << 18U) /*!< The flag of compare-match of channel 3. */
  295. #define TMRA_FLAG_CMP_CH4 (1UL << 19U) /*!< The flag of compare-match of channel 4. */
  296. #define TMRA_FLAG_CMP_CH5 (1UL << 20U) /*!< The flag of compare-match of channel 5. */
  297. #define TMRA_FLAG_CMP_CH6 (1UL << 21U) /*!< The flag of compare-match of channel 6. */
  298. #define TMRA_FLAG_CMP_CH7 (1UL << 22U) /*!< The flag of compare-match of channel 7. */
  299. #define TMRA_FLAG_CMP_CH8 (1UL << 23U) /*!< The flag of compare-match of channel 8. */
  300. #define TMRA_FLAG_CAPT_AGAIN_CH1 (1UL << 24U) /*!< The flag of capture occurs again after successful capture of channel 1. */
  301. #define TMRA_FLAG_CAPT_AGAIN_CH2 (1UL << 25U) /*!< The flag of capture occurs again after successful capture of channel 2. */
  302. #define TMRA_FLAG_CAPT_AGAIN_CH3 (1UL << 26U) /*!< The flag of capture occurs again after successful capture of channel 3. */
  303. #define TMRA_FLAG_CAPT_AGAIN_CH4 (1UL << 27U) /*!< The flag of capture occurs again after successful capture of channel 4. */
  304. #define TMRA_FLAG_CAPT_AGAIN_CH5 (1UL << 28U) /*!< The flag of capture occurs again after successful capture of channel 5. */
  305. #define TMRA_FLAG_CAPT_AGAIN_CH6 (1UL << 29U) /*!< The flag of capture occurs again after successful capture of channel 6. */
  306. #define TMRA_FLAG_CAPT_AGAIN_CH7 (1UL << 30U) /*!< The flag of capture occurs again after successful capture of channel 7. */
  307. #define TMRA_FLAG_CAPT_AGAIN_CH8 (1UL << 31U) /*!< The flag of capture occurs again after successful capture of channel 8. */
  308. #define TMRA_FLAG_ALL (0xFFFFC00UL)
  309. /**
  310. * @}
  311. */
  312. /**
  313. * @defgroup TMRA_Capture_Cond TMRA Capture Condition
  314. * @note 'TMRA_CAPT_COND_TRIG_RISING' and 'TMRA_CAPT_COND_TRIG_FALLING' are only valid for channel 4.
  315. * @{
  316. */
  317. #define TMRA_CAPT_COND_INVD (0x0U) /*!< The condition of capture is INVALID. */
  318. #define TMRA_CAPT_COND_PWM_RISING (TMRA_CCONR_HICP0) /*!< The condition of capture is a rising edge is sampled on pin TIMA_<t>_PWMn. */
  319. #define TMRA_CAPT_COND_PWM_FALLING (TMRA_CCONR_HICP1) /*!< The condition of capture is a falling edge is sampled on pin TIMA_<t>_PWMn. */
  320. #define TMRA_CAPT_COND_EVT (TMRA_CCONR_HICP2) /*!< The condition of capture is the specified event occurred. */
  321. #define TMRA_CAPT_COND_TRIG_RISING (TMRA_CCONR_HICP3) /*!< The condition of capture is a rising edge is sampled on pin TIMA_<t>_TRIG.
  322. This condition is only valid for channle 3. */
  323. #define TMRA_CAPT_COND_TRIG_FALLING (TMRA_CCONR_HICP4) /*!< The condition of capture is a falling edge is sampled on pin TIMA_<t>_TRIG.
  324. This condition is only valid for channle 3. */
  325. #define TMRA_CAPT_COND_XOR_RISING (TMRA_CCONR_HICP5) /*!< The condition of capture is TIMA_<t>_CLKA XOR TIMA_<t>_CLKB == 1.
  326. This condition is only valid for channle 4. */
  327. #define TMRA_CAPT_COND_XOR_FALLING (TMRA_CCONR_HICP6) /*!< The condition of capture is TIMA_<t>_CLKA XOR TIMA_<t>_CLKB == 0.
  328. This condition is only valid for channle 4. */
  329. #define TMRA_CAPT_COND_ALL (TMRA_CAPT_COND_PWM_RISING | TMRA_CAPT_COND_PWM_FALLING | \
  330. TMRA_CAPT_COND_EVT | TMRA_CAPT_COND_TRIG_RISING | \
  331. TMRA_CAPT_COND_TRIG_FALLING | TMRA_CAPT_COND_XOR_RISING | \
  332. TMRA_CAPT_COND_XOR_FALLING)
  333. /**
  334. * @}
  335. */
  336. /**
  337. * @defgroup TMRA_Cmp_Value_Buf_Trans_Cond TMRA Compare Value Buffer Transmission Condition
  338. * @{
  339. */
  340. #define TMRA_BUF_TRANS_COND_OVF_UDF_CLR (0x0U) /*!< This configuration value applies to non-triangular wave counting mode.
  341. When counting overflow or underflow or counting register was cleared,
  342. transfer CMPARm(m=2,4,6,8,...) to CMPARn(n=1,3,5,7,...). */
  343. #define TMRA_BUF_TRANS_COND_PEAK (TMRA_BCONR_BSE0) /*!< In triangle wave count mode, when count reached peak,
  344. transfer CMPARm(m=2,4,6,8,...) to CMPARn(n=1,3,5,7,...). */
  345. #define TMRA_BUF_TRANS_COND_VALLEY (TMRA_BCONR_BSE1) /*!< In triangle wave count mode, when count reached valley,
  346. transfer CMPARm(m=2,4,6,8,...) to CMPARn(n=1,3,5,7,.... */
  347. #define TMRA_BUF_TRANS_COND_PEAK_VALLEY (TMRA_BCONR_BSE1 | \
  348. TMRA_BCONR_BSE0) /*!< In triangle wave count mode, when count reached peak or valley,
  349. transfer CMPARm(m=2,4,6,8,...) to CMPARn(n=1,3,5,7,...). */
  350. /**
  351. * @}
  352. */
  353. /**
  354. * @defgroup TMRA_Filter_Clock_Divider TMRA Filter Clock Divider
  355. * @{
  356. */
  357. #define TMRA_FILTER_CLK_DIV1 (0x0U) /*!< The filter clock is the clock of timerA / 1 */
  358. #define TMRA_FILTER_CLK_DIV4 (0x1U) /*!< The filter clock is the clock of timerA / 4 */
  359. #define TMRA_FILTER_CLK_DIV16 (0x2U) /*!< The filter clock is the clock of timerA / 16 */
  360. #define TMRA_FILTER_CLK_DIV64 (0x3U) /*!< The filter clock is the clock of timerA / 64 */
  361. /**
  362. * @}
  363. */
  364. /**
  365. * @defgroup TMRA_Counter_State TMRA Counter State
  366. * @{
  367. */
  368. #define TMRA_CNT_STAT_START (0U) /*!< Counter start counting. */
  369. #define TMRA_CNT_STAT_STOP (1U) /*!< Counter stop counting. */
  370. #define TMRA_CNT_STAT_MATCH_CMP (2U) /*!< Counter value matchs the compare value. */
  371. #define TMRA_CNT_STAT_MATCH_PERIOD (3U) /*!< Counter value matchs the period value. */
  372. /**
  373. * @}
  374. */
  375. /**
  376. * @defgroup TMRA_PWM_Polarity TMRA PWM Polarity
  377. * @{
  378. */
  379. #define TMRA_PWM_LOW (0x0U) /*!< PWM output low. */
  380. #define TMRA_PWM_HIGH (0x1U) /*!< PWM output high. */
  381. #define TMRA_PWM_HOLD (0x2U) /*!< PWM output holds the current polarity. */
  382. #define TMRA_PWM_INVT (0x3U) /*!< PWM output reverses the current polarity. */
  383. /**
  384. * @}
  385. */
  386. /**
  387. * @defgroup TMRA_PWM_Force_Polarity TMRA PWM Force Polarity
  388. * @{
  389. */
  390. #define TMRA_PWM_FORCE_INVD (0x0U) /*!< Force polarity is invalid. */
  391. #define TMRA_PWM_FORCE_LOW (TMRA_PCONR_FORC_1) /*!< Force the PWM output low at the beginning of the next cycle.
  392. The beginning of the next cycle: overflow position or underflow position
  393. of sawtooth wave; valley position of triangle wave. */
  394. #define TMRA_PWM_FORCE_HIGH (TMRA_PCONR_FORC) /*!< Force the PWM output high at the beginning of the next cycle.
  395. The beginning of the next cycle: overflow position or underflow position
  396. of sawtooth wave; valley position of triangle wave. */
  397. /**
  398. * @}
  399. */
  400. /**
  401. * @defgroup TMRA_Hardware_Start_Condition TMRA Hardware Start Condition
  402. * @{
  403. */
  404. #define TMRA_START_COND_INVD (0x0U) /*!< The condition of start is INVALID. */
  405. #define TMRA_START_COND_TRIG_RISING (TMRA_HCONR_HSTA0) /*!< 1. Sync start is invalid: The condition is that a rising edge is sampled on TRIG of the current TMRA unit.
  406. 2. Sync start is valid: The condition is that a rising edge is sampled on TRIG of the symmetric TMRA unit. */
  407. #define TMRA_START_COND_TRIG_FALLING (TMRA_HCONR_HSTA1) /*!< 1. Sync start is invalid: The condition is that a falling edge is sampled on TRIG of the current TMRA unit.
  408. 2. Sync start is valid: The condition is that a falling edge is sampled on TRIG of the symmetric TMRA unit. */
  409. #define TMRA_START_COND_EVT (TMRA_HCONR_HSTA2) /*!< The condition is that the event which is set in register TMRA_HTSSR0 has occurred. */
  410. #define TMRA_START_COND_ALL (TMRA_START_COND_TRIG_RISING | TMRA_START_COND_TRIG_FALLING | \
  411. TMRA_START_COND_EVT)
  412. /**
  413. * @}
  414. */
  415. /**
  416. * @defgroup TMRA_Hardware_Stop_Condition TMRA Hardware Stop Condition
  417. * @{
  418. */
  419. #define TMRA_STOP_COND_INVD (0x0U) /*!< The condition of stop is INVALID. */
  420. #define TMRA_STOP_COND_TRIG_RISING (TMRA_HCONR_HSTP0) /*!< The condition is that a rising edge is sampled on pin TRIG of the current TMRA unit. */
  421. #define TMRA_STOP_COND_TRIG_FALLING (TMRA_HCONR_HSTP1) /*!< The condition is that a falling edge is sampled on pin TRIG of the current TMRA unit. */
  422. #define TMRA_STOP_COND_EVT (TMRA_HCONR_HSTP2) /*!< The condition is that the event which is set in register TMRA_HTSSR0 has occurred. */
  423. #define TMRA_STOP_COND_ALL (TMRA_STOP_COND_TRIG_RISING | TMRA_STOP_COND_TRIG_FALLING | \
  424. TMRA_STOP_COND_EVT)
  425. /**
  426. * @}
  427. */
  428. /**
  429. * @defgroup TMRA_Hardware_Clear_Condition TMRA Hardware Clear Condition
  430. * @note Symmetric units: unit 1 and 2; unit 3 and 4; ... ; unit 11 and 12.
  431. * @{
  432. */
  433. #define TMRA_CLR_COND_INVD (0x0U) /*!< The condition of clear is INVALID. */
  434. #define TMRA_CLR_COND_TRIG_RISING (TMRA_HCONR_HCLE0) /*!< The condition is that a rising edge is sampled on TRIG of the current TMRA unit. */
  435. #define TMRA_CLR_COND_TRIG_FALLING (TMRA_HCONR_HCLE1) /*!< The condition is that a falling edge is sampled on TRIG of the current TMRA unit. */
  436. #define TMRA_CLR_COND_EVT (TMRA_HCONR_HCLE2) /*!< The condition is that the event which is set in register TMRA_HTSSR0 has occurred. */
  437. #define TMRA_CLR_COND_SYM_TRIG_RISING (TMRA_HCONR_HCLE3) /*!< The condition is that a rising edge is sampled on TRIG of the symmetric unit. */
  438. #define TMRA_CLR_COND_SYM_TRIG_FALLING (TMRA_HCONR_HCLE4) /*!< The condition is that a falling edge is sampled on TRIG of the symmetric unit. */
  439. #define TMRA_CLR_COND_PWM3_RISING (TMRA_HCONR_HCLE5) /*!< The condition is that a rising edge is sampled on PWM3 of the current TMRA unit. */
  440. #define TMRA_CLR_COND_PWM3_FALLING (TMRA_HCONR_HCLE6) /*!< The condition is that a falling edge is sampled on PWM3 of the current TMRA unit. */
  441. #define TMRA_CLR_COND_ALL (TMRA_CLR_COND_TRIG_RISING | TMRA_CLR_COND_TRIG_FALLING | \
  442. TMRA_CLR_COND_EVT| TMRA_CLR_COND_SYM_TRIG_RISING | \
  443. TMRA_CLR_COND_SYM_TRIG_FALLING | TMRA_CLR_COND_PWM3_RISING| \
  444. TMRA_CLR_COND_PWM3_FALLING)
  445. /**
  446. * @}
  447. */
  448. /**
  449. * @}
  450. */
  451. /*******************************************************************************
  452. * Global variable definitions ('extern')
  453. ******************************************************************************/
  454. /*******************************************************************************
  455. Global function prototypes (definition in C source)
  456. ******************************************************************************/
  457. /**
  458. * @addtogroup TMRA_Global_Functions
  459. * @{
  460. */
  461. /* Base count(use software clock PCLK/HCLK) */
  462. int32_t TMRA_Init(CM_TMRA_TypeDef *TMRAx, const stc_tmra_init_t *pstcTmraInit);
  463. int32_t TMRA_StructInit(stc_tmra_init_t *pstcTmraInit);
  464. void TMRA_SetCountMode(CM_TMRA_TypeDef *TMRAx, uint16_t u16Mode);
  465. void TMRA_SetCountDir(CM_TMRA_TypeDef *TMRAx, uint16_t u16Dir);
  466. void TMRA_SetClockDiv(CM_TMRA_TypeDef *TMRAx, uint16_t u16Div);
  467. /* Hardware count */
  468. void TMRA_HWCountUpCondCmd(CM_TMRA_TypeDef *TMRAx, uint16_t u16Cond, en_functional_state_t enNewState);
  469. void TMRA_HWCountDownCondCmd(CM_TMRA_TypeDef *TMRAx, uint16_t u16Cond, en_functional_state_t enNewState);
  470. /* Set function mode */
  471. void TMRA_SetFunc(CM_TMRA_TypeDef *TMRAx, uint32_t u32Ch, uint16_t u16Func);
  472. /* Ouput compare */
  473. int32_t TMRA_PWM_Init(CM_TMRA_TypeDef *TMRAx, uint32_t u32Ch, const stc_tmra_pwm_init_t *pstcPwmInit);
  474. int32_t TMRA_PWM_StructInit(stc_tmra_pwm_init_t *pstcPwmInit);
  475. void TMRA_PWM_OutputCmd(CM_TMRA_TypeDef *TMRAx, uint32_t u32Ch, en_functional_state_t enNewState);
  476. void TMRA_PWM_SetPolarity(CM_TMRA_TypeDef *TMRAx, uint32_t u32Ch, uint8_t u8CountState, uint16_t u16Polarity);
  477. void TMRA_PWM_SetForcePolarity(CM_TMRA_TypeDef *TMRAx, uint32_t u32Ch, uint16_t u16Polarity);
  478. /* Input capture */
  479. void TMRA_HWCaptureCondCmd(CM_TMRA_TypeDef *TMRAx, uint32_t u32Ch, uint16_t u16Cond, en_functional_state_t enNewState);
  480. /* Trigger: hardware trigger to start/stop/clear the counter */
  481. void TMRA_HWStartCondCmd(CM_TMRA_TypeDef *TMRAx, uint16_t u16Cond, en_functional_state_t enNewState);
  482. void TMRA_HWStopCondCmd(CM_TMRA_TypeDef *TMRAx, uint16_t u16Cond, en_functional_state_t enNewState);
  483. void TMRA_HWClearCondCmd(CM_TMRA_TypeDef *TMRAx, uint16_t u16Cond, en_functional_state_t enNewState);
  484. /* Filter */
  485. void TMRA_SetFilterClockDiv(CM_TMRA_TypeDef *TMRAx, uint32_t u32Pin, uint16_t u16Div);
  486. void TMRA_FilterCmd(CM_TMRA_TypeDef *TMRAx, uint32_t u32Pin, en_functional_state_t enNewState);
  487. /* Global */
  488. void TMRA_DeInit(CM_TMRA_TypeDef *TMRAx);
  489. /* Counting direction, period value, counter value, compare value */
  490. uint16_t TMRA_GetCountDir(const CM_TMRA_TypeDef *TMRAx);
  491. void TMRA_SetPeriodValue(CM_TMRA_TypeDef *TMRAx, uint32_t u32Value);
  492. uint32_t TMRA_GetPeriodValue(const CM_TMRA_TypeDef *TMRAx);
  493. void TMRA_SetCountValue(CM_TMRA_TypeDef *TMRAx, uint32_t u32Value);
  494. uint32_t TMRA_GetCountValue(const CM_TMRA_TypeDef *TMRAx);
  495. void TMRA_SetCompareValue(CM_TMRA_TypeDef *TMRAx, uint32_t u32Ch, uint32_t u32Value);
  496. uint32_t TMRA_GetCompareValue(const CM_TMRA_TypeDef *TMRAx, uint32_t u32Ch);
  497. /* Sync start */
  498. void TMRA_SyncStartCmd(CM_TMRA_TypeDef *TMRAx, en_functional_state_t enNewState);
  499. /* Reload and continue counting when overflow/underflow */
  500. void TMRA_CountReloadCmd(CM_TMRA_TypeDef *TMRAx, en_functional_state_t enNewState);
  501. void TMRA_SetCompareBufCond(CM_TMRA_TypeDef *TMRAx, uint32_t u32Ch, uint16_t u16Cond);
  502. void TMRA_CompareBufCmd(CM_TMRA_TypeDef *TMRAx, uint32_t u32Ch, en_functional_state_t enNewState);
  503. en_flag_status_t TMRA_GetStatus(const CM_TMRA_TypeDef *TMRAx, uint32_t u32Flag);
  504. void TMRA_ClearStatus(CM_TMRA_TypeDef *TMRAx, uint32_t u32Flag);
  505. void TMRA_IntCmd(CM_TMRA_TypeDef *TMRAx, uint32_t u32IntType, en_functional_state_t enNewState);
  506. void TMRA_EventCmd(CM_TMRA_TypeDef *TMRAx, uint32_t u32EventType, en_functional_state_t enNewState);
  507. void TMRA_Start(CM_TMRA_TypeDef *TMRAx);
  508. void TMRA_Stop(CM_TMRA_TypeDef *TMRAx);
  509. /**
  510. * @}
  511. */
  512. #endif /* LL_TMRA_ENABLE */
  513. /**
  514. * @}
  515. */
  516. /**
  517. * @}
  518. */
  519. #ifdef __cplusplus
  520. }
  521. #endif
  522. #endif /* __HC32_LL_TMRA_H__ */
  523. /*******************************************************************************
  524. * EOF (not truncated)
  525. ******************************************************************************/