A31L12x F/W Packages  1.4.0
ABOV Cortex-M0+ Core based MCUs Integrated Driver
A31L12x_hal_rtcc.c
Go to the documentation of this file.
1 /***************************************************************************//****************************************************************************/
34 
35 /* Includes ----------------------------------------------------------------- */
36 //******************************************************************************
37 // Include
38 //******************************************************************************
39 
40 #include "A31L12x_hal_rtcc.h"
41 #include "A31L12x_hal_scu.h"
42 
43 /* Public Functions --------------------------------------------------------- */
44 //******************************************************************************
45 // Function
46 //******************************************************************************
47 
48 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
54 HAL_Status_Type HAL_RTCC_Init( void* RTCC_Config )
55 {
56  RTCC_CFG_Type* pRtccCfg;
57  uint32_t reg_val32;
58 
59  /* Check RTCC_Config */
60  if( RTCC_Config == NULL )
61  {
62  return HAL_ERROR;
63  }
64 
65  // enable peripheral clock: RTCC.
66  HAL_SCU_Peripheral_EnableClock2( PPCLKEN2_RTCCLKE, PPxCLKE_Enable );
67 
68  pRtccCfg = ( RTCC_CFG_Type* )RTCC_Config;
69 
70  reg_val32 = 0
71  | RTCC_CR_RTIN_SET( pRtccCfg->rtccIntIn )
72  | RTCC_CR_HS24_SET( pRtccCfg->rtccHS24 )
73  | RTCC_CR_OUTSEL_SET( pRtccCfg->rtccOutsel )
74  ;
75 
76  RTCC->CR = reg_val32;
77 
78  return HAL_OK;
79 }
80 
81 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
85 void HAL_RTCC_DeInit( void )
86 {
87  HAL_SCU_Peripheral_SetReset2( 1 << SCUCG_PPRST2_RTCRST_Pos );
88  HAL_SCU_Peripheral_EnableClock2( PPCLKEN2_RTCCLKE, PPxCLKE_Disable );
89 }
90 
91 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
99 
100 void HAL_RTCC_SetRegister( uint32_t u32rtccSet )
101 {
102  RTCC->CR = u32rtccSet; // Setting RTCC Control Register
103 }
104 
105 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
113 {
114  if( NewState == ENABLE )
115  {
116  RTCC->CR |= RTCC_RTEN;
117  }
118  else
119  {
120  RTCC->CR &= ~RTCC_RTEN;
121  }
122 }
123 
124 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
130 void HAL_RTCC_RewriteYEAR( uint32_t u32rtccReWt )
131 {
132  RTCC->CR |= ( 1 << RTCC_CR_RTWAIT_Pos ); // Stop RTSEC to RTYEAR counters for read/write counter value.
133  while( ( RTCC->CR & ( 1 << RTCC_CR_RTWST_Pos ) ) == 0 ) {} // wait until RTWST = 1
134  RTCC->YEAR = u32rtccReWt; // Write to RTCC->YEAR register
135  RTCC->CR &= ~RTCC_CR_RTWAIT_Msk; // Set counter Operation
136  while( ( RTCC->CR & ( 1 << RTCC_CR_RTWST_Pos ) ) == 1 ) {} // wait until RTWST = 0
137 }
138 
139 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
145 void HAL_RTCC_RewriteMONTH( uint32_t u32rtccReWt )
146 {
147  RTCC->CR |= ( 1 << RTCC_CR_RTWAIT_Pos ); // Stop RTSEC to RTYEAR counters for read/write counter value.
148  while( ( RTCC->CR & ( 1 << RTCC_CR_RTWST_Pos ) ) == 0 ) {} // wait until RTWST = 1
149  RTCC->MONTH = u32rtccReWt; // Write to RTCC->MONTH register
150  RTCC->CR &= ~RTCC_CR_RTWAIT_Msk; // Set counter Operation
151  while( ( RTCC->CR & ( 1 << RTCC_CR_RTWST_Pos ) ) == 1 ) {} // wait until RTWST = 0
152 }
153 
154 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
160 void HAL_RTCC_RewriteWEEK( uint32_t u32rtccReWt )
161 {
162  RTCC->CR |= ( 1 << RTCC_CR_RTWAIT_Pos ); // Stop RTSEC to RTYEAR counters for read/write counter value.
163  while( ( RTCC->CR & ( 1 << RTCC_CR_RTWST_Pos ) ) == 0 ) {} // wait until RTWST = 1
164  RTCC->WEEK = u32rtccReWt; // Write to RTCC->WEEK register
165  RTCC->CR &= ~RTCC_CR_RTWAIT_Msk; // Set counter Operation
166  while( ( RTCC->CR & ( 1 << RTCC_CR_RTWST_Pos ) ) == 1 ) {} // wait until RTWST = 0
167 }
168 
169 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
175 void HAL_RTCC_RewriteDAY( uint32_t u32rtccReWt )
176 {
177  RTCC->CR |= ( 1 << RTCC_CR_RTWAIT_Pos ); // Stop RTSEC to RTYEAR counters for read/write counter value.
178  while( ( RTCC->CR & ( 1 << RTCC_CR_RTWST_Pos ) ) == 0 ) {} // wait until RTWST = 1
179  RTCC->DAY = u32rtccReWt; // Write to RTCC->DAY register
180  RTCC->CR &= ~RTCC_CR_RTWAIT_Msk; // Set counter Operation
181  while( ( RTCC->CR & ( 1 << RTCC_CR_RTWST_Pos ) ) == 1 ) {} // wait until RTWST = 0
182 }
183 
184 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
190 void HAL_RTCC_RewriteHOUR( uint32_t u32rtccReWt )
191 {
192  RTCC->CR |= ( 1 << RTCC_CR_RTWAIT_Pos ); // Stop RTSEC to RTYEAR counters for read/write counter value.
193  while( ( RTCC->CR & ( 1 << RTCC_CR_RTWST_Pos ) ) == 0 ) {} // wait until RTWST = 1
194  RTCC->HOUR = u32rtccReWt; // Write to RTCC->HOUR register
195  RTCC->CR &= ~RTCC_CR_RTWAIT_Msk; // Set counter Operation
196  while( ( RTCC->CR & ( 1 << RTCC_CR_RTWST_Pos ) ) == 1 ) {} // wait until RTWST = 0
197 }
198 
199 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
205 void HAL_RTCC_RewriteMIN( uint32_t u32rtccReWt )
206 {
207  RTCC->CR |= ( 1 << RTCC_CR_RTWAIT_Pos ); // Stop RTSEC to RTYEAR counters for read/write counter value.
208  while( ( RTCC->CR & ( 1 << RTCC_CR_RTWST_Pos ) ) == 0 ) {} // wait until RTWST = 1
209  RTCC->MIN = u32rtccReWt; // Write to RTCC->MIN register
210  RTCC->CR &= ~RTCC_CR_RTWAIT_Msk; // Set counter Operation
211  while( ( RTCC->CR & ( 1 << RTCC_CR_RTWST_Pos ) ) == 1 ) {} // wait until RTWST = 0
212 }
213 
214 /*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------*/
220 void HAL_RTCC_RewriteSEC( uint32_t u32rtccReWt )
221 {
222  RTCC->CR |= ( 1 << RTCC_CR_RTWAIT_Pos ); // Stop RTSEC to RTYEAR counters for read/write counter value.
223  while( ( RTCC->CR & ( 1 << RTCC_CR_RTWST_Pos ) ) == 0 ) {} // wait until RTWST = 1
224  RTCC->SEC = u32rtccReWt; // Write to RTCC->SEC register
225  RTCC->CR &= ~RTCC_CR_RTWAIT_Msk; // Set counter Operation
226  while( ( RTCC->CR & ( 1 << RTCC_CR_RTWST_Pos ) ) == 1 ) {} // wait until RTWST = 0
227 }
228 
void HAL_RTCC_RewriteYEAR(uint32_t u32rtccReWt)
Rewrite to RTCC YEAR Register.
void HAL_RTCC_RewriteSEC(uint32_t u32rtccReWt)
Rewrite to RTCC SEC Register.
void HAL_SCU_Peripheral_EnableClock2(uint32_t u32PeriClk2, uint32_t u32Ind)
Set Each Peripheral Clock.
void HAL_RTCC_DeInit(void)
Close RTCC.
HAL_Status_Type
void HAL_RTCC_RewriteHOUR(uint32_t u32rtccReWt)
Rewrite to RTCC HOUR Register.
void HAL_RTCC_RewriteMONTH(uint32_t u32rtccReWt)
Rewrite to RTCC MONTH Register.
void HAL_RTCC_RewriteWEEK(uint32_t u32rtccReWt)
Rewrite to RTCC WEEK Register.
Contains all macro definitions and function prototypes support for rtcc firmware library on A31L12x.
FunctionalState
void HAL_RTCC_SetRegister(uint32_t u32rtccSet)
Set RTC_CR Registers.
void HAL_RTCC_RewriteDAY(uint32_t u32rtccReWt)
Rewrite to RTCC DAY Register.
HAL_Status_Type HAL_RTCC_Init(void *RTCC_Config)
Initialize the RTCC peripheral with the specified parameters.
void HAL_SCU_Peripheral_SetReset2(uint32_t u32EachPeri2)
Set/Reset Each Peripheral Block Reset of PPRST2 Register.
Contains all macro definitions and function prototypes support for scu firmware library on A31L12x.
void HAL_RTCC_Cmd(FunctionalState NewState)
Enable/Disable RTCC Operation.
void HAL_RTCC_RewriteMIN(uint32_t u32rtccReWt)
Rewrite to RTCC MIN Register.