RTC

概述

实时时钟(RTC)是一个独立的二进制编码十进制(BCD)计时/计数器。它能以年、月、日、时、分、秒为单位,精确提供当前日期和时间信息。 实时时钟使用内部 OSC 作为时钟源,只要供电电压处于工作范围内,无论设备处于运行模式、低功耗模式,RTC 都可以持续工作。

功能特性

  • 具备秒、分钟、小时(支持 12 小时或 24 小时制)、天数和年份的时间管理功能

  • 支持夏令时补偿功能

  • 提供数字校准功能,以补偿固定方向的偏差

  • 提供一个带有中断功能的可编程闹钟,闹钟可通过任意时间字段的组合进行触发

  • 可屏蔽的中断/事件类型包括:

    • 闹钟

    • 日期阈值

    • 周期唤醒定时器

  • 寄存器写保护机制

  • 支持低功耗唤醒

  • 误差小于 2 秒/天

低功耗工作状态

  • 在 sleep 以及 deepsleep 的情况下,系统会定期的唤醒 XTAL 模块(系统不唤醒)来校准 RTC 的时钟源,以确保 RTC 在低功耗模式下的计时精度。

  • RTC 可以在 sleep 以及 deepsleep 的情况下通过闹钟中断和唤醒定时器中断唤醒系统。

供电

RTL8721Dx:
  • 实现简单的 RTC 辅助计时器,在 RTC 电路断电后,辅助计时器会基于原 RTC 时间信息继续计时。当 RTC 再次上电后需要 SW 将辅助计时器内容重新加载到 RTC 电路。

  • RTC 辅助计时器可以独立由 VDH_RTC 供电。

  • RTC 辅助计时器因时钟无法校准,无法实现 RTC 电路同等的精度。

  • VDH_RTC 并未在所有芯片中都有出 Pin。具体参看芯片 Datasheet。

年份寄存器的处理

在 RTC 寄存器中会存储以下时间信息:

  • 年份(从 1900 年开始)

  • 日期(一年中的第几天)

实时时钟内部没有闰年的判定,因此不能实现 day 到 year 的自动进位,需要软件处理。软件可以根据闰年信息,设定 day 的阈值,当 day 到达阈值后会触发中断。

应用示例

SDK 提供了两类功能示例,帮助开发者了解和使用 RTC 功能:

  • mbed 示例

    • 路径:{SDK}\example\peripheral\mbed\RTC\{demo}

    • 展示如何在 mbed 环境中实现 RTC 控制

  • raw 示例

    • 路径:{SDK}\example\peripheral\raw\RTC\{demo}

    • 展示如何在无抽象层的情况下直接控制 RTC

以下是对 raw 示例功能的简要说明:

  • raw_rtc 演示如何设置和获取 RTC 时间;

  • raw_rtc_alarm 演示如何使用 RTC 闹钟中断。

备注

要了解示例支持的芯片,请查看示例路径下的 README.md 文件。

Raw API

RTC Exported Types

struct RTC_AlarmTypeDef

RTC Alarm Structure Definition.

Public Members

RTC_TimeTypeDef RTC_AlarmTime

Specifies the RTC Alarm Time members.

u32 RTC_AlarmMask

Specifies the RTC Alarm1 Masks(H:M:S). This parameter can be a value of RTC Alarm Mask 1

u32 RTC_Alarm2Mask

Specifies the RTC Alarm2 Masks Day. This parameter can be a value of RTC Alarm Mask 2

struct RTC_InitTypeDef

RTC Init Structure Definition.

Public Members

u32 RTC_HourFormat

Specifies the RTC Hour Format. This parameter can be a value of RTC Hour Format

u32 RTC_AsynchPrediv

Specifies the RTC Asynchronous Predivider value. This parameter must be a value of RTC Asynchronous Predivider

u32 RTC_SynchPrediv

Specifies the RTC Synchronous Predivider value. This parameter must be a value of RTC Synchronous Predivider

u32 RTC_DayThreshold

Specifies the RTC Day Threshold value. This parameter must be a value of RTC Day Threshold

struct RTC_TimeTypeDef

RTC Time Structure Definition.

Public Members

u16 RTC_Year

Year in binary format 16bits 1900~2155

