1 /***************************************************************************//**
\r
3 * @brief Real Time Counter (RTC) peripheral API
\r
5 *******************************************************************************
\r
7 * <b>(C) Copyright 2014 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
34 #ifndef __SILICON_LABS_EM_RTC_H_
\r
35 #define __SILICON_LABS_EM_RTC_H_
\r
37 #include "em_device.h"
\r
38 #if defined(RTC_COUNT) && (RTC_COUNT > 0)
\r
40 #include <stdbool.h>
\r
46 /***************************************************************************//**
\r
47 * @addtogroup EM_Library
\r
49 ******************************************************************************/
\r
51 /***************************************************************************//**
\r
54 ******************************************************************************/
\r
56 /*******************************************************************************
\r
57 ******************************* STRUCTS ***********************************
\r
58 ******************************************************************************/
\r
60 /** RTC initialization structure. */
\r
63 bool enable; /**< Start counting when init completed. */
\r
64 bool debugRun; /**< Counter shall keep running during debug halt. */
\r
65 bool comp0Top; /**< Use compare register 0 as max count value. */
\r
68 /** Suggested default config for RTC init structure. */
\r
69 #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 * Set one or more pending RTC interrupts from SW.
\r
172 * RTC interrupt sources to set to pending. Use a set of interrupt flags
\r
173 * OR-ed together to set multiple interrupt sources for the RTC module
\r
175 ******************************************************************************/
\r
176 __STATIC_INLINE void RTC_IntSet(uint32_t flags)
\r
181 void RTC_Reset(void);
\r
183 /** @} (end addtogroup RTC) */
\r
184 /** @} (end addtogroup EM_Library) */
\r
190 #endif /* defined(RTC_COUNT) && (RTC_COUNT > 0) */
\r
191 #endif /* __SILICON_LABS_EM_RTC_H_ */
\r