1 /***************************************************************************//**
2 * @file
3 * @brief Low Energy Timer (LETIMER) Peripheral API
4 *******************************************************************************
5 * # License
6 * <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
7 *******************************************************************************
8 *
9 * SPDX-License-Identifier: Zlib
10 *
11 * The licensor of this software is Silicon Laboratories Inc.
12 *
13 * This software is provided 'as-is', without any express or implied
14 * warranty. In no event will the authors be held liable for any damages
15 * arising from the use of this software.
16 *
17 * Permission is granted to anyone to use this software for any purpose,
18 * including commercial applications, and to alter it and redistribute it
19 * freely, subject to the following restrictions:
20 *
21 * 1. The origin of this software must not be misrepresented; you must not
22 * claim that you wrote the original software. If you use this software
23 * in a product, an acknowledgment in the product documentation would be
24 * appreciated but is not required.
25 * 2. Altered source versions must be plainly marked as such, and must not be
26 * misrepresented as being the original software.
27 * 3. This notice may not be removed or altered from any source distribution.
28 *
29 ******************************************************************************/
30
31 #include "em_letimer.h"
32 #if defined(LETIMER_COUNT) && (LETIMER_COUNT > 0)
33 #include "em_cmu.h"
34 #include "sl_assert.h"
35
36 /***************************************************************************//**
37 * @addtogroup letimer LETIMER - Low Energy Timer
38 * @brief Low Energy Timer (LETIMER) Peripheral API
39 * @details
40 * This module contains functions to control the LETIMER peripheral of Silicon
41 * Labs 32-bit MCUs and SoCs. The LETIMER is a down-counter that can keep track
42 * of time and output configurable waveforms.
43 * @{
44 ******************************************************************************/
45
46 /*******************************************************************************
47 ******************************* DEFINES ***********************************
48 ******************************************************************************/
49
50 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
51
52 /** A validation of the valid comparator register for assert statements. */
53 #define LETIMER_COMP_REG_VALID(reg) (((reg) <= 1))
54
55 /** A validation of the LETIMER register block pointer reference for assert statements. */
56 #if (LETIMER_COUNT == 1)
57 #define LETIMER_REF_VALID(ref) ((ref) == LETIMER0)
58 #elif (LETIMER_COUNT == 2)
59 #define LETIMER_REF_VALID(ref) (((ref) == LETIMER0) || ((ref) == LETIMER1))
60 #else
61 #error Undefined number of analog comparators (ACMP).
62 #endif
63
64 /** A validation of the valid repeat counter register for assert statements. */
65 #define LETIMER_REP_REG_VALID(reg) (((reg) <= 1))
66
67 /** @endcond */
68
69 /*******************************************************************************
70 ************************** LOCAL FUNCTIONS ********************************
71 ******************************************************************************/
72
73 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
74
75 /***************************************************************************//**
76 * @brief
77 * Wait for an ongoing sync of register(s) to the low-frequency domain to complete.
78 *
79 * @note
80 * See the reference manual chapter about Access to Low Energy Peripherals
81 * (Asynchronos Registers) for details.
82 *
83 * @param[in] letimer
84 * A pointer to the LETIMER peripheral register block.
85 *
86 * @param[in] mask
87 * A bitmask corresponding to SYNCBUSY register defined bits, indicating
88 * registers that must complete any ongoing synchronization.
89 ******************************************************************************/
regSync(LETIMER_TypeDef * letimer,uint32_t mask)90 __STATIC_INLINE void regSync(LETIMER_TypeDef *letimer, uint32_t mask)
91 {
92 #if defined(_LETIMER_FREEZE_MASK)
93 /* Avoid a deadlock if modifying the same register twice when freeze mode is */
94 /* activated. */
95 if (letimer->FREEZE & LETIMER_FREEZE_REGFREEZE) {
96 return;
97 }
98 #endif
99
100 /* Wait for any pending write operation to complete. */
101 while (letimer->SYNCBUSY & mask) {
102 }
103 }
104
105 /** @endcond */
106
107 /*******************************************************************************
108 ************************** GLOBAL FUNCTIONS *******************************
109 ******************************************************************************/
110
111 /***************************************************************************//**
112 * @brief
113 * Get the LETIMER compare register value.
114 *
115 * @param[in] letimer
116 * A pointer to the LETIMER peripheral register block.
117 *
118 * @param[in] comp
119 * A compare register to get, either 0 or 1.
120 *
121 * @return
122 * A compare register value, 0 if invalid register selected.
123 ******************************************************************************/
LETIMER_CompareGet(LETIMER_TypeDef * letimer,unsigned int comp)124 uint32_t LETIMER_CompareGet(LETIMER_TypeDef *letimer, unsigned int comp)
125 {
126 uint32_t ret;
127
128 EFM_ASSERT(LETIMER_REF_VALID(letimer) && LETIMER_COMP_REG_VALID(comp));
129
130 /* Initialize the selected compare value. */
131 switch (comp) {
132 case 0:
133 #if defined(LETIMER_SYNCBUSY_COMP0)
134 regSync(letimer, LETIMER_SYNCBUSY_COMP0);
135 #endif
136 ret = letimer->COMP0;
137 break;
138
139 case 1:
140 #if defined(LETIMER_SYNCBUSY_COMP1)
141 regSync(letimer, LETIMER_SYNCBUSY_COMP1);
142 #endif
143 ret = letimer->COMP1;
144 break;
145
146 default:
147 /* An unknown compare register selected. */
148 ret = 0;
149 break;
150 }
151
152 return ret;
153 }
154
155 /***************************************************************************//**
156 * @brief
157 * Get LETIMER counter value.
158 *
159 * @param[in] letimer
160 * Pointer to the LETIMER peripheral register block.
161 *
162 * @return
163 * Current LETIMER counter value.
164 ******************************************************************************/
LETIMER_CounterGet(LETIMER_TypeDef * letimer)165 uint32_t LETIMER_CounterGet(LETIMER_TypeDef *letimer)
166 {
167 #if defined(LETIMER_SYNCBUSY_CNT)
168 regSync(letimer, LETIMER_SYNCBUSY_CNT);
169 #endif
170 return letimer->CNT;
171 }
172
173 #if !defined(_EFM32_GECKO_FAMILY)
174 /***************************************************************************//**
175 * @brief
176 * Set LETIMER counter value.
177 *
178 * @param[in] letimer
179 * Pointer to the LETIMER peripheral register block.
180 *
181 * @param[in] value
182 * New counter value.
183 ******************************************************************************/
LETIMER_CounterSet(LETIMER_TypeDef * letimer,uint32_t value)184 void LETIMER_CounterSet(LETIMER_TypeDef *letimer, uint32_t value)
185 {
186 #if defined(LETIMER_SYNCBUSY_CNT)
187 regSync(letimer, LETIMER_SYNCBUSY_CNT);
188 #endif
189 letimer->CNT = value;
190 }
191 #endif
192
193 /***************************************************************************//**
194 * @brief
195 * Set the LETIMER compare register value.
196 *
197 * @note
198 * The setting of a compare register requires synchronization into the
199 * low frequency domain. If the same register is modified before a previous
200 * update has completed, this function will stall until the previous
201 * synchronization has completed. This only applies to the Gecko Family. See
202 * comments in the LETIMER_Sync() internal function call.
203 *
204 * @param[in] letimer
205 * A pointer to the LETIMER peripheral register block.
206 *
207 * @param[in] comp
208 * A compare register to set, either 0 or 1.
209 *
210 * @param[in] value
211 * An initialization value (<= 0x0000ffff).
212 ******************************************************************************/
LETIMER_CompareSet(LETIMER_TypeDef * letimer,unsigned int comp,uint32_t value)213 void LETIMER_CompareSet(LETIMER_TypeDef *letimer,
214 unsigned int comp,
215 uint32_t value)
216 {
217 EFM_ASSERT(LETIMER_REF_VALID(letimer)
218 && LETIMER_COMP_REG_VALID(comp)
219 && ((value & ~(_LETIMER_COMP0_COMP0_MASK
220 >> _LETIMER_COMP0_COMP0_SHIFT))
221 == 0));
222
223 /* Initialize the selected compare value. */
224 switch (comp) {
225 case 0:
226 #if defined(LETIMER_SYNCBUSY_COMP0)
227 regSync(letimer, LETIMER_SYNCBUSY_COMP0);
228 #endif
229 letimer->COMP0 = value;
230 break;
231
232 case 1:
233 #if defined(LETIMER_SYNCBUSY_COMP1)
234 regSync(letimer, LETIMER_SYNCBUSY_COMP1);
235 #endif
236 letimer->COMP1 = value;
237 break;
238
239 default:
240 /* An unknown compare register selected, abort. */
241 break;
242 }
243 }
244
245 /***************************************************************************//**
246 * @brief
247 * Start/stop LETIMER.
248 *
249 * @note
250 * The enabling/disabling of the LETIMER modifies the LETIMER CMD register
251 * which requires synchronization into the low-frequency domain. If this
252 * register is modified before a previous update to the same register has
253 * completed, this function will stall until the previous synchronization has
254 * completed. This only applies to the Gecko Family. See comments in the
255 * LETIMER_Sync() internal function call.
256 *
257 * @param[in] letimer
258 * A pointer to the LETIMER peripheral register block.
259 *
260 * @param[in] enable
261 * True to enable counting, false to disable.
262 ******************************************************************************/
LETIMER_Enable(LETIMER_TypeDef * letimer,bool enable)263 void LETIMER_Enable(LETIMER_TypeDef *letimer, bool enable)
264 {
265 EFM_ASSERT(LETIMER_REF_VALID(letimer));
266
267 #if defined(LETIMER_SYNCBUSY_CMD)
268 regSync(letimer, LETIMER_SYNCBUSY_CMD);
269 #elif defined (LETIMER_SYNCBUSY_START) && defined (LETIMER_SYNCBUSY_STOP)
270 regSync(letimer, LETIMER_SYNCBUSY_STOP | LETIMER_SYNCBUSY_START);
271 #endif
272
273 if (enable) {
274 letimer->CMD = LETIMER_CMD_START;
275 } else {
276 letimer->CMD = LETIMER_CMD_STOP;
277 }
278 }
279
280 #if defined(_LETIMER_FREEZE_MASK)
281 /***************************************************************************//**
282 * @brief
283 * LETIMER register synchronization freeze control.
284 *
285 * @details
286 * Some LETIMER registers require synchronization into the low-frequency (LF)
287 * domain. The freeze feature allows for several such registers to be
288 * modified before passing them to the LF domain simultaneously (which
289 * takes place when the freeze mode is disabled).
290 *
291 * @note
292 * When enabling freeze mode, this function will wait for all current
293 * ongoing LETIMER synchronization to the LF domain to complete (Normally
294 * synchronization will not be in progress.) However, for this reason, when
295 * using freeze mode, modifications of registers requiring the LF synchronization
296 * should be done within one freeze enable/disable block to avoid unecessary
297 * stalling.
298 *
299 * @param[in] letimer
300 * A pointer to the LETIMER peripheral register block.
301 *
302 * @param[in] enable
303 * @li True - enable freeze, modified registers are not propagated to the
304 * LF domain
305 * @li False - disables freeze, modified registers are propagated to the LF
306 * domain
307 ******************************************************************************/
LETIMER_FreezeEnable(LETIMER_TypeDef * letimer,bool enable)308 void LETIMER_FreezeEnable(LETIMER_TypeDef *letimer, bool enable)
309 {
310 if (enable) {
311 /*
312 * Wait for any ongoing LF synchronization to complete to
313 * protect against the rare case when a user
314 * - modifies a register requiring LF sync
315 * - then enables freeze before LF sync completed
316 * - then modifies the same register again
317 * since modifying a register while it is in sync progress should be
318 * avoided.
319 */
320 while (letimer->SYNCBUSY) {
321 }
322
323 letimer->FREEZE = LETIMER_FREEZE_REGFREEZE;
324 } else {
325 letimer->FREEZE = 0;
326 }
327 }
328 #endif /* defined(_LETIMER_FREEZE_MASK) */
329
330 /***************************************************************************//**
331 * @brief
332 * Initialize LETIMER.
333 *
334 * @details
335 * Note that the compare/repeat values must be set separately with
336 * LETIMER_CompareSet() and LETIMER_RepeatSet(). That should probably be done
337 * prior using this function if configuring the LETIMER to start when
338 * initialization is complete.
339 *
340 * @note
341 * The initialization of the LETIMER modifies the LETIMER CTRL/CMD registers
342 * which require synchronization into the low-frequency domain. If any of those
343 * registers are modified before a previous update to the same register has
344 * completed, this function will stall until the previous synchronization has
345 * completed. This only applies to the Gecko Family. See comments in the
346 * LETIMER_Sync() internal function call.
347 *
348 * @param[in] letimer
349 * A pointer to the LETIMER peripheral register block.
350 *
351 * @param[in] init
352 * A pointer to the LETIMER initialization structure.
353 ******************************************************************************/
LETIMER_Init(LETIMER_TypeDef * letimer,const LETIMER_Init_TypeDef * init)354 void LETIMER_Init(LETIMER_TypeDef *letimer, const LETIMER_Init_TypeDef *init)
355 {
356 uint32_t tmp = 0;
357
358 EFM_ASSERT(LETIMER_REF_VALID(letimer));
359
360 #if defined (LETIMER_EN_EN)
361 letimer->EN_SET = LETIMER_EN_EN;
362 #endif
363
364 /* Stop the timer if specified to be disabled and running. */
365 if (!(init->enable) && (letimer->STATUS & LETIMER_STATUS_RUNNING)) {
366 #if defined(LETIMER_SYNCBUSY_CMD)
367 regSync(letimer, LETIMER_SYNCBUSY_CMD);
368 #elif defined(LETIMER_SYNCBUSY_STOP)
369 regSync(letimer, LETIMER_SYNCBUSY_STOP);
370 #endif
371 letimer->CMD = LETIMER_CMD_STOP;
372 }
373
374 /* Configure the DEBUGRUN flag, which sets whether or not the counter should be
375 * updated when the debugger is active. */
376 if (init->debugRun) {
377 tmp |= LETIMER_CTRL_DEBUGRUN;
378 }
379
380 #if defined(LETIMER_CTRL_RTCC0TEN)
381 if (init->rtcComp0Enable) {
382 tmp |= LETIMER_CTRL_RTCC0TEN;
383 }
384
385 if (init->rtcComp1Enable) {
386 tmp |= LETIMER_CTRL_RTCC1TEN;
387 }
388 #endif
389
390 if ((init->comp0Top) || (init->topValue != 0U)) {
391 #if defined (LETIMER_CTRL_COMP0TOP)
392 tmp |= LETIMER_CTRL_COMP0TOP;
393 if (init->topValue != 0U) {
394 letimer->COMP0 = init->topValue;
395 }
396 #elif defined (LETIMER_CTRL_CNTTOPEN)
397 tmp |= LETIMER_CTRL_CNTTOPEN;
398 if (init->topValue != 0U) {
399 letimer->TOP = init->topValue;
400 }
401 #endif
402 }
403
404 if (init->bufTop) {
405 tmp |= LETIMER_CTRL_BUFTOP;
406 }
407
408 if (init->out0Pol) {
409 tmp |= LETIMER_CTRL_OPOL0;
410 }
411
412 if (init->out1Pol) {
413 tmp |= LETIMER_CTRL_OPOL1;
414 }
415
416 tmp |= init->ufoa0 << _LETIMER_CTRL_UFOA0_SHIFT;
417 tmp |= init->ufoa1 << _LETIMER_CTRL_UFOA1_SHIFT;
418 tmp |= init->repMode << _LETIMER_CTRL_REPMODE_SHIFT;
419
420 #if defined(LETIMER_SYNCBUSY_CTRL)
421 /* LF register about to be modified requires sync; busy check. */
422 regSync(letimer, LETIMER_SYNCBUSY_CTRL);
423 #endif
424 letimer->CTRL = tmp;
425
426 /* Start the timer if specified to be enabled and not already running. */
427 if (init->enable && !(letimer->STATUS & LETIMER_STATUS_RUNNING)) {
428 #if defined(LETIMER_SYNCBUSY_CMD)
429 regSync(letimer, LETIMER_SYNCBUSY_CMD);
430 #elif defined(LETIMER_SYNCBUSY_START)
431 regSync(letimer, LETIMER_SYNCBUSY_START);
432 #endif
433 letimer->CMD = LETIMER_CMD_START;
434 }
435 }
436
437 /***************************************************************************//**
438 * @brief
439 * Get the LETIMER repeat register value.
440 *
441 * @param[in] letimer
442 * A pointer to the LETIMER peripheral register block.
443 *
444 * @param[in] rep
445 * Repeat register to get, either 0 or 1.
446 *
447 * @return
448 * Repeat register value, 0 if invalid register selected.
449 ******************************************************************************/
LETIMER_RepeatGet(LETIMER_TypeDef * letimer,unsigned int rep)450 uint32_t LETIMER_RepeatGet(LETIMER_TypeDef *letimer, unsigned int rep)
451 {
452 uint32_t ret;
453
454 EFM_ASSERT(LETIMER_REF_VALID(letimer) && LETIMER_REP_REG_VALID(rep));
455
456 /* Initialize the selected compare value. */
457 switch (rep) {
458 case 0:
459 #if defined(LETIMER_SYNCBUSY_REP0)
460 /* Wait for sync to complete to read the potentially pending value. */
461 regSync(letimer, LETIMER_SYNCBUSY_REP0);
462 #endif
463 ret = letimer->REP0;
464 break;
465
466 case 1:
467 #if defined(LETIMER_SYNCBUSY_REP1)
468 regSync(letimer, LETIMER_SYNCBUSY_REP1);
469 #endif
470 ret = letimer->REP1;
471 break;
472
473 default:
474 /* An unknown compare register selected. */
475 ret = 0;
476 break;
477 }
478
479 return ret;
480 }
481
482 /***************************************************************************//**
483 * @brief
484 * Set the LETIMER repeat counter register value.
485 *
486 * @note
487 * The setting of a repeat counter register requires synchronization into the
488 * low-frequency domain. If the same register is modified before a previous
489 * update has completed, this function will stall until the previous
490 * synchronization has completed. This only applies to the Gecko Family. See
491 * comments in the LETIMER_Sync() internal function call.
492 *
493 * @param[in] letimer
494 * A pointer to the LETIMER peripheral register block.
495 *
496 * @param[in] rep
497 * Repeat counter register to set, either 0 or 1.
498 *
499 * @param[in] value
500 * An initialization value (<= 0x0000ffff).
501 ******************************************************************************/
LETIMER_RepeatSet(LETIMER_TypeDef * letimer,unsigned int rep,uint32_t value)502 void LETIMER_RepeatSet(LETIMER_TypeDef *letimer,
503 unsigned int rep,
504 uint32_t value)
505 {
506 EFM_ASSERT(LETIMER_REF_VALID(letimer)
507 && LETIMER_REP_REG_VALID(rep)
508 && ((value & ~(_LETIMER_REP0_REP0_MASK
509 >> _LETIMER_REP0_REP0_SHIFT))
510 == 0));
511
512 /* Initialize the selected compare value. */
513 switch (rep) {
514 case 0:
515 #if defined(LETIMER_SYNCBUSY_REP0)
516 regSync(letimer, LETIMER_SYNCBUSY_REP0);
517 #endif
518 letimer->REP0 = value;
519 break;
520
521 case 1:
522 #if defined(LETIMER_SYNCBUSY_REP1)
523 regSync(letimer, LETIMER_SYNCBUSY_REP1);
524 #endif
525 letimer->REP1 = value;
526 break;
527
528 default:
529 /* An unknown compare register selected, abort. */
530 break;
531 }
532 }
533
534 /***************************************************************************//**
535 * @brief
536 * Reset LETIMER to the same state that it was in after a hardware reset.
537 *
538 * @note
539 * The ROUTE register is NOT reset by this function to allow for
540 * a centralized setup of this feature.
541 *
542 * @param[in] letimer
543 * A pointer to the LETIMER peripheral register block.
544 ******************************************************************************/
LETIMER_Reset(LETIMER_TypeDef * letimer)545 void LETIMER_Reset(LETIMER_TypeDef *letimer)
546 {
547 #if defined(LETIMER_EN_EN)
548 letimer->EN_SET = LETIMER_EN_EN;
549 #endif
550 LETIMER_SyncWait(letimer);
551
552 #if defined(LETIMER_SWRST_SWRST)
553 letimer->SWRST_SET = LETIMER_SWRST_SWRST;
554 while (letimer->SWRST & _LETIMER_SWRST_RESETTING_MASK) {
555 }
556 #else
557
558 #if defined(_LETIMER_FREEZE_MASK)
559 /* Freeze registers to avoid stalling for LF synchronization. */
560 LETIMER_FreezeEnable(letimer, true);
561 #endif
562
563 /* Make sure disabled first, before resetting other registers. */
564 letimer->CMD = LETIMER_CMD_STOP | LETIMER_CMD_CLEAR
565 | LETIMER_CMD_CTO0 | LETIMER_CMD_CTO1;
566 letimer->CTRL = _LETIMER_CTRL_RESETVALUE;
567 letimer->COMP0 = _LETIMER_COMP0_RESETVALUE;
568 letimer->COMP1 = _LETIMER_COMP1_RESETVALUE;
569 letimer->REP0 = _LETIMER_REP0_RESETVALUE;
570 letimer->REP1 = _LETIMER_REP1_RESETVALUE;
571 letimer->IEN = _LETIMER_IEN_RESETVALUE;
572 LETIMER_IntClear(letimer, _LETIMER_IF_MASK);
573
574 #if defined(_LETIMER_FREEZE_MASK)
575 /* Unfreeze registers and pass new settings to LETIMER. */
576 LETIMER_FreezeEnable(letimer, false);
577 #endif
578
579 LETIMER_SyncWait(letimer);
580
581 #if defined (LETIMER_EN_EN)
582 letimer->EN_CLR = LETIMER_EN_EN;
583 #if defined(_LETIMER_EN_DISABLING_MASK)
584 /*
585 * Currently, there are no chips without SWRST and with LETIMER_EN_DISABLING
586 * so this code should never be reached, but that way the same pattern of
587 * checking the disabling bit is spread across emlib, and code is slightly
588 * more resilient to feature addition/removal.
589 */
590 while (letimer->EN & _LETIMER_EN_DISABLING_MASK) {
591 }
592 #endif
593 #endif
594 #endif
595 }
596
597 /***************************************************************************//**
598 * @brief
599 * Wait for the LETIMER to complete all synchronization of register changes
600 * and commands.
601 *
602 * @param[in] letimer
603 * A pointer to the LETIMER peripheral register block.
604 ******************************************************************************/
LETIMER_SyncWait(LETIMER_TypeDef * letimer)605 void LETIMER_SyncWait(LETIMER_TypeDef *letimer)
606 {
607 #if defined(_SILICON_LABS_32B_SERIES_2)
608 while ((letimer->EN != 0U) && (letimer->SYNCBUSY != 0U)) {
609 /* Wait for previous synchronization to finish */
610 }
611 #else
612 while (letimer->SYNCBUSY != 0U) {
613 /* Wait for previous synchronization to finish */
614 }
615 #endif
616 }
617
618 /***************************************************************************//**
619 * @brief
620 * Set the LETIMER top value.
621 *
622 * @note
623 * The LETIMER is a down-counter, so when the counter reaches 0 then the top
624 * value will be loaded into the counter. This function can be used to set
625 * the top value.
626 *
627 * If the LETIMER is not already configured to use a top value then this
628 * function will enable that functionality for the user.
629 *
630 * @param[in] letimer
631 * A pointer to the LETIMER peripheral register block.
632 *
633 * @param[in] value
634 * The top value. This can be a 16 bit value on series-0 and series-1 devices
635 * and a 24 bit value on series-2 devices.
636 ******************************************************************************/
LETIMER_TopSet(LETIMER_TypeDef * letimer,uint32_t value)637 void LETIMER_TopSet(LETIMER_TypeDef *letimer, uint32_t value)
638 {
639 #if defined(LETIMER_SYNCBUSY_CTRL)
640 regSync(letimer, LETIMER_SYNCBUSY_CTRL);
641 #elif defined(LETIMER_SYNCBUSY_TOP)
642 regSync(letimer, LETIMER_SYNCBUSY_TOP);
643 #endif
644
645 #if defined(_LETIMER_TOP_MASK)
646 /* Make sure TOP value is enabled. */
647 if ((letimer->CTRL & LETIMER_CTRL_CNTTOPEN) == 0U) {
648 letimer->CTRL_SET = LETIMER_CTRL_CNTTOPEN;
649 }
650 letimer->TOP = value;
651 #else
652 /* Make sure TOP value is enabled. */
653 if ((letimer->CTRL & LETIMER_CTRL_COMP0TOP) == 0U) {
654 letimer->CTRL |= LETIMER_CTRL_COMP0TOP;
655 }
656 LETIMER_CompareSet(letimer, 0, value);
657 #endif
658 }
659
660 /***************************************************************************//**
661 * @brief
662 * Get the current LETIMER top value.
663 *
664 * @param[in] letimer
665 * A pointer to the LETIMER peripheral register block.
666 *
667 * @return
668 * The top value. This will be a 16 bit value on series-0 and series-1
669 * devices and a 24 bit value on series-2 devices.
670 ******************************************************************************/
LETIMER_TopGet(LETIMER_TypeDef * letimer)671 uint32_t LETIMER_TopGet(LETIMER_TypeDef *letimer)
672 {
673 #if defined(_LETIMER_TOP_MASK)
674 regSync(letimer, LETIMER_SYNCBUSY_TOP);
675 return letimer->TOP;
676 #else
677 #if defined(LETIMER_SYNCBUSY_COMP0)
678 regSync(letimer, LETIMER_SYNCBUSY_COMP0);
679 #endif
680 return letimer->COMP0;
681 #endif
682 }
683
684 /** @} (end addtogroup letimer) */
685 #endif /* defined(LETIMER_COUNT) && (LETIMER_COUNT > 0) */
686