u16 RTC_Days

Day in binary format 9bits 0~0x1FF

u8 RTC_Hours

Specifies the RTC Time Hour. This parameter must be set to a value in the 1-12 range if the RTC_HourFormat_12 is selected or 0-23 range if the RTC_HourFormat_24 is selected.

u8 RTC_Minutes

Specifies the RTC Time Minutes. This parameter must be set to a value in the 0-59 range.

u8 RTC_Seconds

Specifies the RTC Time Seconds. This parameter must be set to a value in the 0-59 range.

u8 RTC_H12_PMAM

Specifies the RTC AM/PM Time. This parameter can be a value of RTC AM PM

RTC_IO Exported Types

RTL8721Dx:
struct RTCIO_TimeInfo

Backed-up RTC time and power-off elapsed counter for post-power-on time restoration.

Public Members

u32 Bkup_Seconds

Backed-up seconds before power down (0-59).

u32 Bkup_Minutes

Backed-up minutes before power down (0-59).

u32 Bkup_Hours

Backed-up hours before power down, 24-hour format (0-23).

u32 Bkup_Days

Backed-up days before power down.

u32 Bkup_Year

Backed-up year before power down.

u32 Pwd_Counter

Counter elapsed during power-off period, unit: second.

RTC Exported Constants

Leap Year Check

/* Check if the given year is a leap year. */
#define IS_LEAP_YEAR_CHECK do {\
        if(((!(YEAR % 4)) && (YEAR % 100)) || (!(YEAR % 400))) { \
            RET = 1; \
        } else { \
            RET = 0; \
        } \
} while (0)

RTC AM PM

/* AM or 24-hour format indicator. */
#define RTC_H12_AM ((u8)0x00)

/* PM hour format indicator. */
#define RTC_H12_PM ((u8)0x01)

/* Check if RTC AM/PM value is valid. */
#define IS_RTC_H12_AMPM (((PM) == RTC_H12_AM) || ((PM) == RTC_H12_PM))

RTC Alarm Mask 1

/* No alarm fields are masked. */
#define RTC_AlarmMask_None ((u32)0x00000000)

/* Alarm hours field is masked. */
#define RTC_AlarmMask_Hours ((u32)0x00800000)

/* Alarm minutes field is masked. */
#define RTC_AlarmMask_Minutes ((u32)0x00008000)

/* Alarm seconds field is masked. */
#define RTC_AlarmMask_Seconds ((u32)0x00000080)

/* All alarm time fields are masked. */
#define RTC_AlarmMask_All ((u32)0x00808080)

/* Check if alarm mask value is valid. */
#define IS_ALARM_MASK (((MASK) & 0x7F7F7F) == 0)

RTC Alarm Mask 2

/* No alarm2 day field is masked. */
#define RTC_Alarm2Mask_None ((u32)0x00000000)

/* Alarm2 day field is masked. */
#define RTC_Alarm2Mask_Days ((u32)0x00000200)

/* Check if alarm2 mask value is valid. */
#define IS_ALARM2_MASK (((MASK) & ~RTC_Alarm2Mask_Days) == 0)

RTC Asynchronous Predivider

/* Check if RTC asynchronous predivider value is valid. */
#define IS_RTC_ASYNCH_PREDIV ((PREDIV) <= 0x1FF)

RTC Base Year

/* RTC base year for year calculations. */
#define RTC_BASE_YEAR ((u16)1900)

RTC DayLight Saving Control

/* Subtract one hour for winter time change. */
#define RTC_DayLightSaving_SUB1H ((u32)0x00000002)

/* Add one hour for summer time change. */
#define RTC_DayLightSaving_ADD1H ((u32)0x00000001)

/* Check if RTC daylight saving value is valid. */
#define IS_RTC_DAYLIGHT_SAVING (((SAVE) == RTC_DayLightSaving_SUB1H) || \
    ((SAVE) == RTC_DayLightSaving_ADD1H))

/* Reset the daylight saving backup bit. */
#define RTC_StoreOperation_Reset ((u32)0x00000000)

/* Set the daylight saving backup bit. */
#define RTC_StoreOperation_Set ((u32)0x00000004)

