加入收藏
举报
02-14 20:02
#0
文件名称:
RTC.md
所在目录:
Openharmony v1.0 / docs / api / api-SmartVision-Devices
文件大小:
39.91 KB
下载地址:
fenwii/OpenHarmony
   
免责声明:本网站仅提供指向 GitHub 上的文件的链接,所有文件的版权归原作者所有,本网站不对文件内容的合法性、准确性或安全性承担任何责任。
文本预览:
# RTC
## **Overview**
Provides standard real-time clock \(RTC\) APIs.
These APIs allow you to perform operations such as reading or writing system time, reading or writing alarm time, setting alarm interrupts, registering alarm callbacks, setting the external frequency, resetting the RTC driver, and customizing RTC configurations. The RTC driver provides precise real time for the operating system \(OS\). If the OS is powered off, the RTC driver continues to keep track of the system time using an external battery.
**Since:**
1.0
## **Summary**
## Files









File Name


Description


rtc_if.h


Declares the standard RTC APIs.



## Data Structures









Data Structure Name


Description


RtcTime


Defines the RTC information.



## Typedefs









Typedef Name


Description


RtcAlarmCallback) (enum RtcAlarmIndex)


typedef int32_t(* 


Defines a callback that will be invoked when an alarm is generated at the specified time.



## Enumerations









Enumeration Name


Description


RtcAlarmIndex { RTC_ALARM_INDEX_A = 0, RTC_ALARM_INDEX_B = 1 }


Enumerates alarm indexes.



## Functions













































Function Name


Description


RtcOpen (void)


struct DevHandle


Opens the RTC device to obtain its handle.


RtcClose (struct DevHandle *handle)


void 


Releases a specified handle of the RTC device.


RtcReadTime (struct DevHandle *handle, struct RtcTime *time)


int32_t 


Reads time from the RTC driver.


RtcWriteTime (struct DevHandle *handle, const struct RtcTime *time)


int32_t 


Writes format-compliant time to the RTC driver.


RtcReadAlarm (struct DevHandle *handle, enum RtcAlarmIndex alarmIndex, struct RtcTime *time)


int32_t 


Reads the RTC alarm time that was set last time.


RtcWriteAlarm (struct DevHandle *handle, enum RtcAlarmIndex alarmIndex, const struct RtcTime *time)


int32_t 


Writes the RTC alarm time based on the alarm index.


RtcRegisterAlarmCallback (struct DevHandle *handle, enum RtcAlarmIndex alarmIndex, RtcAlarmCallback cb)


int32_t 


Registers RtcAlarmCallback that will be invoked when an alarm is generated at the specified time.


RtcAlarmInterruptEnable (struct DevHandle *handle, enum RtcAlarmIndex alarmIndex, uint8_t enable)


int32_t 


Enables or disables alarm interrupts.


RtcGetFreq (struct DevHandle *handle, uint32_t *freq)


int32_t 


Reads the RTC external frequency.


RtcSetFreq (struct DevHandle *handle, uint32_t freq)


int32_t 


Sets the frequency of the external crystal oscillator connected to the RTC driver.


RtcReset (struct DevHandle *handle)


int32_t 


Resets the RTC driver.


RtcReadReg (struct DevHandle *handle, uint8_t usrDefIndex, uint8_t *value)


int32_t 


Reads the configuration of a custom RTC register based on the register index.


RtcWriteReg (struct DevHandle *handle, uint8_t usrDefIndex, uint8_t value)


int32_t 


Writes the configuration of a custom RTC register based on the register index.



## **Details**
## **Typedef Documentation**
## RtcAlarmCallback
```
typedef int32_t(* RtcAlarmCallback) (enum [RtcAlarmIndex](RTC.md#gad7b3a575c848e2669db5e5b6f7e74330))
```
**Description:**
Defines a callback that will be invoked when an alarm is generated at the specified time.
## **Enumeration Type Documentation**
## RtcAlarmIndex
```
enum [RtcAlarmIndex](RTC.md#gad7b3a575c848e2669db5e5b6f7e74330)
```
**Description:**
Enumerates alarm indexes.
The alarm indexes will be used when you perform operations related to alarms.












Enumerator


Description


RTC_ALARM_INDEX_A 

Index of alarm A


RTC_ALARM_INDEX_B 

Index of alarm B



## **Function Documentation**
## RtcAlarmInterruptEnable\(\)
```
int32_t RtcAlarmInterruptEnable (struct [DevHandle](DevHandle.md) * handle, enum [RtcAlarmIndex](RTC.md#gad7b3a575c848e2669db5e5b6f7e74330) alarmIndex, uint8_t enable )
```
**Description:**
Enables or disables alarm interrupts.
Before performing alarm operations, you need to call this function to enable alarm interrupts, so that the [RtcRegisterAlarmCallback](RTC.md#gac40e57d996375e1762968b66dedb5914) will be called when the alarm is not generated upon a timeout.
**Parameters:**















Name


Description


handle Indicates the pointer to the RTC device handle, which is obtained via RtcGetHandle.
alarmIndex Indicates the RTC alarm index. For details, see RtcAlarmIndex.
enable Specifies whether to enable RTC alarm interrupts. The value 1 means to enable alarm interrupts and value 0 means to disable alarm interrupts.

**Returns:**
Returns **0** if the operation is successful; returns a negative value if the operation fails. For details, see [HDF\_STATUS](DriverUtils.md#ga7e01536ecbe9b17563dd3fe256202a67).
## RtcClose\(\)
```
void RtcClose (struct [DevHandle](DevHandle.md) * handle)
```
**Description:**
Releases a specified handle of the RTC device.
**Parameters:**









Name


Description


handle Indicates the pointer to the RTC device handle to release, which is created via RtcGetHandle.

## RtcGetFreq\(\)
```
int32_t RtcGetFreq (struct [DevHandle](DevHandle.md) * handle, uint32_t * freq )
```
**Description:**
Reads the RTC external frequency.
This function reads the frequency of the external crystal oscillator connected to the RTC driver.
**Parameters:**












Name


Description


handle Indicates the pointer to the RTC device handle, which is obtained via RtcGetHandle.
freq Indicates the pointer to the frequency of the external crystal oscillator, in Hz.

**Returns:**
Returns **0** if the operation is successful; returns a negative value if the operation fails. For details, see [HDF\_STATUS](DriverUtils.md#ga7e01536ecbe9b17563dd3fe256202a67).
## RtcOpen\(\)
```
struct [DevHandle](DevHandle.md)* RtcOpen (void )
```
**Description:**
Opens the RTC device to obtain its handle.
The OS supports only one RTC device.
**Returns:**
Returns [DevHandle](DevHandle.md) if the operation is successful; returns **NULL** if the operation fails.
## RtcReadAlarm\(\)
```
int32_t RtcReadAlarm (struct [DevHandle](DevHandle.md) * handle, enum [RtcAlarmIndex](RTC.md#gad7b3a575c848e2669db5e5b6f7e74330) alarmIndex, struct [RtcTime](RtcTime.md) * time )
```
**Description:**
Reads the RTC alarm time that was set last time.
**Parameters:**















Name


Description


handle Indicates the pointer to the RTC device handle, which is obtained via RtcGetHandle.
alarmIndex Indicates the RTC alarm index. For details, see RtcAlarmIndex.
time Indicates the pointer to the RTC alarm time information. For details, see RtcTime.

**Returns:**
Returns **0** if the operation is successful; returns a negative value if the operation fails. For details, see [HDF\_STATUS](DriverUtils.md#ga7e01536ecbe9b17563dd3fe256202a67).
## RtcReadReg\(\)
```
int32_t RtcReadReg (struct [DevHandle](DevHandle.md) * handle, uint8_t usrDefIndex, uint8_t * value )
```
**Description:**
Reads the configuration of a custom RTC register based on the register index.
One index corresponds to one byte of the configuration value.
**Parameters:**















Name


Description


handle Indicates the pointer to the RTC device handle, which is obtained via RtcGetHandle.
usrDefIndex Indicates the index of the custom register.
value Indicates the pointer to the configuration value of the specified register index.

**Returns:**
Returns **0** if the operation is successful; returns a negative value if the operation fails. For details, see [HDF\_STATUS](DriverUtils.md#ga7e01536ecbe9b17563dd3fe256202a67).
## RtcReadTime\(\)
```
int32_t RtcReadTime (struct [DevHandle](DevHandle.md) * handle, struct [RtcTime](RtcTime.md) * time )
```
**Description:**
Reads time from the RTC driver.
The time information includes the year, month, day, day of the week, hour, minute, second, and millisecond.
**Parameters:**












Name


Description


handle Indicates the pointer to the RTC device handle, which is obtained via RtcGetHandle.
time Indicates the pointer to the time information read from the RTC driver. For details, see RtcTime.

**Returns:**
Returns **0** if the operation is successful; returns a negative value if the operation fails. For details, see [HDF\_STATUS](DriverUtils.md#ga7e01536ecbe9b17563dd3fe256202a67).
## RtcRegisterAlarmCallback\(\)
```
int32_t RtcRegisterAlarmCallback (struct [DevHandle](DevHandle.md) * handle, enum [RtcAlarmIndex](RTC.md#gad7b3a575c848e2669db5e5b6f7e74330) alarmIndex, [RtcAlarmCallback](RTC.md#gaf9932b7e647bce0503f1314bbe5eef8d) cb )
```
**Description:**
Registers [RtcAlarmCallback](RTC.md#gaf9932b7e647bce0503f1314bbe5eef8d) that will be invoked when an alarm is generated at the specified time.
**Parameters:**















Name


Description


handle Indicates the pointer to the RTC device handle, which is obtained via RtcGetHandle.
alarmIndex Indicates the RTC alarm index. For details, see RtcAlarmIndex.
cb Indicates the callback to register. For details, see RtcAlarmCallback.

**Returns:**
Returns **0** if the operation is successful; returns a negative value if the operation fails. For details, see [HDF\_STATUS](DriverUtils.md#ga7e01536ecbe9b17563dd3fe256202a67).
## RtcReset\(\)
```
int32_t RtcReset (struct [DevHandle](DevHandle.md) * handle)
```
**Description:**
Resets the RTC driver.
After the reset, the configuration registers are restored to the default values.
**Parameters:**









Name


Description


handle Indicates the pointer to the RTC device handle, which is obtained via RtcGetHandle.

**Returns:**
Returns **0** if the operation is successful; returns a negative value if the operation fails. For details, see [HDF\_STATUS](DriverUtils.md#ga7e01536ecbe9b17563dd3fe256202a67).
## RtcSetFreq\(\)
```
int32_t RtcSetFreq (struct [DevHandle](DevHandle.md) * handle, uint32_t freq )
```
**Description:**
Sets the frequency of the external crystal oscillator connected to the RTC driver.
Note that the frequency must be configured in accordance with the requirements specified in the product manual of the in-use component.
**Parameters:**












Name


Description


handle Indicates the pointer to the RTC device handle, which is obtained via RtcGetHandle.
freq Indicates the frequency to set for the external crystal oscillator, in Hz.

**Returns:**
Returns **0** if the operation is successful; returns a negative value if the operation fails. For details, see [HDF\_STATUS](DriverUtils.md#ga7e01536ecbe9b17563dd3fe256202a67).
## RtcWriteAlarm\(\)
```
int32_t RtcWriteAlarm (struct [DevHandle](DevHandle.md) * handle, enum [RtcAlarmIndex](RTC.md#gad7b3a575c848e2669db5e5b6f7e74330) alarmIndex, const struct [RtcTime](RtcTime.md) * time )
```
**Description:**
Writes the RTC alarm time based on the alarm index.
Note that the RTC start time is 1970/01/01 Thursday 00:00:00 \(UTC\). Set the maximum value of **year** based on the requirements specified in the product manual of the in-use component.
**Parameters:**















Name


Description


handle Indicates the pointer to the RTC device handle, which is obtained via RtcGetHandle.
alarmIndex Indicates the RTC alarm index. For details, see RtcAlarmIndex.
tm Indicates the pointer to the RTC alarm time information. For details, see RtcTime.

**Returns:**
Returns **0** if the operation is successful; returns a negative value if the operation fails. For details, see [HDF\_STATUS](DriverUtils.md#ga7e01536ecbe9b17563dd3fe256202a67).
## RtcWriteReg\(\)
```
int32_t RtcWriteReg (struct [DevHandle](DevHandle.md) * handle, uint8_t usrDefIndex, uint8_t value )
```
**Description:**
Writes the configuration of a custom RTC register based on the register index.
One index corresponds to one byte of the configuration value.
**Parameters:**















Name


Description


handle Indicates the pointer to the RTC device handle, which is obtained via RtcGetHandle.
usrDefIndex Indicates the index of the custom register.
value Indicates the configuration value to write at the index of the register.

**Returns:**
Returns **0** if the operation is successful; returns a negative value if the operation fails. For details, see [HDF\_STATUS](DriverUtils.md#ga7e01536ecbe9b17563dd3fe256202a67).
## RtcWriteTime\(\)
```
int32_t RtcWriteTime (struct [DevHandle](DevHandle.md) * handle, const struct [RtcTime](RtcTime.md) * time )
```
**Description:**
Writes format-compliant time to the RTC driver.
Note that the RTC start time is 1970/01/01 Thursday 00:00:00 \(UTC\). Set the maximum value of **year** based on the requirements specified in the product manual of the in-use component.
**Parameters:**












Name


Description


handle Indicates the pointer to the RTC device handle, which is obtained via RtcGetHandle.
time Indicates the pointer to the time information to write. For details, see RtcTime.

**Returns:**
Returns **0** if the operation is successful; returns a negative value if the operation fails. For details, see [HDF\_STATUS](DriverUtils.md#ga7e01536ecbe9b17563dd3fe256202a67).
点赞 回复
回帖
支持markdown部分语法 ?