ald_timer.h 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  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 06 Nov 2017
  10. * @author AE Team
  11. * @note
  12. *
  13. * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
  14. *
  15. *********************************************************************************
  16. */
  17. #ifndef __ALD_TIMER_H__
  18. #define __ALD_TIMER_H__
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #include "utils.h"
  23. #include "ald_dma.h"
  24. /** @addtogroup ES32FXXX_ALD
  25. * @{
  26. */
  27. /** @addtogroup TIMER
  28. * @{
  29. */
  30. /** @defgroup TIMER_Public_Types TIMER Public Types
  31. * @{
  32. */
  33. /**
  34. * @brief TIMER counter mode
  35. */
  36. typedef enum {
  37. TIMER_CNT_MODE_UP = 0, /**< Counter mode up */
  38. TIMER_CNT_MODE_DOWN = 1, /**< Counter mode down */
  39. TIMER_CNT_MODE_CENTER1 = 2, /**< Counter mode center1 */
  40. TIMER_CNT_MODE_CENTER2 = 3, /**< Counter mode center2 */
  41. TIMER_CNT_MODE_CENTER3 = 4, /**< Counter mode center3 */
  42. } timer_cnt_mode_t;
  43. /**
  44. * @brief TIMER clock division
  45. */
  46. typedef enum {
  47. TIMER_CLOCK_DIV1 = 0, /**< No prescaler is used */
  48. TIMER_CLOCK_DIV2 = 1, /** Clock is divided by 2 */
  49. TIMER_CLOCK_DIV4 = 2, /** Clock is divided by 4 */
  50. } timer_clock_division_t;
  51. /**
  52. * @brief TIMER output compare and PWM modes
  53. */
  54. typedef enum {
  55. TIMER_OC_MODE_TIMERING = 0, /**< Output compare mode is timering */
  56. TIMER_OC_MODE_ACTIVE = 1, /**< Output compare mode is active */
  57. TIMER_OC_MODE_INACTIVE = 2, /**< Output compare mode is inactive */
  58. TIMER_OC_MODE_TOGGLE = 3, /**< Output compare mode is toggle */
  59. TIMER_OC_MODE_FORCE_INACTIVE = 4, /**< Output compare mode is force inactive */
  60. TIMER_OC_MODE_FORCE_ACTIVE = 5, /**< Output compare mode is force active */
  61. TIMER_OC_MODE_PWM1 = 6, /**< Output compare mode is pwm1 */
  62. TIMER_OC_MODE_PWM2 = 7, /**< Output compare mode is pwm2 */
  63. } timer_oc_mode_t;
  64. /**
  65. * @brief TIMER output compare polarity
  66. */
  67. typedef enum {
  68. TIMER_OC_POLARITY_HIGH = 0, /**< Output compare polarity is high */
  69. TIMER_OC_POLARITY_LOW = 1, /**< Output compare polarity is low */
  70. } timer_oc_polarity_t;
  71. /**
  72. * @brief TIMER complementary output compare polarity
  73. */
  74. typedef enum {
  75. TIMER_OCN_POLARITY_HIGH = 0, /**< Complementary output compare polarity is high */
  76. TIMER_OCN_POLARITY_LOW = 1, /**< Complementary output compare polarity is low */
  77. } timer_ocn_polarity_t;
  78. /**
  79. * @brief TIMER output compare idle state
  80. */
  81. typedef enum {
  82. TIMER_OC_IDLE_RESET = 0, /**< Output compare idle state is reset */
  83. TIMER_OC_IDLE_SET = 1, /**< Output compare idle state is set */
  84. } timer_oc_idle_t;
  85. /**
  86. * @brief TIMER complementary output compare idle state
  87. */
  88. typedef enum {
  89. TIMER_OCN_IDLE_RESET = 0, /**< Complementary output compare idle state is reset */
  90. TIMER_OCN_IDLE_SET = 1, /**< Complementary output compare idle state is set */
  91. } timer_ocn_idle_t;
  92. /**
  93. * @brief TIMER channel
  94. */
  95. typedef enum {
  96. TIMER_CHANNEL_1 = 0, /**< Channel 1 */
  97. TIMER_CHANNEL_2 = 1, /**< Channel 2 */
  98. TIMER_CHANNEL_3 = 2, /**< Channel 3 */
  99. TIMER_CHANNEL_4 = 4, /**< Channel 4 */
  100. TIMER_CHANNEL_ALL = 0xF, /**< All channel */
  101. } timer_channel_t;
  102. /**
  103. * @brief TIMER one pulse mode
  104. */
  105. typedef enum {
  106. TIMER_OP_MODE_REPEAT = 0, /**< Repetitive */
  107. TIMER_OP_MODE_SINGLE = 1, /**< single */
  108. } timer_op_mode_t;
  109. /**
  110. * @brief TIMER one pulse output channel
  111. */
  112. typedef enum {
  113. TIMER_OP_OUTPUT_CHANNEL_1 = 0, /**< One pulse output channal 1 */
  114. TIMER_OP_OUTPUT_CHANNEL_2 = 1, /**< One pulse output channal 2 */
  115. } timer_op_output_channel_t;
  116. /**
  117. * @brief TIMER time base configuration structure definition
  118. */
  119. typedef struct {
  120. uint32_t prescaler; /**< Specifies the prescaler value used to divide the TIMER clock. */
  121. timer_cnt_mode_t mode; /**< Specifies the counter mode. */
  122. uint32_t period; /**< Specifies the period value to be loaded into ARR at the next update event. */
  123. timer_clock_division_t clk_div; /**< Specifies the clock division.*/
  124. uint32_t re_cnt; /**< Specifies the repetition counter value. */
  125. } timer_base_init_t;
  126. /**
  127. * @brief TIMER output compare configuration structure definition
  128. */
  129. typedef struct {
  130. timer_oc_mode_t oc_mode; /**< Specifies the TIMER mode. */
  131. uint32_t pulse; /**< Specifies the pulse value to be loaded into the Capture Compare Register. */
  132. timer_oc_polarity_t oc_polarity; /**< Specifies the output polarity. */
  133. timer_ocn_polarity_t ocn_polarity; /**< Specifies the complementary output polarity. */
  134. type_func_t oc_fast_en; /**< Specifies the Fast mode state. */
  135. timer_oc_idle_t oc_idle; /**< Specifies the TIMER Output Compare pin state during Idle state. */
  136. timer_ocn_idle_t ocn_idle; /**< Specifies the TIMER Output Compare pin state during Idle state. */
  137. } timer_oc_init_t;
  138. /**
  139. * @brief State structures definition
  140. */
  141. typedef enum {
  142. TIMER_STATE_RESET = 0x00, /**< Peripheral not yet initialized or disabled */
  143. TIMER_STATE_READY = 0x01, /**< Peripheral Initialized and ready for use */
  144. TIMER_STATE_BUSY = 0x02, /**< An internal process is ongoing */
  145. TIMER_STATE_TIMEREOUT = 0x03, /**< Timeout state */
  146. TIMER_STATE_ERROR = 0x04, /**< Reception process is ongoing */
  147. } timer_state_t;
  148. /**
  149. * @brief Active channel structures definition
  150. */
  151. typedef enum {
  152. TIMER_ACTIVE_CHANNEL_1 = 0x01, /**< The active channel is 1 */
  153. TIMER_ACTIVE_CHANNEL_2 = 0x02, /**< The active channel is 2 */
  154. TIMER_ACTIVE_CHANNEL_3 = 0x04, /**< The active channel is 3 */
  155. TIMER_ACTIVE_CHANNEL_4 = 0x08, /**< The active channel is 4 */
  156. TIMER_ACTIVE_CHANNEL_CLEARED = 0x00, /**< All active channels cleared */
  157. } timer_active_channel_t;
  158. /**
  159. * @brief TIMER time base handle structure definition
  160. */
  161. typedef struct timer_handle_s {
  162. TIMER_TypeDef *perh; /**< Register base address */
  163. timer_base_init_t init; /**< TIMER Time Base required parameters */
  164. timer_active_channel_t ch; /**< Active channel */
  165. lock_state_t lock; /**< Locking object */
  166. timer_state_t state; /**< TIMER operation state */
  167. void (*period_elapse_cbk)(struct timer_handle_s *arg); /**< Period elapse callback */
  168. void (*delay_elapse_cbk)(struct timer_handle_s *arg); /**< Delay_elapse callback */
  169. void (*capture_cbk)(struct timer_handle_s *arg); /**< Capture callback */
  170. void (*pwm_pulse_finish_cbk)(struct timer_handle_s *arg); /**< PWM_pulse_finish callback */
  171. void (*trigger_cbk)(struct timer_handle_s *arg); /**< Trigger callback */
  172. void (*break_cbk)(struct timer_handle_s *arg); /**< Break callback */
  173. void (*com_cbk)(struct timer_handle_s *arg); /**< commutation callback */
  174. void (*error_cbk)(struct timer_handle_s *arg); /**< Error callback */
  175. } timer_handle_t;
  176. /**
  177. * @brief TIMER encoder mode
  178. */
  179. typedef enum {
  180. TIMER_ENC_MODE_TI1 = 1, /**< encoder mode 1 */
  181. TIMER_ENC_MODE_TI2 = 2, /**< encoder mode 2 */
  182. TIMER_ENC_MODE_TI12 = 3, /**< encoder mode 3 */
  183. } timer_encoder_mode_t;
  184. /**
  185. * @brief TIMER input capture polarity
  186. */
  187. typedef enum {
  188. TIMER_IC_POLARITY_RISE = 0, /**< Input capture polarity rising */
  189. TIMER_IC_POLARITY_FALL = 1, /**< Input capture polarity falling */
  190. TIMER_IC_POLARITY_BOTH = 3, /**< Input capture polarity rising and falling */
  191. } timer_ic_polarity_t;
  192. /**
  193. *@brief TIMER input capture selection
  194. */
  195. typedef enum {
  196. TIMER_IC_SEL_DIRECT = 1, /**< IC1 -- TI1 */
  197. TIMER_IC_SEL_INDIRECT = 2, /**< IC1 -- TI2 */
  198. TIMER_IC_SEL_TRC = 3, /**< IC1 -- TRC */
  199. } timer_ic_select_t;
  200. /**
  201. * @brief TIMER input capture prescaler
  202. */
  203. typedef enum {
  204. TIMER_IC_PSC_DIV1 = 0, /**< Capture performed once every 1 events */
  205. TIMER_IC_PSC_DIV2 = 1, /**< Capture performed once every 2 events */
  206. TIMER_IC_PSC_DIV4 = 2, /**< Capture performed once every 4 events */
  207. TIMER_IC_PSC_DIV8 = 3, /**< Capture performed once every 4 events */
  208. } timer_ic_prescaler_t;
  209. /**
  210. * @brief TIMER encoder configuration structure definition
  211. */
  212. typedef struct {
  213. timer_encoder_mode_t mode; /**< Specifies the encoder mode */
  214. timer_ic_polarity_t ic1_polarity; /**< Specifies the active edge of the input signal */
  215. timer_ic_select_t ic1_sel; /**< Specifies the input */
  216. timer_ic_prescaler_t ic1_psc; /**< Specifies the Input Capture Prescaler */
  217. uint32_t ic1_filter; /**< Specifies the input capture filter */
  218. timer_ic_polarity_t ic2_polarity; /**< Specifies the active edge of the input signal */
  219. timer_ic_select_t ic2_sel; /**< Specifies the input */
  220. timer_ic_prescaler_t ic2_psc; /**< Specifies the Input Capture Prescaler */
  221. uint32_t ic2_filter; /**< Specifies the input capture filter */
  222. } timer_encoder_init_t;
  223. /**
  224. * @brief TIMER input capture configuration structure definition
  225. */
  226. typedef struct {
  227. timer_ic_polarity_t polarity; /**< Specifies the active edge of the input signal */
  228. timer_ic_select_t sel; /**< Specifies the input */
  229. timer_ic_prescaler_t psc; /**< Specifies the Input Capture Prescaler */
  230. uint32_t filter; /**< Specifies the input capture filter */
  231. } timer_ic_init_t;
  232. /**
  233. * @brief TIMER one pulse mode configuration structure definition
  234. */
  235. typedef struct {
  236. timer_oc_mode_t mode; /**< Specifies the TIMER mode */
  237. uint16_t pulse; /**< Specifies the pulse value */
  238. timer_oc_polarity_t oc_polarity; /**< Specifies the output polarity */
  239. timer_ocn_polarity_t ocn_polarity; /**< Specifies the complementary output polarity */
  240. timer_oc_idle_t oc_idle; /**< Specifies the TIMER Output Compare pin state during Idle state */
  241. timer_ocn_idle_t ocn_idle; /**< Specifies the TIMER Output Compare pin state during Idle state */
  242. timer_ic_polarity_t polarity; /**< Specifies the active edge of the input signal */
  243. timer_ic_select_t sel; /**< Specifies the input */
  244. uint32_t filter; /**< Specifies the input capture filter */
  245. } timer_one_pulse_init_t;
  246. /** @brief TIMER clear input source
  247. */
  248. typedef enum {
  249. TIMER_INPUT_NONE = 0, /**< Clear input none */
  250. TIMER_INPUT_ETR = 1, /**< Clear input etr */
  251. } timer_clear_input_source_t;
  252. /** @brief TIMER clear input polarity
  253. */
  254. typedef enum {
  255. TIMER_POLARITY_NO_INV = 0, /**< Polarity for ETRx pin */
  256. TIMER_POLARITY_INV = 1, /**< Polarity for ETRx pin */
  257. } timer_clear_input_polarity_t;
  258. /** @brief TIMER clear input polarity
  259. */
  260. typedef enum {
  261. TIMER_ETR_PSC_DIV1 = 0, /**< No prescaler is used */
  262. TIMER_ETR_PSC_DIV2 = 1, /**< ETR input source is divided by 2 */
  263. TIMER_ETR_PSC_DIV4 = 2, /**< ETR input source is divided by 4 */
  264. TIMER_ETR_PSC_DIV8 = 3, /**< ETR input source is divided by 8 */
  265. } timer_etr_psc_t;
  266. /**
  267. * @brief TIMER clear input configuration handle structure definition
  268. */
  269. typedef struct {
  270. type_func_t state; /**< TIMER clear Input state */
  271. timer_clear_input_source_t source; /**< TIMER clear Input sources */
  272. timer_clear_input_polarity_t polarity; /**< TIMER Clear Input polarity */
  273. timer_etr_psc_t psc; /**< TIMER Clear Input prescaler */
  274. uint32_t filter; /**< TIMER Clear Input filter */
  275. } timer_clear_input_config_t;
  276. /** @brief TIMER clock source
  277. */
  278. typedef enum {
  279. TIMER_SRC_ETRMODE2 = 0, /**< Clock source is etr mode2 */
  280. TIMER_SRC_INTER = 1, /**< Clock source is etr internal */
  281. TIMER_SRC_ITR0 = 2, /**< Clock source is etr itr0 */
  282. TIMER_SRC_ITR1 = 3, /**< Clock source is etr itr1 */
  283. TIMER_SRC_ITR2 = 4, /**< Clock source is etr itr2 */
  284. TIMER_SRC_ITR3 = 5, /**< Clock source is etr itr3 */
  285. TIMER_SRC_TI1ED = 6, /**< Clock source is etr ti1ed */
  286. TIMER_SRC_TI1 = 7, /**< Clock source is etr ti1 */
  287. TIMER_SRC_TI2 = 8, /**< Clock source is etr ti2 */
  288. TIMER_SRC_ETRMODE1 = 9, /**< Clock source is etr mode1 */
  289. } timer_clock_source_t;
  290. /** @brief TIMER clock polarity
  291. */
  292. typedef enum {
  293. TIMER_CLK_POLARITY_INV = 1, /**< Polarity for ETRx clock sources */
  294. TIMER_CLK_POLARITY_NO_INV = 0, /**< Polarity for ETRx clock sources */
  295. TIMER_CLK_POLARITY_RISE = 0, /**< Polarity for TIx clock sources */
  296. TIMER_CLK_POLARITY_FALL = 1, /**< Polarity for TIx clock sources */
  297. TIMER_CLK_POLARITY_BOTH = 3, /**< Polarity for TIx clock sources */
  298. } timer_clock_polarity_t;
  299. /**
  300. * @brief TIMER clock config structure definition
  301. */
  302. typedef struct {
  303. timer_clock_source_t source; /**< TIMER clock sources */
  304. timer_clock_polarity_t polarity; /**< TIMER clock polarity */
  305. timer_etr_psc_t psc; /**< TIMER clock prescaler */
  306. uint32_t filter; /**< TIMER clock filter */
  307. } timer_clock_config_t;
  308. /**
  309. * @brief TIMER slave mode
  310. */
  311. typedef enum {
  312. TIMER_MODE_DISABLE = 0, /**< Slave mode is disable */
  313. TIMER_MODE_ENC1 = 1, /**< Slave mode is encoder1 */
  314. TIMER_MODE_ENC2 = 2, /**< Slave mode is encoder2 */
  315. TIMER_MODE_ENC3 = 3, /**< Slave mode is encoder3 */
  316. TIMER_MODE_RESET = 4, /**< Slave mode is reset */
  317. TIMER_MODE_GATED = 5, /**< Slave mode is gated */
  318. TIMER_MODE_TRIG = 6, /**< Slave mode is trigger */
  319. TIMER_MODE_EXTERNAL1 = 7, /**< Slave mode is external1 */
  320. } timer_slave_mode_t;
  321. /**
  322. * @brief TIMER ts definition
  323. */
  324. typedef enum {
  325. TIMER_TS_ITR0 = 0, /**< ITR0 */
  326. TIMER_TS_ITR1 = 1, /**< ITR1 */
  327. TIMER_TS_ITR2 = 2, /**< ITR2 */
  328. TIMER_TS_ITR3 = 3, /**< ITR3 */
  329. TIMER_TS_TI1F_ED = 4, /**< TI1F_ED */
  330. TIMER_TS_TI1FP1 = 5, /**< TI1FP1 */
  331. TIMER_TS_TI2FP2 = 6, /**< TI2FP2 */
  332. TIMER_TS_ETRF = 7, /**< ETRF */
  333. } timer_ts_t;
  334. /**
  335. * @brief TIMER slave configuration structure definition
  336. */
  337. typedef struct {
  338. timer_slave_mode_t mode; /**< Slave mode selection */
  339. timer_ts_t input; /**< Input Trigger source */
  340. timer_clock_polarity_t polarity; /**< Input Trigger polarity */
  341. timer_etr_psc_t psc; /**< Input trigger prescaler */
  342. uint32_t filter; /**< Input trigger filter */
  343. } timer_slave_config_t;
  344. /**
  345. * @brief TIMER hall sensor configuretion structure definition
  346. */
  347. typedef struct {
  348. timer_ic_polarity_t polarity; /**< Specifies the active edge of the input signal */
  349. timer_ic_prescaler_t psc; /**< Specifies the Input Capture Prescaler */
  350. uint32_t filter; /**< Specifies the input capture filter [0x0, 0xF] */
  351. uint32_t delay; /**< Specifies the pulse value to be loaded into the register [0x0, 0xFFFF] */
  352. } timer_hall_sensor_init_t;
  353. /**
  354. * @brief TIMER lock level
  355. */
  356. typedef enum {
  357. TIMER_LOCK_LEVEL_OFF = 0, /**< Lock off */
  358. TIMER_LOCK_LEVEL_1 = 1, /**< Lock level 1 */
  359. TIMER_LOCK_LEVEL_2 = 2, /**< Lock level 2 */
  360. TIMER_LOCK_LEVEL_3 = 3, /**< Lock level 3 */
  361. } timer_lock_level_t;
  362. /**
  363. * @brief TIMER break polarity
  364. */
  365. typedef enum {
  366. TIMER_BREAK_POLARITY_LOW = 0, /**< LOW */
  367. TIMER_BREAK_POLARITY_HIGH = 1, /**< HIGH */
  368. } timer_break_polarity_t;
  369. /**
  370. * @brief TIMER break and dead time configuretion structure definition
  371. */
  372. typedef struct {
  373. type_func_t off_run; /**< Enalbe/Disable off state in run mode */
  374. type_func_t off_idle; /**< Enalbe/Disable off state in idle mode */
  375. timer_lock_level_t lock_level; /**< Lock level */
  376. uint32_t dead_time; /**< Dead time, [0x0, 0xFF] */
  377. type_func_t break_state; /**< Break state */
  378. timer_break_polarity_t polarity; /**< Break input polarity */
  379. type_func_t auto_out; /**< Enalbe/Disable automatic output */
  380. } timer_break_dead_time_t;
  381. /**
  382. * @brief TIMER commutation event channel configuretion structure definition
  383. */
  384. typedef struct {
  385. type_func_t en; /**< Enalbe/Disable the channel */
  386. type_func_t n_en; /**< Enalbe/Disable the complementary channel */
  387. timer_oc_mode_t mode; /**< Mode of the channel */
  388. } timer_channel_config_t;
  389. /**
  390. * @brief TIMER commutation event configuretion structure definition
  391. */
  392. typedef struct {
  393. timer_channel_config_t ch[3]; /**< Configure of channel */
  394. } timer_com_channel_config_t;
  395. /**
  396. * @brief TIMER master mode selection
  397. */
  398. typedef enum {
  399. TIMER_TRGO_RESET = 0, /**< RESET */
  400. TIMER_TRGO_ENABLE = 1, /**< ENABLE */
  401. TIMER_TRGO_UPDATE = 2, /**< UPDATE */
  402. TIMER_TRGO_OC1 = 3, /**< OC1 */
  403. TIMER_TRGO_OC1REF = 4, /**< OC1REF */
  404. TIMER_TRGO_OC2REF = 5, /**< OC2REF */
  405. TIMER_TRGO_OC3REF = 6, /**< OC3REF */
  406. TIMER_TRGO_OC4REF = 7, /**< OC4REF */
  407. } timer_master_mode_sel_t;
  408. /**
  409. * @brief TIMER master configuretion structure definition
  410. */
  411. typedef struct {
  412. timer_master_mode_sel_t sel; /**< Specifies the active edge of the input signal */
  413. type_func_t master_en; /**< Master/Slave mode selection */
  414. } timer_master_config_t;
  415. /**
  416. * @brief Specifies the event source
  417. */
  418. typedef enum {
  419. TIMER_SRC_UPDATE = (1U << 0), /**< Event source is update */
  420. TIMER_SRC_CC1 = (1U << 1), /**< Event source is channel1 */
  421. TIMER_SRC_CC2 = (1U << 2), /**< Event source is channel2 */
  422. TIMER_SRC_CC3 = (1U << 3), /**< Event source is channel3 */
  423. TIMER_SRC_CC4 = (1U << 4), /**< Event source is channel4 */
  424. TIMER_SRC_COM = (1U << 5), /**< Event source is compare */
  425. TIMER_SRC_TRIG = (1U << 6), /**< Event source is trigger */
  426. TIMER_SRC_BREAK = (1U << 7), /**< Event source is break */
  427. } timer_event_source_t;
  428. /**
  429. * @brief TIMER interrupt definition
  430. */
  431. typedef enum {
  432. TIMER_IT_UPDATE = (1U << 0), /**< Update interrupt bit */
  433. TIMER_IT_CC1 = (1U << 1), /**< Channel1 interrupt bit */
  434. TIMER_IT_CC2 = (1U << 2), /**< Channel2 interrupt bit */
  435. TIMER_IT_CC3 = (1U << 3), /**< Channel3 interrupt bit */
  436. TIMER_IT_CC4 = (1U << 4), /**< Channel4 interrupt bit */
  437. TIMER_IT_COM = (1U << 5), /**< compare interrupt bit */
  438. TIMER_IT_TRIGGER = (1U << 6), /**< Trigger interrupt bit */
  439. TIMER_IT_BREAK = (1U << 7), /**< Break interrupt bit */
  440. } timer_it_t;
  441. /**
  442. * @brief TIMER DMA request
  443. */
  444. typedef enum {
  445. TIMER_DMA_UPDATE = (1U << 8), /**< DMA request from update */
  446. TIMER_DMA_CC1 = (1U << 9), /**< DMA request from channel1 */
  447. TIMER_DMA_CC2 = (1U << 10), /**< DMA request from channel2 */
  448. TIMER_DMA_CC3 = (1U << 11), /**< DMA request from channel3 */
  449. TIMER_DMA_CC4 = (1U << 12), /**< DMA request from channel4 */
  450. TIMER_DMA_COM = (1U << 13), /**< DMA request from compare */
  451. TIMER_DMA_TRIGGER = (1U << 14), /**< DMA request from trigger */
  452. } timer_dma_req_t;
  453. /**
  454. * @brief TIMER flag definition
  455. */
  456. typedef enum {
  457. TIMER_FLAG_UPDATE = (1U << 0), /**< Update interrupt flag */
  458. TIMER_FLAG_CC1 = (1U << 1), /**< Channel1 interrupt flag */
  459. TIMER_FLAG_CC2 = (1U << 2), /**< Channel2 interrupt flag */
  460. TIMER_FLAG_CC3 = (1U << 3), /**< Channel3 interrupt flag */
  461. TIMER_FLAG_CC4 = (1U << 4), /**< Channel4 interrupt flag */
  462. TIMER_FLAG_COM = (1U << 5), /**< Compare interrupt flag */
  463. TIMER_FLAG_TRIGGER = (1U << 6), /**< Trigger interrupt flag */
  464. TIMER_FLAG_BREAK = (1U << 7), /**< Break interrupt flag */
  465. TIMER_FLAG_CC1OF = (1U << 9), /**< Channel1 override state flag */
  466. TIMER_FLAG_CC2OF = (1U << 10), /**< Channel2 override state flag */
  467. TIMER_FLAG_CC3OF = (1U << 11), /**< Channel3 override state flag */
  468. TIMER_FLAG_CC4OF = (1U << 12), /**< Channel4 override state flag */
  469. } timer_flag_t;
  470. /**
  471. * @}
  472. */
  473. /** @defgroup TIMER_Public_Macros TIMER Public Macros
  474. * @{
  475. */
  476. #define CCER_CCxE_MASK ((1U << 0) | (1U << 4) | (1U << 8) | (1U << 12))
  477. #define CCER_CCxNE_MASK ((1U << 2) | (1U << 6) | (1U << 10))
  478. /**
  479. * @brief Reset TIMER handle state
  480. */
  481. #define TIMER_RESET_HANDLE_STATE(hperh) ((hperh)->state = TIMER_STATE_RESET)
  482. /**
  483. * @brief Enable the TIMER peripheral.
  484. */
  485. #define TIMER_ENABLE(hperh) (SET_BIT((hperh)->perh->CON1, TIMER_CON1_CNTEN_MSK))
  486. /**
  487. * @brief Enable the TIMER main output.
  488. */
  489. #define TIMER_MOE_ENABLE(hperh) (SET_BIT((hperh)->perh->BDCFG, TIMER_BDCFG_GOEN_MSK))
  490. /**
  491. * @brief Disable the TIMER peripheral.
  492. */
  493. #define TIMER_DISABLE(hperh) \
  494. do { \
  495. if ((((hperh)->perh->CCEP & CCER_CCxE_MASK) == 0) \
  496. && (((hperh)->perh->CCEP & CCER_CCxNE_MASK) == 0)) \
  497. CLEAR_BIT((hperh)->perh->CON1, TIMER_CON1_CNTEN_MSK); \
  498. } while (0)
  499. /**
  500. * @brief Disable the TIMER main output.
  501. * @note The Main Output Enable of a timer instance is disabled only if
  502. * all the CCx and CCxN channels have been disabled
  503. */
  504. #define TIMER_MOE_DISABLE(hperh) \
  505. do { \
  506. if ((((hperh)->perh->CCEP & CCER_CCxE_MASK) == 0) \
  507. && (((hperh)->perh->CCEP & CCER_CCxNE_MASK) == 0)) \
  508. CLEAR_BIT((hperh)->perh->BDCFG, TIMER_BDCFG_GOEN_MSK); \
  509. } while (0)
  510. /**
  511. * @brief Sets the TIMER autoreload register value on runtime without calling
  512. * another time any Init function.
  513. */
  514. #define TIMER_SET_AUTORELOAD(handle, AUTORELOAD) \
  515. do { \
  516. (handle)->perh->AR = (AUTORELOAD); \
  517. (handle)->init.period = (AUTORELOAD); \
  518. } while (0)
  519. /**
  520. * @brief Gets the TIMER autoreload register value on runtime
  521. */
  522. #define TIMER_GET_AUTORELOAD(handle) ((handle)->perh->AR)
  523. /**
  524. * @brief Gets the TIMER count register value on runtime
  525. */
  526. #define TIMER_GET_CNT(handle) ((handle)->perh->COUNT)
  527. /**
  528. * @brief Gets the TIMER count direction value on runtime
  529. */
  530. #define TIMER_GET_DIR(handle) (READ_BITS((handle)->perh->CON1, TIMER_CON1_DIRSEL_MSK, TIMER_CON1_DIRSEL_POS))
  531. /**
  532. * @brief CCx DMA request sent when CCx event occurs
  533. */
  534. #define TIMER_CCx_DMA_REQ_CCx(handle) (CLEAR_BIT((handle)->perh->CON2, TIMER_CON2_CCDMASEL_MSK))
  535. /**
  536. * @brief CCx DMA request sent when update event occurs
  537. */
  538. #define TIMER_CCx_DMA_REQ_UPDATE(handle) (SET_BIT((handle)->perh->CON2, TIMER_CON2_CCDMASEL_MSK))
  539. /**
  540. * @brief Enable channel
  541. * @param handle: TIMER handle
  542. * @param ch: Must be one of this:
  543. * TIMER_CHANNEL_1
  544. * TIMER_CHANNEL_2
  545. * TIMER_CHANNEL_3
  546. * TIMER_CHANNEL_4
  547. */
  548. #define TIMER_CCx_ENABLE(handle, ch) (((ch) == TIMER_CHANNEL_4) ? \
  549. (SET_BIT((handle)->perh->CCEP, TIMER_CCEP_CC4POL_MSK)) : (WRITE_REG(((handle)->perh->CCEP), (((handle)->perh->CCEP) | (1 << ((ch) << 2))))))
  550. /**
  551. * @brief Disable channel
  552. * @param handle: TIMER handle
  553. * @param ch: Must be one of this:
  554. * TIMER_CHANNEL_1
  555. * TIMER_CHANNEL_2
  556. * TIMER_CHANNEL_3
  557. * TIMER_CHANNEL_4
  558. */
  559. #define TIMER_CCx_DISABLE(handle, ch) (((ch) == TIMER_CHANNEL_4) ? \
  560. (CLEAR_BIT((handle)->perh->CCEP, TIMER_CCEP_CC4EN_MSK)) : ((handle)->perh->CCEP &= ~(1 << ((ch) << 2))))
  561. /**
  562. * @brief Enable complementary channel
  563. * @param handle: TIMER handle
  564. * @param ch: Must be one of this:
  565. * TIMER_CHANNEL_1
  566. * TIMER_CHANNEL_2
  567. * TIMER_CHANNEL_3
  568. */
  569. #define TIMER_CCxN_ENABLE(handle, ch) ((handle)->perh->CCEP |= (1 << (((ch) << 2) + 2)))
  570. /**
  571. * @brief Disable complementary channel
  572. * @param handle: TIMER handle
  573. * @param ch: Must be one of this:
  574. * TIMER_CHANNEL_1
  575. * TIMER_CHANNEL_2
  576. * TIMER_CHANNEL_3
  577. */
  578. #define TIMER_CCxN_DISABLE(handle, ch) ((handle)->perh->CCEP &= ~(1 << (((ch) << 2) + 2)))
  579. /**
  580. * @}
  581. */
  582. /** @defgroup TIMER_Private_Macros TIMER Private Macros
  583. * @{
  584. */
  585. #define IS_TIMER_INSTANCE(x) (((x) == TIMER0) || \
  586. ((x) == TIMER1) || \
  587. ((x) == TIMER2) || \
  588. ((x) == TIMER3) || \
  589. ((x) == TIMER4) || \
  590. ((x) == TIMER5) || \
  591. ((x) == TIMER6) || \
  592. ((x) == TIMER7))
  593. #define IS_ADTIMER_INSTANCE(x) ((x) == TIMER0)
  594. #define IS_TIMER_XOR_INSTANCE(x) (((x) == TIMER0) || ((x) == TIMER6))
  595. #define IS_TIMER_COM_EVENT_INSTANCE(x) (((x) == TIMER0) || \
  596. ((x) == TIMER2) || \
  597. ((x) == TIMER3))
  598. #define IS_TIMER_CC2_INSTANCE(x) (((x) == TIMER0) || \
  599. ((x) == TIMER2) || \
  600. ((x) == TIMER3) || \
  601. ((x) == TIMER6))
  602. #define IS_TIMER_CC4_INSTANCE(x) (((x) == TIMER0) || \
  603. ((x) == TIMER6))
  604. #define IS_TIMER_BREAK_INSTANCE(x) (((x) == TIMER0) || \
  605. ((x) == TIMER2) || \
  606. ((x) == TIMER3))
  607. #define IS_TIMER_PWM_INPUT_INSTANCE(x, y) ((((x) == TIMER0) && \
  608. (((y) == TIMER_CHANNEL_1) || \
  609. ((y) == TIMER_CHANNEL_2))) || \
  610. (((x) == TIMER2) && \
  611. (((y) == TIMER_CHANNEL_1) || \
  612. ((y) == TIMER_CHANNEL_2))) || \
  613. (((x) == TIMER3) && \
  614. (((y) == TIMER_CHANNEL_1) || \
  615. ((y) == TIMER_CHANNEL_2))) || \
  616. (((x) == TIMER6) && \
  617. (((y) == TIMER_CHANNEL_1) || \
  618. ((y) == TIMER_CHANNEL_2))))
  619. #define IS_TIMER_CCX_INSTANCE(x, y) ((((x) == TIMER0) && \
  620. (((y) == TIMER_CHANNEL_1) || \
  621. ((y) == TIMER_CHANNEL_2) || \
  622. ((y) == TIMER_CHANNEL_3) || \
  623. ((y) == TIMER_CHANNEL_4))) || \
  624. (((x) == TIMER2) && \
  625. (((y) == TIMER_CHANNEL_1) || \
  626. ((y) == TIMER_CHANNEL_2))) || \
  627. (((x) == TIMER3) && \
  628. (((y) == TIMER_CHANNEL_1) || \
  629. ((y) == TIMER_CHANNEL_2))) || \
  630. (((x) == TIMER6) && \
  631. (((y) == TIMER_CHANNEL_1) || \
  632. ((y) == TIMER_CHANNEL_2) || \
  633. ((y) == TIMER_CHANNEL_3) || \
  634. ((y) == TIMER_CHANNEL_4))))
  635. #define IS_TIMER_CCXN_INSTANCE(x, y) ((((x) == TIMER0) || \
  636. ((x) == TIMER2) || \
  637. ((x) == TIMER3)) && \
  638. (((y) == TIMER_CHANNEL_1) || \
  639. ((y) == TIMER_CHANNEL_2) || \
  640. ((y) == TIMER_CHANNEL_3) || \
  641. ((y) == TIMER_CHANNEL_4)))
  642. #define IS_TIMER_REPETITION_COUNTER_INSTANCE(x) (((x) == TIMER0) || \
  643. ((x) == TIMER2) || \
  644. ((x) == TIMER3))
  645. #define IS_TIMER_CLOCK_DIVISION_INSTANCE(x) IS_TIMER_CC2_INSTANCE(x)
  646. #define IS_TIMER_COUNTER_MODE(x) (((x) == TIMER_CNT_MODE_UP) || \
  647. ((x) == TIMER_CNT_MODE_DOWN) || \
  648. ((x) == TIMER_CNT_MODE_CENTER1) || \
  649. ((x) == TIMER_CNT_MODE_CENTER2) || \
  650. ((x) == TIMER_CNT_MODE_CENTER3))
  651. #define IS_TIMER_CLOCK_DIVISION(x) (((x) == TIMER_CLOCK_DIV1) || \
  652. ((x) == TIMER_CLOCK_DIV2) || \
  653. ((x) == TIMER_CLOCK_DIV4))
  654. #define IS_TIMER_PWM_MODE(x) (((x) == TIMER_OC_MODE_PWM1) || \
  655. ((x) == TIMER_OC_MODE_PWM2))
  656. #define IS_TIMER_OC_MODE(x) (((x) == TIMER_OC_MODE_TIMERING) || \
  657. ((x) == TIMER_OC_MODE_ACTIVE) || \
  658. ((x) == TIMER_OC_MODE_INACTIVE) || \
  659. ((x) == TIMER_OC_MODE_TOGGLE) || \
  660. ((x) == TIMER_OC_MODE_FORCE_ACTIVE) || \
  661. ((x) == TIMER_OC_MODE_FORCE_INACTIVE) || \
  662. ((x) == TIMER_OC_MODE_PWM1) || \
  663. ((x) == TIMER_OC_MODE_PWM2))
  664. #define IS_TIMER_OC_POLARITY(x) (((x) == TIMER_OC_POLARITY_HIGH) || \
  665. ((x) == TIMER_OC_POLARITY_LOW))
  666. #define IS_TIMER_OCN_POLARITY(x) (((x) == TIMER_OCN_POLARITY_HIGH) || \
  667. ((x) == TIMER_OCN_POLARITY_LOW))
  668. #define IS_TIMER_OCIDLE_STATE(x) (((x) == TIMER_OC_IDLE_RESET) || \
  669. ((x) == TIMER_OC_IDLE_SET))
  670. #define IS_TIMER_OCNIDLE_STATE(x) (((x) == TIMER_OCN_IDLE_RESET) || \
  671. ((x) == TIMER_OCN_IDLE_SET))
  672. #define IS_TIMER_CHANNELS(x) (((x) == TIMER_CHANNEL_1) || \
  673. ((x) == TIMER_CHANNEL_2) || \
  674. ((x) == TIMER_CHANNEL_3) || \
  675. ((x) == TIMER_CHANNEL_4) || \
  676. ((x) == TIMER_CHANNEL_ALL))
  677. #define IS_TIMER_OP_MODE(x) (((x) == TIMER_OP_MODE_REPEAT) || \
  678. ((x) == TIMER_OP_MODE_SINGLE))
  679. #define IS_TIMER_OP_OUTPUT_CH(x) (((x) == TIMER_OP_OUTPUT_CHANNEL_1) || \
  680. ((x) == TIMER_OP_OUTPUT_CHANNEL_2))
  681. #define IS_TIMER_ENCODER_MODE(x) (((x) == TIMER_ENC_MODE_TI1) || \
  682. ((x) == TIMER_ENC_MODE_TI2) || \
  683. ((x) == TIMER_ENC_MODE_TI12))
  684. #define IS_TIMER_IC_POLARITY(x) (((x) == TIMER_IC_POLARITY_RISE) || \
  685. ((x) == TIMER_IC_POLARITY_FALL) || \
  686. ((x) == TIMER_IC_POLARITY_BOTH))
  687. #define IS_TIMER_IC_SELECT(x) (((x) == TIMER_IC_SEL_DIRECT) || \
  688. ((x) == TIMER_IC_SEL_INDIRECT) || \
  689. ((x) == TIMER_IC_SEL_TRC))
  690. #define IS_TIMER_IC_PSC(x) (((x) == TIMER_IC_PSC_DIV1) || \
  691. ((x) == TIMER_IC_PSC_DIV2) || \
  692. ((x) == TIMER_IC_PSC_DIV4) || \
  693. ((x) == TIMER_IC_PSC_DIV8))
  694. #define IS_TIMER_IC_FILTER(x) ((x) <= 0xF)
  695. #define IS_TIMER_DEAD_TIMERE(x) ((x) <= 0xFF)
  696. #define IS_TIMER_CLEAR_INPUT_SOURCE(x) (((x) == TIMER_INPUT_NONE) || \
  697. ((x) == TIMER_INPUT_ETR))
  698. #define IS_TIMER_CLEAR_INPUT_POLARITY(x) (((x) == TIMER_POLARITY_NO_INV) || \
  699. ((x) == TIMER_POLARITY_INV))
  700. #define IS_TIMER_ETR_PSC(x) (((x) == TIMER_ETR_PSC_DIV1) || \
  701. ((x) == TIMER_ETR_PSC_DIV2) || \
  702. ((x) == TIMER_ETR_PSC_DIV4) || \
  703. ((x) == TIMER_ETR_PSC_DIV8))
  704. #define IS_TIMER_CLOCK_SOURCE(x) (((x) == TIMER_SRC_ETRMODE2) || \
  705. ((x) == TIMER_SRC_INTER) || \
  706. ((x) == TIMER_SRC_ITR0) || \
  707. ((x) == TIMER_SRC_ITR1) || \
  708. ((x) == TIMER_SRC_ITR2) || \
  709. ((x) == TIMER_SRC_ITR3) || \
  710. ((x) == TIMER_SRC_TI1ED) || \
  711. ((x) == TIMER_SRC_TI1) || \
  712. ((x) == TIMER_SRC_TI2) || \
  713. ((x) == TIMER_SRC_ETRMODE1))
  714. #define IS_TIMER_CLOCK_POLARITY(x) (((x) == TIMER_CLK_POLARITY_INV) || \
  715. ((x) == TIMER_CLK_POLARITY_NO_INV) || \
  716. ((x) == TIMER_CLK_POLARITY_RISE) || \
  717. ((x) == TIMER_CLK_POLARITY_FALL) || \
  718. ((x) == TIMER_CLK_POLARITY_BOTH))
  719. #define IS_TIMER_SLAVE_MODE(x) (((x) == TIMER_MODE_DISABLE) || \
  720. ((x) == TIMER_MODE_ENC1) || \
  721. ((x) == TIMER_MODE_ENC2) || \
  722. ((x) == TIMER_MODE_ENC3) || \
  723. ((x) == TIMER_MODE_RESET) || \
  724. ((x) == TIMER_MODE_GATED) || \
  725. ((x) == TIMER_MODE_TRIG) || \
  726. ((x) == TIMER_MODE_EXTERNAL1))
  727. #define IS_TIMER_EVENT_SOURCE(x) (((x) == TIMER_SRC_UPDATE) || \
  728. ((x) == TIMER_SRC_CC1) || \
  729. ((x) == TIMER_SRC_CC2) || \
  730. ((x) == TIMER_SRC_CC3) || \
  731. ((x) == TIMER_SRC_CC4) || \
  732. ((x) == TIMER_SRC_COM) || \
  733. ((x) == TIMER_SRC_TRIG) || \
  734. ((x) == TIMER_SRC_BREAK))
  735. #define IS_TIMER_TS(x) (((x) == TIMER_TS_ITR0) || \
  736. ((x) == TIMER_TS_ITR1) || \
  737. ((x) == TIMER_TS_ITR2) || \
  738. ((x) == TIMER_TS_ITR3) || \
  739. ((x) == TIMER_TS_TI1F_ED) || \
  740. ((x) == TIMER_TS_TI1FP1) || \
  741. ((x) == TIMER_TS_TI2FP2) || \
  742. ((x) == TIMER_TS_ETRF))
  743. #define IS_TIMER_CLOCK_LEVEL(x) (((x) == TIMER_LOCK_LEVEL_OFF) || \
  744. ((x) == TIMER_LOCK_LEVEL_1) || \
  745. ((x) == TIMER_LOCK_LEVEL_2) || \
  746. ((x) == TIMER_LOCK_LEVEL_3))
  747. #define IS_TIMER_BREAK_POLARITY(x) (((x) == TIMER_BREAK_POLARITY_LOW) || \
  748. ((x) == TIMER_BREAK_POLARITY_HIGH))
  749. #define IS_TIMER_MASTER_MODE_SEL(x) (((x) == TIMER_TRGO_RESET) || \
  750. ((x) == TIMER_TRGO_ENABLE) || \
  751. ((x) == TIMER_TRGO_UPDATE) || \
  752. ((x) == TIMER_TRGO_OC1) || \
  753. ((x) == TIMER_TRGO_OC1REF) || \
  754. ((x) == TIMER_TRGO_OC2REF) || \
  755. ((x) == TIMER_TRGO_OC3REF) || \
  756. ((x) == TIMER_TRGO_OC4REF))
  757. #define IS_TIMER_IT(x) (((x) == TIMER_IT_UPDATE) || \
  758. ((x) == TIMER_IT_CC1) || \
  759. ((x) == TIMER_IT_CC2) || \
  760. ((x) == TIMER_IT_CC3) || \
  761. ((x) == TIMER_IT_CC4) || \
  762. ((x) == TIMER_IT_COM) || \
  763. ((x) == TIMER_IT_TRIGGER) || \
  764. ((x) == TIMER_IT_BREAK))
  765. #define IS_TIMER_DMA_REQ(x) (((x) == TIMER_DMA_UPDATE) || \
  766. ((x) == TIMER_DMA_CC1) || \
  767. ((x) == TIMER_DMA_CC2) || \
  768. ((x) == TIMER_DMA_CC3) || \
  769. ((x) == TIMER_DMA_CC4) || \
  770. ((x) == TIMER_DMA_COM) || \
  771. ((x) == TIMER_DMA_TRIGGER))
  772. #define IS_TIMER_FLAG(x) (((x) == TIMER_FLAG_UPDATE) || \
  773. ((x) == TIMER_FLAG_CC1) || \
  774. ((x) == TIMER_FLAG_CC2) || \
  775. ((x) == TIMER_FLAG_CC3) || \
  776. ((x) == TIMER_FLAG_CC4) || \
  777. ((x) == TIMER_FLAG_COM) || \
  778. ((x) == TIMER_FLAG_TRIGGER) || \
  779. ((x) == TIMER_FLAG_BREAK) || \
  780. ((x) == TIMER_FLAG_CC1OF) || \
  781. ((x) == TIMER_FLAG_CC2OF) || \
  782. ((x) == TIMER_FLAG_CC3OF) || \
  783. ((x) == TIMER_FLAG_CC4OF))
  784. /**
  785. * @}
  786. */
  787. /** @addtogroup TIMER_Public_Functions
  788. * @{
  789. */
  790. /** @addtogroup TIMER_Public_Functions_Group1
  791. * @{
  792. */
  793. /* Time Base functions */
  794. ald_status_t timer_base_init(timer_handle_t *hperh);
  795. void timer_base_reset(timer_handle_t *hperh);
  796. void timer_base_start(timer_handle_t *hperh);
  797. void timer_base_stop(timer_handle_t *hperh);
  798. void timer_base_start_by_it(timer_handle_t *hperh);
  799. void timer_base_stop_by_it(timer_handle_t *hperh);
  800. #ifdef ALD_DMA
  801. ald_status_t timer_base_start_by_dma(timer_handle_t *hperh, dma_handle_t *hdma,
  802. uint16_t *buf, uint32_t len, uint8_t dma_ch);
  803. void timer_base_stop_by_dma(timer_handle_t *hperh);
  804. #endif
  805. /**
  806. * @}
  807. */
  808. /** @addtogroup TIMER_Public_Functions_Group2
  809. * @{
  810. */
  811. /* Timer Output Compare functions */
  812. ald_status_t timer_oc_init(timer_handle_t *hperh);
  813. void timer_oc_start(timer_handle_t *hperh, timer_channel_t ch);
  814. void timer_oc_stop(timer_handle_t *hperh, timer_channel_t ch);
  815. void timer_oc_start_by_it(timer_handle_t *hperh, timer_channel_t ch);
  816. void timer_oc_stop_by_it(timer_handle_t *hperh, timer_channel_t ch);
  817. #ifdef ALD_DMA
  818. ald_status_t timer_oc_start_by_dma(timer_handle_t *hperh, timer_channel_t ch,
  819. dma_handle_t *hdma, uint16_t *buf, uint32_t len, uint8_t dma_ch);
  820. void timer_oc_stop_by_dma(timer_handle_t *hperh, timer_channel_t ch);
  821. #endif
  822. /**
  823. * @}
  824. */
  825. /** @addtogroup TIMER_Public_Functions_Group3
  826. * @{
  827. */
  828. /* Timer PWM functions */
  829. ald_status_t timer_pwm_init(timer_handle_t *hperh);
  830. void timer_pwm_start(timer_handle_t *hperh, timer_channel_t ch);
  831. void timer_pwm_stop(timer_handle_t *hperh, timer_channel_t ch);
  832. void timer_pwm_start_by_it(timer_handle_t *hperh, timer_channel_t ch);
  833. void timer_pwm_stop_by_it(timer_handle_t *hperh, timer_channel_t ch);
  834. void timer_pwm_set_freq(timer_handle_t *hperh, uint16_t freq);
  835. void timer_pwm_set_duty(timer_handle_t *hperh, timer_channel_t ch, uint16_t duty);
  836. void timer_pwm_set_input(timer_handle_t *hperh, timer_channel_t ch);
  837. #ifdef ALD_DMA
  838. ald_status_t timer_pwm_start_by_dma(timer_handle_t *hperh, timer_channel_t ch,
  839. dma_handle_t *hdma, uint16_t *buf, uint32_t len, uint8_t dma_ch);
  840. void timer_pwm_stop_by_dma(timer_handle_t *hperh, timer_channel_t ch);
  841. #endif
  842. /**
  843. * @}
  844. */
  845. /** @addtogroup TIMER_Public_Functions_Group4
  846. * @{
  847. */
  848. /* Timer Input Capture functions */
  849. ald_status_t timer_ic_init(timer_handle_t *hperh);
  850. void timer_ic_start(timer_handle_t *hperh, timer_channel_t ch);
  851. void timer_ic_stop(timer_handle_t *hperh, timer_channel_t ch);
  852. void timer_ic_start_by_it(timer_handle_t *hperh, timer_channel_t ch);
  853. void timer_ic_stop_by_it(timer_handle_t *hperh, timer_channel_t ch);
  854. #ifdef ALD_DMA
  855. ald_status_t timer_ic_start_by_dma(timer_handle_t *hperh, timer_channel_t ch,
  856. dma_handle_t *hdma, uint16_t *buf, uint32_t len, uint8_t dma_ch);
  857. void timer_ic_stop_by_dma(timer_handle_t *hperh, timer_channel_t ch);
  858. #endif
  859. /**
  860. * @}
  861. */
  862. /** @addtogroup TIMER_Public_Functions_Group5
  863. * @{
  864. */
  865. /* Timer One Pulse functions */
  866. ald_status_t timer_one_pulse_init(timer_handle_t *hperh, timer_op_mode_t mode);
  867. void timer_one_pulse_start(timer_handle_t *hperh, timer_op_output_channel_t ch);
  868. void timer_one_pulse_stop(timer_handle_t *hperh, timer_op_output_channel_t ch);
  869. void timer_one_pulse_start_by_it(timer_handle_t *hperh, timer_op_output_channel_t ch);
  870. void timer_one_pulse_stop_by_it(timer_handle_t *hperh, timer_op_output_channel_t ch);
  871. /**
  872. * @}
  873. */
  874. /** @addtogroup TIMER_Public_Functions_Group6
  875. * @{
  876. */
  877. /* Timer encoder functions */
  878. ald_status_t timer_encoder_init(timer_handle_t *hperh, timer_encoder_init_t *config);
  879. void timer_encoder_start(timer_handle_t *hperh, timer_channel_t ch);
  880. void timer_encoder_stop(timer_handle_t *hperh, timer_channel_t ch);
  881. void timer_encoder_start_by_it(timer_handle_t *hperh, timer_channel_t ch);
  882. void timer_encoder_stop_by_it(timer_handle_t *hperh, timer_channel_t ch);
  883. #ifdef ALD_DMA
  884. ald_status_t timer_encoder_start_by_dma(timer_handle_t *hperh, timer_channel_t ch,
  885. dma_handle_t *hdma1, dma_handle_t *hdma2, uint16_t *buf1,
  886. uint16_t *buf2, uint32_t len, uint8_t dma_ch1, uint8_t dma_ch2);
  887. void timer_encoder_stop_by_dma(timer_handle_t *hperh, timer_channel_t ch);
  888. #endif
  889. /**
  890. * @}
  891. */
  892. /** @addtogroup TIMER_Public_Functions_Group7
  893. * @{
  894. */
  895. /* Timer hall sensor functions */
  896. ald_status_t timer_hall_sensor_init(timer_handle_t *hperh, timer_hall_sensor_init_t *config);
  897. void timer_hall_sensor_start(timer_handle_t *hperh);
  898. void timer_hall_sensor_stop(timer_handle_t *hperh);
  899. void timer_hall_sensor_start_by_it(timer_handle_t *hperh);
  900. void timer_hall_sensor_stop_by_it(timer_handle_t *hperh);
  901. #ifdef ALD_DMA
  902. ald_status_t timer_hall_sensor_start_by_dma(timer_handle_t *hperh, dma_handle_t *hdma,
  903. uint16_t *buf, uint32_t len, uint8_t dma_ch);
  904. void timer_hall_sensor_stop_by_dma(timer_handle_t *hperh);
  905. #endif
  906. /**
  907. * @}
  908. */
  909. /** @addtogroup TIMER_Public_Functions_Group8
  910. * @{
  911. */
  912. /* Timer complementary output compare functions */
  913. void timer_ocn_start(timer_handle_t *hperh, timer_channel_t ch);
  914. void timer_ocn_stop(timer_handle_t *hperh, timer_channel_t ch);
  915. void timer_ocn_start_by_it(timer_handle_t *hperh, timer_channel_t ch);
  916. void timer_ocn_stop_by_it(timer_handle_t *hperh, timer_channel_t ch);
  917. #ifdef ALD_DMA
  918. ald_status_t timer_ocn_start_by_dma(timer_handle_t *hperh, dma_handle_t *hdma,
  919. timer_channel_t ch, uint16_t *buf, uint32_t len, uint8_t dma_ch);
  920. void timer_ocn_stop_by_dma(timer_handle_t *hperh, timer_channel_t ch);
  921. #endif
  922. /**
  923. * @}
  924. */
  925. /** @addtogroup TIMER_Public_Functions_Group9
  926. * @{
  927. */
  928. /* Timer complementary PWM functions */
  929. void timer_pwmn_start(timer_handle_t *hperh, timer_channel_t ch);
  930. void timer_pwmn_stop(timer_handle_t *hperh, timer_channel_t ch);
  931. void timer_pwmn_start_by_it(timer_handle_t *hperh, timer_channel_t ch);
  932. void timer_pwmn_stop_by_it(timer_handle_t *hperh, timer_channel_t ch);
  933. #ifdef ALD_DMA
  934. ald_status_t timer_pwmn_start_by_dma(timer_handle_t *hperh, dma_handle_t *hdma,
  935. timer_channel_t ch, uint16_t *buf, uint32_t len, uint8_t dma_ch);
  936. void timer_pwmn_stop_by_dma(timer_handle_t *hperh, timer_channel_t ch);
  937. #endif
  938. /**
  939. * @}
  940. */
  941. /** @addtogroup TIMER_Public_Functions_Group10
  942. * @{
  943. */
  944. /* Timer complementary one pulse functions */
  945. void timer_one_pulse_n_start(timer_handle_t *hperh, timer_channel_t ch);
  946. void timer_one_pulse_n_stop(timer_handle_t *hperh, timer_channel_t ch);
  947. void timer_one_pulse_n_start_by_it(timer_handle_t *hperh, timer_channel_t ch);
  948. void timer_one_pulse_n_stop_by_it(timer_handle_t *hperh, timer_channel_t ch);
  949. /**
  950. * @}
  951. */
  952. /** @addtogroup TIMER_Public_Functions_Group11
  953. * @{
  954. */
  955. /* Control functions */
  956. ald_status_t timer_oc_config_channel(timer_handle_t *hperh, timer_oc_init_t* config, timer_channel_t ch);
  957. ald_status_t timer_ic_config_channel(timer_handle_t *hperh, timer_ic_init_t* config, timer_channel_t ch);
  958. ald_status_t timer_one_pulse_config_channel(timer_handle_t *hperh, timer_one_pulse_init_t *config,
  959. timer_channel_t ch_out, timer_channel_t ch_in);
  960. ald_status_t timer_config_oc_ref_clear(timer_handle_t *hperh, timer_clear_input_config_t *config, timer_channel_t ch);
  961. ald_status_t timer_config_clock_source(timer_handle_t *hperh, timer_clock_config_t *config);
  962. ald_status_t timer_config_ti1_input(timer_handle_t *hperh, uint32_t ti1_select);
  963. ald_status_t timer_slave_config_sync(timer_handle_t *hperh, timer_slave_config_t *config);
  964. ald_status_t timer_slave_config_sync_by_it(timer_handle_t *hperh, timer_slave_config_t *config);
  965. ald_status_t timer_generate_event(timer_handle_t *hperh, timer_event_source_t event);
  966. uint32_t timer_read_capture_value(timer_handle_t *hperh, timer_channel_t ch);
  967. void timer_set_output_mode(timer_handle_t *hperh, timer_oc_mode_t mode, timer_channel_t ch);
  968. void timer_com_change_config(timer_handle_t *hperh, timer_com_channel_config_t *config);
  969. void timer_com_event_config(timer_handle_t *hperh, timer_ts_t ts, type_func_t trgi);
  970. void timer_com_event_config_it(timer_handle_t *hperh, timer_ts_t ts, type_func_t trgi);
  971. void timer_break_dead_time_config(timer_handle_t *hperh, timer_break_dead_time_t *config);
  972. void timer_master_sync_config(timer_handle_t *hperh, timer_master_config_t *config);
  973. void timer_irq_handle(timer_handle_t *hperh);
  974. void timer_dma_req_config(timer_handle_t *hperh, timer_dma_req_t req, type_func_t state);
  975. void timer_interrupt_config(timer_handle_t *hperh, timer_it_t it, type_func_t state);
  976. it_status_t timer_get_it_status(timer_handle_t *hperh, timer_it_t it);
  977. flag_status_t timer_get_flag_status(timer_handle_t *hperh, timer_flag_t flag);
  978. void timer_clear_flag_status(timer_handle_t *hperh, timer_flag_t flag);
  979. /**
  980. * @}
  981. */
  982. /** @addtogroup TIMER_Public_Functions_Group12
  983. * @{
  984. */
  985. /* State functions */
  986. timer_state_t timer_get_state(timer_handle_t *hperh);
  987. /**
  988. * @}
  989. */
  990. /**
  991. * @}
  992. */
  993. /**
  994. * @}
  995. */
  996. /**
  997. * @}
  998. */
  999. #ifdef __cplusplus
  1000. }
  1001. #endif
  1002. #endif /* __ALD_TIMER_H__ */