/* Check if RTC store operation value is valid. */
#define IS_RTC_STORE_OPERATION (((OPERATION) == RTC_StoreOperation_Reset) || \
    ((OPERATION) == RTC_StoreOperation_Set))

RTC Day Threshold

/* Mask for RTC day threshold field. */
#define RTC_DAYTHRES_MSK ((u32)0xFF800000)

/* Check if RTC day threshold value is valid. */
#define IS_RTC_DAY_THRES ((DAYS) <= 0x1FF)

RTC Hour Format

/* 24-hour clock format. */
#define RTC_HourFormat_24 ((u32)0x00000000)

/* 12-hour AM/PM clock format. */
#define RTC_HourFormat_12 ((u32)0x00000080)

/* Check if RTC hour format value is valid. */
#define IS_RTC_HOUR_FORMAT (((FORMAT) == RTC_HourFormat_12) || \
    ((FORMAT) == RTC_HourFormat_24))

/* Check if RTC time day threshold value is valid. */
#define IS_RTC_TIME_DAY_THRES ((TIME_DAYS) <= 0x1FF)

RTC Input Parameter Format

/* Binary input parameter format. */
#define RTC_Format_BIN ((u32)0x000000000)

/* BCD input parameter format. */
#define RTC_Format_BCD ((u32)0x000000001)

/* Check if RTC format value is valid. */
#define IS_RTC_FORMAT (((FORMAT) == RTC_Format_BIN) || ((FORMAT) == RTC_Format_BCD))

RTC Output Control

/* Disable RTC output. */
#define RTC_Output_Disable ((u32)0x00000000)

/* Output alarm wakeup signal. */
#define RTC_Output_Alarm ((u32)0x00000020)

/* Output 1 Hz synchronous clock (clk_spre). */
#define RTC_Output_clkspre ((u32)0x00000040)

/* Output 256 Hz asynchronous clock (clk_apre). */
#define RTC_Output_clkapre ((u32)0x00000060)

/* Check if RTC output value is valid. */
#define IS_RTC_OUTPUT (((OUTPUT) == RTC_Output_Disable) || \
    ((OUTPUT) == RTC_Output_Alarm) || \
    ((OUTPUT) == RTC_Output_clkspre) || \
    ((OUTPUT) == RTC_Output_clkapre))

RTC Shift Control

/* Bit shift for alarm hour units field. */
#define RTC_SHIFT_ALR_HU 16

/* Bit shift for alarm minute units field. */
#define RTC_SHIFT_ALR_MNU 8

/* Bit shift for alarm AM/PM field. */
#define RTC_SHIFT_ALR_PM 22

/* Bit shift for time hour units field. */
#define RTC_SHIFT_HU 16

/* Bit shift for time minute units field. */
#define RTC_SHIFT_MNU 8

/* Bit shift for time AM/PM field. */
#define RTC_SHIFT_PM 22

RTC Smooth Calibration Control

/* Calibration period of 1 minute. */
#define RTC_CalibPeriod_1MIN ((u32)0x00000000)

/* Calibration period of 2 minutes. */
#define RTC_CalibPeriod_2MIN ((u32)0x00010000)

/* Calibration period of 3 minutes. */
#define RTC_CalibPeriod_3MIN ((u32)0x00020000)

/* Calibration period of 4 minutes. */
#define RTC_CalibPeriod_4MIN ((u32)0x00030000)

/* Calibration period of 5 minutes. */
#define RTC_CalibPeriod_5MIN ((u32)0x00040000)

/* Calibration period of 6 minutes. */
#define RTC_CalibPeriod_6MIN ((u32)0x00050000)

/* Calibration period of 7 minutes. */
#define RTC_CalibPeriod_7MIN ((u32)0x00060000)

/* Calibration period of 8 minutes. */
#define RTC_CalibPeriod_8MIN ((u32)0x00070000)

/* Check if RTC calibration period value is valid. */
#define IS_RTC_CALIB_PERIOD (((DCP) == RTC_CalibPeriod_1MIN) || \
    ((DCP) == RTC_CalibPeriod_2MIN) || \
    ((DCP) == RTC_CalibPeriod_3MIN) || \
    ((DCP) == RTC_CalibPeriod_4MIN) || \
    ((DCP) == RTC_CalibPeriod_5MIN) || \
    ((DCP) == RTC_CalibPeriod_6MIN) || \
    ((DCP) == RTC_CalibPeriod_7MIN) || \
    ((DCP) == RTC_CalibPeriod_8MIN))

