EFM32 Wonder Gecko Software Documentation  efm32wg-doc-5.1.2
em_rtcc.c
Go to the documentation of this file.
1 /***************************************************************************/
33 #include "em_rtcc.h"
34 #if defined( RTCC_COUNT ) && ( RTCC_COUNT == 1 )
35 #include "em_bus.h"
36 
37 /***************************************************************************/
42 /***************************************************************************/
52 /*******************************************************************************
53  ******************************* DEFINES ***********************************
54  ******************************************************************************/
55 
56 /*******************************************************************************
57  ************************** LOCAL FUNCTIONS ********************************
58  ******************************************************************************/
59 
60 /*******************************************************************************
61  ************************** GLOBAL FUNCTIONS *******************************
62  ******************************************************************************/
63 
64 /***************************************************************************/
81 void RTCC_ChannelInit( int ch, RTCC_CCChConf_TypeDef const *confPtr )
82 {
83  EFM_ASSERT( RTCC_CH_VALID( ch ) );
84  EFM_ASSERT( (uint32_t)confPtr->compMask
85  < ( _RTCC_CC_CTRL_COMPMASK_MASK >> _RTCC_CC_CTRL_COMPMASK_SHIFT )
86  + 1 );
87 
89  RTCC->CC[ch].CTRL = ( (uint32_t)confPtr->chMode << _RTCC_CC_CTRL_MODE_SHIFT )
90  | ( (uint32_t)confPtr->compMatchOutAction << _RTCC_CC_CTRL_CMOA_SHIFT )
91  | ( (uint32_t)confPtr->prsSel << _RTCC_CC_CTRL_PRSSEL_SHIFT )
92  | ( (uint32_t)confPtr->inputEdgeSel << _RTCC_CC_CTRL_ICEDGE_SHIFT )
93  | ( (uint32_t)confPtr->compBase << _RTCC_CC_CTRL_COMPBASE_SHIFT )
94  | ( (uint32_t)confPtr->compMask << _RTCC_CC_CTRL_COMPMASK_SHIFT )
95  | ( (uint32_t)confPtr->dayCompMode << _RTCC_CC_CTRL_DAYCC_SHIFT );
96 }
97 
98 /***************************************************************************/
105 void RTCC_Enable( bool enable )
106 {
107  /* Bitbanding the enable bit in the CTRL register (atomic). */
108  BUS_RegBitWrite((&RTCC->CTRL), _RTCC_CTRL_ENABLE_SHIFT, enable);
109 }
110 
111 /***************************************************************************/
123 void RTCC_Init( const RTCC_Init_TypeDef *init )
124 {
125  RTCC->CTRL = ( (uint32_t)init->enable << _RTCC_CTRL_ENABLE_SHIFT )
126  | ( (uint32_t)init->debugRun << _RTCC_CTRL_DEBUGRUN_SHIFT )
127  | ( (uint32_t)init->precntWrapOnCCV0 << _RTCC_CTRL_PRECCV0TOP_SHIFT )
128  | ( (uint32_t)init->cntWrapOnCCV1 << _RTCC_CTRL_CCV1TOP_SHIFT )
129  | ( (uint32_t)init->presc << _RTCC_CTRL_CNTPRESC_SHIFT )
130  | ( (uint32_t)init->prescMode << _RTCC_CTRL_CNTTICK_SHIFT )
131 #if defined(_RTCC_CTRL_BUMODETSEN_MASK)
132  | ( (uint32_t)init->enaBackupModeSet << _RTCC_CTRL_BUMODETSEN_SHIFT )
133 #endif
134  | ( (uint32_t)init->enaOSCFailDetect << _RTCC_CTRL_OSCFDETEN_SHIFT )
135  | ( (uint32_t)init->cntMode << _RTCC_CTRL_CNTMODE_SHIFT )
136  | ( (uint32_t)init->disLeapYearCorr << _RTCC_CTRL_LYEARCORRDIS_SHIFT );
137 }
138 
139 /***************************************************************************/
143 void RTCC_Reset( void )
144 {
145  int i;
146 
147  /* Restore all RTCC registers to their default values. */
148  RTCC_Unlock();
149  RTCC->CTRL = _RTCC_CTRL_RESETVALUE;
150  RTCC->PRECNT = _RTCC_PRECNT_RESETVALUE;
151  RTCC->CNT = _RTCC_CNT_RESETVALUE;
152  RTCC->TIME = _RTCC_TIME_RESETVALUE;
153  RTCC->DATE = _RTCC_DATE_RESETVALUE;
154  RTCC->IEN = _RTCC_IEN_RESETVALUE;
155  RTCC->IFC = _RTCC_IFC_MASK;
156  RTCC_StatusClear();
157  RTCC->EM4WUEN = _RTCC_EM4WUEN_RESETVALUE;
158 
159  for (i = 0; i < 3; i++)
160  {
161  RTCC->CC[i].CTRL = _RTCC_CC_CTRL_RESETVALUE;
162  RTCC->CC[i].CCV = _RTCC_CC_CCV_RESETVALUE;
163  RTCC->CC[i].TIME = _RTCC_CC_TIME_RESETVALUE;
164  RTCC->CC[i].DATE = _RTCC_CC_DATE_RESETVALUE;
165  }
166 }
167 
168 /***************************************************************************/
172 void RTCC_StatusClear( void )
173 {
174  while ( RTCC->SYNCBUSY & RTCC_SYNCBUSY_CMD )
175  {
176  // Wait for syncronization.
177  }
178  RTCC->CMD = RTCC_CMD_CLRSTATUS;
179 }
180 
184 #endif /* defined( RTCC_COUNT ) && ( RTCC_COUNT == 1 ) */
RAM and peripheral bit-field set and clear API.
Real Time Counter (RTCC) peripheral API.
__STATIC_INLINE void BUS_RegBitWrite(volatile uint32_t *addr, unsigned int bit, unsigned int val)
Perform a single-bit write operation on a peripheral register.
Definition: em_bus.h:148