1 /***************************************************************************//**
2  * @file
3  * @brief System Real Time Counter (SYSRTC) Peripheral API
4  *******************************************************************************
5  * # License
6  * <b>Copyright 2020 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 "peripheral_sysrtc.h"
32 #if defined(SYSRTC_COUNT) && (SYSRTC_COUNT > 0)
33 #include "sl_assert.h"
34 #include "em_bus.h"
35 #include "stddef.h"
36 
37 /***************************************************************************//**
38  * @addtogroup sysrtc SYSRTC - System Real Time Counter
39  * @brief System Real Time Counter (SYSRTC) Peripheral API
40  * @details
41  *  This module contains functions to control the SYSRTC peripheral of Silicon
42  *  Labs 32-bit MCUs and SoCs. The SYSRTC ensures timekeeping in low energy modes.
43  * @{
44  ******************************************************************************/
45 
46 /***************************************************************************//**
47  * Initializes SYSRTC module.
48  ******************************************************************************/
sl_sysrtc_init(const sl_sysrtc_config_t * p_config)49 void sl_sysrtc_init(const sl_sysrtc_config_t *p_config)
50 {
51   // Wait to be ready
52   sl_sysrtc_wait_ready();
53 
54   if (SYSRTC0->EN == SYSRTC_EN_EN) {
55     // Disable the module
56     sl_sysrtc_disable();
57     // Wait to be ready
58     sl_sysrtc_wait_ready();
59   }
60 
61   // Set configuration
62   SYSRTC0->CFG = (p_config->enable_debug_run ? 1UL : 0UL) << _SYSRTC_CFG_DEBUGRUN_SHIFT;
63 }
64 
65 /***************************************************************************//**
66  * Enables SYSRTC counting.
67  ******************************************************************************/
sl_sysrtc_enable(void)68 void sl_sysrtc_enable(void)
69 {
70   // Wait if disabling
71   sl_sysrtc_wait_ready();
72 
73   // Enable SYSRTC module
74   SYSRTC0->EN_SET = SYSRTC_EN_EN;
75 
76   // Start counter
77   SYSRTC0->CMD = SYSRTC_CMD_START;
78 }
79 
80 /***************************************************************************//**
81  * Disables SYSRTC counting.
82  ******************************************************************************/
sl_sysrtc_disable(void)83 void sl_sysrtc_disable(void)
84 {
85   if (SYSRTC0->EN != SYSRTC_EN_EN) {
86     return;
87   }
88 
89   // Stop counter
90   sl_sysrtc_stop();
91 
92   // Disable module
93   SYSRTC0->EN_CLR = SYSRTC_EN_EN;
94 }
95 
96 /***************************************************************************//**
97  * Restores SYSRTC to its reset state.
98  ******************************************************************************/
sl_sysrtc_reset(void)99 void sl_sysrtc_reset(void)
100 {
101   // Reset timer
102   SYSRTC0->SWRST = SYSRTC_SWRST_SWRST;
103 }
104 
105 /***************************************************************************//**
106  * Initializes the selected SYSRTC group.
107  ******************************************************************************/
sl_sysrtc_init_group(uint8_t group_number,sl_sysrtc_group_config_t const * p_group_config)108 void sl_sysrtc_init_group(uint8_t group_number,
109                           sl_sysrtc_group_config_t const *p_group_config)
110 {
111   uint32_t temp = 0;
112 
113   EFM_ASSERT(SYSRTC_GROUP_VALID(group_number));
114 
115   switch (group_number) {
116     case 0:
117       temp = ((p_group_config->compare_channel0_enable ? 1UL : 0UL) << _SYSRTC_GRP0_CTRL_CMP0EN_SHIFT);
118       if (p_group_config->p_compare_channel0_config != NULL) {
119         temp |= ((uint32_t)p_group_config->p_compare_channel0_config->compare_match_out_action << _SYSRTC_GRP0_CTRL_CMP0CMOA_SHIFT);
120       }
121 
122 #ifdef SYSRTC_GRP0_CTRL_CMP1EN
123       temp |= ((p_group_config->compare_channel1_enable ? 1UL : 0UL) << _SYSRTC_GRP0_CTRL_CMP1EN_SHIFT);
124       if (p_group_config->p_compare_channel1_config != NULL) {
125         temp |= ((uint32_t)p_group_config->p_compare_channel1_config->compare_match_out_action << _SYSRTC_GRP0_CTRL_CMP1CMOA_SHIFT);
126       }
127 #endif
128 #ifdef SYSRTC_GRP0_CTRL_CAP0EN
129       temp |= ((p_group_config->capture_channel0_enable ? 1UL : 0UL) << _SYSRTC_GRP0_CTRL_CAP0EN_SHIFT);
130       if (p_group_config->p_capture_channel0_config != NULL) {
131         temp |= ((uint32_t)p_group_config->p_capture_channel0_config->capture_input_edge << _SYSRTC_GRP0_CTRL_CAP0EDGE_SHIFT);
132       }
133 #endif
134       SYSRTC0->GRP0_CTRL = temp;
135       break;
136 
137 #if SYSRTC_GROUP_NUMBER > 1
138     case 1:
139       temp = ((p_group_config->compare_channel0_enable ? 1UL : 0UL) << _SYSRTC_GRP1_CTRL_CMP0EN_SHIFT);
140       if (p_group_config->p_compare_channel0_config != NULL) {
141         temp |= ((uint32_t)p_group_config->p_compare_channel0_config->compare_match_out_action << _SYSRTC_GRP1_CTRL_CMP0CMOA_SHIFT);
142       }
143 #ifdef SYSRTC_GRP1_CTRL_CMP1EN
144       temp |= ((p_group_config->compare_channel1_enable ? 1UL : 0UL) << _SYSRTC_GRP1_CTRL_CMP1EN_SHIFT);
145       if (p_group_config->p_compare_channel1_config != NULL) {
146         temp |= ((uint32_t)p_group_config->p_compare_channel1_config->compare_match_out_action << _SYSRTC_GRP1_CTRL_CMP1CMOA_SHIFT);
147       }
148 #endif
149 #ifdef SYSRTC_GRP1_CTRL_CAP0EN
150       temp |= ((p_group_config->capture_channel0_enable ? 1UL : 0UL) << _SYSRTC_GRP1_CTRL_CAP0EN_SHIFT);
151       if (p_group_config->p_capture_channel0_config != NULL) {
152         temp |=  ((uint32_t)p_group_config->p_capture_channel0_config->capture_input_edge << _SYSRTC_GRP1_CTRL_CAP0EDGE_SHIFT);
153       }
154 #endif
155       SYSRTC0->GRP1_CTRL = temp;
156       break;
157 
158 #if SYSRTC_GROUP_NUMBER > 2
159     case 2:
160 //      SYSRTC0->GRP2_CTRL = ((p_group_config->compare_channel0_enable ? 1UL : 0UL) << _SYSRTC_GRP2_CTRL_CMP0EN_SHIFT)
161 //                           | ((uint32_t)p_group_config->p_compare_channel0_config->compare_match_out_action << _SYSRTC_GRP2_CTRL_CMP0CMOA_SHIFT);
162 #ifdef SYSRTC_GRP2_CTRL_CMP1EN
163       SYSRTC0->GRP2_CTRL |= ((p_group_config->compare_channel1_enable ? 1UL : 0UL) << _SYSRTC_GRP2_CTRL_CMP1EN_SHIFT)
164                             | ((uint32_t)p_group_config->p_compare_channel1_config->compare_match_out_action << _SYSRTC_GRP2_CTRL_CMP1CMOA_SHIFT);
165 #endif
166 #ifdef SYSRTC_GRP2_CTRL_CAP0EN
167       SYSRTC0->GRP2_CTRL |= ((p_group_config->capture_channel0_enable ? 1UL : 0UL) << _SYSRTC_GRP2_CTRL_CAP0EN_SHIFT)
168                             | ((uint32_t)p_group_config->p_capture_channel0_config->capture_input_edge << _SYSRTC_GRP2_CTRL_CAP0EDGE_SHIFT);
169 #endif
170       break;
171 
172 #if SYSRTC_GROUP_NUMBER > 3
173     case 3:
174       SYSRTC0->GRP3_CTRL = ((p_group_config->compare_channel0_enable ? 1UL : 0UL) << _SYSRTC_GRP3_CTRL_CMP0EN_SHIFT)
175                            | ((uint32_t)p_group_config->p_compare_channel0_config->compare_match_out_action << _SYSRTC_GRP3_CTRL_CMP0CMOA_SHIFT);
176 #ifdef SYSRTC_GRP3_CTRL_CMP1EN
177       SYSRTC0->GRP3_CTRL |= ((p_group_config->compare_channel1_enable ? 1UL : 0UL) << _SYSRTC_GRP3_CTRL_CMP1EN_SHIFT)
178                             | ((uint32_t)p_group_config->p_compare_channel1_config->compare_match_out_action << _SYSRTC_GRP3_CTRL_CMP1CMOA_SHIFT);
179 #endif
180 #ifdef SYSRTC_GRP3_CTRL_CAP0EN
181       SYSRTC0->GRP3_CTRL |= ((p_group_config->capture_channel0_enable ? 1UL : 0UL) << _SYSRTC_GRP3_CTRL_CAP0EN_SHIFT)
182                             | ((uint32_t)p_group_config->p_capture_channel0_config->capture_input_edge << _SYSRTC_GRP3_CTRL_CAP0EDGE_SHIFT);
183 #endif
184       break;
185 
186 #if SYSRTC_GROUP_NUMBER > 4
187     case 4:
188       SYSRTC0->GRP4_CTRL = ((p_group_config->compare_channel0_enable ? 1UL : 0UL) << _SYSRTC_GRP4_CTRL_CMP0EN_SHIFT)
189                            | ((uint32_t)p_group_config->p_compare_channel0_config->compare_match_out_action << _SYSRTC_GRP4_CTRL_CMP0CMOA_SHIFT);
190 #ifdef SYSRTC_GRP4_CTRL_CMP1EN
191       SYSRTC0->GRP4_CTRL |= ((p_group_config->compare_channel1_enable ? 1UL : 0UL) << _SYSRTC_GRP4_CTRL_CMP1EN_SHIFT)
192                             | ((uint32_t)p_group_config->p_compare_channel1_config->compare_match_out_action << _SYSRTC_GRP4_CTRL_CMP1CMOA_SHIFT);
193 #endif
194 #ifdef SYSRTC_GRP4_CTRL_CAP0EN
195       SYSRTC0->GRP4_CTRL |= ((p_group_config->capture_channel0_enable ? 1UL : 0UL) << _SYSRTC_GRP4_CTRL_CAP0EN_SHIFT)
196                             | ((uint32_t)p_group_config->p_capture_channel0_config->capture_input_edge << _SYSRTC_GRP4_CTRL_CAP0EDGE_SHIFT);
197 #endif
198       break;
199 
200 #if SYSRTC_GROUP_NUMBER > 5
201     case 5:
202       SYSRTC0->GRP5_CTRL = ((p_group_config->compare_channel0_enable ? 1UL : 0UL) << _SYSRTC_GRP5_CTRL_CMP0EN_SHIFT)
203                            | ((uint32_t)p_group_config->p_compare_channel0_config->compare_match_out_action << _SYSRTC_GRP5_CTRL_CMP0CMOA_SHIFT);
204 #ifdef SYSRTC_GRP5_CTRL_CMP1EN
205       SYSRTC0->GRP5_CTRL |= ((p_group_config->compare_channel1_enable ? 1UL : 0UL) << _SYSRTC_GRP5_CTRL_CMP1EN_SHIFT)
206                             | ((uint32_t)p_group_config->p_compare_channel1_config->compare_match_out_action << _SYSRTC_GRP5_CTRL_CMP1CMOA_SHIFT);
207 #endif
208 #ifdef SYSRTC_GRP5_CTRL_CAP0EN
209       SYSRTC0->GRP5_CTRL |= ((p_group_config->capture_channel0_enable ? 1UL : 0UL) << _SYSRTC_GRP5_CTRL_CAP0EN_SHIFT)
210                             | ((uint32_t)p_group_config->p_capture_channel0_config->capture_input_edge << _SYSRTC_GRP5_CTRL_CAP0EDGE_SHIFT);
211 #endif
212       break;
213 
214 #if SYSRTC_GROUP_NUMBER > 6
215     case 6:
216       SYSRTC0->GRP6_CTRL = ((p_group_config->compare_channel0_enable ? 1UL : 0UL) << _SYSRTC_GRP6_CTRL_CMP0EN_SHIFT)
217                            | ((uint32_t)p_group_config->p_compare_channel0_config->compare_match_out_action << _SYSRTC_GRP6_CTRL_CMP0CMOA_SHIFT);
218 #ifdef SYSRTC_GRP6_CTRL_CMP1EN
219       SYSRTC0->GRP6_CTRL |= ((p_group_config->compare_channel1_enable ? 1UL : 0UL) << _SYSRTC_GRP6_CTRL_CMP1EN_SHIFT)
220                             | ((uint32_t)p_group_config->p_compare_channel1_config->compare_match_out_action << _SYSRTC_GRP6_CTRL_CMP1CMOA_SHIFT);
221 #endif
222 #ifdef SYSRTC_GRP6_CTRL_CAP0EN
223       SYSRTC0->GRP6_CTRL |= ((p_group_config->capture_channel0_enable ? 1UL : 0UL) << _SYSRTC_GRP6_CTRL_CAP0EN_SHIFT)
224                             | ((uint32_t)p_group_config->p_capture_channel0_config->capture_input_edge << _SYSRTC_GRP6_CTRL_CAP0EDGE_SHIFT);
225 #endif
226       break;
227 
228 #if SYSRTC_GROUP_NUMBER > 7
229     case 7:
230       SYSRTC0->GRP7_CTRL = ((p_group_config->compare_channel0_enable ? 1UL : 0UL) << _SYSRTC_GRP7_CTRL_CMP0EN_SHIFT)
231                            | ((uint32_t)p_group_config->p_compare_channel0_config->compare_match_out_action << _SYSRTC_GRP7_CTRL_CMP0CMOA_SHIFT);
232 #ifdef SYSRTC_GRP7_CTRL_CMP1EN
233       SYSRTC0->GRP7_CTRL |= ((p_group_config->compare_channel1_enable ? 1UL : 0UL) << _SYSRTC_GRP7_CTRL_CMP1EN_SHIFT)
234                             | ((uint32_t)p_group_config->p_compare_channel1_config->compare_match_out_action << _SYSRTC_GRP7_CTRL_CMP1CMOA_SHIFT);
235 #endif
236 #ifdef SYSRTC_GRP7_CTRL_CAP0EN
237       SYSRTC0->GRP7_CTRL |= ((p_group_config->capture_channel0_enable ? 1UL : 0UL) << _SYSRTC_GRP7_CTRL_CAP0EN_SHIFT)
238                             | ((uint32_t)p_group_config->p_capture_channel0_config->capture_input_edge << _SYSRTC_GRP7_CTRL_CAP0EDGE_SHIFT);
239 #endif
240       break;
241 #endif
242 #endif
243 #endif
244 #endif
245 #endif
246 #endif
247 #endif
248 
249     default:
250       EFM_ASSERT(1);
251   }
252 }
253 
254 /***************************************************************************//**
255  * Enables one or more SYSRTC interrupts for the given group.
256  ******************************************************************************/
sl_sysrtc_enable_group_interrupts(uint8_t group_number,uint32_t flags)257 void sl_sysrtc_enable_group_interrupts(uint8_t group_number,
258                                        uint32_t flags)
259 {
260   EFM_ASSERT(SYSRTC_GROUP_VALID(group_number));
261 
262   switch (group_number) {
263     case 0:
264       SYSRTC0->GRP0_IEN_SET = flags;
265       break;
266 
267 #if SYSRTC_GROUP_NUMBER > 1
268     case 1:
269       SYSRTC0->GRP1_IEN_SET = flags;
270       break;
271 
272 #if SYSRTC_GROUP_NUMBER > 2
273     case 2:
274       SYSRTC0->GRP2_IEN_SET = flags;
275       break;
276 
277 #if SYSRTC_GROUP_NUMBER > 3
278     case 3:
279       SYSRTC0->GRP3_IEN_SET = flags;
280       break;
281 
282 #if SYSRTC_GROUP_NUMBER > 4
283     case 4:
284       SYSRTC0->GRP4_IEN_SET = flags;
285       break;
286 
287 #if SYSRTC_GROUP_NUMBER > 5
288     case 5:
289       SYSRTC0->GRP5_IEN_SET = flags;
290       break;
291 
292 #if SYSRTC_GROUP_NUMBER > 6
293     case 6:
294       SYSRTC0->GRP6_IEN_SET = flags;
295       break;
296 
297 #if SYSRTC_GROUP_NUMBER > 7
298     case 7:
299       SYSRTC0->GRP7_IEN_SET = flags;
300       break;
301 #endif
302 #endif
303 #endif
304 #endif
305 #endif
306 #endif
307 #endif
308 
309     default:
310       EFM_ASSERT(1);
311   }
312 }
313 
314 /***************************************************************************//**
315  * Disables one or more SYSRTC interrupts for the given group.
316  ******************************************************************************/
sl_sysrtc_disable_group_interrupts(uint8_t group_number,uint32_t flags)317 void sl_sysrtc_disable_group_interrupts(uint8_t group_number,
318                                         uint32_t flags)
319 {
320   EFM_ASSERT(SYSRTC_GROUP_VALID(group_number));
321 
322   switch (group_number) {
323     case 0:
324       SYSRTC0->GRP0_IEN_CLR = flags;
325       break;
326 
327 #if SYSRTC_GROUP_NUMBER > 1
328     case 1:
329       SYSRTC0->GRP1_IEN_CLR = flags;
330       break;
331 
332 #if SYSRTC_GROUP_NUMBER > 2
333     case 2:
334       SYSRTC0->GRP2_IEN_CLR = flags;
335       break;
336 
337 #if SYSRTC_GROUP_NUMBER > 3
338     case 3:
339       SYSRTC0->GRP3_IEN_CLR = flags;
340       break;
341 
342 #if SYSRTC_GROUP_NUMBER > 4
343     case 4:
344       SYSRTC0->GRP4_IEN_CLR = flags;
345       break;
346 
347 #if SYSRTC_GROUP_NUMBER > 5
348     case 5:
349       SYSRTC0->GRP5_IEN_CLR = flags;
350       break;
351 
352 #if SYSRTC_GROUP_NUMBER > 6
353     case 6:
354       SYSRTC0->GRP6_IEN_CLR = flags;
355       break;
356 
357 #if SYSRTC_GROUP_NUMBER > 7
358     case 7:
359       SYSRTC0->GRP7_IEN_CLR = flags;
360       break;
361 #endif
362 #endif
363 #endif
364 #endif
365 #endif
366 #endif
367 #endif
368 
369     default:
370       EFM_ASSERT(1);
371   }
372 }
373 
374 /***************************************************************************//**
375  * Clears one or more pending SYSRTC interrupts for the given group.
376  ******************************************************************************/
sl_sysrtc_clear_group_interrupts(uint8_t group_number,uint32_t flags)377 void sl_sysrtc_clear_group_interrupts(uint8_t group_number,
378                                       uint32_t flags)
379 {
380   EFM_ASSERT(SYSRTC_GROUP_VALID(group_number));
381 
382   switch (group_number) {
383     case 0:
384       SYSRTC0->GRP0_IF_CLR = flags;
385       break;
386 
387 #if SYSRTC_GROUP_NUMBER > 1
388     case 1:
389       SYSRTC0->GRP1_IF_CLR = flags;
390       break;
391 
392 #if SYSRTC_GROUP_NUMBER > 2
393     case 2:
394       SYSRTC0->GRP2_IF_CLR = flags;
395       break;
396 
397 #if SYSRTC_GROUP_NUMBER > 3
398     case 3:
399       SYSRTC0->GRP3_IF_CLR = flags;
400       break;
401 
402 #if SYSRTC_GROUP_NUMBER > 4
403     case 4:
404       SYSRTC0->GRP4_IF_CLR = flags;
405       break;
406 
407 #if SYSRTC_GROUP_NUMBER > 5
408     case 5:
409       SYSRTC0->GRP5_IF_CLR = flags;
410       break;
411 
412 #if SYSRTC_GROUP_NUMBER > 6
413     case 6:
414       SYSRTC0->GRP6_IF_CLR = flags;
415       break;
416 
417 #if SYSRTC_GROUP_NUMBER > 7
418     case 7:
419       SYSRTC0->GRP7_IF_CLR = flags;
420       break;
421 #endif
422 #endif
423 #endif
424 #endif
425 #endif
426 #endif
427 #endif
428 
429     default:
430       EFM_ASSERT(1);
431   }
432 }
433 
434 /***************************************************************************//**
435  * Gets pending SYSRTC interrupt flags for the given group.
436  ******************************************************************************/
sl_sysrtc_get_group_interrupts(uint8_t group_number)437 uint32_t sl_sysrtc_get_group_interrupts(uint8_t group_number)
438 {
439   EFM_ASSERT(SYSRTC_GROUP_VALID(group_number));
440 
441   switch (group_number) {
442     case 0:
443       return SYSRTC0->GRP0_IF;
444 
445 #if SYSRTC_GROUP_NUMBER > 1
446     case 1:
447       return SYSRTC0->GRP1_IF;
448 
449 #if SYSRTC_GROUP_NUMBER > 2
450     case 2:
451       return SYSRTC0->GRP2_IF;
452 
453 #if SYSRTC_GROUP_NUMBER > 3
454     case 3:
455       return SYSRTC0->GRP3_IF;
456 
457 #if SYSRTC_GROUP_NUMBER > 4
458     case 4:
459       return SYSRTC0->GRP4_IF;
460 
461 #if SYSRTC_GROUP_NUMBER > 5
462     case 5:
463       return SYSRTC0->GRP5_IF;
464 
465 #if SYSRTC_GROUP_NUMBER > 6
466     case 6:
467       return SYSRTC0->GRP6_IF;
468 
469 #if SYSRTC_GROUP_NUMBER > 7
470     case 7:
471       return SYSRTC0->GRP7_IF;
472 #endif
473 #endif
474 #endif
475 #endif
476 #endif
477 #endif
478 #endif
479 
480     default:
481       EFM_ASSERT(1);
482       return 0;
483   }
484 }
485 
486 /***************************************************************************//**
487  * Gets enabled and pending SYSRTC interrupt flags.
488  ******************************************************************************/
sl_sysrtc_get_group_enabled_interrupts(uint8_t group_number)489 uint32_t sl_sysrtc_get_group_enabled_interrupts(uint8_t group_number)
490 {
491   uint32_t ien = 0;
492 
493   EFM_ASSERT(SYSRTC_GROUP_VALID(group_number));
494 
495   switch (group_number) {
496     case 0:
497       ien = SYSRTC0->GRP0_IEN;
498       return SYSRTC0->GRP0_IF & ien;
499 
500 #if SYSRTC_GROUP_NUMBER > 1
501     case 1:
502       ien = SYSRTC0->GRP1_IEN;
503       return SYSRTC0->GRP1_IF & ien;
504 
505 #if SYSRTC_GROUP_NUMBER > 2
506     case 2:
507       ien = SYSRTC0->GRP2_IEN;
508       return SYSRTC0->GRP2_IF & ien;
509 
510 #if SYSRTC_GROUP_NUMBER > 3
511     case 3:
512       ien = SYSRTC0->GRP3_IEN;
513       return SYSRTC0->GRP3_IF & ien;
514 
515 #if SYSRTC_GROUP_NUMBER > 4
516     case 4:
517       ien = SYSRTC0->GRP4_IEN;
518       return SYSRTC0->GRP4_IF & ien;
519 
520 #if SYSRTC_GROUP_NUMBER > 5
521     case 5:
522       ien = SYSRTC0->GRP5_IEN;
523       return SYSRTC0->GRP5_IF & ien;
524 
525 #if SYSRTC_GROUP_NUMBER > 6
526     case 6:
527       ien = SYSRTC0->GRP6_IEN;
528       return SYSRTC0->GRP6_IF & ien;
529 
530 #if SYSRTC_GROUP_NUMBER > 7
531     case 7:
532       ien = SYSRTC0->GRP7_IEN;
533       return SYSRTC0->GRP7_IF & ien;
534 #endif
535 #endif
536 #endif
537 #endif
538 #endif
539 #endif
540 #endif
541 
542     default:
543       EFM_ASSERT(1);
544       return 0;
545   }
546 }
547 
548 /***************************************************************************//**
549  * Sets one or more pending SYSRTC interrupts for the given group from Software.
550  ******************************************************************************/
sl_sysrtc_set_group_interrupts(uint8_t group_number,uint32_t flags)551 void sl_sysrtc_set_group_interrupts(uint8_t group_number,
552                                     uint32_t flags)
553 {
554   EFM_ASSERT(SYSRTC_GROUP_VALID(group_number));
555 
556   switch (group_number) {
557     case 0:
558       SYSRTC0->GRP0_IF_SET = flags;
559       break;
560 
561 #if SYSRTC_GROUP_NUMBER > 1
562     case 1:
563       SYSRTC0->GRP1_IF_SET = flags;
564       break;
565 
566 #if SYSRTC_GROUP_NUMBER > 2
567     case 2:
568       SYSRTC0->GRP2_IF_SET = flags;
569       break;
570 
571 #if SYSRTC_GROUP_NUMBER > 3
572     case 3:
573       SYSRTC0->GRP3_IF_SET = flags;
574       break;
575 
576 #if SYSRTC_GROUP_NUMBER > 4
577     case 4:
578       SYSRTC0->GRP4_IF_SET = flags;
579       break;
580 
581 #if SYSRTC_GROUP_NUMBER > 5
582     case 5:
583       SYSRTC0->GRP5_IF_SET = flags;
584       break;
585 
586 #if SYSRTC_GROUP_NUMBER > 6
587     case 6:
588       SYSRTC0->GRP6_IF_SET = flags;
589       break;
590 
591 #if SYSRTC_GROUP_NUMBER > 7
592     case 7:
593       SYSRTC0->GRP7_IF_SET = flags;
594       break;
595 #endif
596 #endif
597 #endif
598 #endif
599 #endif
600 #endif
601 #endif
602 
603     default:
604       EFM_ASSERT(1);
605   }
606 }
607 
608 /***************************************************************************//**
609  * Gets SYSRTC compare register value for selected channel of given group.
610  ******************************************************************************/
sl_sysrtc_get_group_compare_channel_value(uint8_t group_number,uint8_t channel)611 uint32_t sl_sysrtc_get_group_compare_channel_value(uint8_t group_number,
612                                                    uint8_t channel)
613 {
614   EFM_ASSERT(SYSRTC_GROUP_VALID(group_number));
615 
616   switch (group_number) {
617     case 0:
618       switch (channel) {
619         case 0:
620           return SYSRTC0->GRP0_CMP0VALUE;
621 
622 #ifdef SYSRTC_GRP0_CTRL_CMP1EN
623         case 1:
624           return SYSRTC0->GRP0_CMP1VALUE;
625 #endif
626 
627         default:
628           EFM_ASSERT(1);
629           return 0;
630       }
631       break;
632 
633 #if SYSRTC_GROUP_NUMBER > 1
634     case 1:
635       switch (channel) {
636         case 0:
637           return SYSRTC0->GRP1_CMP0VALUE;
638 
639 #ifdef SYSRTC_GRP1_CTRL_CMP1EN
640         case 1:
641           return SYSRTC0->GRP1_CMP1VALUE;
642 #endif
643 
644         default:
645           EFM_ASSERT(1);
646           return 0;
647       }
648       break;
649 
650 #if SYSRTC_GROUP_NUMBER > 2
651     case 2:
652       switch (channel) {
653         case 0:
654           return SYSRTC0->GRP2_CMP0VALUE;
655 
656 #ifdef SYSRTC_GRP2_CTRL_CMP1EN
657         case 1:
658           return SYSRTC0->GRP2_CMP1VALUE;
659 #endif
660 
661         default:
662           EFM_ASSERT(1);
663           return 0;
664       }
665       break;
666 
667 #if SYSRTC_GROUP_NUMBER > 3
668     case 3:
669       switch (channel) {
670         case 0:
671           return SYSRTC0->GRP3_CMP0VALUE;
672 
673 #ifdef SYSRTC_GRP3_CTRL_CMP1EN
674         case 1:
675           return SYSRTC0->GRP3_CMP1VALUE;
676 #endif
677 
678         default:
679           EFM_ASSERT(1);
680           return 0;
681       }
682       break;
683 
684 #if SYSRTC_GROUP_NUMBER > 4
685     case 4:
686       switch (channel) {
687         case 0:
688           return SYSRTC0->GRP4_CMP0VALUE;
689 
690 #ifdef SYSRTC_GRP4_CTRL_CMP1EN
691         case 1:
692           return SYSRTC0->GRP4_CMP1VALUE;
693 #endif
694 
695         default:
696           EFM_ASSERT(1);
697           return 0;
698       }
699       break;
700 
701 #if SYSRTC_GROUP_NUMBER > 5
702     case 5:
703       switch (channel) {
704         case 0:
705           return SYSRTC0->GRP5_CMP0VALUE;
706 
707 #ifdef SYSRTC_GRP5_CTRL_CMP1EN
708         case 1:
709           return SYSRTC0->GRP5_CMP1VALUE;
710 #endif
711 
712         default:
713           EFM_ASSERT(1);
714           return 0;
715       }
716       break;
717 
718 #if SYSRTC_GROUP_NUMBER > 6
719     case 6:
720       switch (channel) {
721         case 0:
722           return SYSRTC0->GRP6_CMP0VALUE;
723 
724 #ifdef SYSRTC_GRP6_CTRL_CMP1EN
725         case 1:
726           return SYSRTC0->GRP6_CMP1VALUE;
727 #endif
728 
729         default:
730           EFM_ASSERT(1);
731           return 0;
732       }
733       break;
734 
735 #if SYSRTC_GROUP_NUMBER > 7
736     case 7:
737       switch (channel) {
738         case 0:
739           return SYSRTC0->GRP7_CMP0VALUE;
740 
741 #ifdef SYSRTC_GRP7_CTRL_CMP1EN
742         case 1:
743           return SYSRTC0->GRP7_CMP1VALUE;
744 #endif
745 
746         default:
747           EFM_ASSERT(1);
748           return 0;
749       }
750       break;
751 #endif
752 #endif
753 #endif
754 #endif
755 #endif
756 #endif
757 #endif
758 
759     default:
760       EFM_ASSERT(1);
761       return 0;
762   }
763 }
764 
765 /***************************************************************************//**
766  * Sets SYSRTC compare register value for selected channel of given group.
767  ******************************************************************************/
sl_sysrtc_set_group_compare_channel_value(uint8_t group_number,uint8_t channel,uint32_t value)768 void sl_sysrtc_set_group_compare_channel_value(uint8_t group_number,
769                                                uint8_t channel,
770                                                uint32_t value)
771 {
772   EFM_ASSERT(SYSRTC_GROUP_VALID(group_number));
773 
774   switch (group_number) {
775     case 0:
776       switch (channel) {
777         case 0:
778           SYSRTC0->GRP0_CMP0VALUE = value;
779           break;
780 
781 #ifdef SYSRTC_GRP0_CTRL_CMP1EN
782         case 1:
783           SYSRTC0->GRP0_CMP1VALUE = value;
784           break;
785 #endif
786 
787         default:
788           EFM_ASSERT(1);
789       }
790       break;
791 
792 #if SYSRTC_GROUP_NUMBER > 1
793     case 1:
794       switch (channel) {
795         case 0:
796           SYSRTC0->GRP1_CMP0VALUE = value;
797           break;
798 
799 #ifdef SYSRTC_GRP1_CTRL_CMP1EN
800         case 1:
801           SYSRTC0->GRP1_CMP1VALUE = value;
802           break;
803 #endif
804 
805         default:
806           EFM_ASSERT(1);
807       }
808       break;
809 
810 #if SYSRTC_GROUP_NUMBER > 2
811     case 2:
812       switch (channel) {
813         case 0:
814           SYSRTC0->GRP2_CMP0VALUE = value;
815           break;
816 
817 #ifdef SYSRTC_GRP2_CTRL_CMP1EN
818         case 1:
819           SYSRTC0->GRP2_CMP1VALUE = value;
820           break;
821 #endif
822 
823         default:
824           EFM_ASSERT(1);
825       }
826       break;
827 
828 #if SYSRTC_GROUP_NUMBER > 3
829     case 3:
830       switch (channel) {
831         case 0:
832           SYSRTC0->GRP3_CMP0VALUE = value;
833           break;
834 
835 #ifdef SYSRTC_GRP3_CTRL_CMP1EN
836         case 1:
837           SYSRTC0->GRP3_CMP1VALUE = value;
838           break;
839 #endif
840 
841         default:
842           EFM_ASSERT(1);
843       }
844       break;
845 
846 #if SYSRTC_GROUP_NUMBER > 4
847     case 4:
848       switch (channel) {
849         case 0:
850           SYSRTC0->GRP4_CMP0VALUE = value;
851           break;
852 
853 #ifdef SYSRTC_GRP4_CTRL_CMP1EN
854         case 1:
855           SYSRTC0->GRP4_CMP1VALUE = value;
856           break;
857 #endif
858 
859         default:
860           EFM_ASSERT(1);
861       }
862       break;
863 
864 #if SYSRTC_GROUP_NUMBER > 5
865     case 5:
866       switch (channel) {
867         case 0:
868           SYSRTC0->GRP5_CMP0VALUE = value;
869           break;
870 
871 #ifdef SYSRTC_GRP5_CTRL_CMP1EN
872         case 1:
873           SYSRTC0->GRP5_CMP1VALUE = value;
874           break;
875 #endif
876 
877         default:
878           EFM_ASSERT(1);
879       }
880       break;
881 
882 #if SYSRTC_GROUP_NUMBER > 6
883     case 6:
884       switch (channel) {
885         case 0:
886           SYSRTC0->GRP6_CMP0VALUE = value;
887           break;
888 
889 #ifdef SYSRTC_GRP6_CTRL_CMP1EN
890         case 1:
891           SYSRTC0->GRP6_CMP1VALUE = value;
892           break;
893 #endif
894 
895         default:
896           EFM_ASSERT(1);
897       }
898       break;
899 
900 #if SYSRTC_GROUP_NUMBER > 7
901     case 7:
902       switch (channel) {
903         case 0:
904           SYSRTC0->GRP7_CMP0VALUE = value;
905           break;
906 
907 #ifdef SYSRTC_GRP7_CTRL_CMP1EN
908         case 1:
909           SYSRTC0->GRP7_CMP1VALUE = value;
910           break;
911 #endif
912 
913         default:
914           EFM_ASSERT(1);
915       }
916       break;
917 #endif
918 #endif
919 #endif
920 #endif
921 #endif
922 #endif
923 #endif
924 
925     default:
926       EFM_ASSERT(1);
927   }
928 }
929 
930 /***************************************************************************//**
931  * Gets SYSRTC input capture register value for selected channel of given group.
932  ******************************************************************************/
sl_sysrtc_get_group_capture_channel_value(uint8_t group_number)933 uint32_t sl_sysrtc_get_group_capture_channel_value(uint8_t group_number)
934 {
935   EFM_ASSERT(SYSRTC_GROUP_VALID(group_number));
936 
937   switch (group_number) {
938 #ifdef SYSRTC_GRP0_CTRL_CAP0EN
939     case 0:
940       return SYSRTC0->GRP0_CAP0VALUE;
941 #endif
942 
943 #if SYSRTC_GROUP_NUMBER > 1
944 #ifdef SYSRTC_GRP1_CTRL_CAP0EN
945     case 1:
946       return SYSRTC0->GRP1_CAP0VALUE;
947 #endif
948 
949 #if SYSRTC_GROUP_NUMBER > 2
950 #ifdef SYSRTC_GRP2_CTRL_CAP0EN
951     case 2:
952       return SYSRTC0->GRP2_CAP0VALUE;
953 #endif
954 
955 #if SYSRTC_GROUP_NUMBER > 3
956 #ifdef SYSRTC_GRP3_CTRL_CAP0EN
957     case 3:
958       return SYSRTC0->GRP3_CAP0VALUE;
959 #endif
960 
961 #if SYSRTC_GROUP_NUMBER > 4
962 #ifdef SYSRTC_GRP4_CTRL_CAP0EN
963     case 4:
964       return SYSRTC0->GRP4_CAP0VALUE;
965 #endif
966 
967 #if SYSRTC_GROUP_NUMBER > 5
968 #ifdef SYSRTC_GRP5_CTRL_CAP0EN
969     case 5:
970       return SYSRTC0->GRP5_CAP0VALUE;
971 #endif
972 
973 #if SYSRTC_GROUP_NUMBER > 6
974 #ifdef SYSRTC_GRP6_CTRL_CAP0EN
975     case 6:
976       return SYSRTC0->GRP6_CAP0VALUE;
977 #endif
978 
979 #if SYSRTC_GROUP_NUMBER > 7
980 #ifdef SYSRTC_GRP7_CTRL_CAP0EN
981     case 7:
982       return SYSRTC0->GRP7_CAP0VALUE;
983 #endif
984 #endif
985 #endif
986 #endif
987 #endif
988 #endif
989 #endif
990 #endif
991 
992     default:
993       EFM_ASSERT(1);
994       return 0;
995   }
996 }
997 
998 /** @} (end addtogroup sysrtc) */
999 #endif /* defined(SYSRTC_COUNT) && (SYSRTC_COUNT > 0) */
1000