/* Disable digital calibration. */
#define RTC_Calib_Disable ((u32)0x00000000)

/* Enable digital calibration. */
#define RTC_Calib_Enable ((u32)0x00008000)

/* Check if RTC calibration enable value is valid. */
#define IS_RTC_CALIB_ENABLE (((DCE) == RTC_Calib_Disable) || \
    ((DCE) == RTC_Calib_Enable))

/* Positive calibration sign (increase frequency). */
#define RTC_CalibSign_Positive ((u32)0x00000000)

/* Negative calibration sign (decrease frequency). */
#define RTC_CalibSign_Negative ((u32)0x00004000)

/* Check if RTC calibration sign value is valid. */
#define IS_RTC_CALIB_SIGN (((SIGN) == RTC_CalibSign_Positive) || \
    ((SIGN) == RTC_CalibSign_Negative))

/* Check if RTC calibration value is valid. */
#define IS_RTC_CALIB_VALUE ((VALUE) <= 0x7F)

RTC Synchronous Predivider

/* Check if RTC synchronous predivider value is valid. */
#define IS_RTC_SYNCH_PREDIV ((PREDIV) <= 0x1FF)

RTC TR Mask

/* Reserved bits mask for RTC_TR register. */
#define RTC_TR_RESERVED_MASK ((u32)0xFFFF7F7F)

RTC Time Definitions

/* Check if RTC 12-hour value is valid. */
#define IS_RTC_HOUR12 (((HOUR) > 0) && ((HOUR) <= 12))

/* Check if RTC 24-hour value is valid. */
#define IS_RTC_HOUR24 ((HOUR) <= 23)

/* Check if RTC minutes value is valid. */
#define IS_RTC_MINUTES ((MINUTES) <= 59)

/* Check if RTC seconds value is valid. */
#define IS_RTC_SECONDS ((SECONDS) <= 59)

RTC Timeout Control

/* Timeout for RTC initialization mode. */
#define INITMODE_TIMEOUT ((u32) 0x00010000)

/* Timeout for RTC synchronization. */
#define SYNCHRO_TIMEOUT ((u32) 0x00020000)

/* Timeout for recalibration pending flag. */
#define RECALPF_TIMEOUT ((u32) 0x00020000)

/* Timeout for alarm disable operation. */
#define ALARMDIS_TIMEOUT ((u32) 0x00020000)

/* Timeout for wakeup timer disable. */
#define WUTDIS_TIMEOUT ((u32) 0x00020000)

RTC Year Threshold

/* Check if RTC year threshold value is valid. */
#define IS_RTC_YEAR_THRES ((YEAR >= RTC_BASE_YEAR) && \
    ((YEAR - RTC_BASE_YEAR) <= 0xFF))

RTC_IO Exported Constants

RTC IO Work Mode

RTL8721Dx:
/* Shift mode disabled. */
#define MODE_SHIFT_DISABLE (0)

/* Shift mode enabled. */
#define MODE_SHIFT_ENABLE (1)

/* RTC start mode. */
#define MODE_RTC_START (2)

RTC IO RECV RVAL

RTL8721Dx:
/* Receive new reset value. */
#define RTCIO_RECV_RVAL_RST TRUE

/* Receive calibrated value. */
#define RTCIO_RECV_RVAL_CAL FALSE

RTC IO Time Convert

RTL8721Dx:
/* Step time value with carry propagation. */
#define TIME_STEP do {\
        TIME_POST = (TIME_PRE + TIME_STEP_CNT) % MOD_NUM; \
        TIME_STEP_CNT = (TIME_PRE + TIME_STEP_CNT) / MOD_NUM; \
} while (0)

RTC Exported Functions

void RTC_AlarmClear(void)

Clear alarm pending interrupt.

void RTC_AlarmCmd(u32 NewState)

Enable or disable the specified RTC Alarm.

参数:
  • NewState -- New state of the specified alarm. This parameter can be: ENABLE or DISABLE.

