123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- /**
- *******************************************************************************
- * @file hc32_ll_rtc.h
- * @brief This file contains all the functions prototypes of the RTC driver
- * library.
- @verbatim
- Change Logs:
- Date Author Notes
- 2022-12-31 CDT First version
- @endverbatim
- *******************************************************************************
- * Copyright (C) 2022, Xiaohua Semiconductor Co., Ltd. All rights reserved.
- *
- * This software component is licensed by XHSC under BSD 3-Clause license
- * (the "License"); You may not use this file except in compliance with the
- * License. You may obtain a copy of the License at:
- * opensource.org/licenses/BSD-3-Clause
- *
- *******************************************************************************
- */
- #ifndef __HC32_LL_RTC_H__
- #define __HC32_LL_RTC_H__
- /* C binding of definitions if building with C++ compiler */
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- /*******************************************************************************
- * Include files
- ******************************************************************************/
- #include "hc32_ll_def.h"
- #include "hc32f4xx.h"
- #include "hc32f4xx_conf.h"
- /**
- * @addtogroup LL_Driver
- * @{
- */
- /**
- * @addtogroup LL_RTC
- * @{
- */
- #if (LL_RTC_ENABLE == DDL_ON)
- /*******************************************************************************
- * Global type definitions ('typedef')
- ******************************************************************************/
- /**
- * @defgroup RTC_Global_Types RTC Global Types
- * @{
- */
- /**
- * @brief RTC Init structure definition
- */
- typedef struct {
- uint8_t u8ClockSrc; /*!< Specifies the RTC clock source.
- This parameter can be a value of @ref RTC_Clock_Source */
- uint8_t u8HourFormat; /*!< Specifies the RTC hour format.
- This parameter can be a value of @ref RTC_Hour_Format */
- uint8_t u8IntPeriod; /*!< Specifies the RTC interrupt period.
- This parameter can be a value of @ref RTC_Interrupt_Period */
- uint8_t u8ClockCompen; /*!< Specifies the validity of RTC clock compensation.
- This parameter can be a value of @ref RTC_Clock_Compensation */
- uint8_t u8CompenMode; /*!< Specifies the mode of RTC clock compensation.
- This parameter can be a value of @ref RTC_Clock_Compensation_Mode */
- uint16_t u16CompenValue; /*!< Specifies the value of RTC clock compensation.
- This parameter can be a number between Min_Data = 0 and Max_Data = 0x1FF */
- } stc_rtc_init_t;
- /**
- * @brief RTC Date structure definition
- */
- typedef struct {
- uint8_t u8Year; /*!< Specifies the RTC Year.
- This parameter can be a number between Min_Data = 0 and Max_Data = 99 */
- uint8_t u8Month; /*!< Specifies the RTC Month (in Decimal format).
- This parameter can be a value of @ref RTC_Month */
- uint8_t u8Day; /*!< Specifies the RTC Day.
- This parameter can be a number between Min_Data = 1 and Max_Data = 31 */
- uint8_t u8Weekday; /*!< Specifies the RTC Weekday.
- This parameter can be a value of @ref RTC_Weekday */
- } stc_rtc_date_t;
- /**
- * @brief RTC Time structure definition
- */
- typedef struct {
- uint8_t u8Hour; /*!< Specifies the RTC Hour.
- This parameter can be a number between Min_Data = 1 and Max_Data = 12 if the RTC_HOUR_FMT_12H is selected.
- This parameter can be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HOUR_FMT_24H is selected */
- uint8_t u8Minute; /*!< Specifies the RTC Minute.
- This parameter can be a number between Min_Data = 0 and Max_Data = 59 */
- uint8_t u8Second; /*!< Specifies the RTC Second.
- This parameter can be a number between Min_Data = 0 and Max_Data = 59 */
- uint8_t u8AmPm; /*!< Specifies the RTC Am/Pm Time (in RTC_HOUR_FMT_12H mode).
- This parameter can be a value of @ref RTC_Hour12_AM_PM */
- } stc_rtc_time_t;
- /**
- * @brief RTC Alarm structure definition
- */
- typedef struct {
- uint8_t u8AlarmHour; /*!< Specifies the RTC Alarm Hour.
- This parameter can be a number between Min_Data = 1 and Max_Data = 12 if the RTC_HOUR_FMT_12H is selected.
- This parameter can be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HOUR_FMT_24H is selected */
- uint8_t u8AlarmMinute; /*!< Specifies the RTC Alarm Minute.
- This parameter can be a number between Min_Data = 0 and Max_Data = 59 */
- uint8_t u8AlarmWeekday; /*!< Specifies the RTC Alarm Weekday.
- This parameter can be a value of @ref RTC_Alarm_Weekday */
- uint8_t u8AlarmAmPm; /*!< Specifies the RTC Alarm Am/Pm Time (in RTC_HOUR_FMT_12H mode).
- This parameter can be a value of @ref RTC_Hour12_AM_PM */
- } stc_rtc_alarm_t;
- /**
- * @}
- */
- /*******************************************************************************
- * Global pre-processor symbols/macros ('#define')
- ******************************************************************************/
- /**
- * @defgroup RTC_Global_Macros RTC Global Macros
- * @{
- */
- /**
- * @defgroup RTC_Data_Format RTC Data Format
- * @{
- */
- #define RTC_DATA_FMT_DEC (0x00U) /*!< Decimal data format */
- #define RTC_DATA_FMT_BCD (0x01U) /*!< BCD data format */
- /**
- * @}
- */
- /**
- * @defgroup RTC_Decimal_BCD_Conversion RTC Decimal BCD Conversion
- * @{
- */
- #define RTC_DEC2BCD(__DATA__) ((((__DATA__) / 10U) << 4U) + ((__DATA__) % 10U))
- #define RTC_BCD2DEC(__DATA__) ((((__DATA__) >> 4U) * 10U) + ((__DATA__) & 0x0FU))
- /**
- * @}
- */
- /**
- * @defgroup RTC_Clock_Source RTC Clock Source
- * @{
- */
- #define RTC_CLK_SRC_XTAL32 (0U) /*!< XTAL32 Clock */
- #define RTC_CLK_SRC_LRC (RTC_CR3_RCKSEL | RTC_CR3_LRCEN) /*!< RTC LRC Clock */
- #define RTC_CLK_SRC_XTAL_DIV (RTC_CR3_RCKSEL | PWC_PWRC6_RTCCKSEL_0) /*!< XTAL division to 32768 */
- /**
- * @}
- */
- /**
- * @defgroup RTC_Hour_Format RTC Hour Format
- * @{
- */
- #define RTC_HOUR_FMT_12H (0U) /*!< 12 hour time system */
- #define RTC_HOUR_FMT_24H (RTC_CR1_AMPM) /*!< 24 hour time system */
- /**
- * @}
- */
- /**
- * @defgroup RTC_Interrupt_Period RTC Interrupt Period
- * @{
- */
- #define RTC_INT_PERIOD_INVD (0U) /*!< Interrupt period invalid */
- #define RTC_INT_PERIOD_PER_HALF_SEC (0x01U << RTC_CR1_PRDS_POS) /*!< Interrupt period per half second */
- #define RTC_INT_PERIOD_PER_SEC (0x02U << RTC_CR1_PRDS_POS) /*!< Interrupt period per second */
- #define RTC_INT_PERIOD_PER_MINUTE (0x03U << RTC_CR1_PRDS_POS) /*!< Interrupt period per minute */
- #define RTC_INT_PERIOD_PER_HOUR (0x04U << RTC_CR1_PRDS_POS) /*!< Interrupt period per hour */
- #define RTC_INT_PERIOD_PER_DAY (0x05U << RTC_CR1_PRDS_POS) /*!< Interrupt period per day */
- #define RTC_INT_PERIOD_PER_MONTH (0x06U << RTC_CR1_PRDS_POS) /*!< Interrupt period per month */
- /**
- * @}
- */
- /**
- * @defgroup RTC_Clock_Compensation RTC Clock Compensation
- * @{
- */
- #define RTC_CLK_COMPEN_DISABLE (0U)
- #define RTC_CLK_COMPEN_ENABLE (RTC_ERRCRH_COMPEN)
- /**
- * @}
- */
- /**
- * @defgroup RTC_Clock_Compensation_Mode RTC Clock Compensation Mode
- * @{
- */
- #define RTC_CLK_COMPEN_MD_DISTRIBUTED (0U) /*!< Distributed compensation 1Hz output */
- #define RTC_CLK_COMPEN_MD_UNIFORM (RTC_CR1_ONEHZSEL) /*!< Uniform compensation 1Hz output */
- /**
- * @}
- */
- /**
- * @defgroup RTC_Hour12_AM_PM RTC Hour12 AM/PM
- * @{
- */
- #define RTC_HOUR_24H (0U) /*!< 24-hour format */
- #define RTC_HOUR_12H_AM (0U) /*!< AM in 12-hour */
- #define RTC_HOUR_12H_PM (RTC_HOUR_HOURD_1) /*!< PM in 12-hour */
- /**
- * @}
- */
- /**
- * @defgroup RTC_Month RTC Month
- * @{
- */
- #define RTC_MONTH_JANUARY (0x01U)
- #define RTC_MONTH_FEBRUARY (0x02U)
- #define RTC_MONTH_MARCH (0x03U)
- #define RTC_MONTH_APRIL (0x04U)
- #define RTC_MONTH_MAY (0x05U)
- #define RTC_MONTH_JUNE (0x06U)
- #define RTC_MONTH_JULY (0x07U)
- #define RTC_MONTH_AUGUST (0x08U)
- #define RTC_MONTH_SEPTEMBER (0x09U)
- #define RTC_MONTH_OCTOBER (0x0AU)
- #define RTC_MONTH_NOVEMBER (0x0BU)
- #define RTC_MONTH_DECEMBER (0x0CU)
- /**
- * @}
- */
- /**
- * @defgroup RTC_Weekday RTC Weekday
- * @{
- */
- #define RTC_WEEKDAY_SUNDAY (0x00U)
- #define RTC_WEEKDAY_MONDAY (0x01U)
- #define RTC_WEEKDAY_TUESDAY (0x02U)
- #define RTC_WEEKDAY_WEDNESDAY (0x03U)
- #define RTC_WEEKDAY_THURSDAY (0x04U)
- #define RTC_WEEKDAY_FRIDAY (0x05U)
- #define RTC_WEEKDAY_SATURDAY (0x06U)
- /**
- * @}
- */
- /**
- * @defgroup RTC_Alarm_Weekday RTC Alarm Weekday
- * @{
- */
- #define RTC_ALARM_WEEKDAY_SUNDAY (0x01U)
- #define RTC_ALARM_WEEKDAY_MONDAY (0x02U)
- #define RTC_ALARM_WEEKDAY_TUESDAY (0x04U)
- #define RTC_ALARM_WEEKDAY_WEDNESDAY (0x08U)
- #define RTC_ALARM_WEEKDAY_THURSDAY (0x10U)
- #define RTC_ALARM_WEEKDAY_FRIDAY (0x20U)
- #define RTC_ALARM_WEEKDAY_SATURDAY (0x40U)
- #define RTC_ALARM_WEEKDAY_EVERYDAY (0x7FU)
- /**
- * @}
- */
- /**
- * @defgroup RTC_Flag RTC Flag
- * @{
- */
- #define RTC_FLAG_RD_WR (RTC_CR2_RWEN) /*!< Read and write permission flag */
- #define RTC_FLAG_ALARM (RTC_CR2_ALMF) /*!< Alarm flag */
- #define RTC_FLAG_PERIOD (RTC_CR2_PRDF) /*!< Period flag */
- #define RTC_FLAG_ALL (RTC_FLAG_RD_WR | RTC_FLAG_ALARM | RTC_FLAG_PERIOD)
- #define RTC_FLAG_CLR_ALL (RTC_FLAG_ALARM | RTC_FLAG_PERIOD)
- /**
- * @}
- */
- /**
- * @defgroup RTC_Interrupt RTC Interrupt
- * @{
- */
- #define RTC_INT_PERIOD (RTC_CR2_PRDIE) /*!< Period interrupt */
- #define RTC_INT_ALARM (RTC_CR2_ALMIE) /*!< Alarm interrupt */
- #define RTC_INT_ALL (RTC_INT_PERIOD | RTC_INT_ALARM)
- /**
- * @}
- */
- /**
- * @}
- */
- /*******************************************************************************
- * Global variable definitions ('extern')
- ******************************************************************************/
- /*******************************************************************************
- Global function prototypes (definition in C source)
- ******************************************************************************/
- /**
- * @addtogroup RTC_Global_Functions
- * @{
- */
- /* Initialization and configuration functions */
- int32_t RTC_DeInit(void);
- int32_t RTC_Init(const stc_rtc_init_t *pstcRtcInit);
- int32_t RTC_StructInit(stc_rtc_init_t *pstcRtcInit);
- int32_t RTC_EnterRwMode(void);
- int32_t RTC_ExitRwMode(void);
- /* Control configuration */
- int32_t RTC_ConfirmLPMCond(void);
- void RTC_SetIntPeriod(uint8_t u8Period);
- void RTC_SetClockSrc(uint8_t u8Src);
- void RTC_SetClockCompenValue(uint16_t u16Value);
- en_functional_state_t RTC_GetCounterState(void);
- void RTC_Cmd(en_functional_state_t enNewState);
- void RTC_LrcCmd(en_functional_state_t enNewState);
- void RTC_OneHzOutputCmd(en_functional_state_t enNewState);
- void RTC_ClockCompenCmd(en_functional_state_t enNewState);
- /* Date and time functions */
- int32_t RTC_SetDate(uint8_t u8Format, stc_rtc_date_t *pstcRtcDate);
- int32_t RTC_GetDate(uint8_t u8Format, stc_rtc_date_t *pstcRtcDate);
- int32_t RTC_SetTime(uint8_t u8Format, stc_rtc_time_t *pstcRtcTime);
- int32_t RTC_GetTime(uint8_t u8Format, stc_rtc_time_t *pstcRtcTime);
- /* Alarm configuration functions */
- int32_t RTC_SetAlarm(uint8_t u8Format, stc_rtc_alarm_t *pstcRtcAlarm);
- int32_t RTC_GetAlarm(uint8_t u8Format, stc_rtc_alarm_t *pstcRtcAlarm);
- void RTC_AlarmCmd(en_functional_state_t enNewState);
- /* Interrupt and flag management functions */
- void RTC_IntCmd(uint32_t u32IntType, en_functional_state_t enNewState);
- en_flag_status_t RTC_GetStatus(uint32_t u32Flag);
- void RTC_ClearStatus(uint32_t u32Flag);
- /**
- * @}
- */
- #endif /* LL_RTC_ENABLE */
- /**
- * @}
- */
- /**
- * @}
- */
- #ifdef __cplusplus
- }
- #endif
- #endif /* __HC32_LL_RTC_H__ */
- /*******************************************************************************
- * EOF (not truncated)
- ******************************************************************************/
|