em_timer.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Timer/counter (TIMER) peripheral API
  4. * @author Energy Micro AS
  5. * @version 3.0.0
  6. *******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
  9. *******************************************************************************
  10. *
  11. * Permission is granted to anyone to use this software for any purpose,
  12. * including commercial applications, and to alter it and redistribute it
  13. * freely, subject to the following restrictions:
  14. *
  15. * 1. The origin of this software must not be misrepresented; you must not
  16. * claim that you wrote the original software.
  17. * 2. Altered source versions must be plainly marked as such, and must not be
  18. * misrepresented as being the original software.
  19. * 3. This notice may not be removed or altered from any source distribution.
  20. *
  21. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  22. * obligation to support this Software. Energy Micro AS is providing the
  23. * Software "AS IS", with no express or implied warranties of any kind,
  24. * including, but not limited to, any implied warranties of merchantability
  25. * or fitness for any particular purpose or warranties against infringement
  26. * of any proprietary rights of a third party.
  27. *
  28. * Energy Micro AS will not be liable for any consequential, incidental, or
  29. * special damages, or any other relief, or for any claim by any third party,
  30. * arising from your use of this Software.
  31. *
  32. ******************************************************************************/
  33. #ifndef __EM_TIMER_H
  34. #define __EM_TIMER_H
  35. #include <stdbool.h>
  36. #include "em_part.h"
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /***************************************************************************//**
  41. * @addtogroup EM_Library
  42. * @{
  43. ******************************************************************************/
  44. /***************************************************************************//**
  45. * @addtogroup TIMER
  46. * @{
  47. ******************************************************************************/
  48. /*******************************************************************************
  49. ******************************** ENUMS ************************************
  50. ******************************************************************************/
  51. /** Timer compare/capture mode. */
  52. typedef enum
  53. {
  54. timerCCModeOff = _TIMER_CC_CTRL_MODE_OFF, /**< Channel turned off. */
  55. timerCCModeCapture = _TIMER_CC_CTRL_MODE_INPUTCAPTURE, /**< Input capture. */
  56. timerCCModeCompare = _TIMER_CC_CTRL_MODE_OUTPUTCOMPARE, /**< Output compare. */
  57. timerCCModePWM = _TIMER_CC_CTRL_MODE_PWM /**< Pulse-Width modulation. */
  58. } TIMER_CCMode_TypeDef;
  59. /** Clock select. */
  60. typedef enum
  61. {
  62. /** Prescaled HFPER clock. */
  63. timerClkSelHFPerClk = _TIMER_CTRL_CLKSEL_PRESCHFPERCLK,
  64. /** Prescaled HFPER clock. */
  65. timerClkSelCC1 = _TIMER_CTRL_CLKSEL_CC1,
  66. /**
  67. * Cascaded, clocked by underflow (down-counting) or overflow (up-counting)
  68. * by lower numbered timer.
  69. */
  70. timerClkSelCascade = _TIMER_CTRL_CLKSEL_TIMEROUF
  71. } TIMER_ClkSel_TypeDef;
  72. /** Input capture edge select. */
  73. typedef enum
  74. {
  75. /** Rising edges detected. */
  76. timerEdgeRising = _TIMER_CC_CTRL_ICEDGE_RISING,
  77. /** Falling edges detected. */
  78. timerEdgeFalling = _TIMER_CC_CTRL_ICEDGE_FALLING,
  79. /** Both edges detected. */
  80. timerEdgeBoth = _TIMER_CC_CTRL_ICEDGE_BOTH,
  81. /** No edge detection, leave signal as is. */
  82. timerEdgeNone = _TIMER_CC_CTRL_ICEDGE_NONE
  83. } TIMER_Edge_TypeDef;
  84. /** Input capture event control. */
  85. typedef enum
  86. {
  87. /** PRS output pulse, interrupt flag and DMA request set on every capture. */
  88. timerEventEveryEdge = _TIMER_CC_CTRL_ICEVCTRL_EVERYEDGE,
  89. /** PRS output pulse, interrupt flag and DMA request set on every second capture. */
  90. timerEventEvery2ndEdge = _TIMER_CC_CTRL_ICEVCTRL_EVERYSECONDEDGE,
  91. /**
  92. * PRS output pulse, interrupt flag and DMA request set on rising edge (if
  93. * input capture edge = BOTH).
  94. */
  95. timerEventRising = _TIMER_CC_CTRL_ICEVCTRL_RISING,
  96. /**
  97. * PRS output pulse, interrupt flag and DMA request set on falling edge (if
  98. * input capture edge = BOTH).
  99. */
  100. timerEventFalling = _TIMER_CC_CTRL_ICEVCTRL_FALLING
  101. } TIMER_Event_TypeDef;
  102. /** Input edge action. */
  103. typedef enum
  104. {
  105. /** No action taken. */
  106. timerInputActionNone = _TIMER_CTRL_FALLA_NONE,
  107. /** Start counter without reload. */
  108. timerInputActionStart = _TIMER_CTRL_FALLA_START,
  109. /** Stop counter without reload. */
  110. timerInputActionStop = _TIMER_CTRL_FALLA_STOP,
  111. /** Reload and start counter. */
  112. timerInputActionReloadStart = _TIMER_CTRL_FALLA_RELOADSTART
  113. } TIMER_InputAction_TypeDef;
  114. /** Timer mode. */
  115. typedef enum
  116. {
  117. timerModeUp = _TIMER_CTRL_MODE_UP, /**< Up-counting. */
  118. timerModeDown = _TIMER_CTRL_MODE_DOWN, /**< Down-counting. */
  119. timerModeUpDown = _TIMER_CTRL_MODE_UPDOWN, /**< Up/down-counting. */
  120. timerModeQDec = _TIMER_CTRL_MODE_QDEC /**< Quadrature decoder. */
  121. } TIMER_Mode_TypeDef;
  122. /** Compare/capture output action. */
  123. typedef enum
  124. {
  125. /** No action. */
  126. timerOutputActionNone = _TIMER_CC_CTRL_CUFOA_NONE,
  127. /** Toggle on event. */
  128. timerOutputActionToggle = _TIMER_CC_CTRL_CUFOA_TOGGLE,
  129. /** Clear on event. */
  130. timerOutputActionClear = _TIMER_CC_CTRL_CUFOA_CLEAR,
  131. /** Set on event. */
  132. timerOutputActionSet = _TIMER_CC_CTRL_CUFOA_SET
  133. } TIMER_OutputAction_TypeDef;
  134. /** Prescaler. */
  135. typedef enum
  136. {
  137. timerPrescale1 = _TIMER_CTRL_PRESC_DIV1, /**< Divide by 1. */
  138. timerPrescale2 = _TIMER_CTRL_PRESC_DIV2, /**< Divide by 2. */
  139. timerPrescale4 = _TIMER_CTRL_PRESC_DIV4, /**< Divide by 4. */
  140. timerPrescale8 = _TIMER_CTRL_PRESC_DIV8, /**< Divide by 8. */
  141. timerPrescale16 = _TIMER_CTRL_PRESC_DIV16, /**< Divide by 16. */
  142. timerPrescale32 = _TIMER_CTRL_PRESC_DIV32, /**< Divide by 32. */
  143. timerPrescale64 = _TIMER_CTRL_PRESC_DIV64, /**< Divide by 64. */
  144. timerPrescale128 = _TIMER_CTRL_PRESC_DIV128, /**< Divide by 128. */
  145. timerPrescale256 = _TIMER_CTRL_PRESC_DIV256, /**< Divide by 256. */
  146. timerPrescale512 = _TIMER_CTRL_PRESC_DIV512, /**< Divide by 512. */
  147. timerPrescale1024 = _TIMER_CTRL_PRESC_DIV1024 /**< Divide by 1024. */
  148. } TIMER_Prescale_TypeDef;
  149. /** Peripheral Reflex System signal. */
  150. typedef enum
  151. {
  152. timerPRSSELCh0 = _ADC_SINGLECTRL_PRSSEL_PRSCH0, /**< PRS channel 0. */
  153. timerPRSSELCh1 = _ADC_SINGLECTRL_PRSSEL_PRSCH1, /**< PRS channel 1. */
  154. timerPRSSELCh2 = _ADC_SINGLECTRL_PRSSEL_PRSCH2, /**< PRS channel 2. */
  155. timerPRSSELCh3 = _ADC_SINGLECTRL_PRSSEL_PRSCH3, /**< PRS channel 3. */
  156. timerPRSSELCh4 = _ADC_SINGLECTRL_PRSSEL_PRSCH4, /**< PRS channel 4. */
  157. timerPRSSELCh5 = _ADC_SINGLECTRL_PRSSEL_PRSCH5, /**< PRS channel 5. */
  158. timerPRSSELCh6 = _ADC_SINGLECTRL_PRSSEL_PRSCH6, /**< PRS channel 6. */
  159. timerPRSSELCh7 = _ADC_SINGLECTRL_PRSSEL_PRSCH7 /**< PRS channel 7. */
  160. } TIMER_PRSSEL_TypeDef;
  161. /*******************************************************************************
  162. ******************************* STRUCTS ***********************************
  163. ******************************************************************************/
  164. /** TIMER initialization structure. */
  165. typedef struct
  166. {
  167. /** Start counting when init completed. */
  168. bool enable;
  169. /** Counter shall keep running during debug halt. */
  170. bool debugRun;
  171. /** Prescaling factor, if HFPER clock used. */
  172. TIMER_Prescale_TypeDef prescale;
  173. /** Clock selection. */
  174. TIMER_ClkSel_TypeDef clkSel;
  175. #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_TINY_FAMILY)
  176. /** 2x Count mode, counter increments/decrements by 2, meant for PWN mode. */
  177. bool count2x;
  178. /** ATI (Always Track Inputs) makes CCPOL always track
  179. * the polarity of the inputs. */
  180. bool ati;
  181. #endif
  182. /** Action on falling input edge. */
  183. TIMER_InputAction_TypeDef fallAction;
  184. /** Action on rising input edge. */
  185. TIMER_InputAction_TypeDef riseAction;
  186. /** Counting mode. */
  187. TIMER_Mode_TypeDef mode;
  188. /** DMA request clear on active. */
  189. bool dmaClrAct;
  190. /** Select X2 or X4 quadrature decode mode (if used). */
  191. bool quadModeX4;
  192. /** Determines if only counting up or down once. */
  193. bool oneShot;
  194. /** Timer start/stop/reload by other timers. */
  195. bool sync;
  196. } TIMER_Init_TypeDef;
  197. /** Default config for TIMER init structure. */
  198. #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_TINY_FAMILY)
  199. #define TIMER_INIT_DEFAULT \
  200. { true, /* Enable timer when init complete. */ \
  201. false, /* Stop counter during debug halt. */ \
  202. timerPrescale1, /* No prescaling. */ \
  203. timerClkSelHFPerClk, /* Select HFPER clock. */ \
  204. false, /* Not 2x count mode. */ \
  205. false, /* No ATI. */ \
  206. timerInputActionNone, /* No action on falling input edge. */ \
  207. timerInputActionNone, /* No action on rising input edge. */ \
  208. timerModeUp, /* Up-counting. */ \
  209. false, /* Do not clear DMA requests when DMA channel is active. */ \
  210. false, /* Select X2 quadrature decode mode (if used). */ \
  211. false, /* Disable one shot. */ \
  212. false /* Not started/stopped/reloaded by other timers. */ \
  213. }
  214. #else
  215. #define TIMER_INIT_DEFAULT \
  216. { true, /* Enable timer when init complete. */ \
  217. false, /* Stop counter during debug halt. */ \
  218. timerPrescale1, /* No prescaling. */ \
  219. timerClkSelHFPerClk, /* Select HFPER clock. */ \
  220. timerInputActionNone, /* No action on falling input edge. */ \
  221. timerInputActionNone, /* No action on rising input edge. */ \
  222. timerModeUp, /* Up-counting. */ \
  223. false, /* Do not clear DMA requests when DMA channel is active. */ \
  224. false, /* Select X2 quadrature decode mode (if used). */ \
  225. false, /* Disable one shot. */ \
  226. false /* Not started/stopped/reloaded by other timers. */ \
  227. }
  228. #endif
  229. /** TIMER compare/capture initialization structure. */
  230. typedef struct
  231. {
  232. /** Input capture event control. */
  233. TIMER_Event_TypeDef eventCtrl;
  234. /** Input capture edge select. */
  235. TIMER_Edge_TypeDef edge;
  236. /**
  237. * Peripheral reflex system trigger selection. Only applicable if @p prsInput
  238. * is enabled.
  239. */
  240. TIMER_PRSSEL_TypeDef prsSel;
  241. /** Counter underflow output action. */
  242. TIMER_OutputAction_TypeDef cufoa;
  243. /** Counter overflow output action. */
  244. TIMER_OutputAction_TypeDef cofoa;
  245. /** Counter match output action. */
  246. TIMER_OutputAction_TypeDef cmoa;
  247. /** Compare/capture channel mode. */
  248. TIMER_CCMode_TypeDef mode;
  249. /** Enable digital filter. */
  250. bool filter;
  251. /** Select TIMERnCCx (false) or PRS input (true). */
  252. bool prsInput;
  253. /**
  254. * Compare output initial state. Only used in Output Compare and PWM mode.
  255. * When true, the compare/PWM output is set high when the counter is
  256. * disabled. When counting resumes, this value will represent the initial
  257. * value for the compare/PWM output. If the bit is cleared, the output
  258. * will be cleared when the counter is disabled.
  259. */
  260. bool coist;
  261. /** Invert output from compare/capture channel. */
  262. bool outInvert;
  263. } TIMER_InitCC_TypeDef;
  264. /** Default config for TIMER compare/capture init structure. */
  265. #define TIMER_INITCC_DEFAULT \
  266. { timerEventEveryEdge, /* Event on every capture. */ \
  267. timerEdgeRising, /* Input capture edge on rising edge. */ \
  268. timerPRSSELCh0, /* Not used by default, select PRS channel 0. */ \
  269. timerOutputActionNone, /* No action on underflow. */ \
  270. timerOutputActionNone, /* No action on overflow. */ \
  271. timerOutputActionNone, /* No action on match. */ \
  272. timerCCModeOff, /* Disable compare/capture channel. */ \
  273. false, /* Disable filter. */ \
  274. false, /* Select TIMERnCCx input. */ \
  275. false, /* Clear output when countre disabled. */ \
  276. false /* Do not invert output. */ \
  277. }
  278. /*******************************************************************************
  279. ***************************** PROTOTYPES **********************************
  280. ******************************************************************************/
  281. /***************************************************************************//**
  282. * @brief
  283. * Get capture value for compare/capture channel when operating in capture
  284. * mode.
  285. *
  286. * @param[in] timer
  287. * Pointer to TIMER peripheral register block.
  288. *
  289. * @param[in] ch
  290. * Compare/capture channel to access.
  291. *
  292. * @return
  293. * Current capture value.
  294. ******************************************************************************/
  295. __STATIC_INLINE uint32_t TIMER_CaptureGet(TIMER_TypeDef *timer, unsigned int ch)
  296. {
  297. return(timer->CC[ch].CCV);
  298. }
  299. /***************************************************************************//**
  300. * @brief
  301. * Set compare value buffer for compare/capture channel when operating in
  302. * compare or PWM mode.
  303. *
  304. * @details
  305. * The compare value buffer holds the value which will be written to
  306. * TIMERn_CCx_CCV on an update event if the buffer has been updated since
  307. * the last event.
  308. *
  309. * @param[in] timer
  310. * Pointer to TIMER peripheral register block.
  311. *
  312. * @param[in] ch
  313. * Compare/capture channel to access.
  314. *
  315. * @param[in] val
  316. * Value to set in compare value buffer register.
  317. ******************************************************************************/
  318. __STATIC_INLINE void TIMER_CompareBufSet(TIMER_TypeDef *timer,
  319. unsigned int ch,
  320. uint32_t val)
  321. {
  322. timer->CC[ch].CCVB = val;
  323. }
  324. /***************************************************************************//**
  325. * @brief
  326. * Set compare value for compare/capture channel when operating in compare
  327. * or PWM mode.
  328. *
  329. * @param[in] timer
  330. * Pointer to TIMER peripheral register block.
  331. *
  332. * @param[in] ch
  333. * Compare/capture channel to access.
  334. *
  335. * @param[in] val
  336. * Value to set in compare value register.
  337. ******************************************************************************/
  338. __STATIC_INLINE void TIMER_CompareSet(TIMER_TypeDef *timer,
  339. unsigned int ch,
  340. uint32_t val)
  341. {
  342. timer->CC[ch].CCV = val;
  343. }
  344. /***************************************************************************//**
  345. * @brief
  346. * Get TIMER counter value.
  347. *
  348. * @param[in] timer
  349. * Pointer to TIMER peripheral register block.
  350. *
  351. * @return
  352. * Current TIMER counter value.
  353. ******************************************************************************/
  354. __STATIC_INLINE uint32_t TIMER_CounterGet(TIMER_TypeDef *timer)
  355. {
  356. return(timer->CNT);
  357. }
  358. /***************************************************************************//**
  359. * @brief
  360. * Set TIMER counter value.
  361. *
  362. * @param[in] timer
  363. * Pointer to TIMER peripheral register block.
  364. *
  365. * @param[in] val
  366. * Value to set counter to.
  367. ******************************************************************************/
  368. __STATIC_INLINE void TIMER_CounterSet(TIMER_TypeDef *timer, uint32_t val)
  369. {
  370. timer->CNT = val;
  371. }
  372. void TIMER_Enable(TIMER_TypeDef *timer, bool enable);
  373. void TIMER_Init(TIMER_TypeDef *timer, const TIMER_Init_TypeDef *init);
  374. void TIMER_InitCC(TIMER_TypeDef *timer,
  375. unsigned int ch,
  376. const TIMER_InitCC_TypeDef *init);
  377. /***************************************************************************//**
  378. * @brief
  379. * Clear one or more pending TIMER interrupts.
  380. *
  381. * @param[in] timer
  382. * Pointer to TIMER peripheral register block.
  383. *
  384. * @param[in] flags
  385. * Pending TIMER interrupt source(s) to clear. Use one or more valid
  386. * interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
  387. ******************************************************************************/
  388. __STATIC_INLINE void TIMER_IntClear(TIMER_TypeDef *timer, uint32_t flags)
  389. {
  390. timer->IFC = flags;
  391. }
  392. /***************************************************************************//**
  393. * @brief
  394. * Disable one or more TIMER interrupts.
  395. *
  396. * @param[in] timer
  397. * Pointer to TIMER peripheral register block.
  398. *
  399. * @param[in] flags
  400. * TIMER interrupt source(s) to disable. Use one or more valid
  401. * interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
  402. ******************************************************************************/
  403. __STATIC_INLINE void TIMER_IntDisable(TIMER_TypeDef *timer, uint32_t flags)
  404. {
  405. timer->IEN &= ~(flags);
  406. }
  407. /***************************************************************************//**
  408. * @brief
  409. * Enable one or more TIMER interrupts.
  410. *
  411. * @note
  412. * Depending on the use, a pending interrupt may already be set prior to
  413. * enabling the interrupt. Consider using TIMER_IntClear() prior to enabling
  414. * if such a pending interrupt should be ignored.
  415. *
  416. * @param[in] timer
  417. * Pointer to TIMER peripheral register block.
  418. *
  419. * @param[in] flags
  420. * TIMER interrupt source(s) to enable. Use one or more valid
  421. * interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
  422. ******************************************************************************/
  423. __STATIC_INLINE void TIMER_IntEnable(TIMER_TypeDef *timer, uint32_t flags)
  424. {
  425. timer->IEN |= flags;
  426. }
  427. /***************************************************************************//**
  428. * @brief
  429. * Get pending TIMER interrupt flags.
  430. *
  431. * @note
  432. * The event bits are not cleared by the use of this function.
  433. *
  434. * @param[in] timer
  435. * Pointer to TIMER peripheral register block.
  436. *
  437. * @return
  438. * TIMER interrupt source(s) pending. Returns one or more valid
  439. * interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
  440. ******************************************************************************/
  441. __STATIC_INLINE uint32_t TIMER_IntGet(TIMER_TypeDef *timer)
  442. {
  443. return(timer->IF);
  444. }
  445. /***************************************************************************//**
  446. * @brief
  447. * Get enabled and pending TIMER interrupt flags.
  448. * Useful for handling more interrupt sources in the same interrupt handler.
  449. *
  450. * @param[in] timer
  451. * Pointer to TIMER peripheral register block.
  452. *
  453. * @note
  454. * Interrupt flags are not cleared by the use of this function.
  455. *
  456. * @return
  457. * Pending and enabled TIMER interrupt sources.
  458. * The return value is the bitwise AND combination of
  459. * - the OR combination of enabled interrupt sources in TIMERx_IEN_nnn
  460. * register (TIMERx_IEN_nnn) and
  461. * - the OR combination of valid interrupt flags of the TIMER module
  462. * (TIMERx_IF_nnn).
  463. ******************************************************************************/
  464. __STATIC_INLINE uint32_t TIMER_IntGetEnabled(TIMER_TypeDef *timer)
  465. {
  466. uint32_t tmp;
  467. /* Store TIMER->IEN in temporary variable in order to define explicit order
  468. * of volatile accesses. */
  469. tmp = timer->IEN;
  470. /* Bitwise AND of pending and enabled interrupts */
  471. return timer->IF & tmp;
  472. }
  473. /***************************************************************************//**
  474. * @brief
  475. * Set one or more pending TIMER interrupts from SW.
  476. *
  477. * @param[in] timer
  478. * Pointer to TIMER peripheral register block.
  479. *
  480. * @param[in] flags
  481. * TIMER interrupt source(s) to set to pending. Use one or more valid
  482. * interrupt flags for the TIMER module (TIMER_IF_nnn) OR'ed together.
  483. ******************************************************************************/
  484. __STATIC_INLINE void TIMER_IntSet(TIMER_TypeDef *timer, uint32_t flags)
  485. {
  486. timer->IFS = flags;
  487. }
  488. #ifdef TIMER_DTLOCK_LOCKKEY_LOCK
  489. void TIMER_Lock(TIMER_TypeDef *timer);
  490. #endif
  491. void TIMER_Reset(TIMER_TypeDef *timer);
  492. /***************************************************************************//**
  493. * @brief
  494. * Set top value buffer for timer.
  495. *
  496. * @details
  497. * When the top value buffer register is updated, the value is loaded into
  498. * the top value register at the next wrap around. This feature is useful
  499. * in order to update the top value safely when the timer is running.
  500. *
  501. * @param[in] timer
  502. * Pointer to TIMER peripheral register block.
  503. *
  504. * @param[in] val
  505. * Value to set in top value buffer register.
  506. ******************************************************************************/
  507. __STATIC_INLINE void TIMER_TopBufSet(TIMER_TypeDef *timer, uint32_t val)
  508. {
  509. timer->TOPB = val;
  510. }
  511. /***************************************************************************//**
  512. * @brief
  513. * Get top value setting for timer.
  514. *
  515. * @param[in] timer
  516. * Pointer to TIMER peripheral register block.
  517. *
  518. * @return
  519. * Current top value.
  520. ******************************************************************************/
  521. __STATIC_INLINE uint32_t TIMER_TopGet(TIMER_TypeDef *timer)
  522. {
  523. return(timer->TOP);
  524. }
  525. /***************************************************************************//**
  526. * @brief
  527. * Set top value for timer.
  528. *
  529. * @param[in] timer
  530. * Pointer to TIMER peripheral register block.
  531. *
  532. * @param[in] val
  533. * Value to set in top value register.
  534. ******************************************************************************/
  535. __STATIC_INLINE void TIMER_TopSet(TIMER_TypeDef *timer, uint32_t val)
  536. {
  537. timer->TOP = val;
  538. }
  539. #ifdef TIMER_DTLOCK_LOCKKEY_UNLOCK
  540. void TIMER_Unlock(TIMER_TypeDef *timer);
  541. #endif
  542. /** @} (end addtogroup TIMER) */
  543. /** @} (end addtogroup EM_Library) */
  544. #ifdef __cplusplus
  545. }
  546. #endif
  547. #endif /* __EM_TIMER_H */