EFR32 Mighty Gecko 1 Software Documentation  efr32mg1-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
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;
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 ) */
#define _RTCC_CTRL_OSCFDETEN_SHIFT
#define _RTCC_CC_TIME_RESETVALUE
RTCC_CntMode_TypeDef cntMode
Definition: em_rtcc.h:219
void RTCC_StatusClear(void)
Clear STATUS register.
Definition: em_rtcc.c:172
RTCC_PrescMode_TypeDef prescMode
Definition: em_rtcc.h:206
void RTCC_Init(const RTCC_Init_TypeDef *init)
Initialize RTCC.
Definition: em_rtcc.c:123
RTCC_InEdgeSel_TypeDef inputEdgeSel
Definition: em_rtcc.h:241
#define _RTCC_CTRL_RESETVALUE
RAM and peripheral bit-field set and clear API.
#define _RTCC_PRECNT_RESETVALUE
void RTCC_Enable(bool enable)
Enable/disable RTCC.
Definition: em_rtcc.c:105
#define _RTCC_CTRL_ENABLE_SHIFT
#define _RTCC_DATE_RESETVALUE
#define _RTCC_CC_CTRL_COMPBASE_SHIFT
#define _RTCC_CTRL_PRECCV0TOP_SHIFT
#define _RTCC_CTRL_CNTPRESC_SHIFT
#define RTCC_CMD_CLRSTATUS
#define _RTCC_EM4WUEN_RESETVALUE
__STATIC_INLINE void RTCC_Unlock(void)
Unlock RTCC registers.
Definition: em_rtcc.h:721
#define _RTCC_CTRL_CNTMODE_SHIFT
RTCC_CompMatchOutAction_TypeDef compMatchOutAction
Definition: em_rtcc.h:235
#define _RTCC_CC_CCV_RESETVALUE
#define _RTCC_CC_CTRL_RESETVALUE
#define _RTCC_CC_CTRL_ICEDGE_SHIFT
bool precntWrapOnCCV0
Definition: em_rtcc.h:197
RTCC_CntPresc_TypeDef presc
Definition: em_rtcc.h:203
RTCC_DayCompareMode_TypeDef dayCompMode
Definition: em_rtcc.h:251
#define RTCC
#define _RTCC_IFC_MASK
bool enaOSCFailDetect
Definition: em_rtcc.h:216
void RTCC_ChannelInit(int ch, RTCC_CCChConf_TypeDef const *confPtr)
Configure the selected capture/compare channel of the RTCC.
Definition: em_rtcc.c:81
void RTCC_Reset(void)
Restore RTCC to its reset state.
Definition: em_rtcc.c:143
#define _RTCC_CTRL_CNTTICK_SHIFT
#define RTCC_SYNCBUSY_CMD
Real Time Counter (RTCC) peripheral API.
RTCC_PRSSel_TypeDef prsSel
Definition: em_rtcc.h:238
#define _RTCC_CTRL_LYEARCORRDIS_SHIFT
bool disLeapYearCorr
Definition: em_rtcc.h:224
#define _RTCC_CC_CTRL_DAYCC_SHIFT
#define _RTCC_IEN_RESETVALUE
#define _RTCC_CC_CTRL_COMPMASK_MASK
#define _RTCC_CC_DATE_RESETVALUE
#define _RTCC_CC_CTRL_PRSSEL_SHIFT
RTCC_CapComChMode_TypeDef chMode
Definition: em_rtcc.h:232
#define _RTCC_CC_CTRL_COMPMASK_SHIFT
bool cntWrapOnCCV1
Definition: em_rtcc.h:200
#define RTCC_CH_VALID(ch)
Definition: em_rtcc.h:314
#define _RTCC_CC_CTRL_MODE_SHIFT
#define _RTCC_CNT_RESETVALUE
#define _RTCC_CTRL_DEBUGRUN_SHIFT
__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
#define _RTCC_CTRL_CCV1TOP_SHIFT
#define _RTCC_TIME_RESETVALUE
RTCC_CompBase_TypeDef compBase
Definition: em_rtcc.h:244
#define _RTCC_CC_CTRL_CMOA_SHIFT