G32R430 Device Driver Layer v1.0.4
G32R4xx Device Driver Layer API Reference
g32r4xx_ddl_rtc.c
Go to the documentation of this file.
1
43#if defined(USE_FULL_DDL_DRIVER)
44
45/* Includes ------------------------------------------------------------------*/
46#include "g32r4xx_ddl_rtc.h"
47#include "g32r4xx_ddl_rcm.h"
48#ifdef USE_FULL_ASSERT
49 #include "g32_assert.h"
50#else
51 #define ASSERT_PARAM(_PARAM_) ((void)0U)
52#endif
53
57
58#if defined(RTC)
59
63
64/* Private types -------------------------------------------------------------*/
65/* Private variables ---------------------------------------------------------*/
66/* Private constants ---------------------------------------------------------*/
70/* Default values used for prescaler */
71#define RTC_PRESC_DEFAULT 0x000000FFU
72
73/* Values used for timeout */
74#define RTC_INITMODE_TIMEOUT 1000U
75#define RTC_SYNCHRO_TIMEOUT 1000U
79
80/* Private macros ------------------------------------------------------------*/
84#define IS_DDL_RTC_PREDIV(__VALUE__) ((__VALUE__) <= 0xFFFFFU)
85
89/* Private function prototypes -----------------------------------------------*/
90/* Exported functions --------------------------------------------------------*/
94
98
108ErrorStatus DDL_RTC_DeInit(RTC_TypeDef* RTCx)
109{
110 ErrorStatus status = ERROR;
111
112 /* Check the parameter */
113 ASSERT_PARAM(IS_RTC_ALL_INSTANCE(RTCx));
114
115 /* Set Initialization mode */
116 if (DDL_RTC_EnterInitMode(RTCx) != ERROR)
117 {
118 /* Reset CNT and CTRL registers */
119 DDL_RTC_WriteReg(RTCx, CTRL, 0x00000000U);
120 DDL_RTC_WriteReg(RTCx, CSTS, 0x00000010U);
121
122 DDL_RTC_WriteReg(RTCx, PSCRLDH, 0x00000000U);
123 DDL_RTC_WriteReg(RTCx, PSCRLDL, (RTC_PSCRLD_PSCRLDL & 0x8000U));
124
125 DDL_RTC_WriteReg(RTCx, CNTH, 0x00000000U);
126 DDL_RTC_WriteReg(RTCx, CNTL, 0x00000000U);
127
128 DDL_RTC_WriteReg(RTCx, ALRH, (RTC_ALRH_ALRH & 0xFFFFU));
129 DDL_RTC_WriteReg(RTCx, ALRL, (RTC_ALRL_ALRL & 0xFFFFU));
130
131 /* Exit Initialization mode */
133
134 /* Wait till the RTC OCF flag is set */
136 }
137
138 return status;
139}
140
153ErrorStatus DDL_RTC_Init(RTC_TypeDef* RTCx, DDL_RTC_InitTypeDef* RTC_InitStruct)
154{
155 ErrorStatus status = ERROR;
156
157 /* Check the parameters */
158 ASSERT_PARAM(IS_RTC_ALL_INSTANCE(RTCx));
159 ASSERT_PARAM(IS_DDL_RTC_PREDIV(RTC_InitStruct->Prescaler));
160
161 /* Set Initialization mode */
162 if (DDL_RTC_EnterInitMode(RTCx) != ERROR)
163 {
164 /* Configure prescaler factor */
165 DDL_RTC_SetPrescaler(RTCx, RTC_InitStruct->Prescaler);
166
167 /* Exit Initialization mode */
169
170 /* Wait till the RTC OCF flag is set */
172
173 status = SUCCESS;
174 }
175
176 return status;
177}
178
185{
186 /* Set RTC_InitStruct fields to default values */
187 RTC_InitStruct->Prescaler = RTC_PRESC_DEFAULT;
188}
189
199ErrorStatus DDL_RTC_TIME_Init(RTC_TypeDef* RTCx, DDL_RTC_TimeTypeDef* RTC_TimeStruct)
200{
201 ErrorStatus status = ERROR;
202
203 /* Check the parameters */
204 ASSERT_PARAM(IS_RTC_ALL_INSTANCE(RTCx));
205
206 /* Enter Initialization mode */
207 if (DDL_RTC_EnterInitMode(RTCx) != ERROR)
208 {
209 DDL_RTC_SetTime(RTCx, RTC_TimeStruct->TimerCounter);
210
211 /* Exit Initialization mode */
213
214 /* Wait till the RTC OCF flag is set */
216
217 status = SUCCESS;
218 }
219
220 return status;
221}
222
229{
230 /* Time = 0sec */
231 RTC_TimeStruct->TimerCounter = 0U;
232}
233
245ErrorStatus DDL_RTC_ALM_Init(RTC_TypeDef* RTCx, DDL_RTC_AlarmTypeDef* RTC_AlarmStruct)
246{
247 ErrorStatus status = ERROR;
248
249 /* Check the parameters */
250 ASSERT_PARAM(IS_RTC_ALL_INSTANCE(RTCx));
251
252 /* Set Initialization mode */
253 if (DDL_RTC_EnterInitMode(RTCx) != ERROR)
254 {
255 DDL_RTC_SetAlarm(RTCx, RTC_AlarmStruct->AlarmTime);
256
257 /* Exit Initialization mode */
259
260 /* Wait till the RTC OCF flag is set */
262
263 status = SUCCESS;
264 }
265
266 return status;
267}
268
275{
276 /* Alarm Time Settings : Time = 0sec */
277 RTC_AlarmStruct->AlarmTime = 0U;
278}
279
288ErrorStatus DDL_RTC_EnterInitMode(RTC_TypeDef* RTCx)
289{
290 __IO uint32_t timeout = RTC_INITMODE_TIMEOUT;
291 ErrorStatus status = SUCCESS;
292 uint32_t tmp = 0U;
293
294 /* Check the parameter */
295 ASSERT_PARAM(IS_RTC_ALL_INSTANCE(RTCx));
296
297 /* Check if the Initialization mode is set */
298 if (DDL_RTC_IsActiveFlag_CFGM(RTCx) == 0U)
299 {
300 /* Set the Initialization mode */
302
303 /* Wait till RTC is in INIT state and if Time out is reached exit */
304 tmp = DDL_RTC_IsActiveFlag_CFGM(RTCx);
305 while ((timeout != 0U) && (tmp != 1U))
306 {
307 timeout--;
308 tmp = DDL_RTC_IsActiveFlag_CFGM(RTCx);
309 if (timeout == 0U)
310 {
311 status = ERROR;
312 }
313 }
314 }
315 return status;
316}
317
329ErrorStatus DDL_RTC_ExitInitMode(RTC_TypeDef* RTCx)
330{
331 /* Check the parameter */
332 ASSERT_PARAM(IS_RTC_ALL_INSTANCE(RTCx));
333
334 /* Disable initialization mode */
336
337 return SUCCESS;
338}
339
351ErrorStatus DDL_RTC_WaitForSynchro(RTC_TypeDef* RTCx)
352{
353 __IO uint32_t timeout = RTC_SYNCHRO_TIMEOUT;
354 ErrorStatus status = SUCCESS;
355 uint32_t tmp = 0U;
356
357 /* Check the parameter */
358 ASSERT_PARAM(IS_RTC_ALL_INSTANCE(RTCx));
359
360 /* Clear RSF flag */
362
363 /* Wait the registers to be synchronised */
364 tmp = DDL_RTC_IsActiveFlag_RS(RTCx);
365 while ((timeout != 0U) && (tmp != 1U))
366 {
367 timeout--;
368 tmp = DDL_RTC_IsActiveFlag_RS(RTCx);
369 if (timeout == 0U)
370 {
371 status = ERROR;
372 }
373 }
374
375 return (status);
376}
377
388ErrorStatus DDL_RTC_WaitForOperationComplete(RTC_TypeDef* RTCx)
389{
390 __IO uint32_t timeout = RTC_INITMODE_TIMEOUT;
391 ErrorStatus status = SUCCESS;
392 uint32_t tmp = 0U;
393
394 /* Check the parameter */
395 ASSERT_PARAM(IS_RTC_ALL_INSTANCE(RTCx));
396
397 /* Clear RSF flag */
399
400 /* Wait for the operation to be completed */
401 tmp = DDL_RTC_IsActiveFlag_OCFLG(RTCx);
402 while ((timeout != 0U) && (tmp != 1U))
403 {
404 timeout--;
405 tmp = DDL_RTC_IsActiveFlag_OCFLG(RTCx);
406 if (timeout == 0U)
407 {
408 status = ERROR;
409 }
410 }
411
412 return (status);
413}
414
415
419
423
427
428#endif /* defined(RTC) */
429
433
434#endif /* USE_FULL_DDL_DRIVER */
G32 assert template file. This file should be copied to the application folder and renamed to g32_ass...
#define ASSERT_PARAM(_PARAM_)
Definition g32_assert.h:58
Header file of RCM DDL module.
Header file of RTC DDL module.
__STATIC_INLINE void DDL_RTC_SetAlarm(RTC_TypeDef *RTCx, uint32_t Time)
Set ALARM time in Binary format.
__STATIC_INLINE void DDL_RTC_DisableInitMode(RTC_TypeDef *RTCx)
Disable initialization mode (Free running mode).
__STATIC_INLINE void DDL_RTC_EnableInitMode(RTC_TypeDef *RTCx)
Enable initialization mode.
__STATIC_INLINE void DDL_RTC_SetPrescaler(RTC_TypeDef *RTCx, uint32_t Prescaler)
Set prescaler factor.
__STATIC_INLINE void DDL_RTC_ClearFlag_RS(RTC_TypeDef *RTCx)
Clear Registers synchronization flag.
__STATIC_INLINE uint32_t DDL_RTC_IsActiveFlag_RS(RTC_TypeDef *RTCx)
Get Registers synchronization flag.
__STATIC_INLINE uint32_t DDL_RTC_IsActiveFlag_OCFLG(RTC_TypeDef *RTCx)
Get Alarm A write flag.
__STATIC_INLINE uint32_t DDL_RTC_IsActiveFlag_CFGM(RTC_TypeDef *RTCx)
Get Initialization status flag.
ErrorStatus DDL_RTC_DeInit(RTC_TypeDef *RTCx)
De-Initializes the RTC registers to their default reset values.
void DDL_RTC_ALM_StructInit(DDL_RTC_AlarmTypeDef *RTC_AlarmStruct)
Set each DDL_RTC_AlarmTypeDef of ALARM field to default value (Time = 00h:00mn:00sec).
ErrorStatus DDL_RTC_WaitForOperationComplete(RTC_TypeDef *RTCx)
Waits until the RTC operation is completed.
ErrorStatus DDL_RTC_Init(RTC_TypeDef *RTCx, DDL_RTC_InitTypeDef *RTC_InitStruct)
Initializes the RTC registers according to the specified parameters in RTC_InitStruct.
ErrorStatus DDL_RTC_TIME_Init(RTC_TypeDef *RTCx, DDL_RTC_TimeTypeDef *RTC_TimeStruct)
Set the RTC current time.
ErrorStatus DDL_RTC_EnterInitMode(RTC_TypeDef *RTCx)
Enters the RTC Initialization mode.
ErrorStatus DDL_RTC_ALM_Init(RTC_TypeDef *RTCx, DDL_RTC_AlarmTypeDef *RTC_AlarmStruct)
Set the RTC Alarm.
void DDL_RTC_StructInit(DDL_RTC_InitTypeDef *RTC_InitStruct)
Set each DDL_RTC_InitTypeDef field to default value.
void DDL_RTC_TIME_StructInit(DDL_RTC_TimeTypeDef *RTC_TimeStruct)
Set each DDL_RTC_TimeTypeDef field to default value (Time = 0sec).
ErrorStatus DDL_RTC_ExitInitMode(RTC_TypeDef *RTCx)
Exit the RTC Initialization mode.
ErrorStatus DDL_RTC_WaitForSynchro(RTC_TypeDef *RTCx)
Waits until the RTC registers (RTC_CNT, RTC_ALR, RTC_PSCRLD) are synchronized with RTC APB clock.
__STATIC_INLINE void DDL_RTC_SetTime(RTC_TypeDef *RTCx, uint32_t TimerCounter)
Set time in Binary format.
#define DDL_RTC_WriteReg(__INSTANCE__, __REG__, __VALUE__)
Write a value in RTC register.
#define RTC_INITMODE_TIMEOUT
#define RTC_PRESC_DEFAULT
#define RTC_SYNCHRO_TIMEOUT
#define IS_DDL_RTC_PREDIV(__VALUE__)
RTC Alarm structure definition.
RTC Init structures definition.
RTC Time structure definition.