tae32f53xx_ll_tmr.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. /**
  2. ******************************************************************************
  3. * @file tae32f53xx_ll_tmr.h
  4. * @author MCD Application Team
  5. * @brief Header for TMR LL module driver
  6. *
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2020 Tai-Action.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software is licensed by Tai-Action under BSD 3-Clause license,
  14. * the "License"; You may not use this file except in compliance with the
  15. * License. You may obtain a copy of the License at:
  16. * opensource.org/licenses/BSD-3-Clause
  17. *
  18. ******************************************************************************
  19. */
  20. /* Define to prevent recursive inclusion -------------------------------------*/
  21. #ifndef _TAE32F53XX_LL_TMR_H_
  22. #define _TAE32F53XX_LL_TMR_H_
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif /* __cplusplus */
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "tae32f53xx_ll_def.h"
  28. /** @addtogroup TAE32F53xx_LL_Driver
  29. * @{
  30. */
  31. /** @addtogroup TMR_LL
  32. * @{
  33. */
  34. /* Exported types ------------------------------------------------------------*/
  35. /** @defgroup TMR_LL_Exported_Types TMR LL Exported Types
  36. * @brief TMR LL Exported Types
  37. * @{
  38. */
  39. /**
  40. * @brief TMR Continuous Mode
  41. */
  42. typedef enum {
  43. TMR_CONTINUOUS_MODE_ENABLE = 0x00000000U, /*!< TMR performed in Continuous counting mode */
  44. TMR_CONTINUOUS_MODE_DISABLE = TMR_CR_MS, /*!< TMR performed in Single counting mode */
  45. } TMR_ContinuousETypeDef;
  46. /**
  47. * @brief TMR Update Event Enable
  48. */
  49. typedef enum {
  50. TMR_UPDATE_ENABLE = 0x00000000U, /*!< Update event generation enabled */
  51. TMR_UPDATE_DISABLE = TMR_CR_UDIS, /*!< Update event generation disabled */
  52. } TMR_UpdateETypeDef;
  53. /**
  54. * @brief TMR_Update_Request_Source TMR Update Request Source
  55. */
  56. typedef enum {
  57. TMR_UPDATE_SOURCE_REGULAR = 0x00000000U, /*!< Counter overflow or Setting the UG bit generates an update request */
  58. TMR_UPDATE_SOURCE_COUNTER = TMR_CR_URS, /*!< Only counter overflow generates an update request */
  59. } TMR_UpdateSrcETypeDef;
  60. /**
  61. * @brief TMR Auto-Reload Preload
  62. */
  63. typedef enum {
  64. TMR_AUTORELOAD_PRELOAD_DISABLE = 0x00000000U, /*!< Disable auto-reload preload feature */
  65. TMR_AUTORELOAD_PRELOAD_ENABLE = TMR_CR_ARPE, /*!< Enable auto-reload preload feature */
  66. } TMR_AutoReloadETypeDef;
  67. /**
  68. * @brief TMR Clock Souce
  69. */
  70. typedef enum {
  71. TMR_CLKSOURCE_INTERNAL = TMR_CR_CKSRC_0, /*!< Internal clock source */
  72. TMR_CLKSOURCE_ETR_RISING = TMR_CR_CKSRC_1, /*!< External clock source rising edge */
  73. TMR_CLKSOURCE_ETR_FALLING = TMR_CR_CKSRC_2, /*!< External clock source falling edge */
  74. TMR_CLKSOURCE_ETR_BOTHEDGE = TMR_CR_CKSRC_3, /*!< External clock source both rising and falling edge */
  75. } TMR_ClkSrcETypeDef;
  76. /**
  77. * @brief TMR PWM Wave Export
  78. */
  79. typedef enum {
  80. TMR_EXT_PWM_WAVE_DISABLE = 0x00000000U, /*!< Disable the export of the PWM Wave */
  81. TMR_EXT_PWM_WAVE_ENABLE = TMR_ETER_PWMOE, /*!< Enable the export of the PWM Wave */
  82. } TMR_Ext_PWMETypeDef;
  83. /**
  84. * @brief TMR Capture Compare Event Trigger Export
  85. */
  86. typedef enum {
  87. TMR_EXT_CC_TRIGGER_DISABLE = 0x00000000U, /*!< Disable the export of the Capture Compare Trigger */
  88. TMR_EXT_CC_TRIGGER_ENABLE = TMR_ETER_CCTE, /*!< Enable the export of the Capture Compare Trigger */
  89. } TMR_Ext_CCETypeDef;
  90. /**
  91. * @brief TMR TRGO Trigger Export
  92. */
  93. typedef enum {
  94. TMR_EXT_TRGO_TRIGGER_DISABLE = 0x00000000U, /*!< Disable the export of the TRGO signal (source from Update Event) Trigger */
  95. TMR_EXT_TRGO_TRIGGER_ENABLE = TMR_ETER_UTE, /*!< Enable the export of the TRGO signal (source from Update Event) Trigger */
  96. } TMR_Ext_TRGOETypeDef;
  97. /**
  98. * @brief TMR Event Source
  99. */
  100. typedef enum {
  101. TMR_EVENTSOURCE_UG = TMR_EGR_UG, /*!< Reinitialize the counter and generates an update of the registers */
  102. TMR_EVENTSOURCE_CCG = TMR_EGR_CCG, /*!< A capture/compare event is generated */
  103. } TMR_EventSRCETypeDef;
  104. /** @brief TMR Input Capture Selection
  105. */
  106. typedef enum {
  107. TMR_ICSELECTION_TMR0 = TMR_CCCR_ICSRS_0, /*!< TMR input capture source TMR0 io (specific to (LS)TMR0/1/2/3). */
  108. TMR_ICSELECTION_TMR4 = TMR_CCCR_ICSRS_0, /*!< TMR input capture source TMR4 io (specific to (HS)TMR4/5/6/7). */
  109. TMR_ICSELECTION_TMR1 = TMR_CCCR_ICSRS_1, /*!< TMR input capture source TMR1 io (specific to (LS)TMR0/1/2/3). */
  110. TMR_ICSELECTION_TMR5 = TMR_CCCR_ICSRS_1, /*!< TMR input capture source TMR5 io (specific to (HS)TMR4/5/6/7). */
  111. TMR_ICSELECTION_TMR2 = TMR_CCCR_ICSRS_2, /*!< TMR input capture source TMR2 io (specific to (LS)TMR0/1/2/3). */
  112. TMR_ICSELECTION_TMR6 = TMR_CCCR_ICSRS_2, /*!< TMR input capture source TMR6 io (specific to (HS)TMR4/5/6/7). */
  113. TMR_ICSELECTION_TMR3 = TMR_CCCR_ICSRS_3, /*!< TMR input capture source TMR3 io (specific to (LS)TMR0/1/2/3). */
  114. TMR_ICSELECTION_TMR7 = TMR_CCCR_ICSRS_3, /*!< TMR input capture source TMR7 io (specific to (HS)TMR4/5/6/7). */
  115. TMR_ICSELECTION_CMP0 = TMR_CCCR_ICSRS_4, /*!< The internal CMP0 output single
  116. will be selected as the input source of LSTMR or HSTMR */
  117. TMR_ICSELECTION_CMP1 = TMR_CCCR_ICSRS_5, /*!< The internal CMP1 output single
  118. will be selected as the input source of LSTMR or HSTMR */
  119. TMR_ICSELECTION_CMP2 = TMR_CCCR_ICSRS_6, /*!< The internal CMP2 output single
  120. will be selected as the input source of LSTMR or HSTMR */
  121. TMR_ICSELECTION_CMP3 = TMR_CCCR_ICSRS_7, /*!< The internal CMP3 output single
  122. will be selected as the input source of LSTMR or HSTMR */
  123. } TMR_ICSelETypeDef;
  124. /**
  125. * @brief TMR Input Capture Polarity
  126. */
  127. typedef enum {
  128. TMR_ICPOLARITY_RISING = 0x00000000U, /*!< Capture triggered by rising edge on timer input */
  129. TMR_ICPOLARITY_FALLING = TMR_CCCR_CCP_0, /*!< Capture triggered by falling edge on timer input */
  130. TMR_ICPOLARITY_BOTHEDGE = TMR_CCCR_CCP_1, /*!< Capture triggered by both rising and falling edges on timer input */
  131. } TMR_ICPolarityETypeDef;
  132. /**
  133. * @brief TMR Output Compare and PWM Modes
  134. */
  135. typedef enum {
  136. TMR_OCMODE_FROZEN = TMR_CCCR_OCM_0, /*!< Frozen */
  137. TMR_OCMODE_ACTIVE = TMR_CCCR_OCM_1, /*!< active on match */
  138. TMR_OCMODE_INACTIVE = TMR_CCCR_OCM_2, /*!< inactive on match */
  139. TMR_OCMODE_TOGGLE = TMR_CCCR_OCM_3, /*!< Toggle */
  140. TMR_OCMODE_FORCED_INACTIVE = TMR_CCCR_OCM_4, /*!< Force inactive */
  141. TMR_OCMODE_FORCED_ACTIVE = TMR_CCCR_OCM_5, /*!< Force active */
  142. TMR_OCMODE_PWM1 = TMR_CCCR_OCM_6, /*!< PWM mode 1 */
  143. TMR_OCMODE_PWM2 = TMR_CCCR_OCM_7, /*!< PWM mode 2 */
  144. } TMR_OCModeETypeDef;
  145. /**
  146. * @brief TMR_OCPreload_Enable TMR OCPreload Enable
  147. */
  148. typedef enum {
  149. TMR_OCPRELOAD_DISABLE = 0x00000000U, /*!< TMR OCPreload Disable */
  150. TMR_OCPRELOAD_ENABLE = TMR_CCCR_OCPE, /*!< TMR OCPreload Enable */
  151. } TMR_OCPreloadETypeDef;
  152. /**
  153. * @brief TMR Complementary Output Compare Polarity
  154. */
  155. typedef enum {
  156. TMR_OCPOLARITY_HIGH = 0x00000000U, /*!< Output Compare polarity active high */
  157. TMR_OCPOLARITY_LOW = TMR_CCCR_CCP_0, /*!< Output Compare polarity active low */
  158. } TMR_OCPolarityETypeDef;
  159. /**
  160. * @brief Timer Base Unit Initialization Structure definition
  161. * @note Please notice that TMR can enable either Input Capture mode or Output Compare mode.
  162. */
  163. typedef struct __TMR_TB_InitTypeDef {
  164. TMR_ClkSrcETypeDef ClockSource; /*!< Specifies the Clock Source. */
  165. uint32_t Prescaler; /*!< Specifies the prescaler value used to divide the TMR clock.
  166. This parameter can be a number in range of:
  167. For low-speed timer(TMR0/1/2/3): from Min 0x0 to Max 0x0000FFFF
  168. For high-speed timer(TMR4/5/6/7): from Min 0x0 to Max 0xFFFFFFFF */
  169. uint32_t StartValue; /*!< Specifies the timer counter start value.
  170. This parameter can be a number in range of:
  171. For low-speed timer(TMR0/1/2/3): from Min 0x0 to Max 0x0000FFFF
  172. For high-speed timer(TMR4/5/6/7): from Min 0x0 to Max 0xFFFFFFFF */
  173. uint32_t EndValue; /*!< Specifies the timer counter end value.
  174. This parameter can be a number in range of:
  175. For low-speed timer(TMR0/1/2/3): from Min 0x0 to Max 0x0000FFFF
  176. For high-speed timer(TMR4/5/6/7): from Min 0x0 to Max 0xFFFFFFFF */
  177. TMR_ContinuousETypeDef ContinuousMode; /*!< Specifies the timer continuous mode enable or disable. */
  178. TMR_AutoReloadETypeDef AutoReloadPreload; /*!< Specifies the auto-reload preload. */
  179. TMR_UpdateETypeDef UpdateEnable; /*!< Specifies the Update event enable or not. */
  180. TMR_UpdateSrcETypeDef UpdateSource; /*!< Specifies the Update request Source */
  181. } TMR_TB_InitTypeDef;
  182. /**
  183. * @brief Timer Input Capture Initialization Structure definition
  184. * @note Please notice that TMR can enable either Input Capture mode or Output Compare mode.
  185. */
  186. typedef struct __TMR_IC_InitTypeDef {
  187. LL_FuncStatusETypeDef ICEnable; /*!< Specifies enable the Input Capture feature or not.
  188. This parameter can be ENABLE or DISABLE */
  189. TMR_ICPolarityETypeDef ICPolarity; /*!< Specifies the active edge of the input signal. */
  190. TMR_ICSelETypeDef ICSelection; /*!< Specifies the input source to be used. */
  191. uint32_t ICFilter; /*!< Specifies the input capture filter.
  192. This parameter can be a number between 0x0 and 0xFF */
  193. } TMR_IC_InitTypeDef;
  194. /**
  195. * @brief Timer Output Compare Initialization Structure definition
  196. * @note Please notice that TMR can enable either Input Capture mode or Output Compare mode.
  197. */
  198. typedef struct __TMR_OC_InitTypeDef {
  199. LL_FuncStatusETypeDef OCEnable; /*!< Specifies enable the Output Compare feature or not.
  200. This parameter can be ENABLE or DISABLE */
  201. TMR_OCPolarityETypeDef OCPolarity; /*!< Specifies the output polarity. */
  202. TMR_OCPreloadETypeDef OCPreload; /*!< Timer Output Compare Preload Enable */
  203. TMR_OCModeETypeDef OCMode; /*!< Specifies the TMR mode. */
  204. uint32_t OCValue; /*!< Specifies the compare value which loaded into Capture Compare Register.
  205. This parameter can be a number in range of:
  206. For low-speed timer(TMR0/1/2/3): from Min 0x0 to Max 0x0000FFFF
  207. For high-speed timer(TMR4/5/6/7): from Min 0x0 to Max 0xFFFFFFFF */
  208. } TMR_OC_InitTypeDef;
  209. /**
  210. * @brief Timer Export Trigger Initialization Structure definition
  211. */
  212. typedef struct __TMR_EXT_InitTypeDef {
  213. LL_FuncStatusETypeDef ExtEnable; /*!< Specifies enable the Export Event Trigger feature or not.
  214. This parameter can be ENABLE or DISABLE */
  215. TMR_Ext_PWMETypeDef ExtPWMWave; /*!< Specifies PWM Wave (output compare) export to internal signal or not. */
  216. TMR_Ext_CCETypeDef ExtCCTrigger; /*!< Specifies Capture Compare Trigger Event export to internal signal or not. */
  217. TMR_Ext_TRGOETypeDef ExtTRGOTrigger;/*!< Specifies TMR TRGO signal (source from Update Event) export to internal signal or not. */
  218. } TMR_EXT_InitTypeDef;
  219. /**
  220. * @brief Timer Initialization Structure definition
  221. * @note Please notice that TMR can be configured to either Input Capture mode or Output Compare mode.
  222. * Witch means that either ICEnable or OCEnable in the Initialization Structure can be enable the feature.
  223. */
  224. typedef struct __TMR_InitTypeDef {
  225. TMR_TB_InitTypeDef TBInit; /*!< Timer Base Unit Initialization Structure definition */
  226. TMR_IC_InitTypeDef ICInit; /*!< Timer Input Capture Initialization Structure definition */
  227. TMR_OC_InitTypeDef OCInit; /*!< Timer Output Compare Initialization Structure */
  228. TMR_EXT_InitTypeDef ExtInit; /*!< Timer Export Event Trigger feature Initialization Structure */
  229. } TMR_InitTypeDef;
  230. /**
  231. * @}
  232. */
  233. /* Exported constants --------------------------------------------------------*/
  234. /** @defgroup TMR_LL_Exported_Constants TMR LL Exported Constants
  235. * @brief TMR LL Exported Constants
  236. * @{
  237. */
  238. /** @defgroup TMR_Interrupt_definition TMR Interrupt Definition
  239. * @{
  240. */
  241. #define TMR_IT_UIE TMR_CR_UIE /*!< Update interrupt */
  242. #define TMR_IT_OVIE TMR_CR_OVIE /*!< Counter Overflow interrupt */
  243. /**
  244. * @}
  245. */
  246. /** @defgroup TMR_CC_Interrupt_definition TMR Capture/Compare Interrupt Definition
  247. * @{
  248. */
  249. #define TMR_IT_ICIE TMR_CCCR_ICIE /*!< Input Capture interrupt */
  250. #define TMR_IT_ICOIE TMR_CCCR_ICOIE /*!< Input Capture OverCapture interrupt */
  251. #define TMR_IT_OCIE TMR_CCCR_OCIE /*!< Output Compare Match interrupt */
  252. /**
  253. * @}
  254. */
  255. /** @defgroup TMR_Flag_definition TMR Flag Definition
  256. * @{
  257. */
  258. #define TMR_FLAG_OVIF TMR_ISR_OVIF /*!< Timer Counter Overflow Interrupt Flag */
  259. #define TMR_FLAG_ICOIF TMR_ISR_ICOIF /*!< Timer Input Capture OverCapture Interrupt Flag */
  260. #define TMR_FLAG_ICIF TMR_ISR_ICIF /*!< Timer Input Capture Interrupt Flag */
  261. #define TMR_FLAG_OCIF TMR_ISR_OCIF /*!< Timer Output Compare Interrupt Flag */
  262. #define TMR_FLAG_UIF TMR_ISR_UIF /*!< Timer Counter Update Interrupt Flag */
  263. /**
  264. * @}
  265. */
  266. /** @defgroup TMR_Sync_definition Timer Group synchronization Definition
  267. * @{
  268. */
  269. #define TMRGRP_SYNC_TMR0 TMRGRP_SYNC0EN /*!< Select TMR0(specific to TMRGRP0) */
  270. #define TMRGRP_SYNC_TMR4 TMRGRP_SYNC0EN /*!< Select TMR4(specific to TMRGRP1) */
  271. #define TMRGRP_SYNC_TMR1 TMRGRP_SYNC1EN /*!< Select TMR1(specific to TMRGRP0) */
  272. #define TMRGRP_SYNC_TMR5 TMRGRP_SYNC1EN /*!< Select TMR5(specific to TMRGRP1) */
  273. #define TMRGRP_SYNC_TMR2 TMRGRP_SYNC2EN /*!< Select TMR2(specific to TMRGRP0) */
  274. #define TMRGRP_SYNC_TMR6 TMRGRP_SYNC2EN /*!< Select TMR6(specific to TMRGRP1) */
  275. #define TMRGRP_SYNC_TMR3 TMRGRP_SYNC3EN /*!< Select TMR2(specific to TMRGRP0) */
  276. #define TMRGRP_SYNC_TMR7 TMRGRP_SYNC3EN /*!< Select TMR6(specific to TMRGRP1) */
  277. #define TMRGRP_SYNC_ALL TMRGRP_SYNCALLEN /*!< Select all TMRs in TMRGRPx(x = 0 or 1) */
  278. /**
  279. * @}
  280. */
  281. /**
  282. * @}
  283. */
  284. /* Exported macro ------------------------------------------------------------*/
  285. /** @defgroup TMR_LL_Exported_Macros TMR LL Exported Macros
  286. * @brief TMR LL Exported Macros
  287. * @{
  288. */
  289. /**
  290. * @brief Enable TMR Base Unit on runtime
  291. * @param __INSTANCE__ TMR peripheral
  292. * @return None
  293. */
  294. #define __LL_TMR_ENABLE(__INSTANCE__) SET_BIT((__INSTANCE__)->CR, TMR_CR_CEN)
  295. /**
  296. * @brief Disable TMR Base Unit on runtime
  297. * @param __INSTANCE__ TMR peripheral
  298. * @return None
  299. */
  300. #define __LL_TMR_DISABLE(__INSTANCE__) CLEAR_BIT((__INSTANCE__)->CR, TMR_CR_CEN)
  301. /**
  302. * @brief Enable TMR Capture/Compare feature on runtime
  303. * @param __INSTANCE__ TMR peripheral
  304. * @return None
  305. */
  306. #define __LL_TMR_CC_ENABLE(__INSTANCE__) SET_BIT((__INSTANCE__)->CCCR, TMR_CCCR_CCE)
  307. /**
  308. * @brief Disable TMR Capture/Compare feature on runtime
  309. * @param __INSTANCE__ TMR peripheral
  310. * @return None
  311. */
  312. #define __LL_TMR_CC_DISABLE(__INSTANCE__) CLEAR_BIT((__INSTANCE__)->CCCR, TMR_CCCR_CCE)
  313. /**
  314. * @brief Enable the specified TMR Basic Unit Interrupt
  315. * @param __INSTANCE__ TMR peripheral
  316. * @param __INTERRUPT__ specifies the TMR base unit interrupt source to enable.
  317. * This parameter can be any combination of @ref TMR_Interrupt_definition:
  318. * @arg TMR_IT_UIE: Update interrupt
  319. * @arg TMR_IT_OVIE: Counter Overflow interrupt
  320. * @return None
  321. */
  322. #define __LL_TMR_IT_ENABLE(__INSTANCE__, __INTERRUPT__) SET_BIT((__INSTANCE__)->CR, (__INTERRUPT__))
  323. /**
  324. * @brief Disable the specified TMR Basic Unit Interrupt
  325. * @param __INSTANCE__ TMR peripheral
  326. * @param __INTERRUPT__ specifies the TMR base unit interrupt source to disable.
  327. * This parameter can be any combination of @ref TMR_Interrupt_definition:
  328. * @arg TMR_IT_UIE: Update interrupt
  329. * @arg TMR_IT_OVIE: Counter Overflow interrupt
  330. * @return None
  331. */
  332. #define __LL_TMR_IT_DISABLE(__INSTANCE__, __INTERRUPT__) CLEAR_BIT((__INSTANCE__)->CR, (__INTERRUPT__))
  333. /**
  334. * @brief Check whether the specified TMR Basic Unit interrupt source is set or not.
  335. * @param __INSTANCE__ TMR peripheral
  336. * @param __INTERRUPT__ specifies the TMR interrupt source to check.
  337. * This parameter can be any combination of @ref TMR_Interrupt_definition:
  338. * @arg TMR_IT_UIE: Update interrupt
  339. * @arg TMR_IT_OVIE: Counter Overflow interrupt
  340. * @return The state of __INTERRUPT__ (SET or RESET).
  341. */
  342. #define __LL_TMR_IT_CHECK_SOURCE(__INSTANCE__, __INTERRUPT__) ((READ_BIT((__INSTANCE__)->CR, (__INTERRUPT__)) \
  343. == (__INTERRUPT__)) ? SET : RESET)
  344. /**
  345. * @brief Enable the specified Capture/Compare Interrupt
  346. * @param __INSTANCE__ TMR peripheral
  347. * @param __INTERRUPT__ specifies the TMR Capture/Compare interrupt source to enable.
  348. * This parameter can be any combination of @ref TMR_CC_Interrupt_definition:
  349. * @arg TMR_IT_ICIE: Input Capture interrupt
  350. * @arg TMR_IT_ICOIE: Input Capture OverCapture interrupt
  351. * @arg TMR_IT_OCIE: Output Compare Match interrupt
  352. * @return None
  353. */
  354. #define __LL_TMR_CC_IT_ENABLE(__INSTANCE__, __INTERRUPT__) SET_BIT((__INSTANCE__)->CCCR, (__INTERRUPT__))
  355. /**
  356. * @brief Disable Input Capture Interrupt
  357. * @param __INSTANCE__ TMR peripheral
  358. * @param __INTERRUPT__ specifies the TMR Capture/Compare interrupt source to disable.
  359. * This parameter can be any combination of @ref TMR_CC_Interrupt_definition:
  360. * @arg TMR_IT_ICIE: Input Capture interrupt
  361. * @arg TMR_IT_ICOIE: Input Capture OverCapture interrupt
  362. * @arg TMR_IT_OCIE: Output Compare Matched interrupt
  363. * @return None
  364. */
  365. #define __LL_TMR_CC_IT_DISABLE(__INSTANCE__, __INTERRUPT__) CLEAR_BIT((__INSTANCE__)->CCCR, (__INTERRUPT__))
  366. /**
  367. * @brief Check whether the specified TMR Capture/Compare interrupt source is set or not.
  368. * @param __INSTANCE__ TMR peripheral
  369. * @param __INTERRUPT__ specifies the TMR Capture/Compare interrupt source to check.
  370. * This parameter can be any combination of @ref TMR_CC_Interrupt_definition:
  371. * @arg TMR_IT_ICIE: Input Capture interrupt
  372. * @arg TMR_IT_ICOIE: Input Capture OverCapture interrupt
  373. * @arg TMR_IT_OCIE: Output Compare Matched interrupt
  374. * @return he state of __INTERRUPT__ (SET or RESET).
  375. */
  376. #define __LL_TMR_CC_IT_CHECK_SOURCE(__INSTANCE__, __INTERRUPT__) \
  377. ((READ_BIT((__INSTANCE__)->CCCR, (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  378. /**
  379. * @brief Check whether the specified TMR interrupt flag is set or not.
  380. * @param __INSTANCE__ TMR peripheral.
  381. * @param __FLAG__ specifies the TMR flags to check.
  382. * This parameter can be any combination of @ref TMR_Flag_definition:
  383. * @arg TMR_FLAG_OVIF: Counter Overflow Interrupt Flag
  384. * @arg TMR_FLAG_ICOIF: Input Capture OverCapture Interrupt Flag
  385. * @arg TMR_FLAG_ICIF: Input Capture Interrupt Flag
  386. * @arg TMR_FLAG_OCIF: Output Compare Interrupt Flag
  387. * @arg TMR_FLAG_UIF: Counter Update Interrupt Flag
  388. * @return The state of __FLAG__ (SET or RESET).
  389. */
  390. #define __LL_TMR_GET_FLAG(__INSTANCE__, __FLAG__) \
  391. ((READ_BIT((__INSTANCE__)->ISR, (__FLAG__)) == (__FLAG__)) ? SET : RESET)
  392. /**
  393. * @brief Clear the specified TMR interrupt flags
  394. * @param __INSTANCE__ TMR peripheral
  395. * @param __FLAG__ specifies the TMR flags to clear.
  396. * This parameter can be any combination of @ref TMR_Flag_definition:
  397. * @arg TMR_FLAG_OVIF: Counter Overflow Interrupt Flag
  398. * @arg TMR_FLAG_ICOIF: Input Capture OverCapture Interrupt Flag
  399. * @arg TMR_FLAG_ICIF: Input Capture Interrupt Flag
  400. * @arg TMR_FLAG_OCIF: Output Compare Interrupt Flag
  401. * @arg TMR_FLAG_UIF: Counter Update Interrupt Flag
  402. * @return None
  403. */
  404. #define __LL_TMR_CLEAR_FLAG(__INSTANCE__, __FLAG__) WRITE_REG((__INSTANCE__)->ISR, (__FLAG__))
  405. /**
  406. * @brief Enable TMR Auto-Reload feature
  407. * @param __INSTANCE__ TMR peripheral
  408. * @return None
  409. */
  410. #define __LL_TMR_AUTORELOAD_ENABLE(__INSTANCE__) SET_BIT((__INSTANCE__)->CR, TMR_CR_ARPE)
  411. /**
  412. * @brief Disable TMR Auto-Reload feature
  413. * @param __INSTANCE__ TMR peripheral
  414. * @return None
  415. */
  416. #define __LL_TMR_AUTORELOAD_DISABLE(__INSTANCE__) CLEAR_BIT((__INSTANCE__)->CR, TMR_CR_ARPE)
  417. /**
  418. * @brief Enable TMR Output Compare Preload feature
  419. * @param __INSTANCE__ TMR peripheral
  420. * @return None
  421. */
  422. #define __LL_TMR_OC_PRELOAD_ENABLE(__INSTANCE__) SET_BIT((__INSTANCE__)->CCCR, TMR_CCCR_OCPE)
  423. /**
  424. * @brief Disable TMR Output Compare Preload feature
  425. * @param __INSTANCE__ TMR peripheral
  426. * @return None
  427. */
  428. #define __LL_TMR_OC_PRELOAD_DISABLE(__INSTANCE__) CLEAR_BIT((__INSTANCE__)->CCCR, TMR_CCCR_OCPE)
  429. /**
  430. * @brief Enable TMR Update event (UDIS)
  431. * @param __INSTANCE__ TMR peripheral
  432. * @return None
  433. */
  434. #define __LL_TMR_UPDATE_ENABLE(__INSTANCE__) CLEAR_BIT((__INSTANCE__)->CR, TMR_CR_UDIS)
  435. /**
  436. * @brief Disable TMR Update event (UDIS)
  437. * @param __INSTANCE__ TMR peripheral
  438. * @return None
  439. */
  440. #define __LL_TMR_UPDATE_DISABLE(__INSTANCE__) SET_BIT((__INSTANCE__)->CR, TMR_CR_UDIS)
  441. /**
  442. * @brief Selection of the Update Request Source (URS) bit of the TMRx_CR register.
  443. * @param __INSTANCE__ TMR peripheral
  444. * @param __SOURCE__ specifies the Update Request Source
  445. * This parameter can be one of the following values in @ref TMR_Update_Request_Source:
  446. * @arg TMR_UPDATE_SOURCE_REGULAR: Counter overflow or Setting the UG bit generates an update request
  447. * @arg TMR_UPDATE_SOURCE_COUNTER: Only counter overflow generates an update request
  448. * @note To generate the update request, Update event should be enabled(reset UDIS bit in TMRx_CR register).
  449. * @return None
  450. */
  451. #define __LL_TMR_UPDATE_SOURCE(__INSTANCE__, __SOURCE__) MODIFY_REG((__INSTANCE__)->CR, TMR_CR_URS_Msk, (__SOURCE__))
  452. /**
  453. * @brief Set the TMR Prescaler on runtime.
  454. * @param __INSTANCE__ TMR peripheral
  455. * @param __PRESC__ specifies the Prescaler new value.
  456. * @retval None
  457. */
  458. #define __LL_TMR_SET_PRESCALER(__INSTANCE__, __PRESC__) WRITE_REG((__INSTANCE__)->PSCR, (__PRESC__))
  459. /**
  460. * @brief Get the TMR Prescaler on runtime.
  461. * @param __INSTANCE__ TMR peripheral
  462. * @retval 16-bit or 32-bit value of the timer prescaler register (TMRx_PSCR)
  463. */
  464. #define __LL_TMR_GET_PRESCALER(__INSTANCE__) READ_REG((__INSTANCE__)->PSCR)
  465. /**
  466. * @brief Set the TMR Start value on runtime.
  467. * @param __INSTANCE__ TMR peripheral
  468. * @param __START__ specifies the new starting value.
  469. * @retval None
  470. */
  471. #define __LL_TMR_SET_START_VAL(__INSTANCE__, __START__) WRITE_REG((__INSTANCE__)->CSVR, (__START__))
  472. /**
  473. * @brief Get the TMR Start value on runtime.
  474. * @param __INSTANCE__ TMR peripheral
  475. * @retval 16-bit or 32-bit value of the timer start value register (TMRx_CSVR)
  476. */
  477. #define __LL_TMR_GET_START_VAL(__INSTANCE__) READ_REG((__INSTANCE__)->CSVR)
  478. /**
  479. * @brief Set the TMR End value on runtime.
  480. * @param __INSTANCE__ TMR peripheral
  481. * @param __END__ specifies the new ending value.
  482. * @retval None
  483. */
  484. #define __LL_TMR_SET_END_VAL(__INSTANCE__, __END__) WRITE_REG((__INSTANCE__)->CEVR, (__END__))
  485. /**
  486. * @brief Get the TMR End value on runtime.
  487. * @param __INSTANCE__ TMR peripheral
  488. * @retval 16-bit or 32-bit value of the timer end value register (TMRx_CEVR)
  489. */
  490. #define __LL_TMR_GET_END_VAL(__INSTANCE__) READ_REG((__INSTANCE__)->CEVR)
  491. /**
  492. * @brief Set the TMR Counter Register value on runtime.
  493. * @param __INSTANCE__ TMR peripheral
  494. * @param __COUNTER__ specifies the Counter register new value.
  495. * @return None
  496. */
  497. #define __LL_TMR_SET_COUNTER(__INSTANCE__, __COUNTER__) WRITE_REG((__INSTANCE__)->CNTR, (__COUNTER__))
  498. /**
  499. * @brief Get the TMR Counter Register value on runtime.
  500. * @param __INSTANCE__ TMR peripheral
  501. * @return 16-bit or 32-bit value of the timer counter register (TMRx_CNTR)
  502. */
  503. #define __LL_TMR_GET_COUNTER(__INSTANCE__) READ_REG((__INSTANCE__)->CNTR)
  504. /**
  505. * @brief Set the TMR Capture Compare Register(TMRx_CCR) value on runtime.
  506. * @note This macro normally used when the TMR is configured in Output Compare mode.
  507. * User can use the macro to change the compare value on runtime without calling
  508. * another time Config function.
  509. * @note The new value will take effect immediately when Output Compare Preload (OCPE)
  510. * is disabled. Otherwise it will take effect by following condition:
  511. * - Update event generated by counter overflow only (if Update event enabled)
  512. * - Compare Matching event with the older value.
  513. * - Software generate by setting the CCG bit in TMRx_EGR register
  514. * @param __INSTANCE__ TMR peripheral
  515. * @param __COMPARE__ specifies the Counter register new value.
  516. * @return None
  517. */
  518. #define __LL_TMR_SET_COMPARE(__INSTANCE__, __COMPARE__) WRITE_REG((__INSTANCE__)->CCR, (__COMPARE__))
  519. /**
  520. * @brief Get the TMR Capture Compare Register(TMRx_CCR) value on runtime.
  521. * @note This macro normally used when the TMR is configured in Input Capture mode.
  522. * User can use the macro to get the new capture value on runtime when a Capture event
  523. * is generated by fllowing condition:
  524. * - Input source trigger an edge matches the Input Capture Polarity edge configuration (CCP)
  525. * - Software generate by setting the CCG bit in TMRx_EGR register
  526. * @param __INSTANCE__ TMR peripheral
  527. * @return 16-bit or 32-bit value of the timer capture compare register (TMRx_CCR)
  528. */
  529. #define __LL_TMR_GET_CAPTURE(__INSTANCE__) READ_REG((__INSTANCE__)->CCR)
  530. /**
  531. * @brief Set the input channel polarity.
  532. * @param __INSTANCE__ Timer peripheral
  533. * @param __POLARITY__ This parameter can be one of the following values in @ref TMR_Input_Capture_Polarity:
  534. * @arg @ref TMR_ICPOLARITY_RISING :Capture triggered by rising edge on timer input
  535. * @arg @ref TMR_ICPOLARITY_FALLING :Capture triggered by falling edge on timer input
  536. * @arg @ref TMR_ICPOLARITY_BOTHEDGE :Capture triggered by both rising and falling edges on timer input
  537. * @retval None
  538. */
  539. #define __LL_TMR_POLARITY_SET(__INSTANCE__, __POLARITY__) MODIFY_REG((__INSTANCE__)->CCCR, TMR_CCCR_CCP_Msk, (__POLARITY__))
  540. /**
  541. * @brief Set the TMR Ouput Compare Mode on runtime.
  542. * @param __INSTANCE__ TMR peripheral
  543. * @param __OCMODE__ TMR Output Compare and PWM Modes
  544. * This parameter can be one of @ref TMR_Output_Compare_and_PWM_modes
  545. * @return None
  546. */
  547. #define __LL_TMR_SET_OCMODE(__INSTANCE__, __OCMODE__) MODIFY_REG((__INSTANCE__)->CCCR, TMR_CCCR_OCM_Msk, (__OCMODE__))
  548. /**
  549. * @}
  550. */
  551. /* Exported functions --------------------------------------------------------*/
  552. /** @addtogroup TMR_LL_Exported_Functions
  553. * @{
  554. */
  555. /** @addtogroup TMR_LL_Exported_Functions_Group1
  556. * @{
  557. */
  558. LL_StatusETypeDef LL_TMR_Init(TMR_TypeDef *Instance, TMR_InitTypeDef *Init);
  559. LL_StatusETypeDef LL_TMR_DeInit(TMR_TypeDef *Instance);
  560. void LL_TMR_MspInit(TMR_TypeDef *Instance);
  561. void LL_TMR_MspDeInit(TMR_TypeDef *Instance);
  562. /**
  563. * @}
  564. */
  565. /** @addtogroup TMR_LL_Exported_Functions_Group2
  566. * @{
  567. */
  568. LL_StatusETypeDef LL_TMR_TB_Config(TMR_TypeDef *Instance, TMR_TB_InitTypeDef *sConfig);
  569. LL_StatusETypeDef LL_TMR_IC_Config(TMR_TypeDef *Instance, TMR_IC_InitTypeDef *sConfig);
  570. LL_StatusETypeDef LL_TMR_OC_Config(TMR_TypeDef *Instance, TMR_OC_InitTypeDef *sConfig);
  571. LL_StatusETypeDef LL_TMR_EXT_Config(TMR_TypeDef *Instance, TMR_EXT_InitTypeDef *sConfig);
  572. /**
  573. * @}
  574. */
  575. /** @addtogroup TMR_LL_Exported_Functions_Group3
  576. * @{
  577. */
  578. LL_StatusETypeDef LL_TMR_Start(TMR_TypeDef *Instance);
  579. LL_StatusETypeDef LL_TMR_Stop(TMR_TypeDef *Instance);
  580. LL_StatusETypeDef LL_TMR_Start_IT(TMR_TypeDef *Instance);
  581. LL_StatusETypeDef LL_TMR_Stop_IT(TMR_TypeDef *Instance);
  582. LL_StatusETypeDef LL_TMR_Start_Synchro(TMRGRP_TypeDef *TMRGRPx, uint32_t SynchroMask);
  583. LL_StatusETypeDef LL_TMR_Stop_Synchro(TMRGRP_TypeDef *TMRGRPx, uint32_t SynchroMask);
  584. LL_StatusETypeDef LL_TMR_EventGenerate(TMR_TypeDef *Instance, TMR_EventSRCETypeDef EventSource);
  585. /**
  586. * @}
  587. */
  588. /** @addtogroup TMR_LL_Exported_Functions_Interrupt
  589. * @{
  590. */
  591. void LL_TMR_IRQHandler(TMR_TypeDef *Instance);
  592. void LL_TMR_TB_UpdateCallback(TMR_TypeDef *Instance);
  593. void LL_TMR_TB_OverflowCallback(TMR_TypeDef *Instance);
  594. void LL_TMR_IC_CaptureCallback(TMR_TypeDef *Instance);
  595. void LL_TMR_IC_OverCaptureCallback(TMR_TypeDef *Instance);
  596. void LL_TMR_OC_CompareMatchedCallback(TMR_TypeDef *Instance);
  597. /**
  598. * @}
  599. */
  600. /**
  601. * @}
  602. */
  603. /* Private types -------------------------------------------------------------*/
  604. /* Private variables ---------------------------------------------------------*/
  605. /* Private constants ---------------------------------------------------------*/
  606. /* Private macros ------------------------------------------------------------*/
  607. /** @defgroup TMR_LL_Private_Macros TMR LL Private Macros
  608. * @brief TMR LL Private Macros
  609. * @{
  610. */
  611. /**
  612. * @brief Judge is LSTMR instance or not
  613. * @param __INSTANCE__ instance to judge
  614. * @retval 0 isn't LSTMR instance
  615. * @retval 1 is LSTMR instance
  616. */
  617. #define IS_TMR_LSTMR_INSTANCE(__INSTANCE__) (((__INSTANCE__) == TMR0) || \
  618. ((__INSTANCE__) == TMR1) || \
  619. ((__INSTANCE__) == TMR2) || \
  620. ((__INSTANCE__) == TMR3))
  621. /**
  622. * @brief Judge is HSTMR instance or not
  623. * @param __INSTANCE__ instance to judge
  624. * @retval 0 isn't HSTMR instance
  625. * @retval 1 is HSTMR instance
  626. */
  627. #define IS_TMR_HSTMR_INSTANCE(__INSTANCE__) (((__INSTANCE__) == TMR4) || \
  628. ((__INSTANCE__) == TMR5) || \
  629. ((__INSTANCE__) == TMR6) || \
  630. ((__INSTANCE__) == TMR7))
  631. /**
  632. * @brief Judge is LSTMR prescaler or not
  633. * @param __PRESCALER__ prescaler to judge
  634. * @retval 0 isn't LSTMR prescaler
  635. * @retval 1 is LSTMR prescaler
  636. */
  637. #define IS_TMR_LSTMR_PRESCALER(__PRESCALER__) ((__PRESCALER__) <= 0xFFFFU )
  638. /**
  639. * @brief Judge is HSTMR prescaler or not
  640. * @param __PRESCALER__ prescaler to judge
  641. * @retval 0 isn't HSTMR prescaler
  642. * @retval 1 is HSTMR prescaler
  643. */
  644. #define IS_TMR_HSTMR_PRSCALER(__PRESCALER__) ((__PRESCALER__) <= 0xFFFFFFFFU )
  645. /**
  646. * @brief Judge is LSTMR start value or not
  647. * @param __VAL__ value to judge
  648. * @retval 0 is LSTMR start value
  649. * @retval 1 is LSTMR start value
  650. */
  651. #define IS_TMR_LSTMR_START_VAL(__VAL__) ((__VAL__) <= 0xFFFFUL)
  652. /**
  653. * @brief Judge is HSTMR start value or not
  654. * @param __VAL__ value to judge
  655. * @retval 0 is HSTMR start value
  656. * @retval 1 is HSTMR start value
  657. */
  658. #define IS_TMR_HSTMR_START_VAL(__VAL__) ((__VAL__) <= 0xFFFFFFFFUL)
  659. /**
  660. * @brief Judge is LSTMR end value or not
  661. * @param __VAL__ value to judge
  662. * @retval 0 is LSTMR end value
  663. * @retval 1 is LSTMR end value
  664. */
  665. #define IS_TMR_LSTMR_END_VAL(__VAL__) ((__VAL__) <= 0xFFFFUL)
  666. /**
  667. * @brief Judge is HSTMR end value or not
  668. * @param __VAL__ value to judge
  669. * @retval 0 is HSTMR end value
  670. * @retval 1 is HSTMR end value
  671. */
  672. #define IS_TMR_HSTMR_END_VAL(__VAL__) ((__VAL__) <= 0xFFFFFFFFUL)
  673. /**
  674. * @brief Judge is LSTMR compare value or not
  675. * @param __VAL__ value to judge
  676. * @retval 0 isn't LSTMR compare value
  677. * @retval 1 is LSTMR compare value
  678. */
  679. #define IS_TMR_LSTMR_COMPARE_VAL(__VAL__) ((__VAL__) <= 0xFFFFUL)
  680. /**
  681. * @brief Judge is HSTMR compare value or not
  682. * @param __VAL__ value to judge
  683. * @retval 0 isn't HSTMR compare value
  684. * @retval 1 is HSTMR compare value
  685. */
  686. #define IS_TMR_HSTMR_COMPARE_VAL(__VAL__) ((__VAL__) <= 0xFFFFFFFFUL)
  687. /**
  688. * @brief Judge is TMR input capture filter or not
  689. * @param __FILTER__ filter to judge
  690. * @retval 0 isn't TMR input capture filter
  691. * @retval 1 is TMR input capture filter
  692. */
  693. #define IS_TMR_ICFILTER(__FILTER__) ((__FILTER__) <= 0xFFUL)
  694. /**
  695. * @}
  696. */
  697. /* Private functions ---------------------------------------------------------*/
  698. /**
  699. * @}
  700. */
  701. /**
  702. * @}
  703. */
  704. #ifdef __cplusplus
  705. }
  706. #endif /* __cplusplus */
  707. #endif /* _TAE32F53XX_LL_TMR_H_ */
  708. /************************* (C) COPYRIGHT Tai-Action *****END OF FILE***********/