fm33lc0xx_fl_bstim32.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. /**
  2. *******************************************************************************************************
  3. * @file fm33lc0xx_fl_bstim32.h
  4. * @author FMSH Application Team
  5. * @brief Head file of BSTIM32 FL Module
  6. *******************************************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) [2019] [Fudan Microelectronics]
  10. * THIS SOFTWARE is licensed under the Mulan PSL v1.
  11. * can use this software according to the terms and conditions of the Mulan PSL v1.
  12. * You may obtain a copy of Mulan PSL v1 at:
  13. * http://license.coscl.org.cn/MulanPSL
  14. * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
  16. * PURPOSE.
  17. * See the Mulan PSL v1 for more details.
  18. *
  19. *******************************************************************************************************
  20. */
  21. /* Define to prevent recursive inclusion---------------------------------------------------------------*/
  22. #ifndef __FM33LC0XX_FL_BSTIM32_H
  23. #define __FM33LC0XX_FL_BSTIM32_H
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /* Includes -------------------------------------------------------------------------------------------*/
  28. #include "fm33lc0xx_fl.h"
  29. /** @addtogroup FM33LC0XX_FL_Driver
  30. * @{
  31. */
  32. /** @defgroup BSTIM32 BSTIM32
  33. * @brief BSTIM32 FL driver
  34. * @{
  35. */
  36. /* Exported types -------------------------------------------------------------------------------------*/
  37. /** @defgroup BSTIM32_FL_ES_INIT BSTIM32 Exported Init structures
  38. * @{
  39. */
  40. /**
  41. * @brief BSTIM32 Init Sturcture Definition
  42. */
  43. typedef struct
  44. {
  45. /* 预分频系数 */
  46. uint32_t prescaler;
  47. /* 自动重装载值 */
  48. uint32_t autoReload;
  49. /* 自动重装载值 */
  50. uint32_t autoReloadState;
  51. /* 时钟源 */
  52. uint32_t clockSource;
  53. } FL_BSTIM32_InitTypeDef;
  54. /**
  55. * @}
  56. */
  57. /* Exported constants ---------------------------------------------------------------------------------*/
  58. /** @defgroup BSTIM32_FL_Exported_Constants BSTIM32 Exported Constants
  59. * @{
  60. */
  61. #define BSTIM32_CR1_ARPE_Pos (7U)
  62. #define BSTIM32_CR1_ARPE_Msk (0x1U << BSTIM32_CR1_ARPE_Pos)
  63. #define BSTIM32_CR1_ARPE BSTIM32_CR1_ARPE_Msk
  64. #define BSTIM32_CR1_OPM_Pos (3U)
  65. #define BSTIM32_CR1_OPM_Msk (0x1U << BSTIM32_CR1_OPM_Pos)
  66. #define BSTIM32_CR1_OPM BSTIM32_CR1_OPM_Msk
  67. #define BSTIM32_CR1_URS_Pos (2U)
  68. #define BSTIM32_CR1_URS_Msk (0x1U << BSTIM32_CR1_URS_Pos)
  69. #define BSTIM32_CR1_URS BSTIM32_CR1_URS_Msk
  70. #define BSTIM32_CR1_UDIS_Pos (1U)
  71. #define BSTIM32_CR1_UDIS_Msk (0x1U << BSTIM32_CR1_UDIS_Pos)
  72. #define BSTIM32_CR1_UDIS BSTIM32_CR1_UDIS_Msk
  73. #define BSTIM32_CR1_CEN_Pos (0U)
  74. #define BSTIM32_CR1_CEN_Msk (0x1U << BSTIM32_CR1_CEN_Pos)
  75. #define BSTIM32_CR1_CEN BSTIM32_CR1_CEN_Msk
  76. #define BSTIM32_CR2_MMS_Pos (4U)
  77. #define BSTIM32_CR2_MMS_Msk (0x7U << BSTIM32_CR2_MMS_Pos)
  78. #define BSTIM32_CR2_MMS BSTIM32_CR2_MMS_Msk
  79. #define BSTIM32_IER_UIE_Pos (0U)
  80. #define BSTIM32_IER_UIE_Msk (0x1U << BSTIM32_IER_UIE_Pos)
  81. #define BSTIM32_IER_UIE BSTIM32_IER_UIE_Msk
  82. #define BSTIM32_ISR_UIF_Pos (0U)
  83. #define BSTIM32_ISR_UIF_Msk (0x1U << BSTIM32_ISR_UIF_Pos)
  84. #define BSTIM32_ISR_UIF BSTIM32_ISR_UIF_Msk
  85. #define BSTIM32_EGR_UG_Pos (0U)
  86. #define BSTIM32_EGR_UG_Msk (0x1U << BSTIM32_EGR_UG_Pos)
  87. #define BSTIM32_EGR_UG BSTIM32_EGR_UG_Msk
  88. #define FL_BSTIM32_ONE_PULSE_MODE_CONTINUOUS (0x0U << BSTIM32_CR1_OPM_Pos)
  89. #define FL_BSTIM32_ONE_PULSE_MODE_SINGLE (0x1U << BSTIM32_CR1_OPM_Pos)
  90. #define FL_BSTIM32_UPDATE_SOURCE_REGULAR (0x0U << BSTIM32_CR1_URS_Pos)
  91. #define FL_BSTIM32_UPDATE_SOURCE_COUNTER (0x1U << BSTIM32_CR1_URS_Pos)
  92. #define FL_BSTIM32_TRGO_UG (0x0U << BSTIM32_CR2_MMS_Pos)
  93. #define FL_BSTIM32_TRGO_ENABLE (0x1U << BSTIM32_CR2_MMS_Pos)
  94. #define FL_BSTIM32_TRGO_UPDATE (0x2U << BSTIM32_CR2_MMS_Pos)
  95. /**
  96. * @}
  97. */
  98. /* Exported functions ---------------------------------------------------------------------------------*/
  99. /** @defgroup BSTIM32_FL_Exported_Functions BSTIM32 Exported Functions
  100. * @{
  101. */
  102. /**
  103. * @brief Auto-Reload preload enable
  104. * @rmtoll CR1 ARPE FL_BSTIM32_EnableARRPreload
  105. * @param BSTIM32x BSTIM32 instance
  106. * @retval None
  107. */
  108. __STATIC_INLINE void FL_BSTIM32_EnableARRPreload(BSTIM32_Type *BSTIM32x)
  109. {
  110. SET_BIT(BSTIM32x->CR1, BSTIM32_CR1_ARPE_Msk);
  111. }
  112. /**
  113. * @brief Get Auto-Reload preload enable status
  114. * @rmtoll CR1 ARPE FL_BSTIM32_IsEnabledARRPreload
  115. * @param BSTIM32x BSTIM32 instance
  116. * @retval State of bit (1 or 0).
  117. */
  118. __STATIC_INLINE uint32_t FL_BSTIM32_IsEnabledARRPreload(BSTIM32_Type *BSTIM32x)
  119. {
  120. return (uint32_t)(READ_BIT(BSTIM32x->CR1, BSTIM32_CR1_ARPE_Msk) == BSTIM32_CR1_ARPE_Msk);
  121. }
  122. /**
  123. * @brief Auto-Reload preload disable
  124. * @rmtoll CR1 ARPE FL_BSTIM32_DisableARRPreload
  125. * @param BSTIM32x BSTIM32 instance
  126. * @retval None
  127. */
  128. __STATIC_INLINE void FL_BSTIM32_DisableARRPreload(BSTIM32_Type *BSTIM32x)
  129. {
  130. CLEAR_BIT(BSTIM32x->CR1, BSTIM32_CR1_ARPE_Msk);
  131. }
  132. /**
  133. * @brief Set one pulse mode
  134. * @rmtoll CR1 OPM FL_BSTIM32_SetOnePulseMode
  135. * @param BSTIM32x BSTIM32 instance
  136. * @param mode This parameter can be one of the following values:
  137. * @arg @ref FL_BSTIM32_ONE_PULSE_MODE_CONTINUOUS
  138. * @arg @ref FL_BSTIM32_ONE_PULSE_MODE_SINGLE
  139. * @retval None
  140. */
  141. __STATIC_INLINE void FL_BSTIM32_SetOnePulseMode(BSTIM32_Type *BSTIM32x, uint32_t mode)
  142. {
  143. MODIFY_REG(BSTIM32x->CR1, BSTIM32_CR1_OPM_Msk, mode);
  144. }
  145. /**
  146. * @brief Get one pulse mode
  147. * @rmtoll CR1 OPM FL_BSTIM32_GetOnePulseMode
  148. * @param BSTIM32x BSTIM32 instance
  149. * @retval Returned value can be one of the following values:
  150. * @arg @ref FL_BSTIM32_ONE_PULSE_MODE_CONTINUOUS
  151. * @arg @ref FL_BSTIM32_ONE_PULSE_MODE_SINGLE
  152. */
  153. __STATIC_INLINE uint32_t FL_BSTIM32_GetOnePulseMode(BSTIM32_Type *BSTIM32x)
  154. {
  155. return (uint32_t)(READ_BIT(BSTIM32x->CR1, BSTIM32_CR1_OPM_Msk));
  156. }
  157. /**
  158. * @brief Set update request
  159. * @rmtoll CR1 URS FL_BSTIM32_SetUpdateSource
  160. * @param BSTIM32x BSTIM32 instance
  161. * @param source This parameter can be one of the following values:
  162. * @arg @ref FL_BSTIM32_UPDATE_SOURCE_REGULAR
  163. * @arg @ref FL_BSTIM32_UPDATE_SOURCE_COUNTER
  164. * @retval None
  165. */
  166. __STATIC_INLINE void FL_BSTIM32_SetUpdateSource(BSTIM32_Type *BSTIM32x, uint32_t source)
  167. {
  168. MODIFY_REG(BSTIM32x->CR1, BSTIM32_CR1_URS_Msk, source);
  169. }
  170. /**
  171. * @brief Get update request status
  172. * @rmtoll CR1 URS FL_BSTIM32_GetUpdateSource
  173. * @param BSTIM32x BSTIM32 instance
  174. * @retval Returned value can be one of the following values:
  175. * @arg @ref FL_BSTIM32_UPDATE_SOURCE_REGULAR
  176. * @arg @ref FL_BSTIM32_UPDATE_SOURCE_COUNTER
  177. */
  178. __STATIC_INLINE uint32_t FL_BSTIM32_GetUpdateSource(BSTIM32_Type *BSTIM32x)
  179. {
  180. return (uint32_t)(READ_BIT(BSTIM32x->CR1, BSTIM32_CR1_URS_Msk));
  181. }
  182. /**
  183. * @brief Update event enable
  184. * @rmtoll CR1 UDIS FL_BSTIM32_EnableUpdateEvent
  185. * @param BSTIM32x BSTIM32 instance
  186. * @retval None
  187. */
  188. __STATIC_INLINE void FL_BSTIM32_EnableUpdateEvent(BSTIM32_Type *BSTIM32x)
  189. {
  190. CLEAR_BIT(BSTIM32x->CR1, BSTIM32_CR1_UDIS_Msk);
  191. }
  192. /**
  193. * @brief Get update event disable status
  194. * @rmtoll CR1 UDIS FL_BSTIM32_IsEnabledUpdateEvent
  195. * @param BSTIM32x BSTIM32 instance
  196. * @retval State of bit (1 or 0).
  197. */
  198. __STATIC_INLINE uint32_t FL_BSTIM32_IsEnabledUpdateEvent(BSTIM32_Type *BSTIM32x)
  199. {
  200. return (uint32_t)!(READ_BIT(BSTIM32x->CR1, BSTIM32_CR1_UDIS_Msk) == BSTIM32_CR1_UDIS_Msk);
  201. }
  202. /**
  203. * @brief Update event disable
  204. * @rmtoll CR1 UDIS FL_BSTIM32_DisableUpdateEvent
  205. * @param BSTIM32x BSTIM32 instance
  206. * @retval None
  207. */
  208. __STATIC_INLINE void FL_BSTIM32_DisableUpdateEvent(BSTIM32_Type *BSTIM32x)
  209. {
  210. CLEAR_BIT(BSTIM32x->CR1, BSTIM32_CR1_UDIS_Msk);
  211. }
  212. /**
  213. * @brief Counter enable
  214. * @rmtoll CR1 CEN FL_BSTIM32_Enable
  215. * @param BSTIM32x BSTIM32 instance
  216. * @retval None
  217. */
  218. __STATIC_INLINE void FL_BSTIM32_Enable(BSTIM32_Type *BSTIM32x)
  219. {
  220. SET_BIT(BSTIM32x->CR1, BSTIM32_CR1_CEN_Msk);
  221. }
  222. /**
  223. * @brief Get counter enable status
  224. * @rmtoll CR1 CEN FL_BSTIM32_IsEnabled
  225. * @param BSTIM32x BSTIM32 instance
  226. * @retval State of bit (1 or 0).
  227. */
  228. __STATIC_INLINE uint32_t FL_BSTIM32_IsEnabled(BSTIM32_Type *BSTIM32x)
  229. {
  230. return (uint32_t)(READ_BIT(BSTIM32x->CR1, BSTIM32_CR1_CEN_Msk) == BSTIM32_CR1_CEN_Msk);
  231. }
  232. /**
  233. * @brief Counter disable
  234. * @rmtoll CR1 CEN FL_BSTIM32_Disable
  235. * @param BSTIM32x BSTIM32 instance
  236. * @retval None
  237. */
  238. __STATIC_INLINE void FL_BSTIM32_Disable(BSTIM32_Type *BSTIM32x)
  239. {
  240. CLEAR_BIT(BSTIM32x->CR1, BSTIM32_CR1_CEN_Msk);
  241. }
  242. /**
  243. * @brief Set master mode
  244. * @rmtoll CR2 MMS FL_BSTIM32_SetTriggerOutput
  245. * @param BSTIM32x BSTIM32 instance
  246. * @param triggerOutput This parameter can be one of the following values:
  247. * @arg @ref FL_BSTIM32_TRGO_UG
  248. * @arg @ref FL_BSTIM32_TRGO_ENABLE
  249. * @arg @ref FL_BSTIM32_TRGO_UPDATE
  250. * @retval None
  251. */
  252. __STATIC_INLINE void FL_BSTIM32_SetTriggerOutput(BSTIM32_Type *BSTIM32x, uint32_t triggerOutput)
  253. {
  254. MODIFY_REG(BSTIM32x->CR2, BSTIM32_CR2_MMS_Msk, triggerOutput);
  255. }
  256. /**
  257. * @brief Get master mode status
  258. * @rmtoll CR2 MMS FL_BSTIM32_GetTriggerOutput
  259. * @param BSTIM32x BSTIM32 instance
  260. * @retval Returned value can be one of the following values:
  261. * @arg @ref FL_BSTIM32_TRGO_UG
  262. * @arg @ref FL_BSTIM32_TRGO_ENABLE
  263. * @arg @ref FL_BSTIM32_TRGO_UPDATE
  264. */
  265. __STATIC_INLINE uint32_t FL_BSTIM32_GetTriggerOutput(BSTIM32_Type *BSTIM32x)
  266. {
  267. return (uint32_t)(READ_BIT(BSTIM32x->CR2, BSTIM32_CR2_MMS_Msk));
  268. }
  269. /**
  270. * @brief Update event interrupt disable
  271. * @rmtoll IER UIE FL_BSTIM32_DisableIT_Update
  272. * @param BSTIM32x BSTIM32 instance
  273. * @retval None
  274. */
  275. __STATIC_INLINE void FL_BSTIM32_DisableIT_Update(BSTIM32_Type *BSTIM32x)
  276. {
  277. CLEAR_BIT(BSTIM32x->IER, BSTIM32_IER_UIE_Msk);
  278. }
  279. /**
  280. * @brief Update event interrupt enable
  281. * @rmtoll IER UIE FL_BSTIM32_EnableIT_Update
  282. * @param BSTIM32x BSTIM32 instance
  283. * @retval None
  284. */
  285. __STATIC_INLINE void FL_BSTIM32_EnableIT_Update(BSTIM32_Type *BSTIM32x)
  286. {
  287. SET_BIT(BSTIM32x->IER, BSTIM32_IER_UIE_Msk);
  288. }
  289. /**
  290. * @brief Get update event interrupt enable status
  291. * @rmtoll IER UIE FL_BSTIM32_IsEnabledIT_Update
  292. * @param BSTIM32x BSTIM32 instance
  293. * @retval State of bit (1 or 0).
  294. */
  295. __STATIC_INLINE uint32_t FL_BSTIM32_IsEnabledIT_Update(BSTIM32_Type *BSTIM32x)
  296. {
  297. return (uint32_t)(READ_BIT(BSTIM32x->IER, BSTIM32_IER_UIE_Msk) == BSTIM32_IER_UIE_Msk);
  298. }
  299. /**
  300. * @brief Get update event interrupt flag
  301. * @rmtoll ISR UIF FL_BSTIM32_IsActiveFlag_Update
  302. * @param BSTIM32x BSTIM32 instance
  303. * @retval State of bit (1 or 0).
  304. */
  305. __STATIC_INLINE uint32_t FL_BSTIM32_IsActiveFlag_Update(BSTIM32_Type *BSTIM32x)
  306. {
  307. return (uint32_t)(READ_BIT(BSTIM32x->ISR, BSTIM32_ISR_UIF_Msk) == (BSTIM32_ISR_UIF_Msk));
  308. }
  309. /**
  310. * @brief Clear update event interrupt flag
  311. * @rmtoll ISR UIF FL_BSTIM32_ClearFlag_Update
  312. * @param BSTIM32x BSTIM32 instance
  313. * @retval None
  314. */
  315. __STATIC_INLINE void FL_BSTIM32_ClearFlag_Update(BSTIM32_Type *BSTIM32x)
  316. {
  317. WRITE_REG(BSTIM32x->ISR, BSTIM32_ISR_UIF_Msk);
  318. }
  319. /**
  320. * @brief Software update event enable
  321. * @rmtoll EGR UG FL_BSTIM32_GenerateUpdateEvent
  322. * @param BSTIM32x BSTIM32 instance
  323. * @retval None
  324. */
  325. __STATIC_INLINE void FL_BSTIM32_GenerateUpdateEvent(BSTIM32_Type *BSTIM32x)
  326. {
  327. SET_BIT(BSTIM32x->EGR, BSTIM32_EGR_UG_Msk);
  328. }
  329. /**
  330. * @brief Set counter value
  331. * @rmtoll CNT FL_BSTIM32_WriteCounter
  332. * @param BSTIM32x BSTIM32 instance
  333. * @param cnt
  334. * @retval None
  335. */
  336. __STATIC_INLINE void FL_BSTIM32_WriteCounter(BSTIM32_Type *BSTIM32x, uint32_t cnt)
  337. {
  338. MODIFY_REG(BSTIM32x->CNT, (0xffffffffU << 0U), (cnt << 0U));
  339. }
  340. /**
  341. * @brief Get counter value
  342. * @rmtoll CNT FL_BSTIM32_ReadCounter
  343. * @param BSTIM32x BSTIM32 instance
  344. * @retval
  345. */
  346. __STATIC_INLINE uint32_t FL_BSTIM32_ReadCounter(BSTIM32_Type *BSTIM32x)
  347. {
  348. return (uint32_t)(READ_BIT(BSTIM32x->CNT, 0xffffffffU) >> 0U);
  349. }
  350. /**
  351. * @brief Set counter Clock prescaler value
  352. * @rmtoll PSC FL_BSTIM32_WritePrescaler
  353. * @param BSTIM32x BSTIM32 instance
  354. * @param psc
  355. * @retval None
  356. */
  357. __STATIC_INLINE void FL_BSTIM32_WritePrescaler(BSTIM32_Type *BSTIM32x, uint32_t psc)
  358. {
  359. MODIFY_REG(BSTIM32x->PSC, (0xffffffffU << 0U), (psc << 0U));
  360. }
  361. /**
  362. * @brief Get counter Clock prescaler value
  363. * @rmtoll PSC FL_BSTIM32_ReadPrescaler
  364. * @param BSTIM32x BSTIM32 instance
  365. * @retval
  366. */
  367. __STATIC_INLINE uint32_t FL_BSTIM32_ReadPrescaler(BSTIM32_Type *BSTIM32x)
  368. {
  369. return (uint32_t)(READ_BIT(BSTIM32x->PSC, 0xffffffffU) >> 0U);
  370. }
  371. /**
  372. * @brief Set Auto-Reload register value
  373. * @rmtoll ARR FL_BSTIM32_WriteAutoReload
  374. * @param BSTIM32x BSTIM32 instance
  375. * @param value
  376. * @retval None
  377. */
  378. __STATIC_INLINE void FL_BSTIM32_WriteAutoReload(BSTIM32_Type *BSTIM32x, uint32_t value)
  379. {
  380. MODIFY_REG(BSTIM32x->ARR, (0xffffffffU << 0U), (value << 0U));
  381. }
  382. /**
  383. * @brief Get Auto-Reload register value
  384. * @rmtoll ARR FL_BSTIM32_ReadAutoReload
  385. * @param BSTIM32x BSTIM32 instance
  386. * @retval
  387. */
  388. __STATIC_INLINE uint32_t FL_BSTIM32_ReadAutoReload(BSTIM32_Type *BSTIM32x)
  389. {
  390. return (uint32_t)(READ_BIT(BSTIM32x->ARR, 0xffffffffU) >> 0U);
  391. }
  392. /**
  393. * @}
  394. */
  395. /** @defgroup BSTIM32_FL_EF_Init Initialization and de-initialization functions
  396. * @{
  397. */
  398. FL_ErrorStatus FL_BSTIM32_DeInit(BSTIM32_Type *BSTIM32x);
  399. FL_ErrorStatus FL_BSTIM32_Init(BSTIM32_Type *BSTIM32x, FL_BSTIM32_InitTypeDef *initStruct);
  400. void FL_BSTIM32_StructInit(FL_BSTIM32_InitTypeDef *initStruct);
  401. /**
  402. * @}
  403. */
  404. /**
  405. * @}
  406. */
  407. /**
  408. * @}
  409. */
  410. #ifdef __cplusplus
  411. }
  412. #endif
  413. #endif /* __FM33LC0XX_FL_BSTIM32_H*/
  414. /*************************Py_Code_Generator Version: 0.1-0.11-0.2 @ 2020-09-23*************************/
  415. /*************************(C) COPYRIGHT Fudan Microelectronics **** END OF FILE*************************/