void RTC_AlarmStructInit(RTC_AlarmTypeDef *RTC_AlarmStruct)

Fill each RTC_AlarmStruct member with its default value (Time = 00d:00h:00mn:20sec / Date = 1st day of the month/Mask = all fields are masked except Alarm Seconds field).

参数:
  • RTC_AlarmStruct -- Pointer to a RTC_AlarmTypeDef structure which will be initialized.

u32 RTC_BypassShadowCmd(u32 NewState)

Enable or Disable the Bypass Shadow feature.

参数:
  • NewState -- New state of the Bypass Shadow feature. This parameter can be: ENABLE or DISABLE.

返回:

Status value:

  • 1: success

  • 0: fail

备注

When the Bypass Shadow is enabled the calendar value are taken directly from the Calendar counter.

void RTC_DayIntClear(void)

Clear day over threshold pending interrupt.

u32 RTC_DayIntCmd(u32 NewState)

Enable or disable the RTC day over threshold interrupt.

参数:
  • NewState -- New state of the RTC day over threshold interrupt. This parameter can be: ENABLE or DISABLE.

返回:

Status value:

  • 1: success

  • 0: fail

u32 RTC_DayLightSavingConfig(u32 RTC_DayLightSaving, u32 RTC_StoreOperation)

Add or substract one hour from the current time.

参数:
  • RTC_DayLightSaving --

    The value of hour adjustment. This parameter can be one of the following values:

    • RTC_DayLightSaving_SUB1H: Substract one hour (winter time)

    • RTC_DayLightSaving_ADD1H: Add one hour (summer time)

  • RTC_StoreOperation --

    Specifies the value to be written in the BCK bit in CR register to store the operation. This parameter can be one of the following values:

    • RTC_StoreOperation_Reset: BCK Bit Reset

    • RTC_StoreOperation_Set: BCK Bit Set

返回:

Status value:

  • 1: success

  • 0: fail

u32 RTC_DayThresGet(void)

Get the RTC day threshold value in RTC_CR register.

返回:

RTC day threshold value.

u32 RTC_DayThresSet(u32 DayThres)

Set the RTC day threshold.

参数:
  • DayThres -- Specifies the day threshold to be configured. This parameter can be a value of RTC Day Threshold.

返回:

Status value:

  • 1: RTC day threshold is configured

  • 0: RTC day threshold is not configured

void RTC_GetAlarm(u32 RTC_Format, RTC_AlarmTypeDef *RTC_AlarmStruct)

Get the RTC Alarm value and masks.

参数:
  • RTC_Format --

    Specifies the format of the output parameters. This parameter can be one of the following values:

    • RTC_Format_BIN: Binary data format

    • RTC_Format_BCD: BCD data format

  • RTC_AlarmStruct -- Pointer to a RTC_AlarmTypeDef structure that will contains the output alarm configuration values.

u32 RTC_GetStoreOperation(void)

Return the RTC Day Light Saving stored operation.

返回:

RTC Day Light Saving stored operation.

  • RTC_StoreOperation_Reset

  • RTC_StoreOperation_Set

void RTC_GetTime(u32 RTC_Format, RTC_TimeTypeDef *RTC_TimeStruct)

Get the RTC current Time.

参数:
  • RTC_Format --

    Specifies the format of the returned parameters. This parameter can be one of the following values:

    • RTC_Format_BIN: Binary data format

    • RTC_Format_BCD: BCD data format

  • RTC_TimeStruct -- Pointer to a RTC_TimeTypeDef structure that will contain the returned current time configuration.

u32 RTC_GetWakeup(void)

Get the RTC Wakeup Timer value and masks.

返回:

The wakeup time value.

u32 RTC_Init(RTC_InitTypeDef *RTC_InitStruct)

Initialize the RTC registers according to the specified parameters in RTC_InitStruct.

参数:
  • RTC_InitStruct -- Pointer to a RTC_InitTypeDef structure that contains the configuration information for the RTC peripheral.

返回:

Status value:

  • 1: RTC registers are initialized

  • 0: RTC registers are not initialized

备注

The RTC Prescaler register is write protected and can be written in initialization mode only.

u32 RTC_OutputConfig(u32 RTC_Output)

