提交 707e657b 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 7f52a358
......@@ -260,7 +260,7 @@ The method for determining the GPIO pin number varies depending on the GPIO cont
```
## Development Example
## Example
The procedure is as follows:
......
......@@ -63,7 +63,7 @@ The GPIO module adaptation involves the following steps:
- Initialize **GpioCntlr**.
- Instantiate **GpioMethod** in the **GpioCntlr** object.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> For details about the callbacks in **GpioMethod**, see [Available APIs](#available_apis).
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> For details about the callbacks in **GpioMethod**, see [Available APIs](#available-apis).
4. Debug the driver.
......
......@@ -467,7 +467,7 @@ The following is an example of closing an HDMI controller:
HdmiClose(hdmiHandle);
```
### Development Example
### Example
This following example shows how to use HDMI APIs to manage an HDMI device on a Hi3516D V300 development board.
......
# RTC<a name="EN-US_TOPIC_0000001206373007"></a>
## Overview<a name="section104842041574"></a>
The real-time clock \(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.
## Available APIs<a name="section20331159102519"></a>
**Table 1** APIs provided by the RTC driver
<a name="table1731550155318"></a>
<table><thead align="left"><tr id="row4419501537"><th class="cellrowborder" valign="top" width="21.902190219021904%" id="mcps1.2.4.1.1"><p id="p641050105320"><a name="p641050105320"></a><a name="p641050105320"></a><strong id="b17744818255"><a name="b17744818255"></a><a name="b17744818255"></a>Capability</strong></p>
</th>
<th class="cellrowborder" valign="top" width="24.98249824982498%" id="mcps1.2.4.1.2"><p id="p54150165315"><a name="p54150165315"></a><a name="p54150165315"></a><strong id="b257315114254"><a name="b257315114254"></a><a name="b257315114254"></a>Function</strong></p>
</th>
<th class="cellrowborder" valign="top" width="53.11531153115312%" id="mcps1.2.4.1.3"><p id="p941150145313"><a name="p941150145313"></a><a name="p941150145313"></a><strong id="b384185962317"><a name="b384185962317"></a><a name="b384185962317"></a>Description</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="row17550163418501"><td class="cellrowborder" rowspan="2" valign="top" width="21.902190219021904%" headers="mcps1.2.4.1.1 "><p id="p11670643205012"><a name="p11670643205012"></a><a name="p11670643205012"></a>RTC handle</p>
</td>
<td class="cellrowborder" valign="top" width="24.98249824982498%" headers="mcps1.2.4.1.2 "><p id="p16550143465015"><a name="p16550143465015"></a><a name="p16550143465015"></a>RtcOpen</p>
</td>
<td class="cellrowborder" valign="top" width="53.11531153115312%" headers="mcps1.2.4.1.3 "><p id="p9550103415015"><a name="p9550103415015"></a><a name="p9550103415015"></a>Opens the RTC device to obtain its handle.</p>
</td>
</tr>
<tr id="row1879052755020"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1479062716506"><a name="p1479062716506"></a><a name="p1479062716506"></a>RtcClose</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1579142745012"><a name="p1579142745012"></a><a name="p1579142745012"></a>Releases a specified handle of the RTC device.</p>
</td>
</tr>
<tr id="row34145016535"><td class="cellrowborder" rowspan="2" valign="top" width="21.902190219021904%" headers="mcps1.2.4.1.1 "><p id="p229610227124"><a name="p229610227124"></a><a name="p229610227124"></a>RTC time</p>
</td>
<td class="cellrowborder" valign="top" width="24.98249824982498%" headers="mcps1.2.4.1.2 "><p id="p19389143041518"><a name="p19389143041518"></a><a name="p19389143041518"></a>RtcReadTime</p>
</td>
<td class="cellrowborder" valign="top" width="53.11531153115312%" headers="mcps1.2.4.1.3 "><p id="p8738101941716"><a name="p8738101941716"></a><a name="p8738101941716"></a>Reads time information from the RTC driver, including the year, month, the day of the week, day, hour, minute, second, and millisecond.</p>
</td>
</tr>
<tr id="row5632152611414"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p143890309153"><a name="p143890309153"></a><a name="p143890309153"></a>RtcWriteTime</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p573815197171"><a name="p573815197171"></a><a name="p573815197171"></a>Writes time information from the RTC driver, including the year, month, the day of the week, day, hour, minute, second, and millisecond.</p>
</td>
</tr>
<tr id="row1468016592416"><td class="cellrowborder" rowspan="4" valign="top" width="21.902190219021904%" headers="mcps1.2.4.1.1 "><p id="p36817591648"><a name="p36817591648"></a><a name="p36817591648"></a>RTC alarm</p>
</td>
<td class="cellrowborder" valign="top" width="24.98249824982498%" headers="mcps1.2.4.1.2 "><p id="p968116598418"><a name="p968116598418"></a><a name="p968116598418"></a>RtcReadAlarm</p>
</td>
<td class="cellrowborder" valign="top" width="53.11531153115312%" headers="mcps1.2.4.1.3 "><p id="p768110592416"><a name="p768110592416"></a><a name="p768110592416"></a>Reads the RTC alarm time that was set last time.</p>
</td>
</tr>
<tr id="row19313155514"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p73141951155"><a name="p73141951155"></a><a name="p73141951155"></a>RtcWriteAlarm</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p15314656511"><a name="p15314656511"></a><a name="p15314656511"></a>Writes the RTC alarm time based on the alarm index.</p>
</td>
</tr>
<tr id="row138283422555"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p2829142165513"><a name="p2829142165513"></a><a name="p2829142165513"></a>RtcRegisterAlarmCallback</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p118291242155518"><a name="p118291242155518"></a><a name="p118291242155518"></a>Registers <strong id="b1648234343210"><a name="b1648234343210"></a><a name="b1648234343210"></a>RtcAlarmCallback</strong> that will be invoked when an alarm is generated at the specified time.</p>
</td>
</tr>
<tr id="row13344113914568"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p2344103915616"><a name="p2344103915616"></a><a name="p2344103915616"></a>RtcAlarmInterruptEnable</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p034415397565"><a name="p034415397565"></a><a name="p034415397565"></a>Enables or disables RTC alarm interrupts.</p>
</td>
</tr>
<tr id="row11801203517565"><td class="cellrowborder" rowspan="3" valign="top" width="21.902190219021904%" headers="mcps1.2.4.1.1 "><p id="p17261458942"><a name="p17261458942"></a><a name="p17261458942"></a>RTC configuration</p>
</td>
<td class="cellrowborder" valign="top" width="24.98249824982498%" headers="mcps1.2.4.1.2 "><p id="p15801153515561"><a name="p15801153515561"></a><a name="p15801153515561"></a>RtcGetFreq</p>
</td>
<td class="cellrowborder" valign="top" width="53.11531153115312%" headers="mcps1.2.4.1.3 "><p id="p980133515566"><a name="p980133515566"></a><a name="p980133515566"></a>Reads the frequency of the external crystal oscillator connected to the RTC driver.</p>
</td>
</tr>
<tr id="row111502322563"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1615073225618"><a name="p1615073225618"></a><a name="p1615073225618"></a>RtcSetFreq</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p10150832165613"><a name="p10150832165613"></a><a name="p10150832165613"></a>Sets the frequency of the external crystal oscillator connected to the RTC driver.</p>
</td>
</tr>
<tr id="row21771259145618"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1717725916562"><a name="p1717725916562"></a><a name="p1717725916562"></a>RtcReset</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p517712598569"><a name="p517712598569"></a><a name="p517712598569"></a>Resets the RTC.</p>
</td>
</tr>
<tr id="row917116425716"><td class="cellrowborder" rowspan="2" valign="top" width="21.902190219021904%" headers="mcps1.2.4.1.1 "><p id="p144765201754"><a name="p144765201754"></a><a name="p144765201754"></a>Custom register</p>
</td>
<td class="cellrowborder" valign="top" width="24.98249824982498%" headers="mcps1.2.4.1.2 "><p id="p1117110418570"><a name="p1117110418570"></a><a name="p1117110418570"></a>RtcReadReg</p>
</td>
<td class="cellrowborder" valign="top" width="53.11531153115312%" headers="mcps1.2.4.1.3 "><p id="p1517114410578"><a name="p1517114410578"></a><a name="p1517114410578"></a>Reads the configuration of a custom RTC register based on the register index.</p>
</td>
</tr>
<tr id="row46738190576"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1567331910573"><a name="p1567331910573"></a><a name="p1567331910573"></a>RtcWriteReg</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1967391913576"><a name="p1967391913576"></a><a name="p1967391913576"></a>Writes the configuration of a custom RTC register based on the register index.</p>
</td>
</tr>
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>All functions provided in this document can be called only in kernel mode.
## Usage Guidelines<a name="section20636145604113"></a>
### How to Use<a name="section16919828134215"></a>
During the OS startup, the HDF loads the RTC driver based on the configuration file. The RTC driver detects the RTC component and initializes the driver.
The figure below illustrates how to use the APIs.
**Figure 1** Process of using an RTC device
![](figures/using-rtc-process.png "process-of-using-an-rtc-device")
### Opening the RTC Device Handle<a name="section1131212144310"></a>
After the RTC driver is loaded, you can use the API provided by the HDF and call APIs of the RTC driver.
>![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>Currently, only one RTC device is supported in the OS.
DevHandle RtcOpen\(void\);
**Table 2** Description of RtcOpen
<a name="table1380712985611"></a>
<table><tbody><tr id="row580722985616"><td class="cellrowborder" valign="top" width="21.45%"><p id="p1280722911565"><a name="p1280722911565"></a><a name="p1280722911565"></a><strong id="b748651620573"><a name="b748651620573"></a><a name="b748651620573"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.55%"><p id="p5807112965618"><a name="p5807112965618"></a><a name="p5807112965618"></a><strong id="b08682171578"><a name="b08682171578"></a><a name="b08682171578"></a>Description</strong></p>
</td>
</tr>
<tr id="row17807112935611"><td class="cellrowborder" valign="top" width="21.45%"><p id="p13807132915565"><a name="p13807132915565"></a><a name="p13807132915565"></a>void</p>
</td>
<td class="cellrowborder" valign="top" width="78.55%"><p id="p15807429185612"><a name="p15807429185612"></a><a name="p15807429185612"></a>NA</p>
</td>
</tr>
<tr id="row1980782911567"><td class="cellrowborder" valign="top" width="21.45%"><p id="p0807529165613"><a name="p0807529165613"></a><a name="p0807529165613"></a><strong id="b086691895718"><a name="b086691895718"></a><a name="b086691895718"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.55%"><p id="p9808162935612"><a name="p9808162935612"></a><a name="p9808162935612"></a><strong id="b6676151975710"><a name="b6676151975710"></a><a name="b6676151975710"></a>Description</strong></p>
</td>
</tr>
<tr id="row2808192935615"><td class="cellrowborder" valign="top" width="21.45%"><p id="p380852915567"><a name="p380852915567"></a><a name="p380852915567"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="78.55%"><p id="p26881319114110"><a name="p26881319114110"></a><a name="p26881319114110"></a>The operation is successful.</p>
</td>
</tr>
<tr id="row4808142945615"><td class="cellrowborder" valign="top" width="21.45%"><p id="p188084291561"><a name="p188084291561"></a><a name="p188084291561"></a>NULL</p>
</td>
<td class="cellrowborder" valign="top" width="78.55%"><p id="p780852912566"><a name="p780852912566"></a><a name="p780852912566"></a>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
# RTC
## Overview
The real-time clock (RTC) provides precise real time for the operating system (OS) and scheduled alarming function. When the device is powered off, the RTC can accurately keep track of the system time using an auxiliary battery. The RTC regulates time with the use of a crystal oscillator.
## Available APIs
**Table 1** RTC APIs
| Category| Description|
| -------- | -------- |
| RTC handle| **RtcOpen**: Opens the RTC device to obtain its handle.<br>**RtcClose**: Closes the RTC device handle.|
| RTC time| **RtcReadTime**: reads the RTC time information, which includes the year, month, day, day of week, hour, minute, second, and millisecond.<br>**RtcWriteTime**: writes the RTC time, including the year, month, day, day of week, hour, minute, second, and millisecond.|
| RTC alarm| **RtcReadAlarm**: reads the RTC alarm time.<br>**RtcWriteAlarm**: writes the RTC alarm time.<br>**RtcRegisterAlarmCallback**: registers a callback to be invoked when an alarm is not generated at the specified time.<br>**RtcAlarmInterruptEnable**: enables or disables interrupts for an RTC alarm.|
| RTC configuration| **RtcGetFreq**: obtains the frequency of the external crystal oscillator connected to the RTC driver.<br>**RtcSetFreq**: sets the frequency of the external crystal oscillator connected to the RTC driver.<br>**RtcReset**: resets the RTC.|
| Custom register| **RtcReadReg**: reads a custom register.<br>**RtcWriteReg**: writes a custom register.|
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> All APIs described in this document can be called only in kernel mode.
## Usage Guidelines
### How to Use
During the OS startup, the HDF loads the RTC driver based on the configuration file. The RTC driver detects the RTC device and initializes the driver.
The figure below illustrates the general development process of an RTC device.
**Figure 1** Using the RTC APIs
![image](figures/using-RTC-process.png "Using RTC APIs")
### Opening the RTC Device Handle
After the RTC driver is loaded, the API provided by the HDF is called to invoke the APIs of the RTC driver.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> Only one RTC device is supported in the OS.
```c
DevHandle RtcOpen(void);
```
**Table 2** Description of RtcOpen
| **Parameter**| **Description**|
| -------- | -------- |
| void | NA |
| **Return Value**| **Description**|
| handle | The operation is successful.|
| NULL | The operation failed.|
```
DevHandle handle = NULL;
/* Obtain the RTC device handle. */
/* Open the RTC device handle. */
handle = RtcOpen();
if (handle == NULL) {
/* Process the error. */
/* Error handling. */
}
```
### Releasing the RTC Device Handle<a name="section10744117144314"></a>
You can call **RtcClose()** function to release the RTC device handle, thereby releasing resources of the device.
### Closing the RTC Device Handle
Call **RtcClose()** to release the resources used by the RTC device.
```c
void RtcClose(DevHandle handle);
```
void RtcClose\(DevHandle handle\);
**Table 3** Description of RtcClose
**Table 3** Description of RtcClose
| **Parameter**| **Description**|
| -------- | -------- |
| handle | RTC device handle to close.|
<a name="table37525421510"></a>
<table><tbody><tr id="row10752134216114"><td class="cellrowborder" valign="top" width="21.45%"><p id="p1075217421019"><a name="p1075217421019"></a><a name="p1075217421019"></a><strong id="b229461765710"><a name="b229461765710"></a><a name="b229461765710"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.55%"><p id="p117531421411"><a name="p117531421411"></a><a name="p117531421411"></a><strong id="b2038421875712"><a name="b2038421875712"></a><a name="b2038421875712"></a>Description</strong></p>
</td>
</tr>
<tr id="row57531442914"><td class="cellrowborder" valign="top" width="21.45%"><p id="p8753164210119"><a name="p8753164210119"></a><a name="p8753164210119"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="78.55%"><p id="p17533425113"><a name="p17533425113"></a><a name="p17533425113"></a>RTC device handle.</p>
</td>
</tr>
</tbody>
</table>
```
/* Release the RTC device handle. */
/* Close the RTC device handle. */
RtcClose(handle);
```
### Registering RtcAlarmCallback
After the OS is started, call the following function to register **RtcAlarmCallback**, which will be invoked when an alarm is generated at the specified time:
int32\_t RtcRegisterAlarmCallback\(DevHandle handle, enum RtcAlarmIndex alarmIndex, RtcAlarmCallback cb\);
**Table 4** Description of RtcRegisterAlarmCallback
<a name="table7603619123820"></a>
<table><thead align="left"><tr id="row1060351914386"><th class="cellrowborder" valign="top" width="21.36%" id="mcps1.2.3.1.1"><p id="p14603181917382"><a name="p14603181917382"></a><a name="p14603181917382"></a><strong id="b4295161718571"><a name="b4295161718571"></a><a name="b4295161718571"></a>Parameter</strong></p>
</th>
<th class="cellrowborder" valign="top" width="78.64%" id="mcps1.2.3.1.2"><p id="p36031519183819"><a name="p36031519183819"></a><a name="p36031519183819"></a><strong id="b43851218195716"><a name="b43851218195716"></a><a name="b43851218195716"></a>Description</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="row1181618191115"><td class="cellrowborder" valign="top" width="21.36%" headers="mcps1.2.3.1.1 "><p id="p131811218131116"><a name="p131811218131116"></a><a name="p131811218131116"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%" headers="mcps1.2.3.1.2 "><p id="p6181191851111"><a name="p6181191851111"></a><a name="p6181191851111"></a>RTC device handle.</p>
</td>
</tr>
<tr id="row960361918383"><td class="cellrowborder" valign="top" width="21.36%" headers="mcps1.2.3.1.1 "><p id="p1775535165418"><a name="p1775535165418"></a><a name="p1775535165418"></a>alarmIndex</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%" headers="mcps1.2.3.1.2 "><p id="p137551851185412"><a name="p137551851185412"></a><a name="p137551851185412"></a>Alarm index.</p>
</td>
</tr>
<tr id="row1960431983813"><td class="cellrowborder" valign="top" width="21.36%" headers="mcps1.2.3.1.1 "><p id="p3604719123817"><a name="p3604719123817"></a><a name="p3604719123817"></a>cb</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%" headers="mcps1.2.3.1.2 "><p id="p1560441923818"><a name="p1560441923818"></a><a name="p1560441923818"></a>Callback that will be invoked when an alarm is generated at the specified time.</p>
</td>
</tr>
<tr id="row11410612183019"><td class="cellrowborder" valign="top" width="21.36%" headers="mcps1.2.3.1.1 "><p id="p460381915385"><a name="p460381915385"></a><a name="p460381915385"></a><strong id="b132291719185715"><a name="b132291719185715"></a><a name="b132291719185715"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.64%" headers="mcps1.2.3.1.2 "><p id="p96031619153812"><a name="p96031619153812"></a><a name="p96031619153812"></a><strong id="b5130182016576"><a name="b5130182016576"></a><a name="b5130182016576"></a>Description</strong></p>
</td>
</tr>
<tr id="row15410111273017"><td class="cellrowborder" valign="top" width="21.36%" headers="mcps1.2.3.1.1 "><p id="p133081510112813"><a name="p133081510112813"></a><a name="p133081510112813"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%" headers="mcps1.2.3.1.2 "><p id="p530813107289"><a name="p530813107289"></a><a name="p530813107289"></a>The operation is successful.</p>
</td>
</tr>
<tr id="row1241081213303"><td class="cellrowborder" valign="top" width="21.36%" headers="mcps1.2.3.1.1 "><p id="p1123362173010"><a name="p1123362173010"></a><a name="p1123362173010"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%" headers="mcps1.2.3.1.2 "><p id="p1723362153010"><a name="p1723362153010"></a><a name="p1723362153010"></a>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
The following is an example of registering **RtcAlarmCallback** for processing alarm **RTC\_ALARM\_INDEX\_A**:
```
/* Register an RTC alarm callback. */
### Registering an Alarm Callback
Call **RtcRegisterAlarmCallback** to register a callback, which will be invoked when the specified alarm is not generated at the specified time.
```c
int32_t RtcRegisterAlarmCallback(DevHandle handle, enum RtcAlarmIndex alarmIndex, RtcAlarmCallback cb);
```
**Table 4** Description of RtcRegisterAlarmCallback
| **Parameter**| **Description**|
| -------- | -------- |
| handle | RTC device handle.|
| alarmIndex | Alarm index.|
| cb | Callback to be invoked when the alarm is not generated at the specified time.|
| **Return Value**| **Description**|
| 0 | The operation is successful.|
| Negative value| The operation failed.|
The following is an example of registering a callback for processing alarm RTC_ALARM_INDEX_A:
```
/* Register a callback for alarm RTC_ALARM_INDEX_A. */
int32_t RtcAlarmACallback(enum RtcAlarmIndex alarmIndex)
{
if (alarmIndex == RTC_ALARM_INDEX_A) {
/* Process alarm A. */
/* Processing of alarm A. */
} else if (alarmIndex == RTC_ALARM_INDEX_B) {
/* Process alarm B. */
/* Processing of alarm B. */
} else {
/* Process the error. */
/* Error handling. */
}
return 0;
}
int32_t ret;
/* Register RtcAlarmCallback for alarm A. */
/* Register a callback to be invoked when alarm A is not generated at the specified time. */
ret = RtcRegisterAlarmCallback(handle, RTC_ALARM_INDEX_A, RtcAlarmACallback);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
```
### Performing RTC-related Operations
- Reading RTC time
Call the **RtcReadTime()** function to read time information from the RTC driver, including the year, month, the day of the week, day, hour, minute, second, and millisecond.
int32\_t RtcReadTime\(DevHandle handle, struct RtcTime \*time\);
**Table 5** Description of RtcReadTime
<a name="table1018490043"></a>
<table><tbody><tr id="row31848013417"><td class="cellrowborder" valign="top" width="21.45%"><p id="p1415816132411"><a name="p1415816132411"></a><a name="p1415816132411"></a><strong id="b10296717125710"><a name="b10296717125710"></a><a name="b10296717125710"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.55%"><p id="p11158111316410"><a name="p11158111316410"></a><a name="p11158111316410"></a><strong id="b33873181576"><a name="b33873181576"></a><a name="b33873181576"></a>Description</strong></p>
</td>
</tr>
<tr id="row1246615200297"><td class="cellrowborder" valign="top" width="21.45%"><p id="p188871821142917"><a name="p188871821142917"></a><a name="p188871821142917"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="78.55%"><p id="p1788742182910"><a name="p1788742182910"></a><a name="p1788742182910"></a>RTC device handle.</p>
</td>
</tr>
<tr id="row10184701945"><td class="cellrowborder" valign="top" width="21.45%"><p id="p104891871157"><a name="p104891871157"></a><a name="p104891871157"></a>time</p>
</td>
<td class="cellrowborder" valign="top" width="78.55%"><p id="p204891671156"><a name="p204891671156"></a><a name="p204891671156"></a>Pointer to the time information read from the RTC driver. The time information includes the year, month, the day of the week, day, hour, minute, second, and millisecond.</p>
</td>
</tr>
<tr id="row17393154515328"><td class="cellrowborder" valign="top" width="21.45%"><p id="p8158313248"><a name="p8158313248"></a><a name="p8158313248"></a><strong id="b162312198575"><a name="b162312198575"></a><a name="b162312198575"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.55%"><p id="p161591413741"><a name="p161591413741"></a><a name="p161591413741"></a><strong id="b3131220165711"><a name="b3131220165711"></a><a name="b3131220165711"></a>Description</strong></p>
</td>
</tr>
<tr id="row339324593215"><td class="cellrowborder" valign="top" width="21.45%"><p id="p139599615287"><a name="p139599615287"></a><a name="p139599615287"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="78.55%"><p id="p1895911611284"><a name="p1895911611284"></a><a name="p1895911611284"></a>The operation is successful.</p>
</td>
</tr>
<tr id="row15393184519323"><td class="cellrowborder" valign="top" width="21.45%"><p id="p13521182309"><a name="p13521182309"></a><a name="p13521182309"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="78.55%"><p id="p1035216186309"><a name="p1035216186309"></a><a name="p1035216186309"></a>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
- Reading the RTC time
Call **RtcReadTime()** to obtain the RTC time, which includes the year, month, day, day of week, hour, minute, second, and millisecond.
```c
int32_t RtcReadTime(DevHandle handle, struct RtcTime *time);
```
**Table 5** Description of RtcReadTime
| **Parameter**| **Description**|
| -------- | -------- |
| handle | RTC device handle. |
| time | RTC time information, which includes the year, month, day, day of the week, hour, minute, second, and millisecond.|
| **Return Value**| **Description** |
| 0 | The operation is successful. |
| Negative value | The operation failed. |
```
int32_t ret;
struct RtcTime tm;
/* Read time information from the RTC driver. */
/* Read RTC time from the RTC driver. */
ret = RtcReadTime(handle, &tm);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
```
- Setting RTC time
Call the **RtcWriteTime()** function to set the RTC time.
int32\_t RtcWriteTime\(DevHandle handle, struct RtcTime \*time\);
**Table 6** Description of RtcWriteTime
<a name="table223910318361"></a>
<table><tbody><tr id="row924033173613"><td class="cellrowborder" valign="top" width="21.54%"><p id="p16240143143611"><a name="p16240143143611"></a><a name="p16240143143611"></a><strong id="b17297111720576"><a name="b17297111720576"></a><a name="b17297111720576"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.46%"><p id="p32401031113610"><a name="p32401031113610"></a><a name="p32401031113610"></a><strong id="b11388191825715"><a name="b11388191825715"></a><a name="b11388191825715"></a>Description</strong></p>
</td>
</tr>
<tr id="row148011248153018"><td class="cellrowborder" valign="top" width="21.54%"><p id="p189641849113018"><a name="p189641849113018"></a><a name="p189641849113018"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="78.46%"><p id="p20964249123013"><a name="p20964249123013"></a><a name="p20964249123013"></a>RTC device handle.</p>
</td>
</tr>
<tr id="row024043193619"><td class="cellrowborder" valign="top" width="21.54%"><p id="p157679281384"><a name="p157679281384"></a><a name="p157679281384"></a>time</p>
</td>
<td class="cellrowborder" valign="top" width="78.46%"><p id="p167675286381"><a name="p167675286381"></a><a name="p167675286381"></a>Pointer to the time information written into the RTC driver. The time information includes the year, month, the day of the week, day, hour, minute, second, and millisecond.</p>
</td>
</tr>
<tr id="row424093120369"><td class="cellrowborder" valign="top" width="21.54%"><p id="p1240143114366"><a name="p1240143114366"></a><a name="p1240143114366"></a><strong id="b1023212194579"><a name="b1023212194579"></a><a name="b1023212194579"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.46%"><p id="p18241173133619"><a name="p18241173133619"></a><a name="p18241173133619"></a><strong id="b18132142035712"><a name="b18132142035712"></a><a name="b18132142035712"></a>Description</strong></p>
</td>
</tr>
<tr id="row18241531153610"><td class="cellrowborder" valign="top" width="21.54%"><p id="p8550174182810"><a name="p8550174182810"></a><a name="p8550174182810"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="78.46%"><p id="p145503417284"><a name="p145503417284"></a><a name="p145503417284"></a>The operation is successful.</p>
</td>
</tr>
<tr id="row024153123616"><td class="cellrowborder" valign="top" width="21.54%"><p id="p5602191619300"><a name="p5602191619300"></a><a name="p5602191619300"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="78.46%"><p id="p12602131643015"><a name="p12602131643015"></a><a name="p12602131643015"></a>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>The RTC start time is 1970/01/01 Thursday 00:00:00 \(UTC\). The maximum value of **year** must be set based on the requirements specified in the product manual of the in-use component. You do not need to configure the day of the week.
- Setting the RTC time
Call **RtcWriteTime()** to set the RTC time.
```c
int32_t RtcWriteTime(DevHandle handle, struct RtcTime *time);
```
**Table 6** Description of RtcWriteTime
| **Parameter**| **Description**|
| -------- | -------- |
| handle | RTC device handle.|
| time | RTC time to set, which includes the year, month, day, day of the week, hour, minute, second, and millisecond.|
| **Return Value**| **Description**|
| 0 | The operation is successful.|
| Negative value| The operation failed.|
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> The RTC start time is 1970/01/01 Thursday 00:00:00 (UTC). The maximum value of **year** must be set based on the requirements specified in the manual of the device you use. You do not need to set the day of week.
```
int32_t ret;
......@@ -370,120 +198,66 @@ tm.hour= 00;
tm.minute = 59;
tm.second = 00;
tm.millisecond = 0;
/* Write the RTC time information. */
/* Write the RTC time. */
ret = RtcWriteTime(handle, &tm);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
```
- Reading the RTC alarm time
Call the **RtcReadAlarm()** function to read the alarm time.
int32\_t RtcReadAlarm\(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct RtcTime \*time\);
**Table 7** Description of RtcReadAlarm
<a name="table11342203111420"></a>
<table><tbody><tr id="row133429310140"><td class="cellrowborder" valign="top" width="21.54%"><p id="p9886411201416"><a name="p9886411201416"></a><a name="p9886411201416"></a><strong id="b152971517185720"><a name="b152971517185720"></a><a name="b152971517185720"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.46%"><p id="p2886411171417"><a name="p2886411171417"></a><a name="p2886411171417"></a><strong id="b4389418135718"><a name="b4389418135718"></a><a name="b4389418135718"></a>Description</strong></p>
</td>
</tr>
<tr id="row13835647114113"><td class="cellrowborder" valign="top" width="21.54%"><p id="p1183011486412"><a name="p1183011486412"></a><a name="p1183011486412"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="78.46%"><p id="p1583074815413"><a name="p1583074815413"></a><a name="p1583074815413"></a>RTC device handle.</p>
</td>
</tr>
<tr id="row113439391410"><td class="cellrowborder" valign="top" width="21.54%"><p id="p132281120194318"><a name="p132281120194318"></a><a name="p132281120194318"></a>alarmIndex</p>
</td>
<td class="cellrowborder" valign="top" width="78.46%"><p id="p1022852034315"><a name="p1022852034315"></a><a name="p1022852034315"></a>Alarm index.</p>
</td>
</tr>
<tr id="row193431836147"><td class="cellrowborder" valign="top" width="21.54%"><p id="p1926195164011"><a name="p1926195164011"></a><a name="p1926195164011"></a>time</p>
</td>
<td class="cellrowborder" valign="top" width="78.46%"><p id="p112695144013"><a name="p112695144013"></a><a name="p112695144013"></a>Pointer to the RTC alarm time information. The time information includes the year, month, the day of the week, day, hour, minute, second, and millisecond.</p>
</td>
</tr>
<tr id="row43438361419"><td class="cellrowborder" valign="top" width="21.54%"><p id="p388715117143"><a name="p388715117143"></a><a name="p388715117143"></a><strong id="b14234111985715"><a name="b14234111985715"></a><a name="b14234111985715"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.46%"><p id="p088719117143"><a name="p088719117143"></a><a name="p088719117143"></a><strong id="b413222011570"><a name="b413222011570"></a><a name="b413222011570"></a>Description</strong></p>
</td>
</tr>
<tr id="row17169595467"><td class="cellrowborder" valign="top" width="21.54%"><p id="p107751111283"><a name="p107751111283"></a><a name="p107751111283"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="78.46%"><p id="p87751917289"><a name="p87751917289"></a><a name="p87751917289"></a>The operation is successful.</p>
</td>
</tr>
<tr id="row016911915461"><td class="cellrowborder" valign="top" width="21.54%"><p id="p6833213133013"><a name="p6833213133013"></a><a name="p6833213133013"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="78.46%"><p id="p168341213143015"><a name="p168341213143015"></a><a name="p168341213143015"></a>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
- Reading the RTC alarm time
Call **RtcReadAlarm()** to obtain the RTC alarm time.
```c
int32_t RtcReadAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct RtcTime *time);
```
**Table 7** Description of RtcReadAlarm
| **Parameter**| **Description**|
| -------- | -------- |
| handle | RTC device handle.|
| alarmIndex | Alarm index.|
| time | RTC alarm time information, which includes the year, month, day, day of the week, hour, minute, second, and millisecond.|
| **Return Value**| **Description**|
| 0 | The operation is successful.|
| Negative value | The operation failed.|
```
int32_t ret;
struct RtcTime alarmTime;
/* Read the RTC alarm time information of alarm RTC_ALARM_INDEX_A. */
/* Read the RTC alarm time of alarm RTC_ALARM_INDEX_A. */
ret = RtcReadAlarm(handle, RTC_ALARM_INDEX_A, &alarmTime);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
```
- Setting RTC alarm time
Call the **RtcWriteAlarm()** function to set the RTC alarm time based on the alarm index.
int32\_t RtcWriteAlarm\(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct RtcTime \*time\);
**Table 8** Description of RtcWriteAlarm
<a name="table107922162179"></a>
<table><tbody><tr id="row14793316131710"><td class="cellrowborder" valign="top" width="21.62%"><p id="p1891718412183"><a name="p1891718412183"></a><a name="p1891718412183"></a><strong id="b029811725716"><a name="b029811725716"></a><a name="b029811725716"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p891712461814"><a name="p891712461814"></a><a name="p891712461814"></a><strong id="b1339017181576"><a name="b1339017181576"></a><a name="b1339017181576"></a>Description</strong></p>
</td>
</tr>
<tr id="row18419611133117"><td class="cellrowborder" valign="top" width="21.62%"><p id="p075881210314"><a name="p075881210314"></a><a name="p075881210314"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p975811215317"><a name="p975811215317"></a><a name="p975811215317"></a>RTC device handle.</p>
</td>
</tr>
<tr id="row11793151613176"><td class="cellrowborder" valign="top" width="21.62%"><p id="p562522145215"><a name="p562522145215"></a><a name="p562522145215"></a>alarmIndex</p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p126257215217"><a name="p126257215217"></a><a name="p126257215217"></a>Alarm index.</p>
</td>
</tr>
<tr id="row37932016201720"><td class="cellrowborder" valign="top" width="21.62%"><p id="p26269212527"><a name="p26269212527"></a><a name="p26269212527"></a>time</p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p462602125211"><a name="p462602125211"></a><a name="p462602125211"></a>Pointer to the RTC alarm time information. The time information includes the year, month, the day of the week, day, hour, minute, second, and millisecond.</p>
</td>
</tr>
<tr id="row586915225485"><td class="cellrowborder" valign="top" width="21.62%"><p id="p591712441810"><a name="p591712441810"></a><a name="p591712441810"></a><strong id="b1923501915574"><a name="b1923501915574"></a><a name="b1923501915574"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p1591720461810"><a name="p1591720461810"></a><a name="p1591720461810"></a><strong id="b8133152014571"><a name="b8133152014571"></a><a name="b8133152014571"></a>Description</strong></p>
</td>
</tr>
<tr id="row19869122210483"><td class="cellrowborder" valign="top" width="21.62%"><p id="p10798105812717"><a name="p10798105812717"></a><a name="p10798105812717"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p1179817586276"><a name="p1179817586276"></a><a name="p1179817586276"></a>The operation is successful.</p>
</td>
</tr>
<tr id="row1686918225483"><td class="cellrowborder" valign="top" width="21.62%"><p id="p16246181033012"><a name="p16246181033012"></a><a name="p16246181033012"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p3246111019309"><a name="p3246111019309"></a><a name="p3246111019309"></a>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **NOTE**<br>
>The RTC start time is 1970/01/01 Thursday 00:00:00 \(UTC\). The maximum value of **year** must be set based on the requirements specified in the product manual of the in-use component. You do not need to configure the day of the week.
- Setting the RTC alarm time
Call **RtcWriteAlarm()** to set the RTC alarm time based on the alarm index.
```c
int32_t RtcWriteAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct RtcTime *time);
```
**Table 8** Description of RtcWriteAlarm
| **Parameter**| **Description**|
| -------- | -------- |
| handle | RTC device handle.|
| alarmIndex | Alarm index.|
| time | RTC alarm time to set, which includes the year, month, day, day of the week, hour, minute, second, and millisecond.|
| **Return Value**| **Description**|
| 0 | The operation is successful.|
| Negative value| The operation failed.|
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> The RTC start time is 1970/01/01 Thursday 00:00:00 (UTC). The maximum value of **year** must be set based on the requirements specified in the manual of the device you use. You do not need to set the day of week.
```
int32_t ret;
......@@ -500,361 +274,220 @@ alarmTime.millisecond = 0;
/* Set the alarm time of alarm RTC_ALARM_INDEX_A. */
ret = RtcWriteAlarm(handle, RTC_ALARM_INDEX_A, &alarmTime);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
```
- Enabling or disabling alarm interrupts
Before performing alarm operations, use the **RtcAlarmInterruptEnable()** function to enable alarm interrupts, so that **RtcAlarmCallback** will be called when the alarm is not generated upon a timeout.
int32\_t RtcAlarmInterruptEnable\(DevHandle handle, enum RtcAlarmIndex alarmIndex, uint8\_t enable\);
**Table 9** Description of RtcAlarmInterruptEnable
<a name="table1934615314159"></a>
<table><tbody><tr id="row5346853171519"><td class="cellrowborder" valign="top" width="21.36%"><p id="p143464533153"><a name="p143464533153"></a><a name="p143464533153"></a><strong id="b829913171576"><a name="b829913171576"></a><a name="b829913171576"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p113461853171514"><a name="p113461853171514"></a><a name="p113461853171514"></a><strong id="b9391318185714"><a name="b9391318185714"></a><a name="b9391318185714"></a>Description</strong></p>
</td>
</tr>
<tr id="row2125652144213"><td class="cellrowborder" valign="top" width="21.36%"><p id="p3150105313422"><a name="p3150105313422"></a><a name="p3150105313422"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p9151653144212"><a name="p9151653144212"></a><a name="p9151653144212"></a>RTC device handle.</p>
</td>
</tr>
<tr id="row153794518293"><td class="cellrowborder" valign="top" width="21.36%"><p id="p4259165518294"><a name="p4259165518294"></a><a name="p4259165518294"></a>alarmIndex</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p725985522917"><a name="p725985522917"></a><a name="p725985522917"></a>Alarm index.</p>
</td>
</tr>
<tr id="row19346653141518"><td class="cellrowborder" valign="top" width="21.36%"><p id="p6346253101516"><a name="p6346253101516"></a><a name="p6346253101516"></a>enable</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p234655341511"><a name="p234655341511"></a><a name="p234655341511"></a>Whether to enable RTC alarm interrupts. The value <strong id="b879021119010"><a name="b879021119010"></a><a name="b879021119010"></a>1</strong> means to enable alarm interrupts and <strong id="b779617111204"><a name="b779617111204"></a><a name="b779617111204"></a>0</strong> means to disable alarm interrupts.</p>
</td>
</tr>
<tr id="row18346953111513"><td class="cellrowborder" valign="top" width="21.36%"><p id="p53460537156"><a name="p53460537156"></a><a name="p53460537156"></a><strong id="b1023631919578"><a name="b1023631919578"></a><a name="b1023631919578"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p4346153171510"><a name="p4346153171510"></a><a name="p4346153171510"></a><strong id="b7134132075718"><a name="b7134132075718"></a><a name="b7134132075718"></a>Description</strong></p>
</td>
</tr>
<tr id="row1234685314151"><td class="cellrowborder" valign="top" width="21.36%"><p id="p8947195310279"><a name="p8947195310279"></a><a name="p8947195310279"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p99471953152712"><a name="p99471953152712"></a><a name="p99471953152712"></a>The operation is successful.</p>
</td>
</tr>
<tr id="row2347115321514"><td class="cellrowborder" valign="top" width="21.36%"><p id="p324855163018"><a name="p324855163018"></a><a name="p324855163018"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p7248857302"><a name="p7248857302"></a><a name="p7248857302"></a>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
- Enabling or disabling alarm interrupts
Call **RtcAlarmInterruptEnable** to enable interrupts for an RTC alarm so that the registered callback can be invoked when the alarm is not generated at the specified time.
```c
int32_t RtcAlarmInterruptEnable(DevHandle handle, enum RtcAlarmIndex alarmIndex, uint8_t enable);
```
**Table 9** Description of RtcAlarmInterruptEnable
| **Parameter**| **Description**|
| -------- | -------- |
| handle | RTC device handle.|
| alarmIndex | Alarm index.|
| enable | Whether to enable RTC alarm interrupts. The value **1** means to enable interrupts and **0** means to disable interrupts.|
| **Return Value**| **Description**|
| 0 | The operation is successful.|
| Negative value| The operation failed.|
```
int32_t ret;
/* Enable the RTC alarm interrupts. */
/* Enable interrupts for an RTC alarm. */
ret = RtcAlarmInterruptEnable(handle, RTC_ALARM_INDEX_A, 1);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
```
- Reading RTC external frequency
Call the **RtcGetFreq()** function to read the frequency of the external crystal oscillator connected to the RTC driver.
int32\_t RtcGetFreq\(DevHandle handle, uint32\_t \*freq\);
**Table 10** Description of RtcGetFreq
<a name="table125881625185"></a>
<table><tbody><tr id="row1458811241816"><td class="cellrowborder" valign="top" width="21.36%"><p id="p658820241813"><a name="p658820241813"></a><a name="p658820241813"></a><strong id="b3300217175712"><a name="b3300217175712"></a><a name="b3300217175712"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p758812261820"><a name="p758812261820"></a><a name="p758812261820"></a><strong id="b33921718195713"><a name="b33921718195713"></a><a name="b33921718195713"></a>Description</strong></p>
</td>
</tr>
<tr id="row831259124219"><td class="cellrowborder" valign="top" width="21.36%"><p id="p171541407431"><a name="p171541407431"></a><a name="p171541407431"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p715413094314"><a name="p715413094314"></a><a name="p715413094314"></a>RTC device handle.</p>
</td>
</tr>
<tr id="row1358842171820"><td class="cellrowborder" valign="top" width="21.36%"><p id="p258814210188"><a name="p258814210188"></a><a name="p258814210188"></a>freq</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p165888211810"><a name="p165888211810"></a><a name="p165888211810"></a>Pointer to the frequency to set for the external crystal oscillator, in Hz.</p>
</td>
</tr>
<tr id="row2058818281817"><td class="cellrowborder" valign="top" width="21.36%"><p id="p458872151810"><a name="p458872151810"></a><a name="p458872151810"></a><strong id="b223851915718"><a name="b223851915718"></a><a name="b223851915718"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p155880251819"><a name="p155880251819"></a><a name="p155880251819"></a><strong id="b0135182045715"><a name="b0135182045715"></a><a name="b0135182045715"></a>Description</strong></p>
</td>
</tr>
<tr id="row35883213183"><td class="cellrowborder" valign="top" width="21.36%"><p id="p8133145211272"><a name="p8133145211272"></a><a name="p8133145211272"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p13133352202719"><a name="p13133352202719"></a><a name="p13133352202719"></a>The operation is successful.</p>
</td>
</tr>
<tr id="row135892261811"><td class="cellrowborder" valign="top" width="21.36%"><p id="p152692538292"><a name="p152692538292"></a><a name="p152692538292"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p327015313294"><a name="p327015313294"></a><a name="p327015313294"></a>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
- Obtaining the RTC external frequency
Call **RtcGetFreq()** to obtain the frequency of the external crystal oscillator connected to the RTC driver.
```c
int32_t RtcGetFreq(DevHandle handle, uint32_t \*freq);
```
**Table 10** Description of RtcGetFreq
| **Parameter**| **Description**|
| -------- | -------- |
| handle | RTC device handle.|
| freq | Pointer to the frequency of the external crystal oscillator, in Hz.|
| **Return Value**| **Description**|
| 0 | The operation is successful.|
| Negative value| The operation failed.|
```
int32_t ret;
uint32_t freq = 0;
/* Read frequency of the external crystal oscillator connected to the RTC driver */
/* Obtain the frequency of the external crystal oscillator connected to the RTC driver. */
ret = RtcGetFreq(handle, &freq);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
```
- Setting the frequency of the external crystal oscillator connected to the RTC driver
Call the **RtcSetFreq()** function to set the frequency of the external crystal oscillator connected to the RTC driver.
int32\_t RtcSetFreq\(DevHandle handle, uint32\_t freq\);
**Table 11** Description of RtcSetFreq
<a name="table1170124316209"></a>
<table><tbody><tr id="row270119432202"><td class="cellrowborder" valign="top" width="21.36%"><p id="p127011343132010"><a name="p127011343132010"></a><a name="p127011343132010"></a><strong id="b130031711578"><a name="b130031711578"></a><a name="b130031711578"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p7701184372013"><a name="p7701184372013"></a><a name="p7701184372013"></a><strong id="b153942183570"><a name="b153942183570"></a><a name="b153942183570"></a>Description</strong></p>
</td>
</tr>
<tr id="row36067554319"><td class="cellrowborder" valign="top" width="21.36%"><p id="p881511716433"><a name="p881511716433"></a><a name="p881511716433"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p188157714432"><a name="p188157714432"></a><a name="p188157714432"></a>RTC device handle.</p>
</td>
</tr>
<tr id="row127019437204"><td class="cellrowborder" valign="top" width="21.36%"><p id="p27019438207"><a name="p27019438207"></a><a name="p27019438207"></a>freq</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p167021043182011"><a name="p167021043182011"></a><a name="p167021043182011"></a>Frequency to set for the external crystal oscillator, in Hz</p>
</td>
</tr>
<tr id="row97022434205"><td class="cellrowborder" valign="top" width="21.36%"><p id="p1770218431208"><a name="p1770218431208"></a><a name="p1770218431208"></a><strong id="b18239121916575"><a name="b18239121916575"></a><a name="b18239121916575"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p1170217432201"><a name="p1170217432201"></a><a name="p1170217432201"></a><strong id="b161361720205713"><a name="b161361720205713"></a><a name="b161361720205713"></a>Description</strong></p>
</td>
</tr>
<tr id="row1670212432206"><td class="cellrowborder" valign="top" width="21.36%"><p id="p77021543152017"><a name="p77021543152017"></a><a name="p77021543152017"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p770214310209"><a name="p770214310209"></a><a name="p770214310209"></a>The operation is successful.</p>
</td>
</tr>
<tr id="row10702194313201"><td class="cellrowborder" valign="top" width="21.36%"><p id="p165182216306"><a name="p165182216306"></a><a name="p165182216306"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p651815219302"><a name="p651815219302"></a><a name="p651815219302"></a>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
- Setting the RTC external frequency
Call **RtcSetFreq()** to set the frequency of the external crystal oscillator connected to the RTC driver.
```c
int32_t RtcSetFreq(DevHandle handle, uint32_t freq);
```
**Table 11** Description of RtcSetFreq
| **Parameter**| **Description**|
| -------- | -------- |
| handle | RTC device handle.|
| freq | Pointer to the frequency to set for the external crystal oscillator, in Hz.|
| **Return Value**| **Description**|
| 0 | The operation is successful.|
| Negative value| The operation failed.|
```
int32_t ret;
uint32_t freq = 32768; /* 32768 Hz */
/* Set the frequency of the external crystal oscillator. Note that the frequency must be configured in accordance with the requirements specified in the product manual of the in-use component. */
/* Set the frequency of the external crystal oscillator based on the requirements specified in the manual of the device you use. */
ret = RtcSetFreq(handle, freq);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
```
- Resetting the RTC driver
Call the **RtcReset()** function to perform a reset on the RTC driver \(after the reset, the registers are restored to the default values\).
int32\_t RtcReset\(DevHandle handle\);
**Table 12** Description of RtcReset
<a name="table398973152517"></a>
<table><tbody><tr id="row179899311254"><td class="cellrowborder" valign="top" width="21.36%"><p id="p199899314257"><a name="p199899314257"></a><a name="p199899314257"></a><strong id="b1330101719577"><a name="b1330101719577"></a><a name="b1330101719577"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p179897315257"><a name="p179897315257"></a><a name="p179897315257"></a><strong id="b9395318115714"><a name="b9395318115714"></a><a name="b9395318115714"></a>Description</strong></p>
</td>
</tr>
<tr id="row14989113118257"><td class="cellrowborder" valign="top" width="21.36%"><p id="p129018136436"><a name="p129018136436"></a><a name="p129018136436"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p290111304310"><a name="p290111304310"></a><a name="p290111304310"></a>RTC device handle.</p>
</td>
</tr>
<tr id="row7989123111254"><td class="cellrowborder" valign="top" width="21.36%"><p id="p129894313251"><a name="p129894313251"></a><a name="p129894313251"></a><strong id="b424019198572"><a name="b424019198572"></a><a name="b424019198572"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p799013112256"><a name="p799013112256"></a><a name="p799013112256"></a><strong id="b913613204578"><a name="b913613204578"></a><a name="b913613204578"></a>Description</strong></p>
</td>
</tr>
<tr id="row9990193142513"><td class="cellrowborder" valign="top" width="21.36%"><p id="p1999043111257"><a name="p1999043111257"></a><a name="p1999043111257"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p1799093182516"><a name="p1799093182516"></a><a name="p1799093182516"></a>The operation is successful.</p>
</td>
</tr>
<tr id="row16990133152516"><td class="cellrowborder" valign="top" width="21.36%"><p id="p17536173573015"><a name="p17536173573015"></a><a name="p17536173573015"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="78.64%"><p id="p1153623503014"><a name="p1153623503014"></a><a name="p1153623503014"></a>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
- Resetting the RTC
Call **RtcReset()** to reset the RTC. After the reset, the registers are restored to default values.
```c
int32_t RtcReset(DevHandle handle);
```
**Table 12** Description of RtcReset
| **Parameter**| **Description**|
| -------- | -------- |
| handle | RTC device handle.|
| **Return Value**| **Description**|
| 0 | The operation is successful.|
| Negative value| The operation failed.|
```
int32_t ret;
/* Reset the RTC driver. After the reset, the configuration registers are restored to the default values. */
/* Reset the RTC to restore default values of registers. */
ret = RtcReset(handle);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
```
- Reading the configuration of a custom RTC register
Call the **RtcReadReg()** function to read the configuration of a custom RTC register based on the register index \(one index corresponds to one byte of the configuration value\):
int32\_t RtcReadReg\(DevHandle handle, uint8\_t usrDefIndex, uint8\_t \*value\);
**Table 13** Description of RtcReadReg
<a name="table1624674153319"></a>
<table><tbody><tr id="row92469423320"><td class="cellrowborder" valign="top" width="21.62%"><p id="p102461548331"><a name="p102461548331"></a><a name="p102461548331"></a><strong id="b73024170576"><a name="b73024170576"></a><a name="b73024170576"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p15246847331"><a name="p15246847331"></a><a name="p15246847331"></a><strong id="b1439611818570"><a name="b1439611818570"></a><a name="b1439611818570"></a>Description</strong></p>
</td>
</tr>
<tr id="row171318200434"><td class="cellrowborder" valign="top" width="21.62%"><p id="p9895321184320"><a name="p9895321184320"></a><a name="p9895321184320"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p68951214436"><a name="p68951214436"></a><a name="p68951214436"></a>RTC device handle.</p>
</td>
</tr>
<tr id="row324614143314"><td class="cellrowborder" valign="top" width="21.62%"><p id="p82466433320"><a name="p82466433320"></a><a name="p82466433320"></a>usrDefIndex</p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p181671825470"><a name="p181671825470"></a><a name="p181671825470"></a>Index of the custom register</p>
</td>
</tr>
<tr id="row524716420334"><td class="cellrowborder" valign="top" width="21.62%"><p id="p8247844333"><a name="p8247844333"></a><a name="p8247844333"></a>value</p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p524711413319"><a name="p524711413319"></a><a name="p524711413319"></a>Pointer to the register value</p>
</td>
</tr>
<tr id="row112471143334"><td class="cellrowborder" valign="top" width="21.62%"><p id="p1124716483312"><a name="p1124716483312"></a><a name="p1124716483312"></a><strong id="b102421419175714"><a name="b102421419175714"></a><a name="b102421419175714"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p1524716443313"><a name="p1524716443313"></a><a name="p1524716443313"></a><strong id="b11376206578"><a name="b11376206578"></a><a name="b11376206578"></a>Description</strong></p>
</td>
</tr>
<tr id="row9247194183314"><td class="cellrowborder" valign="top" width="21.62%"><p id="p62476410334"><a name="p62476410334"></a><a name="p62476410334"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p152471433317"><a name="p152471433317"></a><a name="p152471433317"></a>The operation is successful.</p>
</td>
</tr>
<tr id="row1424719410333"><td class="cellrowborder" valign="top" width="21.62%"><p id="p112477417335"><a name="p112477417335"></a><a name="p112477417335"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p7247547338"><a name="p7247547338"></a><a name="p7247547338"></a>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
- Reading a custom RTC register
Call **RtcReadReg()** to read the configuration of a custom RTC register based on the register index. One index corresponds to one byte of the register value.
```c
int32_t RtcReadReg(DevHandle handle, uint8_t usrDefIndex, uint8_t \*value);
```
**Table 13** Description of RtcReadReg
| **Parameter**| **Description**|
| -------- | -------- |
| handle | RTC device handle.|
| usrDefIndex | Index of the custom register.|
| value | Register value.|
| **Return Value** | **Description**|
| 0 | The operation is successful.|
| Negative value| The operation failed.|
```
int32_t ret;
uint8_t usrDefIndex = 0; /* Define index 0 for the first custom register. */
uint8_t value = 0;
/* Read the configuration of a custom RTC register based on the register index. One index corresponds to one byte of the configuration value. */
/* Read the value of custom RTC register 0. One index corresponds to one byte of the register value. */
ret = RtcReadReg(handle, usrDefIndex, &value);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
```
- Setting the configuration of a custom RTC register
Call the **RtcWriteReg()** function to configure a register based on the specified register index \(one index corresponds to one byte of the configuration value\).
int32\_t RtcWriteReg\(DevHandle handle, uint8\_t usrDefIndex, uint8\_t value\);
**Table 14** Description of RtcWriteReg
<a name="table1072216482360"></a>
<table><tbody><tr id="row187221648133611"><td class="cellrowborder" valign="top" width="21.62%"><p id="p2722184823617"><a name="p2722184823617"></a><a name="p2722184823617"></a><strong id="b530321795712"><a name="b530321795712"></a><a name="b530321795712"></a>Parameter</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p1372374810367"><a name="p1372374810367"></a><a name="p1372374810367"></a><strong id="b1339761865714"><a name="b1339761865714"></a><a name="b1339761865714"></a>Description</strong></p>
</td>
</tr>
<tr id="row1675092612435"><td class="cellrowborder" valign="top" width="21.62%"><p id="p7783927144312"><a name="p7783927144312"></a><a name="p7783927144312"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p197831427134310"><a name="p197831427134310"></a><a name="p197831427134310"></a>RTC device handle.</p>
</td>
</tr>
<tr id="row1723174815367"><td class="cellrowborder" valign="top" width="21.62%"><p id="p1972364814366"><a name="p1972364814366"></a><a name="p1972364814366"></a>usrDefIndex</p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p18723184819365"><a name="p18723184819365"></a><a name="p18723184819365"></a>Index of the custom register</p>
</td>
</tr>
<tr id="row2723548163611"><td class="cellrowborder" valign="top" width="21.62%"><p id="p1772364893610"><a name="p1772364893610"></a><a name="p1772364893610"></a>value</p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p1772324803619"><a name="p1772324803619"></a><a name="p1772324803619"></a>Register value</p>
</td>
</tr>
<tr id="row1072314482361"><td class="cellrowborder" valign="top" width="21.62%"><p id="p6723194853618"><a name="p6723194853618"></a><a name="p6723194853618"></a><strong id="b172432193575"><a name="b172432193575"></a><a name="b172432193575"></a>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p1872314893614"><a name="p1872314893614"></a><a name="p1872314893614"></a><strong id="b131382020165711"><a name="b131382020165711"></a><a name="b131382020165711"></a>Description</strong></p>
</td>
</tr>
<tr id="row20723148173617"><td class="cellrowborder" valign="top" width="21.62%"><p id="p12723348133615"><a name="p12723348133615"></a><a name="p12723348133615"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p472324873620"><a name="p472324873620"></a><a name="p472324873620"></a>The operation is successful.</p>
</td>
</tr>
<tr id="row127231848123615"><td class="cellrowborder" valign="top" width="21.62%"><p id="p197231148173613"><a name="p197231148173613"></a><a name="p197231148173613"></a>Negative value</p>
</td>
<td class="cellrowborder" valign="top" width="78.38000000000001%"><p id="p16723134823618"><a name="p16723134823618"></a><a name="p16723134823618"></a>The operation failed.</p>
</td>
</tr>
</tbody>
</table>
- Setting a custom RTC register
Call **RtcWriteReg()** to set a register based on the specified register index. One index corresponds to one byte of the register value.
```c
int32_t RtcWriteReg(DevHandle handle, uint8_t usrDefIndex, uint8_t value);
```
**Table 14** Description of RtcWriteReg
| **Parameter**| **Description**|
| -------- | -------- |
| handle | RTC device handle.|
| usrDefIndex | Index of the custom register.|
| value | Register value.|
| **Return Value** | **Description**|
| 0 | The operation is successful.|
| Negative value| The operation failed.|
```
int32_t ret;
uint8_t usrDefIndex = 0; /* Define index 0 for the first custom register. */
uint8_t value = 0x10;
/* Configure a register based on the specified register index. One index corresponds to one byte of the configuration value. */
/* Set a value for register 0. One index corresponds to one byte of the configuration value. */
ret = RtcWriteReg(handle, usrDefIndex, value);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
```
## Usage Example<a name="section1186111020456"></a>
This section describes the process of using RTC APIs:
## Example
1. During the OS startup, the HDF identifies the RTC component in the system.
2. The HDF initializes and creates the RTC device.
3. You can perform operations on the RTC device by calling different APIs.
4. Call the **RtcClose** function to release the device handle and device resources.
The procedure is as follows:
1. During the OS startup, the HDF identifies the RTC device in the system.
2. The HDF initializes and creates the RTC device.
3. Call APIs to perform operations on the RTC device.
4. Close the RTC device handle to release resources.
The sample code is as follows:
Example:
```
#include "rtc_if.h"
int32_t RtcAlarmACallback(enum RtcAlarmIndex alarmIndex)
{
if (alarmIndex == RTC_ALARM_INDEX_A) {
/* Process alarm A. */
/* Processing of alarm A. */
printf("RTC Alarm A callback function\n\r");
} else if (alarmIndex == RTC_ALARM_INDEX_B) {
/* Process alarm B. */
/* Processing of alarm B. */
printf("RTC Alarm B callback function\n\r");
} else {
/* Process the error. */
/* Error handling. */
}
return 0;
}
......@@ -867,26 +500,26 @@ void RtcTestSample(void)
uint32_t freq;
DevHandle handle = NULL;
/* Obtain the RTC device handle. */
/* Open the RTC device handle. */
handle = RtcOpen();
if (handle == NULL) {
/* Process the error. */
/* Error handling. */
}
/* Register RtcAlarmCallback for alarm A. */
/* Register a callback for alarm A if it is not generated at the specified time. */
ret = RtcRegisterAlarmCallback(handle, RTC_ALARM_INDEX_A, RtcAlarmACallback);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
/* Set the RTC external crystal frequency. Note that the frequency must be configured in accordance with the requirements specified in the product manual of the in-use component. */
/* Set the frequency of the external crystal oscillator based on the requirements specified in the manual of the device you use. */
freq = 32768; /* 32768 Hz */
ret = RtcSetFreq(handle, freq);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
/* Enable the RTC alarm interrupts. */
/* Enable interrupts for RTC alarm A. */
ret = RtcAlarmInterruptEnable(handle, RTC_ALARM_INDEX_A, 1);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
/* Set the RTC time to 2020/01/01 00:00:10 .990. */
tm.year = 2020;
......@@ -896,10 +529,10 @@ void RtcTestSample(void)
tm.minute = 0;
tm.second = 10;
tm.millisecond = 990;
/* Write the RTC time information. */
/* Write the RTC time. */
ret = RtcWriteTime(handle, &tm);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
/* Set the RTC alarm time to 2020/01/01 00:00:30 .100. */
alarmTime.year = 2020;
......@@ -909,22 +542,22 @@ void RtcTestSample(void)
alarmTime.minute = 0;
alarmTime.second = 30;
alarmTime.millisecond = 100;
/* Set the alarm time information for RTC_ALARM_INDEX_A. When the specified time is reached, "RTC Alarm A callback function" is printed. */
/* Set the alarm time for RTC_ALARM_INDEX_A. When the specified time is reached, "RTC Alarm A callback function" will be printed. */
ret = RtcWriteAlarm(handle, RTC_ALARM_INDEX_A, &alarmTime);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
/* Read the RTC real time. */
/* Read the RTC time. */
ret = RtcReadTime(handle, &tm);
if (ret != 0) {
/* Process the error. */
/* Error handling. */
}
sleep(5)
printf("RTC read time:\n\r");
printf("year-month-date-weekday hour:minute:second .millisecond %04u-%02u-%02u-%u %02u:%02u:%02u .%03u",
tm.year, tm.month, tm.day, tm.weekday, tm.hour, tm.minute, tm.second, tm.millisecond);
/* Release the RTC device handle. */
/* Close the RTC device handle. */
RtcClose(handle);
}
```
\ No newline at end of file
```
# RTC<a name="EN-US_TOPIC_0000001153785954"></a>
# RTC
## Overview<a name="section509989381142407"></a>
In the Hardware Driver Foundation \(HDF\) framework, the real-time clock \(RTC\) uses the independent service mode for API adaptation. In this mode, each device independently publishes a device service to handle external access requests. After receiving an access request from an API, the device manager extracts the parameters in the request to call the internal method of the target device. In the independent service mode, the service management capabilities of the HDFDeviceManager can be directly used. However, you need to configure a device node for each device, which increases the memory usage.
## Overview
**Figure 1** Independent service mode<a name="fig6742142611299"></a>
![](figures/independent-service-mode.png "independent-service-mode-11")
The real-time clock (RTC) is a real-time clock device in the operating system. In the HDF, the RTC uses the independent service mode for API adaptation. In this mode, each device independently publishes a service to process external access requests. When receiving an access request, the HDF DeviceManager extracts parameters from the request to call the internal APIs of the target device. In the independent service mode, the HDF DeviceManager provides service management capabilities. However, you need to configure a node for each device to increase memory resources.
## Available APIs<a name="section752964871810"></a>
**Figure 1** Independent service mode
RtcMethod
![image](figures/independent-service-mode.png "RTC independent service mode")
## Available APIs
**RtcMethod**:
```
struct RtcMethod {
int32_t (*ReadTime)(struct RtcHost *host, struct RtcTime *time);
......@@ -27,437 +31,273 @@ struct RtcMethod {
};
```
**Table 1** Callbacks for the members in the RtcMethod structure
<a name="table12929217311"></a>
<table><thead align="left"><tr id="row293621203111"><th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.1"><p id="p15932212314"><a name="p15932212314"></a><a name="p15932212314"></a>Callback</p>
</th>
<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.2"><p id="p1193421113111"><a name="p1193421113111"></a><a name="p1193421113111"></a>Input Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.3"><p id="p179312214317"><a name="p179312214317"></a><a name="p179312214317"></a>Output Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.4"><p id="p993521163113"><a name="p993521163113"></a><a name="p993521163113"></a>Return Value</p>
</th>
<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.5"><p id="p5931821123115"><a name="p5931821123115"></a><a name="p5931821123115"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1093521113114"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p14941421163112"><a name="p14941421163112"></a><a name="p14941421163112"></a>ReadTime</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p094112118314"><a name="p094112118314"></a><a name="p094112118314"></a><strong id="b1264214345404"><a name="b1264214345404"></a><a name="b1264214345404"></a>host</strong>: structure pointer to the RTC controller at the core layer.</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p19945219318"><a name="p19945219318"></a><a name="p19945219318"></a><strong id="b6902125819406"><a name="b6902125819406"></a><a name="b6902125819406"></a>time</strong>: structure pointer to the output time value.</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p20941021143120"><a name="p20941021143120"></a><a name="p20941021143120"></a>HDF_STATUS</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p094132115317"><a name="p094132115317"></a><a name="p094132115317"></a>Reads the RTC time information.</p>
</td>
</tr>
<tr id="row199472183111"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p69418214318"><a name="p69418214318"></a><a name="p69418214318"></a>WriteTime</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p10306227052"><a name="p10306227052"></a><a name="p10306227052"></a><strong id="b1330617271556"><a name="b1330617271556"></a><a name="b1330617271556"></a>host</strong>: structure pointer to the RTC controller at the core layer.</p>
<p id="p89418214311"><a name="p89418214311"></a><a name="p89418214311"></a><strong id="b1411813377426"><a name="b1411813377426"></a><a name="b1411813377426"></a>time</strong>: structure pointer to the input time.</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p3944214314"><a name="p3944214314"></a><a name="p3944214314"></a></p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p1194321113112"><a name="p1194321113112"></a><a name="p1194321113112"></a>HDF_STATUS</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p5941521123118"><a name="p5941521123118"></a><a name="p5941521123118"></a>Writes the RTC time information (from milliseconds to years).</p>
</td>
</tr>
<tr id="row4941521113111"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p19462119319"><a name="p19462119319"></a><a name="p19462119319"></a>ReadAlarm</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p1362015341251"><a name="p1362015341251"></a><a name="p1362015341251"></a><strong id="b14620934553"><a name="b14620934553"></a><a name="b14620934553"></a>host</strong>: structure pointer to the RTC controller at the core layer.</p>
<p id="p9951721113113"><a name="p9951721113113"></a><a name="p9951721113113"></a><strong id="b477221417458"><a name="b477221417458"></a><a name="b477221417458"></a>alarmIndex</strong>: clock alarm index, which is an enumerated value.</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p1995921113112"><a name="p1995921113112"></a><a name="p1995921113112"></a><strong id="b0371144014414"><a name="b0371144014414"></a><a name="b0371144014414"></a>time</strong>: structure pointer to the output time.</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p10951721133115"><a name="p10951721133115"></a><a name="p10951721133115"></a>HDF_STATUS</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p14951121193113"><a name="p14951121193113"></a><a name="p14951121193113"></a>Reads the RTC alarm time.</p>
</td>
</tr>
<tr id="row6957211313"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p129517219311"><a name="p129517219311"></a><a name="p129517219311"></a>WriteAlarm</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p136914402055"><a name="p136914402055"></a><a name="p136914402055"></a><strong id="b176918401258"><a name="b176918401258"></a><a name="b176918401258"></a>host</strong>: structure pointer to the RTC controller at the core layer.</p>
<p id="p11512468517"><a name="p11512468517"></a><a name="p11512468517"></a><strong id="b195114613519"><a name="b195114613519"></a><a name="b195114613519"></a>alarmIndex</strong>: clock alarm index, which is an enumerated value.</p>
<p id="p595152114315"><a name="p595152114315"></a><a name="p595152114315"></a><strong id="b1892302045019"><a name="b1892302045019"></a><a name="b1892302045019"></a>time</strong>: structure pointer to the input time.</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p16951321203115"><a name="p16951321203115"></a><a name="p16951321203115"></a></p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p195321113116"><a name="p195321113116"></a><a name="p195321113116"></a>HDF_STATUS</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p1095122163116"><a name="p1095122163116"></a><a name="p1095122163116"></a>Writes the RTC alarm time.</p>
</td>
</tr>
<tr id="row1495021173112"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p795421193118"><a name="p795421193118"></a><a name="p795421193118"></a>RegisterAlarmCallback</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p7793145219520"><a name="p7793145219520"></a><a name="p7793145219520"></a><strong id="b37931529513"><a name="b37931529513"></a><a name="b37931529513"></a>host</strong>: structure pointer to the RTC controller at the core layer.</p>
<p id="p109352055359"><a name="p109352055359"></a><a name="p109352055359"></a><strong id="b393518551159"><a name="b393518551159"></a><a name="b393518551159"></a>alarmIndex</strong>: clock alarm index, which is an enumerated value.</p>
<p id="p1295182163112"><a name="p1295182163112"></a><a name="p1295182163112"></a><strong id="b11371112513"><a name="b11371112513"></a><a name="b11371112513"></a>cb</strong>: pointer to the callback.</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p79582123118"><a name="p79582123118"></a><a name="p79582123118"></a></p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p1996122173116"><a name="p1996122173116"></a><a name="p1996122173116"></a>HDF_STATUS</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p39602133113"><a name="p39602133113"></a><a name="p39602133113"></a>Registers <strong id="b176627580513"><a name="b176627580513"></a><a name="b176627580513"></a>RtcAlarmCallback</strong> that will be invoked when an alarm is generated at the specified time.</p>
</td>
</tr>
<tr id="row6961321113110"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p129682193119"><a name="p129682193119"></a><a name="p129682193119"></a>AlarmInterruptEnable</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p796015120619"><a name="p796015120619"></a><a name="p796015120619"></a><strong id="b149601210611"><a name="b149601210611"></a><a name="b149601210611"></a>host</strong>: structure pointer to the RTC controller at the core layer.</p>
<p id="p174501061561"><a name="p174501061561"></a><a name="p174501061561"></a><strong id="b7450562062"><a name="b7450562062"></a><a name="b7450562062"></a>alarmIndex</strong>: clock alarm index, which is an enumerated value.</p>
<p id="p59682173112"><a name="p59682173112"></a><a name="p59682173112"></a><strong id="b6999711105518"><a name="b6999711105518"></a><a name="b6999711105518"></a>enable</strong>: specifies whether to enable the RTC alarm interrupt.</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p5962021123110"><a name="p5962021123110"></a><a name="p5962021123110"></a></p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p16961621143119"><a name="p16961621143119"></a><a name="p16961621143119"></a>HDF_STATUS</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p996182112316"><a name="p996182112316"></a><a name="p996182112316"></a>Enables or disables the RTC alarm interrupt.</p>
</td>
</tr>
<tr id="row199622114317"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p09615216315"><a name="p09615216315"></a><a name="p09615216315"></a>GetFreq</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p16961021103119"><a name="p16961021103119"></a><a name="p16961021103119"></a><strong id="b17147182285715"><a name="b17147182285715"></a><a name="b17147182285715"></a>host</strong>: structure pointer to the RTC controller at the core layer.</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p09620218318"><a name="p09620218318"></a><a name="p09620218318"></a><strong id="b11413184435713"><a name="b11413184435713"></a><a name="b11413184435713"></a>freq</strong>: pointer to the output frequency, which is of the uint32_t type.</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p15961121163111"><a name="p15961121163111"></a><a name="p15961121163111"></a>HDF_STATUS</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p3968214311"><a name="p3968214311"></a><a name="p3968214311"></a>Reads the frequency of the external crystal oscillator connected to the RTC driver.</p>
</td>
</tr>
<tr id="row29692120319"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p1296421103115"><a name="p1296421103115"></a><a name="p1296421103115"></a>SetFreq</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p38121311169"><a name="p38121311169"></a><a name="p38121311169"></a><strong id="b481218117612"><a name="b481218117612"></a><a name="b481218117612"></a>host</strong>: structure pointer to the RTC controller at the core layer.</p>
<p id="p79792114315"><a name="p79792114315"></a><a name="p79792114315"></a><strong id="b1220510308"><a name="b1220510308"></a><a name="b1220510308"></a>freq</strong>: input frequency, which is of the uint32_t type.</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p4971021103118"><a name="p4971021103118"></a><a name="p4971021103118"></a></p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p109772117315"><a name="p109772117315"></a><a name="p109772117315"></a>HDF_STATUS</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p11971621193115"><a name="p11971621193115"></a><a name="p11971621193115"></a>Sets the frequency of the external crystal oscillator connected to the RTC driver.</p>
</td>
</tr>
<tr id="row1697112123114"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p99712117318"><a name="p99712117318"></a><a name="p99712117318"></a>Reset</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p169712123111"><a name="p169712123111"></a><a name="p169712123111"></a><strong id="b13129173210577"><a name="b13129173210577"></a><a name="b13129173210577"></a>host</strong>: structure pointer to the RTC controller at the core layer.</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p3974213312"><a name="p3974213312"></a><a name="p3974213312"></a></p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p109718210315"><a name="p109718210315"></a><a name="p109718210315"></a>HDF_STATUS</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p197112116316"><a name="p197112116316"></a><a name="p197112116316"></a>Resets the RTC.</p>
</td>
</tr>
<tr id="row3971821103115"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p2971221173111"><a name="p2971221173111"></a><a name="p2971221173111"></a>ReadReg</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p12704168619"><a name="p12704168619"></a><a name="p12704168619"></a><strong id="b1570171616616"><a name="b1570171616616"></a><a name="b1570171616616"></a>host</strong>: structure pointer to the RTC controller at the core layer.</p>
<p id="p18975210312"><a name="p18975210312"></a><a name="p18975210312"></a><strong id="b1020311128520"><a name="b1020311128520"></a><a name="b1020311128520"></a>usrDefIndex</strong>: structure defining the index of a custom register.</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p14975211314"><a name="p14975211314"></a><a name="p14975211314"></a><strong id="b10580501973"><a name="b10580501973"></a><a name="b10580501973"></a>value</strong>: pointer to the output register value, which is of the uint8_t type.</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p15981221193114"><a name="p15981221193114"></a><a name="p15981221193114"></a>HDF_STATUS</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p1098821143115"><a name="p1098821143115"></a><a name="p1098821143115"></a>Reads the configuration of a custom RTC register based on the register index. One index corresponds to one byte of the configuration value.</p>
</td>
</tr>
<tr id="row1298102119313"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p598121153114"><a name="p598121153114"></a><a name="p598121153114"></a>WriteReg</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p1747714196613"><a name="p1747714196613"></a><a name="p1747714196613"></a><strong id="b6477519469"><a name="b6477519469"></a><a name="b6477519469"></a>host</strong>: structure pointer to the RTC controller at the core layer.</p>
<p id="p1527912317612"><a name="p1527912317612"></a><a name="p1527912317612"></a><strong id="b72791123968"><a name="b72791123968"></a><a name="b72791123968"></a>usrDefIndex</strong>: structure defining the index of a custom register.</p>
<p id="p1498172173115"><a name="p1498172173115"></a><a name="p1498172173115"></a><strong id="b68893701014"><a name="b68893701014"></a><a name="b68893701014"></a>value</strong>: input register value, which is of the uint8_t type.</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p1998162193110"><a name="p1998162193110"></a><a name="p1998162193110"></a></p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p198162173118"><a name="p198162173118"></a><a name="p198162173118"></a>HDF_STATUS</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p13981421203110"><a name="p13981421203110"></a><a name="p13981421203110"></a>Configures the RTC register based on the register index. One index corresponds to one byte of the configuration value.</p>
</td>
</tr>
</tbody>
</table>
## How to Develop<a name="section1784450860142407"></a>
The RTC module adaptation involves the following steps:
**Table 1** Description of the callback functions in RtcMethod
1. Instantiate the driver entry.
- Instantiate the **HdfDriverEntry** structure.
- Call **HDF\_INIT** to register the **HdfDriverEntry** instance with the HDF.
| Function| Input Parameter| Output Parameter| Return Value| Description|
| -------- | -------- | -------- | -------- | -------- |
| ReadTime | **host**: structure pointer to the RTC controller at the core layer.| **time**: structure pointer to the time read.| HDF_STATUS| Reads the RTC time.|
| WriteTime | **host**: structure pointer to the RTC controller at the core layer.<br>**time**: structure pointer to the time to write.| –| HDF_STATUS| Writes the RTC time (including the year, month, day, day of week, hour, minute, second, and millisecond).|
| ReadAlarm | **host**: structure pointer to the RTC controller at the core layer.<br>**alarmIndex**: RTC alarm index, which is an enumerated value.| **time**: structure pointer to the time read.| HDF_STATUS| Reads the RTC alarm time.|
| WriteAlarm | **host**: structure pointer to the RTC controller at the core layer.<br>**alarmIndex**: RTC alarm index, which is an enumerated value.<br>**time**: structure pointer to the time to write.| –| HDF_STATUS| Writes the RTC alarm time.|
| RegisterAlarmCallback | **host**: structure pointer to the RTC controller at the core layer.<br>**alarmIndex**: RTC alarm index, which is an enumerated value.<br>**cb**: pointer to the callback to register.| –| HDF_STATUS| Registers a callback to be invoked when an alarm is not generated at the specified time.|
| AlarmInterruptEnable | **host**: structure pointer to the RTC controller at the core layer.<br>**alarmIndex**: RTC alarm index, which is an enumerated value.<br>**enable**: whether to enable interrupts for an RTC alarm. | –| HDF_STATUS| Enables or disables interrupts for an RTC alarm.|
| GetFreq | **host**: structure pointer to the RTC controller at the core layer.| **freq**: pointer to the frequency obtained, which is of the uint32_t type.| HDF_STATUS| Obtains the frequency of the external crystal oscillator connected to the RTC driver.|
| SetFreq | **host**: structure pointer to the RTC controller at the core layer.<br>**freq**: frequency to set, which is of the uint32_t type.| –| HDF_STATUS| Sets the frequency of the external crystal oscillator connected to the RTC driver.|
| Reset | **host**: structure pointer to the RTC controller at the core layer.| –| HDF_STATUS| Resets the RTC.|
| ReadReg | **host**: structure pointer to the RTC controller at the core layer.<br>**usrDefIndex**: index of a custom register.| **value**: pointer to the register value obtained, which is of the uint8_t type.| HDF_STATUS| Reads a custom RTC register. A register index corresponds to one byte of the register value.|
| WriteReg | **host**: structure pointer to the RTC controller at the core layer.<br>**usrDefIndex**: index of a custom register.<br>**value**: register value to write, which is of the uint8_t type.| –| HDF_STATUS| Writes a custom RTC register. A register index corresponds to one byte of the register value.|
2. Configure attribute files.
- Add the **deviceNode** information to the **device\_info.hcs** file.
- \(Optional\) Add the **rtc\_config.hcs** file.
3. Instantiate the RTC controller object.
- Initialize **RtcHost**.
- Instantiate **RtcMethod** in the **RtcHost** object.
## How to Develop
For details, see [Available APIs](#available-apis).
4. \(Optional\) Debug the driver.
The RTC module adaptation involves the following steps:
For new drivers, verify the basic functions, such as the RTC control status and response to interrupts.
1. Instantiate the driver entry.
- Instantiate the **HdfDriverEntry** structure.
- Call **HDF_INIT** to register the **HdfDriverEntry** instance with the HDF.
2. Configure attribute files.
- Add the **deviceNode** information to the **device_info.hcs** file.
- (Optional) Add the **rtc_config.hcs** file.
3. Instantiate the RTC controller object.
- Initialize **RtcHost**.
- Instantiate **RtcMethod** in the **RtcHost** object.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
> For details about the functions in **RtcMethod**, see [API APIs](#available-apis).
4. Debug the driver.
(Optional) For new drivers, verify the basic functions, such as the RTC status control and response to interrupts.
## Development Example
The following uses **rtc_hi35xx.c** as an example to present the information to be provided by the vendor to implement device functions.
1. Instantiate the driver entry.<br/>The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**. In the HDF framework, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
RTC driver entry example:
```
struct HdfDriverEntry g_rtcDriverEntry = {
.moduleVersion = 1,
.Bind = HiRtcBind, // See the Bind function.
.Init = HiRtcInit, // See the Init function.
.Release = HiRtcRelease, //See the Release function.
.moduleName = "HDF_PLATFORM_RTC", // (Mandatory) The value must be the same as that in the .hcs file.
};
// Call HDF_INIT to register the driver entry with the HDF.
HDF_INIT(g_rtcDriverEntry);
```
2. Add the **deviceNode** information to the **device_info.hcs** file and configure the device attributes in the **rtc_config.hcs** file. The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **RtcHost** members at the core layer.
In this example, there is only one RTC controller. If there are multiple RTC controllers, you need to add the **deviceNode** information to the **device_info** file and add the corresponding device attributes to the **rtc_config** file for each controller.
- **device_info.hcs** configuration example
```
root {
device_info {
platform :: host {
device_rtc :: device {
device0 :: deviceNode {
policy = 1; // The driver publishes services for kernel-mode processes only.
priority = 30; // A smaller value indicates a higher priority.
permission = 0644; // Permission for the driver to create a device node
moduleName = "HDF_PLATFORM_RTC"; // (Mandatory) Driver name, which must be the same as moduleName in the driver entry.
serviceName = "HDF_PLATFORM_RTC"; // (Mandatory) Unique name of the service published by the driver.
deviceMatchAttr = "hisilicon_hi35xx_rtc";// The value must be the same as that of match_attr in the .hcs file.
}
}
}
}
}
```
- **rtc_config.hcs** configuration example
```
root {
platform {
rtc_config {
controller_0x12080000 {
match_attr = "hisilicon_hi35xx_rtc";// (Mandatory) The value must be the same as that of deviceMatchAttr in device_info.hcs.
rtcSpiBaseAddr = 0x12080000; // Used for address mapping.
regAddrLength = 0x100; // Used for address mapping.
irq = 37; // Interrupt number.
supportAnaCtrl = false;
supportLock = false;
anaCtrlAddr = 0xff;
lock0Addr = 0xff;
lock1Addr = 0xff;
lock2Addr = 0xff;
lock3Addr = 0xff;
}
}
}
}
```
3. Initialize the **RtcHost** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init** and **Release**) to instantiate **RtcMethod** in **RtcHost** (so that the underlying driver functions can be called).
- Defining a custom structure
To the driver, the custom structure holds parameters and data. The **DeviceResourceIface** method provided by the HDF reads the values in the **rtc_config.hcs** file to initialize the members in the custom structure.
```
struct RtcConfigInfo {
uint32_t spiBaseAddr; // Used for address mapping.
volatile void *remapBaseAddr; // Used for address mapping.
uint16_t regAddrLength; // Used for address mapping.
uint8_t supportAnaCtrl; // Whether ANACTRL is supported.
uint8_t supportLock; // Whether lock is supported.
uint8_t irq; // Interrupt number.
uint8_t alarmIndex; // RTC alarm index.
uint8_t anaCtrlAddr; // ANACTRL address.
struct RtcLockAddr lockAddr; // Lock address.
RtcAlarmCallback cb; // Callback.
struct OsalMutex mutex; // Mutex.
};
// RtcHost is the controller structure at the core layer. The Init function assigns values to the members of RtcHost.
struct RtcHost {
struct IDeviceIoService service;
struct HdfDeviceObject *device;
struct RtcMethod *method;
void *data;
};
```
- Instantiating **RtcMethod** in **RtcHost** (other members are initialized by **Init**)
## Development Example<a name="section1594883301142407"></a>
```
// Example in rtc_hi35xx.c: instantiate the hook.
static struct RtcMethod g_method = {
.ReadTime = HiRtcReadTime,
.WriteTime = HiRtcWriteTime,
.ReadAlarm = HiReadAlarm,
.WriteAlarm = HiWriteAlarm,
.RegisterAlarmCallback = HiRegisterAlarmCallback,
.AlarmInterruptEnable = HiAlarmInterruptEnable,
.GetFreq = HiGetFreq,
.SetFreq = HiSetFreq,
.Reset = HiReset,
.ReadReg = HiReadReg,
.WriteReg = HiWriteReg,
};
```
- Bind function
Input parameter:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
Return value:
HDF_STATUS<br/>The table below describes some status. For more information, see **HDF_STATUS** in the **/drivers/framework/include/utils/hdf_base.h** file.
**Table 2** HDF_STATUS
| Status| Description|
| -------- | -------- |
| HDF_ERR_INVALID_OBJECT | Invalid controller object.|
| HDF_ERR_MALLOC_FAIL | Failed to allocate memory.|
| HDF_ERR_INVALID_PARAM | Invalid parameter.|
| HDF_ERR_IO | I/O error.|
| HDF_SUCCESS | Initialization successful.|
| HDF_FAILURE | Initialization failed.|
Function description:
Binds the **HdfDeviceObject** object and **RtcHost**.
The following uses **rtc\_hi35xx.c** as an example to present the contents that need to be provided by the vendor to implement device functions.
```
static int32_t HiRtcBind(struct HdfDeviceObject *device)
{
struct RtcHost *host = NULL;
host = RtcHostCreate(device); // Allocate memory and attach the device host and the device.
// Prerequisite for conversion between HdfDeviceObject and RtcHost.
...
device->service = &host->service; // Prerequisite for conversion between HdfDeviceObject and RtcHost.
// It allows the global use of host by calling RtcHostFromDevice.
return HDF_SUCCESS;
}
```
1. Instantiate the driver entry. The driver entry must be a global variable of the **HdfDriverEntry** type \(defined in **hdf\_device\_desc.h**\), and the value of **moduleName** must be the same as that in **device\_info.hcs**. In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
- **Init** function
Generally, HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, HDF calls **Release** to release driver resources and exit.
Input parameter:
- RTC driver entry reference
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
```
struct HdfDriverEntry g_rtcDriverEntry = {
.moduleVersion = 1,
.Bind = HiRtcBind, // See the Bind function.
.Init = HiRtcInit, // See the Init function.
.Release = HiRtcRelease, //See the Release function.
.moduleName = "HDF_PLATFORM_RTC", // (Mandatory) This parameter must be the same as that in the .hcs file.
};
// Call HDF_INIT to register the driver entry with the HDF.
HDF_INIT(g_rtcDriverEntry);
```
Return value:
2. Add the **deviceNode** information to the **device\_info.hcs** file and configure the device attributes in the **rtc\_config.hcs** file. The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **RtcHost** members at the core layer.
HDF_STATUS
In this example, there is only one RTC controller. If there are multiple RTC controllers, you need to add the **deviceNode** information to the **device\_info** file and add the corresponding device attributes to the **rtc\_config** file.
Function description:
- **device\_info.hcs** configuration reference
Initializes the custom structure object and **RtcHost**.
```
root {
device_info {
platform :: host {
device_rtc :: device {
device0 :: deviceNode {
policy = 1; // 2: The driver publishes user-mode services. 1: The driver publishes kernel-mode services. 0: No service needs to be published.
priority = 30; // A smaller value indicates a higher priority.
permission = 0644; // Permission for the driver to create a device node
moduleName = "HDF_PLATFORM_RTC"; // (Mandatory) Driver name, which must be the same as the moduleName in the driver entry.
serviceName = "HDF_PLATFORM_RTC"; // (Mandatory) Unique name of the service published by the driver
deviceMatchAttr = "hisilicon_hi35xx_rtc";// The value must be the same as that of match_attr in the .hcs file.
}
}
}
}
```
static int32_t HiRtcInit(struct HdfDeviceObject *device)
{
struct RtcHost *host = NULL;
struct RtcConfigInfo *rtcInfo = NULL;
...
host = RtcHostFromDevice(device);// A forced conversion from HdfDeviceObject to RtcHost is involved.
rtcInfo = OsalMemCalloc(sizeof(*rtcInfo));
...
// HiRtcConfigData reads attributes from the device configuration tree and fills the values in supportAnaCtrl, supportLock, spiBaseAddr, regAddrLength, and irq in rtcInfo.
// Provide parameters for HiRtcSwInit and HiRtcSwInit, and perform operations such as releasing memory when the function internal processing fails.
if (HiRtcConfigData(rtcInfo, device->property) != 0) {
...
}
```
- **rtc\_config.hcs** configuration reference
```
root {
platform {
rtc_config {
controller_0x12080000 {
match_attr = "hisilicon_hi35xx_rtc";// (Mandatory) The value must be the same as that of deviceMatchAttr in device_info.hcs.
rtcSpiBaseAddr = 0x12080000; // Used for address mapping
regAddrLength = 0x100; // Used for address mapping
irq = 37; // Interruption number
supportAnaCtrl = false;
supportLock = false;
anaCtrlAddr = 0xff;
lock0Addr = 0xff;
lock1Addr = 0xff;
lock2Addr = 0xff;
lock3Addr = 0xff;
}
}
}
if (HiRtcSwInit(rtcInfo)! = 0) {// Address mapping and interrupt registration.
...
}
```
3. Initialize the **RtcHost** object at the core layer, including initializing the vendor custom structure \(transferring parameters and data\), instantiating **RtcMethod** \(used to call underlying functions of the driver\) in **RtcHost**, and implementing the **HdfDriverEntry** member functions \(**Bind**, **Init**, and **Release**\).
- Custom structure reference
To the driver, the custom structure carries parameters and data. The values in the **rtc\_config.hcs** file are read by HDF, and the structure members are initialized through **DeviceResourceIface**.
```
struct RtcConfigInfo {
uint32_t spiBaseAddr; // Used for address mapping
volatile void *remapBaseAddr; // Used for address mapping
uint16_t regAddrLength; // Used for address mapping
uint8_t supportAnaCtrl; // Indicates whether ANACTRL is supported.
uint8_t supportLock; // Indicates whether lock is supported.
uint8_t irq; // Interrupt number
uint8_t alarmIndex; // Clock alarm index
uint8_t anaCtrlAddr; // ANACTRL address
struct RtcLockAddr lockAddr; // Lock address
RtcAlarmCallback cb; // Callback
struct OsalMutex mutex; // Mutex
};
// RtcHost is the controller structure at the core layer. Its members are assigned with values by using the Init function.
struct RtcHost {
struct IDeviceIoService service;
struct HdfDeviceObject *device;
struct RtcMethod *method;
void *data;
};
```
- Instantiate the callback function structure **RtcMethod** in **RtcHost**. Other members are initialized by using the **Init** function.
```
// Example in rtc_hi35xx.c: instantiate the hook.
static struct RtcMethod g_method = {
.ReadTime = HiRtcReadTime,
.WriteTime = HiRtcWriteTime,
.ReadAlarm = HiReadAlarm,
.WriteAlarm = HiWriteAlarm,
.RegisterAlarmCallback = HiRegisterAlarmCallback,
.AlarmInterruptEnable = HiAlarmInterruptEnable,
.GetFreq = HiGetFreq,
.SetFreq = HiSetFreq,
.Reset = HiReset,
.ReadReg = HiReadReg,
.WriteReg = HiWriteReg,
};
```
- Bind function
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
Return values:
HDF\_STATUS \(The following table lists some status. For details about other status, see **HDF\_STATUS** in the **//drivers/framework/include/utils/hdf\_base.h** file.\)
**Table 2** Input parameters and return values of the Bind function
<a name="table14285177465"></a>
<table><thead align="left"><tr id="row6280177461"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p528181764613"><a name="p528181764613"></a><a name="p528181764613"></a>Status (Value)</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p192891754615"><a name="p192891754615"></a><a name="p192891754615"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1328191713465"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p02812173467"><a name="p02812173467"></a><a name="p02812173467"></a>HDF_ERR_INVALID_OBJECT</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p142861714610"><a name="p142861714610"></a><a name="p142861714610"></a>Invalid controller object</p>
</td>
</tr>
<tr id="row19288170464"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p16282017184619"><a name="p16282017184619"></a><a name="p16282017184619"></a>HDF_ERR_MALLOC_FAIL</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p02841754611"><a name="p02841754611"></a><a name="p02841754611"></a>Failed to allocate memory</p>
</td>
</tr>
<tr id="row229131734619"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p429171784617"><a name="p429171784617"></a><a name="p429171784617"></a>HDF_ERR_INVALID_PARAM</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1229151764617"><a name="p1229151764617"></a><a name="p1229151764617"></a>Invalid parameter</p>
</td>
</tr>
<tr id="row6291017154612"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p15294179461"><a name="p15294179461"></a><a name="p15294179461"></a>HDF_ERR_IO</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p329517154617"><a name="p329517154617"></a><a name="p329517154617"></a>I/O error</p>
</td>
</tr>
<tr id="row9298171469"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p13297172461"><a name="p13297172461"></a><a name="p13297172461"></a>HDF_SUCCESS</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p11299171460"><a name="p11299171460"></a><a name="p11299171460"></a>Initialization successful</p>
</td>
</tr>
<tr id="row122911175467"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p32931744612"><a name="p32931744612"></a><a name="p32931744612"></a>HDF_FAILURE</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p102911724610"><a name="p102911724610"></a><a name="p102911724610"></a>Initialization failed</p>
</td>
</tr>
</tbody>
</table>
Function description:
Associates the **HdfDeviceObject** object and **RtcHost**.
```
static int32_t HiRtcBind(struct HdfDeviceObject *device)
{
struct RtcHost *host = NULL;
host = RtcHostCreate(device); // Apply for memory and connect to the device: host->device = device;
// Enable conversion between HdfDeviceObject and RtcHost.
if (HiRtcHwInit(rtcInfo)! = 0) {// Initialize ANACTRL and lockAddr.
...
device->service = &host->service; // Enable conversion between HdfDeviceObject and RtcHost.
// This setting enables the host to be globally used by calling RtcHostFromDevice.
return HDF_SUCCESS;
}
```
host->method = &g_method; // Attach the RtcMethod instance.
host->data = rtcInfo; // Prerequisites for conversion between RtcConfigInfo and RtcHost.
HDF_LOGI("Hdf dev service:%s init success!", HdfDeviceGetServiceName(device));
return HDF_SUCCESS;
}
```
- **Release** function
- Init function
Input parameter:
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
Return value:
Return values:
No value is returned.
HDF\_STATUS
Function description:
Function description:
Releases the memory and deletes the controller. This function assigns values to the **Release** function in the driver entry structure. If the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources. All forced conversion operations for obtaining the corresponding object can be successful only when the **Init** or **Bind** function has the corresponding value assignment operations.
Initializes the custom structure object and **RtcHost**.
```
static int32_t HiRtcInit(struct HdfDeviceObject *device)
{
```
static void HiRtcRelease(struct HdfDeviceObject *device)
{
struct RtcHost *host = NULL;
struct RtcConfigInfo *rtcInfo = NULL;
...
host = RtcHostFromDevice(device);// A forced conversion from HdfDeviceObject to RtcHost is involved.
rtcInfo = OsalMemCalloc(sizeof(*rtcInfo));
...
// HiRtcConfigData reads attributes from the device configuration tree and fills in supportAnaCtrl, supportLock, spiBaseAddr, regAddrLength, and irq in rtcInfo.
// Provide parameters for HiRtcSwInit and HiRtcSwInit, and perform operations such as releasing memory when the function internal processing fails.
if (HiRtcConfigData(rtcInfo, device->property) != 0) {
...
}
if (HiRtcSwInit(rtcInfo)! = 0) {// Related to address mapping and interrupt registration
...
host = RtcHostFromDevice(device); // A forced conversion from HdfDeviceObject to RtcHost is involved.
rtcInfo = (struct RtcConfigInfo *)host->data;// A forced conversion from RtcHost to RtcConfigInfo is involved.
if (rtcInfo != NULL) {
HiRtcSwExit(rtcInfo);
OsalMemFree(rtcInfo); // Release RtcConfigInfo.
host->data = NULL;
}
if (HiRtcHwInit(rtcInfo)! = 0) {// Initialize ANACTRL and lockAddr.
...
}
host->method = &g_method; // Connect to the UARTHostMethod instance.
host->data = rtcInfo; // Enable conversion between RtcConfigInfo and RtcHost.
HDF_LOGI("Hdf dev service:%s init success!", HdfDeviceGetServiceName(device));
return HDF_SUCCESS;
}
```
- Release function
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
Return values:
**Function description**:
Releases the memory and deletes the controller. This function assigns a value to the **Release** API in the driver entry structure. When the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources. All forced conversion operations for obtaining the corresponding object can be successful only when the **Init** or **Bind** function has the corresponding value assignment operations.
```
static void HiRtcRelease(struct HdfDeviceObject *device)
{
struct RtcHost *host = NULL;
struct RtcConfigInfo *rtcInfo = NULL;
...
host = RtcHostFromDevice(device); // A forced conversion from HdfDeviceObject to RtcHost is involved.
rtcInfo = (struct RtcConfigInfo *)host->data;// A forced conversion from RtcHost to RtcConfigInfo is involved.
if (rtcInfo != NULL) {
HiRtcSwExit(rtcInfo);
OsalMemFree(rtcInfo); // Release RtcConfigInfo.
host->data = NULL;
}
RtcHostDestroy(host); // Release RtcHost.
}
```
\ No newline at end of file
RtcHostDestroy(host); // Release RtcHost.
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册