1 /***************************************************************************//**
\r
3 * @brief Real Time Counter with Calendar (RTCC) 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 #include "em_rtcc.h"
\r
34 #if defined( RTCC_COUNT ) && ( RTCC_COUNT == 1 )
\r
37 /***************************************************************************//**
\r
38 * @addtogroup EM_Library
\r
40 ******************************************************************************/
\r
42 /***************************************************************************//**
\r
44 * @brief Real Time Counter (RTCC) Peripheral API
\r
46 ******************************************************************************/
\r
48 /*******************************************************************************
\r
49 ******************************* DEFINES ***********************************
\r
50 ******************************************************************************/
\r
52 /*******************************************************************************
\r
53 ************************** LOCAL FUNCTIONS ********************************
\r
54 ******************************************************************************/
\r
56 /*******************************************************************************
\r
57 ************************** GLOBAL FUNCTIONS *******************************
\r
58 ******************************************************************************/
\r
60 /***************************************************************************//**
\r
62 * Configure the selected capture/compare channel of the RTCC.
\r
65 * Use this function to configure a RTCC channel.
\r
66 * Select capture/compare mode, match output action, overflow output action
\r
67 * and PRS input configuration.
\r
68 * Refer to the configuration structure @ref RTCC_CCChConf_TypeDef for more
\r
74 * @param[in] confPtr
\r
75 * Pointer to configuration structure.
\r
76 ******************************************************************************/
\r
77 void RTCC_ChannelInit( int ch, RTCC_CCChConf_TypeDef const *confPtr )
\r
79 EFM_ASSERT( RTCC_CH_VALID( ch ) );
\r
80 EFM_ASSERT( (uint32_t)confPtr->compMask
\r
81 < ( _RTCC_CC_CTRL_COMPMASK_MASK >> _RTCC_CC_CTRL_COMPMASK_SHIFT )
\r
84 /** Configure the selected capture/compare channel. */
\r
85 RTCC->CC[ch].CTRL = ( (uint32_t)confPtr->chMode << _RTCC_CC_CTRL_MODE_SHIFT )
\r
86 | ( (uint32_t)confPtr->compMatchOutAction << _RTCC_CC_CTRL_CMOA_SHIFT )
\r
87 | ( (uint32_t)confPtr->prsSel << _RTCC_CC_CTRL_PRSSEL_SHIFT )
\r
88 | ( (uint32_t)confPtr->inputEdgeSel << _RTCC_CC_CTRL_ICEDGE_SHIFT )
\r
89 | ( (uint32_t)confPtr->compBase << _RTCC_CC_CTRL_COMPBASE_SHIFT )
\r
90 | ( (uint32_t)confPtr->compMask << _RTCC_CC_CTRL_COMPMASK_SHIFT )
\r
91 | ( (uint32_t)confPtr->dayCompMode << _RTCC_CC_CTRL_DAYCC_SHIFT );
\r
94 /***************************************************************************//**
\r
96 * Enable/disable RTCC.
\r
99 * True to enable RTCC, false to disable.
\r
100 ******************************************************************************/
\r
101 void RTCC_Enable( bool enable )
\r
103 /* Bitbanding the enable bit in the CTRL register (atomic). */
\r
104 BUS_RegBitWrite((&RTCC->CTRL), _RTCC_CTRL_ENABLE_SHIFT, enable);
\r
107 /***************************************************************************//**
\r
112 * Note that the compare values must be set separately with RTCC_CompareSet().
\r
113 * That should probably be done prior to the use of this function if
\r
114 * configuring the RTCC to start when initialization is completed.
\r
117 * Pointer to RTCC initialization structure.
\r
118 ******************************************************************************/
\r
119 void RTCC_Init( const RTCC_Init_TypeDef *init )
\r
121 RTCC->CTRL = ( (uint32_t)init->enable << _RTCC_CTRL_ENABLE_SHIFT )
\r
122 | ( (uint32_t)init->debugRun << _RTCC_CTRL_DEBUGRUN_SHIFT )
\r
123 | ( (uint32_t)init->precntWrapOnCCV0 << _RTCC_CTRL_PRECCV0TOP_SHIFT )
\r
124 | ( (uint32_t)init->cntWrapOnCCV1 << _RTCC_CTRL_CCV1TOP_SHIFT )
\r
125 | ( (uint32_t)init->presc << _RTCC_CTRL_CNTPRESC_SHIFT )
\r
126 | ( (uint32_t)init->prescMode << _RTCC_CTRL_CNTTICK_SHIFT )
\r
127 #if defined(_RTCC_CTRL_BUMODETSEN_MASK)
\r
128 | ( (uint32_t)init->enaBackupModeSet << _RTCC_CTRL_BUMODETSEN_SHIFT )
\r
130 | ( (uint32_t)init->enaOSCFailDetect << _RTCC_CTRL_OSCFDETEN_SHIFT )
\r
131 | ( (uint32_t)init->cntMode << _RTCC_CTRL_CNTMODE_SHIFT )
\r
132 | ( (uint32_t)init->disLeapYearCorr << _RTCC_CTRL_LYEARCORRDIS_SHIFT );
\r
135 /***************************************************************************//**
\r
137 * Restore RTCC to its reset state.
\r
138 ******************************************************************************/
\r
139 void RTCC_Reset( void )
\r
143 /* Restore all RTCC registers to their default values. */
\r
145 RTCC->CTRL = _RTCC_CTRL_RESETVALUE;
\r
146 RTCC->PRECNT = _RTCC_PRECNT_RESETVALUE;
\r
147 RTCC->CNT = _RTCC_CNT_RESETVALUE;
\r
148 RTCC->TIME = _RTCC_TIME_RESETVALUE;
\r
149 RTCC->DATE = _RTCC_DATE_RESETVALUE;
\r
150 RTCC->IEN = _RTCC_IEN_RESETVALUE;
\r
151 RTCC->IFC = _RTCC_IFC_MASK;
\r
152 RTCC_StatusClear();
\r
153 RTCC->EM4WUEN = _RTCC_EM4WUEN_RESETVALUE;
\r
155 for (i = 0; i < 3; i++)
\r
157 RTCC->CC[i].CTRL = _RTCC_CC_CTRL_RESETVALUE;
\r
158 RTCC->CC[i].CCV = _RTCC_CC_CCV_RESETVALUE;
\r
159 RTCC->CC[i].TIME = _RTCC_CC_TIME_RESETVALUE;
\r
160 RTCC->CC[i].DATE = _RTCC_CC_DATE_RESETVALUE;
\r
164 /***************************************************************************//**
\r
166 * Clear STATUS register.
\r
167 ******************************************************************************/
\r
168 void RTCC_StatusClear( void )
\r
170 while ( RTCC->SYNCBUSY & RTCC_SYNCBUSY_CMD )
\r
172 // Wait for syncronization.
\r
174 RTCC->CMD = RTCC_CMD_CLRSTATUS;
\r
177 /** @} (end addtogroup RTCC) */
\r
178 /** @} (end addtogroup EM_Library) */
\r
180 #endif /* defined( RTCC_COUNT ) && ( RTCC_COUNT == 1 ) */
\r