Configure the RTC output.

参数:
  • RTC_Output --

    Specifies which signal will be routed to the RTC output. This parameter can be one of the following values:

    • RTC_Output_Disable: No output selected

    • RTC_Output_Alarm: signal of Alarm mapped to output

    • RTC_Output_clkspre: signal of clkspre mapped to output

    • RTC_Output_clkapre: signal of clkapre mapped to output

返回:

Status value:

  • 1: success

  • 0: fail

u32 RTC_SetAlarm(u32 RTC_Format, RTC_AlarmTypeDef *RTC_AlarmStruct)

Set the specified RTC Alarm.

参数:
  • RTC_Format --

    Specifies the format of the returned parameters. This parameter can be one of the following values:

    • RTC_Format_BIN: Binary data format

    • RTC_Format_BCD: BCD data format

  • RTC_AlarmStruct -- Pointer to a RTC_AlarmTypeDef structure that contains the alarm configuration parameters.

返回:

Status value:

  • 1: RTC Time Alarm is configured

  • 0: RTC Time Alarm is not configured

备注

The Alarm register can only be written when the corresponding Alarm is disabled (Use RTC_AlarmCmd (DISABLE)).

u32 RTC_SetTime(u32 RTC_Format, RTC_TimeTypeDef *RTC_TimeStruct)

Set the RTC current time.

参数:
  • RTC_Format --

    Specifies the format of the entered parameters. This parameter can be one of the following values:

    • RTC_Format_BIN: Binary data format

    • RTC_Format_BCD: BCD data format

  • RTC_TimeStruct -- Pointer to a RTC_TimeTypeDef structure that contains the time configuration information for the RTC.

返回:

Status value:

  • 1: RTC Time register is configured

  • 0: RTC Time register is not configured

u32 RTC_SetTimeDayYear(u32 RTC_TimeDay, u32 RTC_TimeYear)

Set the RTC current time for day and year.

参数:
  • RTC_TimeDay -- Specifies the day to be set. Starts from 0.

  • RTC_TimeYear -- Specifies the year to be set. Starts from 1900.

返回:

Status value:

  • 1: RTC Time day and year are configured

  • 0: RTC Time day and year are not configured

u32 RTC_SetWakeup(u32 RTC_WakeupRange)

Set the specified RTC Wakeup Timer.

参数:
  • RTC_WakeupRange -- Wakeup time to be configured. This parameter can be a value from 0x1 to 0x1FF.

返回:

Status value:

  • 1: RTC WakeupTimer is configured

  • 0: RTC WakeupTimer is not configured

备注

The Wakeup Timer register can only be written when the WakeupTimer is disabled (Use RTC_WakeupCmd (DISABLE)).

u32 RTC_SmoothCalibConfig(u32 CalibSign, u32 Value, u32 CalibPeriod, u32 Calib_Enable)

Configure the Coarse calibration parameters.

参数:
  • CalibSign --

    CalibSign specifies the sign of the coarse calibration value. This parameter can be one of the following values:

    • RTC_CalibSign_Positive: The value sign is positive

    • RTC_CalibSign_Negative: The value sign is negative

  • Value -- Value of coarse calibration expressed in ppm (coded on 7 bits).

  • CalibPeriod --

    Calibration period, Compensate DC clkapre cycles every (CALP+1) minutes (coded on 3 bits). This parameter can be one of the following values:

    • RTC_CalibPeriod_1MIN

    • RTC_CalibPeriod_2MIN

    • RTC_CalibPeriod_3MIN

    • RTC_CalibPeriod_4MIN

    • RTC_CalibPeriod_5MIN

    • RTC_CalibPeriod_6MIN

    • RTC_CalibPeriod_7MIN

    • RTC_CalibPeriod_8MIN

  • Calib_Enable -- RTC_Calib_Disable or RTC_Calib_Enable .

返回:

Status value:

  • 1: RTC Coarse calibration are initialized

  • 0: RTC Coarse calibration are not initialized

void RTC_StructInit(RTC_InitTypeDef *RTC_InitStruct)

Fill each RTC_InitStruct member with its default value.

参数:
  • RTC_InitStruct -- Pointer to a RTC_InitTypeDef structure which will be initialized.

