1 /***************************************************************************//**
\r
3 * @brief Real Time Counter (RTC) peripheral API
\r
5 *******************************************************************************
\r
7 * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
\r
8 *******************************************************************************
\r
10 * Permission is granted to anyone to use this software for any purpose,
\r
11 * including commercial applications, and to alter it and redistribute it
\r
12 * freely, subject to the following restrictions:
\r
14 * 1. The origin of this software must not be misrepresented; you must not
\r
15 * claim that you wrote the original software.
\r
16 * 2. Altered source versions must be plainly marked as such, and must not be
\r
17 * misrepresented as being the original software.
\r
18 * 3. This notice may not be removed or altered from any source distribution.
\r
20 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
\r
21 * obligation to support this Software. Silicon Labs is providing the
\r
22 * Software "AS IS", with no express or implied warranties of any kind,
\r
23 * including, but not limited to, any implied warranties of merchantability
\r
24 * or fitness for any particular purpose or warranties against infringement
\r
25 * of any proprietary rights of a third party.
\r
27 * Silicon Labs will not be liable for any consequential, incidental, or
\r
28 * special damages, or any other relief, or for any claim by any third party,
\r
29 * arising from your use of this Software.
\r
31 ******************************************************************************/
\r
33 #ifndef __SILICON_LABS_EM_RTC_H__
\r
34 #define __SILICON_LABS_EM_RTC_H__
\r
36 #include "em_device.h"
\r
37 #if defined(RTC_COUNT) && (RTC_COUNT > 0)
\r
39 #include <stdbool.h>
\r
45 /***************************************************************************//**
\r
46 * @addtogroup EM_Library
\r
48 ******************************************************************************/
\r
50 /***************************************************************************//**
\r
53 ******************************************************************************/
\r
55 /*******************************************************************************
\r
56 ******************************* STRUCTS ***********************************
\r
57 ******************************************************************************/
\r
59 /** RTC initialization structure. */
\r
62 bool enable; /**< Start counting when init completed. */
\r
63 bool debugRun; /**< Counter shall keep running during debug halt. */
\r
64 bool comp0Top; /**< Use compare register 0 as max count value. */
\r
67 /** Suggested default config for RTC init structure. */
\r
68 #define RTC_INIT_DEFAULT \
\r
70 true, /* Start counting when init done */ \
\r
71 false, /* Disable updating during debug halt */ \
\r
72 true /* Restart counting from 0 when reaching COMP0 */ \
\r
76 /*******************************************************************************
\r
77 ***************************** PROTOTYPES **********************************
\r
78 ******************************************************************************/
\r
80 uint32_t RTC_CompareGet(unsigned int comp);
\r
81 void RTC_CompareSet(unsigned int comp, uint32_t value);
\r
83 /***************************************************************************//**
\r
85 * Get RTC counter value.
\r
88 * Current RTC counter value.
\r
89 ******************************************************************************/
\r
90 __STATIC_INLINE uint32_t RTC_CounterGet(void)
\r
95 void RTC_CounterReset(void);
\r
96 void RTC_Enable(bool enable);
\r
97 void RTC_FreezeEnable(bool enable);
\r
98 void RTC_Init(const RTC_Init_TypeDef *init);
\r
100 /***************************************************************************//**
\r
102 * Clear one or more pending RTC interrupts.
\r
105 * RTC interrupt sources to clear. Use a set of interrupt flags OR-ed
\r
106 * together to clear multiple interrupt sources for the RTC module
\r
108 ******************************************************************************/
\r
109 __STATIC_INLINE void RTC_IntClear(uint32_t flags)
\r
115 /***************************************************************************//**
\r
117 * Disable one or more RTC interrupts.
\r
120 * RTC interrupt sources to disable. Use a set of interrupt flags OR-ed
\r
121 * together to disable multiple interrupt sources for the RTC module
\r
123 ******************************************************************************/
\r
124 __STATIC_INLINE void RTC_IntDisable(uint32_t flags)
\r
126 RTC->IEN &= ~flags;
\r
130 /***************************************************************************//**
\r
132 * Enable one or more RTC interrupts.
\r
135 * Depending on the use, a pending interrupt may already be set prior to
\r
136 * enabling the interrupt. Consider using RTC_IntClear() prior to enabling
\r
137 * if such a pending interrupt should be ignored.
\r
140 * RTC interrupt sources to enable. Use a set of interrupt flags OR-ed
\r
141 * together to set multiple interrupt sources for the RTC module
\r
143 ******************************************************************************/
\r
144 __STATIC_INLINE void RTC_IntEnable(uint32_t flags)
\r
150 /***************************************************************************//**
\r
152 * Get pending RTC interrupt flags.
\r
155 * The event bits are not cleared by the use of this function.
\r
158 * Pending RTC interrupt sources. Returns a set of interrupt flags OR-ed
\r
159 * together for multiple interrupt sources in the RTC module (RTC_IFS_nnn).
\r
160 ******************************************************************************/
\r
161 __STATIC_INLINE uint32_t RTC_IntGet(void)
\r
167 /***************************************************************************//**
\r
169 * Get enabled and pending RTC interrupt flags.
\r
170 * Useful for handling more interrupt sources in the same interrupt handler.
\r
173 * Interrupt flags are not cleared by the use of this function.
\r
176 * Pending and enabled RTC interrupt sources
\r
177 * The return value is the bitwise AND of
\r
178 * - the enabled interrupt sources in RTC_IEN and
\r
179 * - the pending interrupt flags RTC_IF
\r
180 ******************************************************************************/
\r
181 __STATIC_INLINE uint32_t RTC_IntGetEnabled(void)
\r
186 return RTC->IF & ien;
\r
190 /***************************************************************************//**
\r
192 * Set one or more pending RTC interrupts from SW.
\r
195 * RTC interrupt sources to set to pending. Use a set of interrupt flags
\r
196 * OR-ed together to set multiple interrupt sources for the RTC module
\r
198 ******************************************************************************/
\r
199 __STATIC_INLINE void RTC_IntSet(uint32_t flags)
\r
204 void RTC_Reset(void);
\r
206 /** @} (end addtogroup RTC) */
\r
207 /** @} (end addtogroup EM_Library) */
\r
213 #endif /* defined(RTC_COUNT) && (RTC_COUNT > 0) */
\r
214 #endif /* __SILICON_LABS_EM_RTC_H__ */
\r