ald_timer.h 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  1. /**
  2. *********************************************************************************
  3. *
  4. * @file ald_timer.h
  5. * @brief TIMER module driver.
  6. * This is the common part of the TIMER initialization
  7. *
  8. * @version V1.0
  9. * @date 03 Mar. 2023
  10. * @author AE Team
  11. * @note
  12. * Change Logs:
  13. * Date Author Notes
  14. * 03 Mar. 2023 Lisq The first version
  15. *
  16. * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
  17. *
  18. * SPDX-License-Identifier: Apache-2.0
  19. *
  20. * Licensed under the Apache License, Version 2.0 (the License); you may
  21. * not use this file except in compliance with the License.
  22. * You may obtain a copy of the License at
  23. *
  24. * www.apache.org/licenses/LICENSE-2.0
  25. *
  26. * Unless required by applicable law or agreed to in writing, software
  27. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  28. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  29. * See the License for the specific language governing permissions and
  30. * limitations under the License.
  31. **********************************************************************************
  32. */
  33. #ifndef __ALD_TIMER_H__
  34. #define __ALD_TIMER_H__
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif /* __cplusplus */
  38. #include "ald_utils.h"
  39. #include "ald_cmu.h"
  40. #include "ald_dma.h"
  41. /** @addtogroup ES32VF2264_ALD
  42. * @{
  43. */
  44. /** @addtogroup TIMER
  45. * @{
  46. */
  47. /** @defgroup TIMER_Public_Types TIMER Public Types
  48. * @{
  49. */
  50. /**
  51. * @brief TIMER counter mode
  52. */
  53. typedef enum {
  54. ALD_TIMER_CNT_MODE_UP = 0U, /**< Counter mode up */
  55. ALD_TIMER_CNT_MODE_DOWN = 1U, /**< Counter mode down */
  56. ALD_TIMER_CNT_MODE_CENTER1 = 2U, /**< Counter mode center1 */
  57. ALD_TIMER_CNT_MODE_CENTER2 = 3U, /**< Counter mode center2 */
  58. ALD_TIMER_CNT_MODE_CENTER3 = 4U, /**< Counter mode center3 */
  59. } ald_timer_cnt_mode_t;
  60. /**
  61. * @brief TIMER clock division
  62. */
  63. typedef enum {
  64. ALD_TIMER_CLOCK_DIV1 = 0U, /**< No prescaler is used */
  65. ALD_TIMER_CLOCK_DIV2 = 1U, /** Clock is divided by 2 */
  66. ALD_TIMER_CLOCK_DIV4 = 2U, /** Clock is divided by 4 */
  67. } ald_timer_clock_division_t;
  68. /**
  69. * @brief TIMER output compare and PWM modes
  70. */
  71. typedef enum {
  72. ALD_TIMER_OC_MODE_TIMERING = 0U, /**< Output compare mode is timering */
  73. ALD_TIMER_OC_MODE_ACTIVE = 1U, /**< Output compare mode is active */
  74. ALD_TIMER_OC_MODE_INACTIVE = 2U, /**< Output compare mode is inactive */
  75. ALD_TIMER_OC_MODE_TOGGLE = 3U, /**< Output compare mode is toggle */
  76. ALD_TIMER_OC_MODE_FORCE_INACTIVE = 4U, /**< Output compare mode is force inactive */
  77. ALD_TIMER_OC_MODE_FORCE_ACTIVE = 5U, /**< Output compare mode is force active */
  78. ALD_TIMER_OC_MODE_PWM1 = 6U, /**< Output compare mode is pwm1 */
  79. ALD_TIMER_OC_MODE_PWM2 = 7U, /**< Output compare mode is pwm2 */
  80. } ald_timer_oc_mode_t;
  81. /**
  82. * @brief TIMER output compare polarity
  83. */
  84. typedef enum {
  85. ALD_TIMER_OC_POLARITY_HIGH = 0U, /**< Output compare polarity is high */
  86. ALD_TIMER_OC_POLARITY_LOW = 1U, /**< Output compare polarity is low */
  87. } ald_timer_oc_polarity_t;
  88. /**
  89. * @brief TIMER complementary output compare polarity
  90. */
  91. typedef enum {
  92. ALD_TIMER_OCN_POLARITY_HIGH = 0U, /**< Complementary output compare polarity is high */
  93. ALD_TIMER_OCN_POLARITY_LOW = 1U, /**< Complementary output compare polarity is low */
  94. } ald_timer_ocn_polarity_t;
  95. /**
  96. * @brief TIMER output compare idle state
  97. */
  98. typedef enum {
  99. ALD_TIMER_OC_IDLE_RESET = 0U, /**< Output compare idle state is reset */
  100. ALD_TIMER_OC_IDLE_SET = 1U, /**< Output compare idle state is set */
  101. } ald_timer_oc_idle_t;
  102. /**
  103. * @brief TIMER complementary output compare idle state
  104. */
  105. typedef enum {
  106. ALD_TIMER_OCN_IDLE_RESET = 0U, /**< Complementary output compare idle state is reset */
  107. ALD_TIMER_OCN_IDLE_SET = 1U, /**< Complementary output compare idle state is set */
  108. } ald_timer_ocn_idle_t;
  109. /**
  110. * @brief TIMER channel
  111. */
  112. typedef enum {
  113. ALD_TIMER_CHANNEL_1 = 0U, /**< Channel 1 */
  114. ALD_TIMER_CHANNEL_2 = 1U, /**< Channel 2 */
  115. ALD_TIMER_CHANNEL_3 = 2U, /**< Channel 3 */
  116. ALD_TIMER_CHANNEL_4 = 3U, /**< Channel 4 */
  117. ALD_TIMER_CHANNEL_ALL = 0xFU, /**< All channel */
  118. } ald_timer_channel_t;
  119. /**
  120. * @brief TIMER one pulse mode
  121. */
  122. typedef enum {
  123. ALD_TIMER_OP_MODE_REPEAT = 0U, /**< Repetitive */
  124. ALD_TIMER_OP_MODE_SINGLE = 1U, /**< single */
  125. } ald_timer_op_mode_t;
  126. /**
  127. * @brief TIMER one pulse output channel
  128. */
  129. typedef enum {
  130. ALD_TIMER_OP_OUTPUT_CHANNEL_1 = 0U, /**< One pulse output channal 1 */
  131. ALD_TIMER_OP_OUTPUT_CHANNEL_2 = 1U, /**< One pulse output channal 2 */
  132. } ald_timer_op_output_channel_t;
  133. /**
  134. * @brief TIMER time base configuration structure definition
  135. */
  136. typedef struct {
  137. uint32_t prescaler; /**< Specifies the prescaler value used to divide the TIMER clock. */
  138. ald_timer_cnt_mode_t mode; /**< Specifies the counter mode. */
  139. uint32_t period; /**< Specifies the period value to be loaded into ARR at the next update event. */
  140. ald_timer_clock_division_t clk_div; /**< Specifies the clock division.*/
  141. uint32_t re_cnt; /**< Specifies the repetition counter value. */
  142. } ald_timer_base_init_t;
  143. /**
  144. * @brief TIMER output compare configuration structure definition
  145. */
  146. typedef struct {
  147. ald_timer_oc_mode_t oc_mode; /**< Specifies the TIMER mode. */
  148. uint32_t pulse; /**< Specifies the pulse value to be loaded into the Capture Compare Register. */
  149. ald_timer_oc_polarity_t oc_polarity; /**< Specifies the output polarity. */
  150. ald_timer_ocn_polarity_t ocn_polarity; /**< Specifies the complementary output polarity. */
  151. type_func_t oc_fast_en; /**< Specifies the Fast mode state. */
  152. ald_timer_oc_idle_t oc_idle; /**< Specifies the TIMER Output Compare pin state during Idle state. */
  153. ald_timer_ocn_idle_t ocn_idle; /**< Specifies the TIMER Output Compare pin state during Idle state. */
  154. } ald_timer_oc_init_t;
  155. /**
  156. * @brief State structures definition
  157. */
  158. typedef enum {
  159. ALD_TIMER_STATE_RESET = 0x00U, /**< Peripheral not yet initialized or disabled */
  160. ALD_TIMER_STATE_READY = 0x01U, /**< Peripheral Initialized and ready for use */
  161. ALD_TIMER_STATE_BUSY = 0x02U, /**< An internal process is ongoing */
  162. ALD_TIMER_STATE_TIMEREOUT = 0x03U, /**< Timeout state */
  163. ALD_TIMER_STATE_ERROR = 0x04U, /**< Reception process is ongoing */
  164. } ald_timer_state_t;
  165. /**
  166. * @brief Active channel structures definition
  167. */
  168. typedef enum {
  169. ALD_TIMER_ACTIVE_CHANNEL_1 = 0x01U, /**< The active channel is 1 */
  170. ALD_TIMER_ACTIVE_CHANNEL_2 = 0x02U, /**< The active channel is 2 */
  171. ALD_TIMER_ACTIVE_CHANNEL_3 = 0x04U, /**< The active channel is 3 */
  172. ALD_TIMER_ACTIVE_CHANNEL_4 = 0x08U, /**< The active channel is 4 */
  173. ALD_TIMER_ACTIVE_CHANNEL_CLEARED = 0x00U, /**< All active channels cleared */
  174. } ald_timer_active_channel_t;
  175. /**
  176. * @brief TIMER time base handle structure definition
  177. */
  178. typedef struct ald_timer_handle_s {
  179. TIMER_TypeDef *perh; /**< Register base address */
  180. ald_timer_base_init_t init; /**< TIMER Time Base required parameters */
  181. ald_timer_active_channel_t ch; /**< Active channel */
  182. lock_state_t lock; /**< Locking object */
  183. ald_timer_state_t state; /**< TIMER operation state */
  184. ald_dma_handle_t hdma1; /**< Timer DMA handle parameters */
  185. ald_dma_handle_t hdma2;
  186. void (*period_elapse_cbk)(struct ald_timer_handle_s *arg); /**< Period elapse callback */
  187. void (*delay_elapse_cbk)(struct ald_timer_handle_s *arg); /**< Delay_elapse callback */
  188. void (*capture_cbk)(struct ald_timer_handle_s *arg); /**< Capture callback */
  189. void (*pwm_pulse_finish_cbk)(struct ald_timer_handle_s *arg); /**< PWM_pulse_finish callback */
  190. void (*trigger_cbk)(struct ald_timer_handle_s *arg); /**< Trigger callback */
  191. void (*break_cbk)(struct ald_timer_handle_s *arg); /**< Break callback */
  192. void (*com_cbk)(struct ald_timer_handle_s *arg); /**< commutation callback */
  193. void (*error_cbk)(struct ald_timer_handle_s *arg); /**< Error callback */
  194. } ald_timer_handle_t;
  195. /**
  196. * @brief TIMER encoder mode
  197. */
  198. typedef enum {
  199. ALD_TIMER_ENC_MODE_TI1 = 1U, /**< encoder mode 1 */
  200. ALD_TIMER_ENC_MODE_TI2 = 2U, /**< encoder mode 2 */
  201. ALD_TIMER_ENC_MODE_TI12 = 3U, /**< encoder mode 3 */
  202. } ald_timer_encoder_mode_t;
  203. /**
  204. * @brief TIMER input capture polarity
  205. */
  206. typedef enum {
  207. ALD_TIMER_IC_POLARITY_RISE = 0U, /**< Input capture polarity rising */
  208. ALD_TIMER_IC_POLARITY_FALL = 1U, /**< Input capture polarity falling */
  209. } ald_timer_ic_polarity_t;
  210. /**
  211. *@brief TIMER input capture selection
  212. */
  213. typedef enum {
  214. ALD_TIMER_IC_SEL_DIRECT = 1U, /**< IC1 -- TI1 */
  215. ALD_TIMER_IC_SEL_INDIRECT = 2U, /**< IC1 -- TI2 */
  216. ALD_TIMER_IC_SEL_TRC = 3U, /**< IC1 -- TRC */
  217. } ald_timer_ic_select_t;
  218. /**
  219. * @brief TIMER input capture prescaler
  220. */
  221. typedef enum {
  222. ALD_TIMER_IC_PSC_DIV1 = 0U, /**< Capture performed once every 1 events */
  223. ALD_TIMER_IC_PSC_DIV2 = 1U, /**< Capture performed once every 2 events */
  224. ALD_TIMER_IC_PSC_DIV4 = 2U, /**< Capture performed once every 4 events */
  225. ALD_TIMER_IC_PSC_DIV8 = 3U, /**< Capture performed once every 4 events */
  226. } ald_timer_ic_prescaler_t;
  227. /**
  228. * @brief TIMER encoder configuration structure definition
  229. */
  230. typedef struct {
  231. ald_timer_encoder_mode_t mode; /**< Specifies the encoder mode */
  232. ald_timer_ic_polarity_t ic1_polarity; /**< Specifies the active edge of the input signal */
  233. ald_timer_ic_select_t ic1_sel; /**< Specifies the input */
  234. ald_timer_ic_prescaler_t ic1_psc; /**< Specifies the Input Capture Prescaler */
  235. uint32_t ic1_filter; /**< Specifies the input capture filter */
  236. ald_timer_ic_polarity_t ic2_polarity; /**< Specifies the active edge of the input signal */
  237. ald_timer_ic_select_t ic2_sel; /**< Specifies the input */
  238. ald_timer_ic_prescaler_t ic2_psc; /**< Specifies the Input Capture Prescaler */
  239. uint32_t ic2_filter; /**< Specifies the input capture filter */
  240. } ald_timer_encoder_init_t;
  241. /**
  242. * @brief TIMER input capture configuration structure definition
  243. */
  244. typedef struct {
  245. ald_timer_ic_polarity_t polarity; /**< Specifies the active edge of the input signal */
  246. ald_timer_ic_select_t sel; /**< Specifies the input */
  247. ald_timer_ic_prescaler_t psc; /**< Specifies the Input Capture Prescaler */
  248. uint32_t filter; /**< Specifies the input capture filter */
  249. } ald_timer_ic_init_t;
  250. /**
  251. * @brief TIMER one pulse mode configuration structure definition
  252. */
  253. typedef struct {
  254. ald_timer_oc_mode_t mode; /**< Specifies the TIMER mode */
  255. uint16_t pulse; /**< Specifies the pulse value */
  256. ald_timer_oc_polarity_t oc_polarity; /**< Specifies the output polarity */
  257. ald_timer_ocn_polarity_t ocn_polarity; /**< Specifies the complementary output polarity */
  258. ald_timer_oc_idle_t oc_idle; /**< Specifies the TIMER Output Compare pin state during Idle state */
  259. ald_timer_ocn_idle_t ocn_idle; /**< Specifies the TIMER Output Compare pin state during Idle state */
  260. ald_timer_ic_polarity_t polarity; /**< Specifies the active edge of the input signal */
  261. ald_timer_ic_select_t sel; /**< Specifies the input */
  262. uint32_t filter; /**< Specifies the input capture filter */
  263. } ald_timer_one_pulse_init_t;
  264. /** @brief TIMER clear input source
  265. */
  266. typedef enum {
  267. ALD_TIMER_INPUT_NONE = 0U, /**< Clear input none */
  268. ALD_TIMER_INPUT_ETR = 1U, /**< Clear input etr */
  269. } ald_timer_clear_input_source_t;
  270. /** @brief TIMER clear input polarity
  271. */
  272. typedef enum {
  273. ALD_TIMER_POLARITY_NO_INV = 0U, /**< Polarity for ETRx pin */
  274. ALD_TIMER_POLARITY_INV = 1U, /**< Polarity for ETRx pin */
  275. } ald_timer_clear_input_polarity_t;
  276. /** @brief TIMER clear input polarity
  277. */
  278. typedef enum {
  279. ALD_TIMER_ETR_PSC_DIV1 = 0U, /**< No prescaler is used */
  280. ALD_TIMER_ETR_PSC_DIV2 = 1U, /**< ETR input source is divided by 2 */
  281. ALD_TIMER_ETR_PSC_DIV4 = 2U, /**< ETR input source is divided by 4 */
  282. ALD_TIMER_ETR_PSC_DIV8 = 3U, /**< ETR input source is divided by 8 */
  283. } ald_timer_etr_psc_t;
  284. /** @brief TIMER CHnREF Clear Select
  285. */
  286. typedef enum {
  287. ALD_TIMER_CHNREF_CLR_CMP_IN = 0U, /**< Comparator CMP_IN */
  288. ALD_TIMER_CHNREF_CLR_ETF = 1U, /**< External Trigger Signal ETF */
  289. } ald_timer_chnref_clr_sel_t;
  290. /** @brief TIMER clear input configuration handle structure definition
  291. */
  292. typedef struct {
  293. type_func_t state; /**< TIMER clear Input state */
  294. ald_timer_clear_input_source_t source; /**< TIMER clear Input sources */
  295. ald_timer_clear_input_polarity_t polarity; /**< TIMER Clear Input polarity */
  296. ald_timer_etr_psc_t psc; /**< TIMER Clear Input prescaler */
  297. ald_timer_chnref_clr_sel_t clrsel; /**<TIMER CHnREF_Clear */
  298. uint32_t filter; /**< TIMER Clear Input filter */
  299. } ald_timer_clear_input_config_t;
  300. /** @brief TIMER clock source
  301. */
  302. typedef enum {
  303. ALD_TIMER_SRC_ETRMODE2 = 0U, /**< Clock source is etr mode2 */
  304. ALD_TIMER_SRC_INTER = 1U, /**< Clock source is etr internal */
  305. ALD_TIMER_SRC_ITR0 = 2U, /**< Clock source is etr itr0 */
  306. ALD_TIMER_SRC_ITR1 = 3U, /**< Clock source is etr itr1 */
  307. ALD_TIMER_SRC_ITR2 = 4U, /**< Clock source is etr itr2 */
  308. ALD_TIMER_SRC_ITR3 = 5U, /**< Clock source is etr itr3 */
  309. ALD_TIMER_SRC_TI1ED = 6U, /**< Clock source is etr ti1ed */
  310. ALD_TIMER_SRC_TI1 = 7U, /**< Clock source is etr ti1 */
  311. ALD_TIMER_SRC_TI2 = 8U, /**< Clock source is etr ti2 */
  312. ALD_TIMER_SRC_ETRMODE1 = 9U, /**< Clock source is etr mode1 */
  313. } ald_timer_clock_source_t;
  314. /** @brief TIMER clock polarity
  315. */
  316. typedef enum {
  317. ALD_TIMER_CLK_POLARITY_INV = 1U, /**< Polarity for ETRx clock sources */
  318. ALD_TIMER_CLK_POLARITY_NO_INV = 0U, /**< Polarity for ETRx clock sources */
  319. ALD_TIMER_CLK_POLARITY_RISE = 0U, /**< Polarity for TIx clock sources */
  320. ALD_TIMER_CLK_POLARITY_FALL = 1U, /**< Polarity for TIx clock sources */
  321. ALD_TIMER_CLK_POLARITY_BOTH = 3U, /**< Polarity for TIx clock sources */
  322. } ald_timer_clock_polarity_t;
  323. /**
  324. * @brief TIMER clock config structure definition
  325. */
  326. typedef struct {
  327. ald_timer_clock_source_t source; /**< TIMER clock sources */
  328. ald_timer_clock_polarity_t polarity; /**< TIMER clock polarity */
  329. ald_timer_etr_psc_t psc; /**< TIMER clock prescaler */
  330. uint32_t filter; /**< TIMER clock filter */
  331. } ald_timer_clock_config_t;
  332. /**
  333. * @brief TIMER slave mode
  334. */
  335. typedef enum {
  336. ALD_TIMER_MODE_DISABLE = 0U, /**< Slave mode is disable */
  337. ALD_TIMER_MODE_ENC1 = 1U, /**< Slave mode is encoder1 */
  338. ALD_TIMER_MODE_ENC2 = 2U, /**< Slave mode is encoder2 */
  339. ALD_TIMER_MODE_ENC3 = 3U, /**< Slave mode is encoder3 */
  340. ALD_TIMER_MODE_RESET = 4U, /**< Slave mode is reset */
  341. ALD_TIMER_MODE_GATED = 5U, /**< Slave mode is gated */
  342. ALD_TIMER_MODE_TRIG = 6U, /**< Slave mode is trigger */
  343. ALD_TIMER_MODE_EXTERNAL1 = 7U, /**< Slave mode is external1 */
  344. } ald_timer_slave_mode_t;
  345. /**
  346. * @brief TIMER ts definition
  347. */
  348. typedef enum {
  349. ALD_TIMER_TS_ITR0 = 0U, /**< ITR0 */
  350. ALD_TIMER_TS_ITR1 = 1U, /**< ITR1 */
  351. ALD_TIMER_TS_ITR2 = 2U, /**< ITR2 */
  352. ALD_TIMER_TS_ITR3 = 3U, /**< ITR3 */
  353. ALD_TIMER_TS_TI1F_ED = 4U, /**< TI1F_ED */
  354. ALD_TIMER_TS_TI1FP1 = 5U, /**< TI1FP1 */
  355. ALD_TIMER_TS_TI2FP2 = 6U, /**< TI2FP2 */
  356. ALD_TIMER_TS_ETRF = 7U, /**< ETRF */
  357. } ald_timer_ts_t;
  358. /**
  359. * @brief TIMER slave configuration structure definition
  360. */
  361. typedef struct {
  362. ald_timer_slave_mode_t mode; /**< Slave mode selection */
  363. ald_timer_ts_t input; /**< Input Trigger source */
  364. ald_timer_clock_polarity_t polarity; /**< Input Trigger polarity */
  365. ald_timer_etr_psc_t psc; /**< Input trigger prescaler */
  366. uint32_t filter; /**< Input trigger filter */
  367. } ald_timer_slave_config_t;
  368. /**
  369. * @brief TIMER hall sensor configuretion structure definition
  370. */
  371. typedef struct {
  372. ald_timer_ic_polarity_t polarity; /**< Specifies the active edge of the input signal */
  373. ald_timer_ic_prescaler_t psc; /**< Specifies the Input Capture Prescaler */
  374. uint32_t filter; /**< Specifies the input capture filter [0x0, 0xF] */
  375. uint32_t delay; /**< Specifies the pulse value to be loaded into the register [0x0, 0xFFFF] */
  376. } ald_timer_hall_sensor_init_t;
  377. /**
  378. * @brief TIMER lock level
  379. */
  380. typedef enum {
  381. ALD_TIMER_LOCK_LEVEL_OFF = 0U, /**< Lock off */
  382. ALD_TIMER_LOCK_LEVEL_1 = 1U, /**< Lock level 1 */
  383. ALD_TIMER_LOCK_LEVEL_2 = 2U, /**< Lock level 2 */
  384. ALD_TIMER_LOCK_LEVEL_3 = 3U, /**< Lock level 3 */
  385. } ald_timer_lock_level_t;
  386. /**
  387. * @brief TIMER break polarity
  388. */
  389. typedef enum {
  390. ALD_TIMER_BREAK_POLARITY_LOW = 0U, /**< LOW */
  391. ALD_TIMER_BREAK_POLARITY_HIGH = 1U, /**< HIGH */
  392. } ald_timer_break_polarity_t;
  393. /**
  394. * @brief TIMER break and dead time configuretion structure definition
  395. */
  396. typedef struct {
  397. type_func_t off_run; /**< Enalbe/Disable off state in run mode */
  398. type_func_t off_idle; /**< Enalbe/Disable off state in idle mode */
  399. ald_timer_lock_level_t lock_level; /**< Lock level */
  400. uint32_t dead_time; /**< Dead time, [0x0, 0xFF] */
  401. type_func_t break_state; /**< Break state */
  402. ald_timer_break_polarity_t polarity; /**< Break input polarity */
  403. type_func_t auto_out; /**< Enalbe/Disable automatic output */
  404. } ald_timer_break_dead_time_t;
  405. /**
  406. * @brief TIMER commutation event channel configuretion structure definition
  407. */
  408. typedef struct {
  409. type_func_t en; /**< Enalbe/Disable the channel */
  410. type_func_t n_en; /**< Enalbe/Disable the complementary channel */
  411. ald_timer_oc_mode_t mode; /**< Mode of the channel */
  412. } ald_timer_channel_config_t;
  413. /**
  414. * @brief TIMER commutation event configuretion structure definition
  415. */
  416. typedef struct {
  417. ald_timer_channel_config_t ch[3]; /**< Configure of channel */
  418. } ald_timer_com_channel_config_t;
  419. /**
  420. * @brief TIMER master mode selection
  421. */
  422. typedef enum {
  423. ALD_TIMER_TRGO_RESET = 0U, /**< RESET */
  424. ALD_TIMER_TRGO_ENABLE = 1U, /**< ENABLE */
  425. ALD_TIMER_TRGO_UPDATE = 2U, /**< UPDATE */
  426. ALD_TIMER_TRGO_OC1 = 3U, /**< OC1 */
  427. ALD_TIMER_TRGO_OC1REF = 4U, /**< OC1REF */
  428. ALD_TIMER_TRGO_OC2REF = 5U, /**< OC2REF */
  429. ALD_TIMER_TRGO_OC3REF = 6U, /**< OC3REF */
  430. ALD_TIMER_TRGO_OC4REF = 7U, /**< OC4REF */
  431. } ald_timer_master_mode_sel_t;
  432. /**
  433. * @brief TIMER master configuretion structure definition
  434. */
  435. typedef struct {
  436. ald_timer_master_mode_sel_t sel; /**< Specifies the active edge of the input signal */
  437. type_func_t master_en; /**< Master/Slave mode selection */
  438. } ald_timer_master_config_t;
  439. /**
  440. * @brief Specifies the event source
  441. */
  442. typedef enum {
  443. ALD_TIMER_SRC_UPDATE = (1U << 0), /**< Event source is update */
  444. ALD_TIMER_SRC_CC1 = (1U << 1), /**< Event source is channel1 */
  445. ALD_TIMER_SRC_CC2 = (1U << 2), /**< Event source is channel2 */
  446. ALD_TIMER_SRC_CC3 = (1U << 3), /**< Event source is channel3 */
  447. ALD_TIMER_SRC_CC4 = (1U << 4), /**< Event source is channel4 */
  448. ALD_TIMER_SRC_COM = (1U << 5), /**< Event source is compare */
  449. ALD_TIMER_SRC_TRIG = (1U << 6), /**< Event source is trigger */
  450. ALD_TIMER_SRC_BREAK = (1U << 7), /**< Event source is break */
  451. } ald_timer_event_source_t;
  452. /**
  453. * @brief TIMER interrupt definition
  454. */
  455. typedef enum {
  456. ALD_TIMER_IT_UPDATE = (1U << 0), /**< Update interrupt bit */
  457. ALD_TIMER_IT_CC1 = (1U << 1), /**< Channel1 interrupt bit */
  458. ALD_TIMER_IT_CC2 = (1U << 2), /**< Channel2 interrupt bit */
  459. ALD_TIMER_IT_CC3 = (1U << 3), /**< Channel3 interrupt bit */
  460. ALD_TIMER_IT_CC4 = (1U << 4), /**< Channel4 interrupt bit */
  461. ALD_TIMER_IT_COM = (1U << 5), /**< compare interrupt bit */
  462. ALD_TIMER_IT_TRIGGER = (1U << 6), /**< Trigger interrupt bit */
  463. ALD_TIMER_IT_BREAK = (1U << 7), /**< Break interrupt bit */
  464. } ald_timer_it_t;
  465. /**
  466. * @brief TIMER DMA request
  467. */
  468. typedef enum {
  469. ALD_TIMER_DMA_UPDATE = (1U << 0), /**< DMA request from update */
  470. ALD_TIMER_DMA_CC1 = (1U << 1), /**< DMA request from channel1 */
  471. ALD_TIMER_DMA_CC2 = (1U << 2), /**< DMA request from channel2 */
  472. ALD_TIMER_DMA_CC3 = (1U << 3), /**< DMA request from channel3 */
  473. ALD_TIMER_DMA_CC4 = (1U << 4), /**< DMA request from channel4 */
  474. ALD_TIMER_DMA_COM = (1U << 5), /**< DMA request from compare */
  475. ALD_TIMER_DMA_TRIGGER = (1U << 6), /**< DMA request from trigger */
  476. } ald_timer_dma_req_t;
  477. /**
  478. * @brief TIMER flag definition
  479. */
  480. typedef enum {
  481. ALD_TIMER_FLAG_UPDATE = (1U << 0), /**< Update interrupt flag */
  482. ALD_TIMER_FLAG_CC1 = (1U << 1), /**< Channel1 interrupt flag */
  483. ALD_TIMER_FLAG_CC2 = (1U << 2), /**< Channel2 interrupt flag */
  484. ALD_TIMER_FLAG_CC3 = (1U << 3), /**< Channel3 interrupt flag */
  485. ALD_TIMER_FLAG_CC4 = (1U << 4), /**< Channel4 interrupt flag */
  486. ALD_TIMER_FLAG_COM = (1U << 5), /**< Compare interrupt flag */
  487. ALD_TIMER_FLAG_TRIGGER = (1U << 6), /**< Trigger interrupt flag */
  488. ALD_TIMER_FLAG_BREAK = (1U << 7), /**< Break interrupt flag */
  489. ALD_TIMER_FLAG_CC1OF = (1U << 9), /**< Channel1 override state flag */
  490. ALD_TIMER_FLAG_CC2OF = (1U << 10), /**< Channel2 override state flag */
  491. ALD_TIMER_FLAG_CC3OF = (1U << 11), /**< Channel3 override state flag */
  492. ALD_TIMER_FLAG_CC4OF = (1U << 12), /**< Channel4 override state flag */
  493. } ald_timer_flag_t;
  494. /**
  495. * @}
  496. */
  497. /** @defgroup TIMER_Public_Macros TIMER Public Macros
  498. * @{
  499. */
  500. #define ALD_CCER_CCxE_MASK ((1U << 0) | (1U << 4) | (1U << 8) | (1U << 12))
  501. #define ALD_CCER_CCxNE_MASK ((1U << 2) | (1U << 6) | (1U << 10))
  502. /**
  503. * @brief Reset TIMER handle state
  504. */
  505. #define ALD_TIMER_RESET_HANDLE_STATE(hperh) ((hperh)->state = TIMER_STATE_RESET)
  506. /**
  507. * @brief Enable the TIMER peripheral.
  508. */
  509. #define ALD_TIMER_ENABLE(hperh) (SET_BIT((hperh)->perh->CON1, TIMER_CON1_CNTEN_MSK))
  510. /**
  511. * @brief Enable the TIMER main output.
  512. */
  513. #define ALD_TIMER_MOE_ENABLE(hperh) (SET_BIT((hperh)->perh->BDCFG, TIMER_BDCFG_GOEN_MSK))
  514. /**
  515. * @brief Disable the TIMER peripheral.
  516. */
  517. #define ALD_TIMER_DISABLE(hperh) \
  518. do { \
  519. if ((((hperh)->perh->CCEP & ALD_CCER_CCxE_MASK) == 0) \
  520. && (((hperh)->perh->CCEP & ALD_CCER_CCxNE_MASK) == 0)) \
  521. CLEAR_BIT((hperh)->perh->CON1, TIMER_CON1_CNTEN_MSK); \
  522. } while (0)
  523. /**
  524. * @brief Disable the TIMER main output.
  525. * @note The Main Output Enable of a timer instance is disabled only if
  526. * all the CCx and CCxN channels have been disabled
  527. */
  528. #define ALD_TIMER_MOE_DISABLE(hperh) \
  529. do { \
  530. if ((((hperh)->perh->CCEP & ALD_CCER_CCxE_MASK) == 0) \
  531. && (((hperh)->perh->CCEP & ALD_CCER_CCxNE_MASK) == 0)) \
  532. CLEAR_BIT((hperh)->perh->BDCFG, TIMER_BDCFG_GOEN_MSK); \
  533. } while (0)
  534. /**
  535. * @brief Sets the TIMER autoreload register value on runtime without calling
  536. * another time any Init function.
  537. */
  538. #define ALD_TIMER_SET_AUTORELOAD(handle, AUTORELOAD) \
  539. do { \
  540. (handle)->perh->AR = (AUTORELOAD); \
  541. (handle)->init.period = (AUTORELOAD); \
  542. } while (0)
  543. /**
  544. * @brief Gets the TIMER autoreload register value on runtime
  545. */
  546. #define ALD_TIMER_GET_AUTORELOAD(handle) ((handle)->perh->AR)
  547. /**
  548. * @brief Gets the TIMER count register value on runtime
  549. */
  550. #define ALD_TIMER_GET_CNT(handle) ((handle)->perh->COUNT)
  551. /**
  552. * @brief Gets the TIMER count direction value on runtime
  553. */
  554. #define ALD_TIMER_GET_DIR(handle) (READ_BITS((handle)->perh->CON1, TIMER_CON1_DIRSEL_MSK, TIMER_CON1_DIRSEL_POS))
  555. /**
  556. * @brief CCx DMA request sent when CCx event occurs
  557. */
  558. #define ALD_TIMER_CCx_DMA_REQ_CCx(handle) (CLEAR_BIT((handle)->perh->CON2, TIMER_CON2_CCDMASEL_MSK))
  559. /**
  560. * @brief CCx DMA request sent when update event occurs
  561. */
  562. #define ALD_TIMER_CCx_DMA_REQ_UPDATE(handle) (SET_BIT((handle)->perh->CON2, TIMER_CON2_CCDMASEL_MSK))
  563. /**
  564. * @brief Enable channel
  565. * @param handle: TIMER handle
  566. * @param ch: Must be one of this:
  567. * TIMER_CHANNEL_1
  568. * TIMER_CHANNEL_2
  569. * TIMER_CHANNEL_3
  570. * TIMER_CHANNEL_4
  571. */
  572. #define ALD_TIMER_CCx_ENABLE(handle, ch) (((ch) == ALD_TIMER_CHANNEL_4) ? \
  573. (SET_BIT((handle)->perh->CCEP, TIMER_CCEP_CC4POL_MSK)) : (WRITE_REG(((handle)->perh->CCEP), (((handle)->perh->CCEP) | (1 << ((ch) << 2))))))
  574. /**
  575. * @brief Disable channel
  576. * @param handle: TIMER handle
  577. * @param ch: Must be one of this:
  578. * TIMER_CHANNEL_1
  579. * TIMER_CHANNEL_2
  580. * TIMER_CHANNEL_3
  581. * TIMER_CHANNEL_4
  582. */
  583. #define ALD_TIMER_CCx_DISABLE(handle, ch) (((ch) == ALD_TIMER_CHANNEL_4) ? \
  584. (CLEAR_BIT((handle)->perh->CCEP, TIMER_CCEP_CC4EN_MSK)) : ((handle)->perh->CCEP &= ~(1 << ((ch) << 2))))
  585. /**
  586. * @brief Enable complementary channel
  587. * @param handle: TIMER handle
  588. * @param ch: Must be one of this:
  589. * TIMER_CHANNEL_1
  590. * TIMER_CHANNEL_2
  591. * TIMER_CHANNEL_3
  592. */
  593. #define ALD_TIMER_CCxN_ENABLE(handle, ch) ((handle)->perh->CCEP |= (1 << (((ch) << 2) + 2)))
  594. /**
  595. * @brief Disable complementary channel
  596. * @param handle: TIMER handle
  597. * @param ch: Must be one of this:
  598. * TIMER_CHANNEL_1
  599. * TIMER_CHANNEL_2
  600. * TIMER_CHANNEL_3
  601. */
  602. #define ALD_TIMER_CCxN_DISABLE(handle, ch) ((handle)->perh->CCEP &= ~(1 << (((ch) << 2) + 2)))
  603. /**
  604. * @}
  605. */
  606. /** @defgroup TIMER_Private_Macros TIMER Private Macros
  607. * @{
  608. */
  609. #define IS_TIMER_INSTANCE(x) (((x) == AD16C4T) || \
  610. ((x) == BS16T) || \
  611. ((x) == GP16C4T0) || \
  612. ((x) == GP16C4T1) || \
  613. ((x) == GP16C4T2))
  614. #define IS_ADTIMER_INSTANCE(x) ((x) == AD16C4T)
  615. #define IS_TIMER_XOR_INSTANCE(x) (((x) == AD16C4T) || \
  616. ((x) == GP16C4T2) || \
  617. ((x) == GP16C4T1) || \
  618. ((x) == GP16C4T0))
  619. #define IS_TIMER_COM_EVENT_INSTANCE(x) (((x) == AD16C4T) || \
  620. ((x) == GP16C4T2) || \
  621. ((x) == GP16C4T1) || \
  622. ((x) == GP16C4T0))
  623. #define IS_TIMER_CC2_INSTANCE(x) (((x) == AD16C4T) || \
  624. ((x) == GP16C4T0) || \
  625. ((x) == GP16C4T1) || \
  626. ((x) == GP16C4T2))
  627. #define IS_TIMER_CC4_INSTANCE(x) (((x) == AD16C4T) || \
  628. ((x) == GP16C4T0) || \
  629. ((x) == GP16C4T1) || \
  630. ((x) == GP16C4T2))
  631. #define IS_TIMER_BREAK_INSTANCE(x) ((x) == AD16C4T)
  632. #define IS_TIMER_PWM_INPUT_INSTANCE(x, y) ((((x) == AD16C4T) && \
  633. (((y) == ALD_TIMER_CHANNEL_1) || \
  634. ((y) == ALD_TIMER_CHANNEL_2))) || \
  635. (((x) == GP16C4T0) && \
  636. (((y) == ALD_TIMER_CHANNEL_1) || \
  637. ((y) == ALD_TIMER_CHANNEL_2))) || \
  638. (((x) == GP16C4T1) && \
  639. (((y) == ALD_TIMER_CHANNEL_1) || \
  640. ((y) == ALD_TIMER_CHANNEL_2))) || \
  641. (((x) == GP16C4T2) && \
  642. (((y) == ALD_TIMER_CHANNEL_1) || \
  643. ((y) == ALD_TIMER_CHANNEL_2))))
  644. #define IS_TIMER_CCX_INSTANCE(x, y) ((((x) == AD16C4T) && \
  645. (((y) == ALD_TIMER_CHANNEL_1) || \
  646. ((y) == ALD_TIMER_CHANNEL_2) || \
  647. ((y) == ALD_TIMER_CHANNEL_3) || \
  648. ((y) == ALD_TIMER_CHANNEL_4))) || \
  649. (((x) == GP16C4T0) && \
  650. (((y) == ALD_TIMER_CHANNEL_1) || \
  651. ((y) == ALD_TIMER_CHANNEL_2) || \
  652. ((y) == ALD_TIMER_CHANNEL_3) || \
  653. ((y) == ALD_TIMER_CHANNEL_4))) || \
  654. (((x) == GP16C4T1) && \
  655. (((y) == ALD_TIMER_CHANNEL_1) || \
  656. ((y) == ALD_TIMER_CHANNEL_2) || \
  657. ((y) == ALD_TIMER_CHANNEL_3) || \
  658. ((y) == ALD_TIMER_CHANNEL_4))) || \
  659. (((x) == GP16C4T2) && \
  660. (((y) == ALD_TIMER_CHANNEL_1) || \
  661. ((y) == ALD_TIMER_CHANNEL_2) || \
  662. ((y) == ALD_TIMER_CHANNEL_3) || \
  663. ((y) == ALD_TIMER_CHANNEL_4))))
  664. #define IS_TIMER_CCXN_INSTANCE(x, y) (((x) == AD16C4T) && \
  665. (((y) == ALD_TIMER_CHANNEL_1) || \
  666. ((y) == ALD_TIMER_CHANNEL_2) || \
  667. ((y) == ALD_TIMER_CHANNEL_3) || \
  668. ((y) == ALD_TIMER_CHANNEL_4)))
  669. #define IS_TIMER_REPETITION_COUNTER_INSTANCE(x) ((x) == AD16C4T)
  670. #define IS_TIMER_CLOCK_DIVISION_INSTANCE(x) IS_TIMER_CC2_INSTANCE(x)
  671. #define IS_TIMER_COUNTER_MODE(x) (((x) == ALD_TIMER_CNT_MODE_UP) || \
  672. ((x) == ALD_TIMER_CNT_MODE_DOWN) || \
  673. ((x) == ALD_TIMER_CNT_MODE_CENTER1) || \
  674. ((x) == ALD_TIMER_CNT_MODE_CENTER2) || \
  675. ((x) == ALD_TIMER_CNT_MODE_CENTER3))
  676. #define IS_TIMER_CLOCK_DIVISION(x) (((x) == ALD_TIMER_CLOCK_DIV1) || \
  677. ((x) == ALD_TIMER_CLOCK_DIV2) || \
  678. ((x) == ALD_TIMER_CLOCK_DIV4))
  679. #define IS_TIMER_PWM_MODE(x) (((x) == ALD_TIMER_OC_MODE_PWM1) || \
  680. ((x) == ALD_TIMER_OC_MODE_PWM2))
  681. #define IS_TIMER_OC_MODE(x) (((x) == ALD_TIMER_OC_MODE_TIMERING) || \
  682. ((x) == ALD_TIMER_OC_MODE_ACTIVE) || \
  683. ((x) == ALD_TIMER_OC_MODE_INACTIVE) || \
  684. ((x) == ALD_TIMER_OC_MODE_TOGGLE) || \
  685. ((x) == ALD_TIMER_OC_MODE_FORCE_ACTIVE) || \
  686. ((x) == ALD_TIMER_OC_MODE_FORCE_INACTIVE) || \
  687. ((x) == ALD_TIMER_OC_MODE_PWM1) || \
  688. ((x) == ALD_TIMER_OC_MODE_PWM2))
  689. #define IS_TIMER_OC_POLARITY(x) (((x) == ALD_TIMER_OC_POLARITY_HIGH) || \
  690. ((x) == ALD_TIMER_OC_POLARITY_LOW))
  691. #define IS_TIMER_OCN_POLARITY(x) (((x) == ALD_TIMER_OCN_POLARITY_HIGH) || \
  692. ((x) == ALD_TIMER_OCN_POLARITY_LOW))
  693. #define IS_TIMER_OCIDLE_STATE(x) (((x) == ALD_TIMER_OC_IDLE_RESET) || \
  694. ((x) == ALD_TIMER_OC_IDLE_SET))
  695. #define IS_TIMER_OCNIDLE_STATE(x) (((x) == ALD_TIMER_OCN_IDLE_RESET) || \
  696. ((x) == ALD_TIMER_OCN_IDLE_SET))
  697. #define IS_TIMER_CHANNELS(x) (((x) == ALD_TIMER_CHANNEL_1) || \
  698. ((x) == ALD_TIMER_CHANNEL_2) || \
  699. ((x) == ALD_TIMER_CHANNEL_3) || \
  700. ((x) == ALD_TIMER_CHANNEL_4) || \
  701. ((x) == ALD_TIMER_CHANNEL_ALL))
  702. #define IS_TIMER_OP_MODE(x) (((x) == ALD_TIMER_OP_MODE_REPEAT) || \
  703. ((x) == ALD_TIMER_OP_MODE_SINGLE))
  704. #define IS_TIMER_OP_OUTPUT_CH(x) (((x) == ALD_TIMER_OP_OUTPUT_CHANNEL_1) || \
  705. ((x) == ALD_TIMER_OP_OUTPUT_CHANNEL_2))
  706. #define IS_TIMER_ENCODER_MODE(x) (((x) == ALD_TIMER_ENC_MODE_TI1) || \
  707. ((x) == ALD_TIMER_ENC_MODE_TI2) || \
  708. ((x) == ALD_TIMER_ENC_MODE_TI12))
  709. #define IS_TIMER_IC_POLARITY(x) (((x) == ALD_TIMER_IC_POLARITY_RISE) || \
  710. ((x) == ALD_TIMER_IC_POLARITY_FALL))
  711. #define IS_TIMER_IC_SELECT(x) (((x) == ALD_TIMER_IC_SEL_DIRECT) || \
  712. ((x) == ALD_TIMER_IC_SEL_INDIRECT) || \
  713. ((x) == ALD_TIMER_IC_SEL_TRC))
  714. #define IS_TIMER_IC_PSC(x) (((x) == ALD_TIMER_IC_PSC_DIV1) || \
  715. ((x) == ALD_TIMER_IC_PSC_DIV2) || \
  716. ((x) == ALD_TIMER_IC_PSC_DIV4) || \
  717. ((x) == ALD_TIMER_IC_PSC_DIV8))
  718. #define IS_TIMER_IC_FILTER(x) ((x) <= 0xF)
  719. #define IS_TIMER_DEAD_TIMERE(x) ((x) <= 0xFF)
  720. #define IS_TIMER_CLEAR_INPUT_SOURCE(x) (((x) == ALD_TIMER_INPUT_NONE) || \
  721. ((x) == ALD_TIMER_INPUT_ETR))
  722. #define IS_TIMER_CLEAR_INPUT_POLARITY(x) (((x) == ALD_TIMER_POLARITY_NO_INV) || \
  723. ((x) == ALD_TIMER_POLARITY_INV))
  724. #define IS_TIMER_ETR_PSC(x) (((x) == ALD_TIMER_ETR_PSC_DIV1) || \
  725. ((x) == ALD_TIMER_ETR_PSC_DIV2) || \
  726. ((x) == ALD_TIMER_ETR_PSC_DIV4) || \
  727. ((x) == ALD_TIMER_ETR_PSC_DIV8))
  728. #define IS_TIMER_CHNREF_CLEAR(X) (((X) == ALD_TIMER_CHNREF_CLR_CMP_IN) || \
  729. ((X) == ALD_TIMER_CHNREF_CLR_ETF))
  730. #define IS_TIMER_CLOCK_SOURCE(x) (((x) == ALD_TIMER_SRC_ETRMODE2) || \
  731. ((x) == ALD_TIMER_SRC_INTER) || \
  732. ((x) == ALD_TIMER_SRC_ITR0) || \
  733. ((x) == ALD_TIMER_SRC_ITR1) || \
  734. ((x) == ALD_TIMER_SRC_ITR2) || \
  735. ((x) == ALD_TIMER_SRC_ITR3) || \
  736. ((x) == ALD_TIMER_SRC_TI1ED) || \
  737. ((x) == ALD_TIMER_SRC_TI1) || \
  738. ((x) == ALD_TIMER_SRC_TI2) || \
  739. ((x) == ALD_TIMER_SRC_ETRMODE1))
  740. #define IS_TIMER_CLOCK_POLARITY(x) (((x) == ALD_TIMER_CLK_POLARITY_INV) || \
  741. ((x) == ALD_TIMER_CLK_POLARITY_NO_INV) || \
  742. ((x) == ALD_TIMER_CLK_POLARITY_RISE) || \
  743. ((x) == ALD_TIMER_CLK_POLARITY_FALL) || \
  744. ((x) == ALD_TIMER_CLK_POLARITY_BOTH))
  745. #define IS_TIMER_SLAVE_MODE(x) (((x) == ALD_TIMER_MODE_DISABLE) || \
  746. ((x) == ALD_TIMER_MODE_ENC1) || \
  747. ((x) == ALD_TIMER_MODE_ENC2) || \
  748. ((x) == ALD_TIMER_MODE_ENC3) || \
  749. ((x) == ALD_TIMER_MODE_RESET) || \
  750. ((x) == ALD_TIMER_MODE_GATED) || \
  751. ((x) == ALD_TIMER_MODE_TRIG) || \
  752. ((x) == ALD_TIMER_MODE_EXTERNAL1))
  753. #define IS_TIMER_EVENT_SOURCE(x) (((x) == ALD_TIMER_SRC_UPDATE) || \
  754. ((x) == ALD_TIMER_SRC_CC1) || \
  755. ((x) == ALD_TIMER_SRC_CC2) || \
  756. ((x) == ALD_TIMER_SRC_CC3) || \
  757. ((x) == ALD_TIMER_SRC_CC4) || \
  758. ((x) == ALD_TIMER_SRC_COM) || \
  759. ((x) == ALD_TIMER_SRC_TRIG) || \
  760. ((x) == ALD_TIMER_SRC_BREAK))
  761. #define IS_TIMER_TS(x) (((x) == ALD_TIMER_TS_ITR0) || \
  762. ((x) == ALD_TIMER_TS_ITR1) || \
  763. ((x) == ALD_TIMER_TS_ITR2) || \
  764. ((x) == ALD_TIMER_TS_ITR3) || \
  765. ((x) == ALD_TIMER_TS_TI1F_ED) || \
  766. ((x) == ALD_TIMER_TS_TI1FP1) || \
  767. ((x) == ALD_TIMER_TS_TI2FP2) || \
  768. ((x) == ALD_TIMER_TS_ETRF))
  769. #define IS_TIMER_CLOCK_LEVEL(x) (((x) == ALD_TIMER_LOCK_LEVEL_OFF) || \
  770. ((x) == ALD_TIMER_LOCK_LEVEL_1) || \
  771. ((x) == ALD_TIMER_LOCK_LEVEL_2) || \
  772. ((x) == ALD_TIMER_LOCK_LEVEL_3))
  773. #define IS_TIMER_BREAK_POLARITY(x) (((x) == ALD_TIMER_BREAK_POLARITY_LOW) || \
  774. ((x) == ALD_TIMER_BREAK_POLARITY_HIGH))
  775. #define IS_TIMER_MASTER_MODE_SEL(x) (((x) == ALD_TIMER_TRGO_RESET) || \
  776. ((x) == ALD_TIMER_TRGO_ENABLE) || \
  777. ((x) == ALD_TIMER_TRGO_UPDATE) || \
  778. ((x) == ALD_TIMER_TRGO_OC1) || \
  779. ((x) == ALD_TIMER_TRGO_OC1REF) || \
  780. ((x) == ALD_TIMER_TRGO_OC2REF) || \
  781. ((x) == ALD_TIMER_TRGO_OC3REF) || \
  782. ((x) == ALD_TIMER_TRGO_OC4REF))
  783. #define IS_TIMER_IT(x) (((x) == ALD_TIMER_IT_UPDATE) || \
  784. ((x) == ALD_TIMER_IT_CC1) || \
  785. ((x) == ALD_TIMER_IT_CC2) || \
  786. ((x) == ALD_TIMER_IT_CC3) || \
  787. ((x) == ALD_TIMER_IT_CC4) || \
  788. ((x) == ALD_TIMER_IT_COM) || \
  789. ((x) == ALD_TIMER_IT_TRIGGER) || \
  790. ((x) == ALD_TIMER_IT_BREAK))
  791. #define IS_TIMER_DMA_REQ(x) (((x) == ALD_TIMER_DMA_UPDATE) || \
  792. ((x) == ALD_TIMER_DMA_CC1) || \
  793. ((x) == ALD_TIMER_DMA_CC2) || \
  794. ((x) == ALD_TIMER_DMA_CC3) || \
  795. ((x) == ALD_TIMER_DMA_CC4) || \
  796. ((x) == ALD_TIMER_DMA_COM) || \
  797. ((x) == ALD_TIMER_DMA_TRIGGER))
  798. #define IS_TIMER_FLAG(x) (((x) == ALD_TIMER_FLAG_UPDATE) || \
  799. ((x) == ALD_TIMER_FLAG_CC1) || \
  800. ((x) == ALD_TIMER_FLAG_CC2) || \
  801. ((x) == ALD_TIMER_FLAG_CC3) || \
  802. ((x) == ALD_TIMER_FLAG_CC4) || \
  803. ((x) == ALD_TIMER_FLAG_COM) || \
  804. ((x) == ALD_TIMER_FLAG_TRIGGER) || \
  805. ((x) == ALD_TIMER_FLAG_BREAK) || \
  806. ((x) == ALD_TIMER_FLAG_CC1OF) || \
  807. ((x) == ALD_TIMER_FLAG_CC2OF) || \
  808. ((x) == ALD_TIMER_FLAG_CC3OF) || \
  809. ((x) == ALD_TIMER_FLAG_CC4OF))
  810. /**
  811. * @}
  812. */
  813. /** @addtogroup TIMER_Public_Functions
  814. * @{
  815. */
  816. /** @addtogroup TIMER_Public_Functions_Group1
  817. * @{
  818. */
  819. /* Time Base functions */
  820. ald_status_t ald_timer_base_init(ald_timer_handle_t *hperh);
  821. void ald_timer_base_reset(ald_timer_handle_t *hperh);
  822. void ald_timer_base_start(ald_timer_handle_t *hperh);
  823. void ald_timer_base_stop(ald_timer_handle_t *hperh);
  824. void ald_timer_base_start_by_it(ald_timer_handle_t *hperh);
  825. void ald_timer_base_stop_by_it(ald_timer_handle_t *hperh);
  826. ald_status_t ald_timer_base_start_by_dma(ald_timer_handle_t *hperh,
  827. uint16_t *buf, uint32_t len, uint8_t dma_ch);
  828. void ald_timer_base_stop_by_dma(ald_timer_handle_t *hperh);
  829. /**
  830. * @}
  831. */
  832. /** @addtogroup TIMER_Public_Functions_Group2
  833. * @{
  834. */
  835. /* Timer Output Compare functions */
  836. ald_status_t ald_timer_oc_init(ald_timer_handle_t *hperh);
  837. void ald_timer_oc_start(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  838. void ald_timer_oc_stop(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  839. void ald_timer_oc_start_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  840. void ald_timer_oc_stop_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  841. ald_status_t ald_timer_oc_start_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch,
  842. uint16_t *buf, uint32_t len, uint8_t dma_ch);
  843. void ald_timer_oc_stop_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  844. /**
  845. * @}
  846. */
  847. /** @addtogroup TIMER_Public_Functions_Group3
  848. * @{
  849. */
  850. /* Timer PWM functions */
  851. ald_status_t ald_timer_pwm_init(ald_timer_handle_t *hperh);
  852. void ald_timer_pwm_start(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  853. void ald_timer_pwm_stop(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  854. void ald_timer_pwm_start_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  855. void ald_timer_pwm_stop_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  856. void ald_timer_pwm_set_freq(ald_timer_handle_t *hperh, uint32_t freq);
  857. void ald_timer_pwm_set_duty(ald_timer_handle_t *hperh, ald_timer_channel_t ch, uint16_t duty);
  858. void ald_timer_pwm_set_input(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  859. ald_status_t ald_timer_pwm_start_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch,
  860. uint16_t *buf, uint32_t len, uint8_t dma_ch);
  861. void ald_timer_pwm_stop_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  862. /**
  863. * @}
  864. */
  865. /** @addtogroup TIMER_Public_Functions_Group4
  866. * @{
  867. */
  868. /* Timer Input Capture functions */
  869. ald_status_t ald_timer_ic_init(ald_timer_handle_t *hperh);
  870. void ald_timer_ic_start(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  871. void ald_timer_ic_stop(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  872. void ald_timer_ic_start_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  873. void ald_timer_ic_stop_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  874. ald_status_t ald_timer_ic_start_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch,
  875. uint16_t *buf, uint32_t len, uint8_t dma_ch);
  876. void ald_timer_ic_stop_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  877. /**
  878. * @}
  879. */
  880. /** @addtogroup TIMER_Public_Functions_Group5
  881. * @{
  882. */
  883. /* Timer One Pulse functions */
  884. ald_status_t ald_timer_one_pulse_init(ald_timer_handle_t *hperh, ald_timer_op_mode_t mode);
  885. void ald_timer_one_pulse_start(ald_timer_handle_t *hperh, ald_timer_op_output_channel_t ch);
  886. void ald_timer_one_pulse_stop(ald_timer_handle_t *hperh, ald_timer_op_output_channel_t ch);
  887. void ald_timer_one_pulse_start_by_it(ald_timer_handle_t *hperh, ald_timer_op_output_channel_t ch);
  888. void ald_timer_one_pulse_stop_by_it(ald_timer_handle_t *hperh, ald_timer_op_output_channel_t ch);
  889. /**
  890. * @}
  891. */
  892. /** @addtogroup TIMER_Public_Functions_Group6
  893. * @{
  894. */
  895. /* Timer encoder functions */
  896. ald_status_t ald_timer_encoder_init(ald_timer_handle_t *hperh, ald_timer_encoder_init_t *config);
  897. void ald_timer_encoder_start(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  898. void ald_timer_encoder_stop(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  899. void ald_timer_encoder_start_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  900. void ald_timer_encoder_stop_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  901. ald_status_t ald_timer_encoder_start_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch,
  902. uint16_t *buf1, uint16_t *buf2, uint32_t len,
  903. uint8_t dma_ch1, uint8_t dma_ch2);
  904. void ald_timer_encoder_stop_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  905. /**
  906. * @}
  907. */
  908. /** @addtogroup TIMER_Public_Functions_Group7
  909. * @{
  910. */
  911. /* Timer hall sensor functions */
  912. ald_status_t ald_timer_hall_sensor_init(ald_timer_handle_t *hperh, ald_timer_hall_sensor_init_t *config);
  913. void ald_timer_hall_sensor_start(ald_timer_handle_t *hperh);
  914. void ald_timer_hall_sensor_stop(ald_timer_handle_t *hperh);
  915. void ald_timer_hall_sensor_start_by_it(ald_timer_handle_t *hperh);
  916. void ald_timer_hall_sensor_stop_by_it(ald_timer_handle_t *hperh);
  917. ald_status_t ald_timer_hall_sensor_start_by_dma(ald_timer_handle_t *hperh,
  918. uint16_t *buf, uint32_t len, uint8_t dma_ch);
  919. void ald_timer_hall_sensor_stop_by_dma(ald_timer_handle_t *hperh);
  920. /**
  921. * @}
  922. */
  923. /** @addtogroup TIMER_Public_Functions_Group8
  924. * @{
  925. */
  926. /* Timer complementary output compare functions */
  927. void ald_timer_ocn_start(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  928. void ald_timer_ocn_stop(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  929. void ald_timer_ocn_start_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  930. void ald_timer_ocn_stop_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  931. ald_status_t ald_timer_ocn_start_by_dma(ald_timer_handle_t *hperh,
  932. ald_timer_channel_t ch, uint16_t *buf, uint32_t len, uint8_t dma_ch);
  933. void ald_timer_ocn_stop_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  934. /**
  935. * @}
  936. */
  937. /** @addtogroup TIMER_Public_Functions_Group9
  938. * @{
  939. */
  940. /* Timer complementary PWM functions */
  941. void ald_timer_pwmn_start(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  942. void ald_timer_pwmn_stop(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  943. void ald_timer_pwmn_start_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  944. void ald_timer_pwmn_stop_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  945. ald_status_t ald_timer_pwmn_start_by_dma(ald_timer_handle_t *hperh,
  946. ald_timer_channel_t ch, uint16_t *buf, uint32_t len, uint8_t dma_ch);
  947. void ald_timer_pwmn_stop_by_dma(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  948. /**
  949. * @}
  950. */
  951. /** @addtogroup TIMER_Public_Functions_Group10
  952. * @{
  953. */
  954. /* Timer complementary one pulse functions */
  955. void ald_timer_one_pulse_n_start(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  956. void ald_timer_one_pulse_n_stop(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  957. void ald_timer_one_pulse_n_start_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  958. void ald_timer_one_pulse_n_stop_by_it(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  959. /**
  960. * @}
  961. */
  962. /** @addtogroup TIMER_Public_Functions_Group11
  963. * @{
  964. */
  965. /* Control functions */
  966. ald_status_t ald_timer_oc_config_channel(ald_timer_handle_t *hperh, ald_timer_oc_init_t* config, ald_timer_channel_t ch);
  967. ald_status_t ald_timer_ic_config_channel(ald_timer_handle_t *hperh, ald_timer_ic_init_t* config, ald_timer_channel_t ch);
  968. ald_status_t ald_timer_one_pulse_config_channel(ald_timer_handle_t *hperh, ald_timer_one_pulse_init_t *config, ald_timer_channel_t ch_out, ald_timer_channel_t ch_in);
  969. ald_status_t ald_timer_config_oc_ref_clear(ald_timer_handle_t *hperh, ald_timer_clear_input_config_t *config, ald_timer_channel_t ch);
  970. ald_status_t ald_timer_config_clock_source(ald_timer_handle_t *hperh, ald_timer_clock_config_t *config);
  971. ald_status_t ald_timer_config_ti1_input(ald_timer_handle_t *hperh, uint32_t ti1_select);
  972. ald_status_t ald_timer_slave_config_sync(ald_timer_handle_t *hperh, ald_timer_slave_config_t *config);
  973. ald_status_t ald_timer_slave_config_sync_by_it(ald_timer_handle_t *hperh, ald_timer_slave_config_t *config);
  974. ald_status_t ald_timer_generate_event(ald_timer_handle_t *hperh, ald_timer_event_source_t event);
  975. uint32_t ald_timer_read_capture_value(ald_timer_handle_t *hperh, ald_timer_channel_t ch);
  976. void ald_timer_set_output_mode(ald_timer_handle_t *hperh, ald_timer_oc_mode_t mode, ald_timer_channel_t ch);
  977. void ald_timer_com_change_config(ald_timer_handle_t *hperh, ald_timer_com_channel_config_t *config);
  978. void ald_timer_com_event_config(ald_timer_handle_t *hperh, ald_timer_ts_t ts, type_func_t trgi);
  979. void ald_timer_com_event_config_it(ald_timer_handle_t *hperh, ald_timer_ts_t ts, type_func_t trgi);
  980. void ald_timer_break_dead_time_config(ald_timer_handle_t *hperh, ald_timer_break_dead_time_t *config);
  981. void ald_timer_master_sync_config(ald_timer_handle_t *hperh, ald_timer_master_config_t *config);
  982. void ald_timer_irq_handler(ald_timer_handle_t *hperh);
  983. void ald_timer_dma_req_config(ald_timer_handle_t *hperh, ald_timer_dma_req_t req, type_func_t state);
  984. void ald_timer_interrupt_config(ald_timer_handle_t *hperh, ald_timer_it_t it, type_func_t state);
  985. it_status_t ald_timer_get_it_status(ald_timer_handle_t *hperh, ald_timer_it_t it);
  986. flag_status_t ald_timer_get_flag_status(ald_timer_handle_t *hperh, ald_timer_flag_t flag);
  987. void ald_timer_clear_flag_status(ald_timer_handle_t *hperh, ald_timer_flag_t flag);
  988. /**
  989. * @}
  990. */
  991. /** @addtogroup TIMER_Public_Functions_Group12
  992. * @{
  993. */
  994. /* State functions */
  995. ald_timer_state_t ald_timer_get_state(ald_timer_handle_t *hperh);
  996. /**
  997. * @}
  998. */
  999. /**
  1000. * @}
  1001. */
  1002. /**
  1003. * @}
  1004. */
  1005. /**
  1006. * @}
  1007. */
  1008. #ifdef __cplusplus
  1009. }
  1010. #endif /* __cplusplus */
  1011. #endif /* __ALD_TIMER_H__ */