void RTC_TimeStructInit(RTC_TimeTypeDef *RTC_TimeStruct)

Fill each RTC_TimeStruct member with its default value (Time = 00d:00h:00min:00sec).

参数:
  • RTC_TimeStruct -- Pointer to a RTC_TimeTypeDef structure which will be initialized.

u32 RTC_WaitForWUTSynchro(void)

Wait until the RTC Wakeup timer enable bit (WUTE bit) is synchronized with RTC APB clock.

返回:

Status value:

  • 1: RTC Wakeup Timer registers are synchronised

  • 0: RTC Wakeup Timer registers are not synchronised

备注

The software must then wait until it is set again before wakeup timer works, which means that the WUTE bit have been correctly copied into the shadow register. By the time WUTE bit is synchronized, other control bits of wakeup timer has already been synchronized, because these bits are configure before WUTE bit.

void RTC_WakeupClear(void)

Clear wakeup pending interrupt.

void RTC_WakeupCmd(u32 NewState)

Enable or disable the specified RTC Wakeup Timer.

参数:
  • NewState -- New state of the specified wakeup timer. This parameter can be: ENABLE or DISABLE.

备注

Wakeup timer starts down counting after 3 to 4 seconds

RTL8721Dx:

Not supported.

RTC_IO Exported Functions

RTL8721Dx:
void RTCIO_GetTimeInfo(RTCIO_TimeInfo *pDataOut)

Output time info after setting work mode to MODE_SHIFT_ENABLE.

参数:
  • pDataOut -- Pointer to RTCIO_TimeInfo structure to store time information.

u32 RTCIO_GetWorkMode(void)

Get RTCIO work mode.

返回:

Current work mode of RTCIO:

  • 0: MODE_SHIFT_DISABLE

  • 1: MODE_SHIFT_ENABLE

  • 2: MODE_RTC_START

u32 RTCIO_IsEnabled(void)

Check RTCIO Module enabled or not.

返回:

Whether RTCIO is enabled:

  • TRUE: enabled

  • FALSE: disabled

void RTCIO_ModeRTCStart(void)

Enable RTCIO by setting work mode to MODE_RTC_START.

void RTCIO_SetRValue(u32 ResetRcal)

Receive calibration value from rtc_sio.

参数:
  • ResetRcal -- Reset Rcal flag. This parameter can be: RTCIO_RECV_RVAL_RST, RTCIO_RECV_RVAL_CAL

void RTCIO_SetWorkMode(u32 Mode)

Configure RTCIO work mode,it works MODE_SHIFT_DISABLE by default.

参数:
  • Mode -- New work mode of RTCIO. This parameter can be: MODE_SHIFT_DISABLE, MODE_SHIFT_ENABLE, MODE_RTC_START,

Mbed API

MBED_RTC Exported Types

Structure Type

struct alarm_s

RTC alarm time configuration.

Public Members

uint32_t yday

Day of year (1-365/366).

uint32_t hour

Hour (0-23).

uint32_t min

Minute (0-59).

uint32_t sec

Second (0-59).

typedef struct alarm_s alarm_t

RTC alarm time configuration.

MBED_RTC Exported Functions

void rtc_disable_alarm(void)

Disable RTC Alarm.

void rtc_free(void)

Deinitialize the RTC device.

void rtc_init(void)

Initialize the RTC device, including clock, function and RTC registers.

int rtc_isenabled(void)

Judge whether RTC is enabled or not.

返回:

RTC status:

  • 1: RTC has been enabled.

  • 0: RTC has not been enabled.

time_t rtc_read(void)

Get current timestamp in seconds from RTC.

返回:

Current timestamp in seconds which is calculated from 1970.1.1 00:00:00.

u32 rtc_set_alarm(alarm_t *alrm, alarm_irq_handler alarmHandler)

Set the specified RTC Alarm and interrupt.

参数:
  • alrm -- Alarm object defined in application software.

  • alarmHandler -- Alarm interrupt callback function.

返回:

Status:

  • 1: Success.

  • Others: Error.

void rtc_write(time_t t)

Set the specified timestamp in seconds to RTC.

参数:
  • t -- Seconds from 1970.1.1 00:00:00 to specified data and time which is to be set.