• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2023 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "rtc_if.h"
10 #include "devsvc_manager_clnt.h"
11 #include "hdf_log.h"
12 #include "osal_mem.h"
13 #include "rtc_base.h"
14 #include "rtc_core.h"
15 #include "securec.h"
16 
17 #define HDF_LOG_TAG rtc_if_c
18 
RtcOpen(void)19 DevHandle RtcOpen(void)
20 {
21     struct RtcHost *host = NULL;
22 
23     host = (struct RtcHost *)DevSvcManagerClntGetService("HDF_PLATFORM_RTC");
24     if (host == NULL) {
25         HDF_LOGE("RtcOpen: rtc get service name fail!");
26         return NULL;
27     }
28 
29     return (DevHandle)host;
30 }
31 
RtcClose(DevHandle handle)32 void RtcClose(DevHandle handle)
33 {
34     (void)handle;
35 }
36 
RtcReadTime(DevHandle handle,struct RtcTime * time)37 int32_t RtcReadTime(DevHandle handle, struct RtcTime *time)
38 {
39     if (handle == NULL || time == NULL) {
40         HDF_LOGE("RtcReadTime: handle or time is null!");
41         return HDF_ERR_INVALID_OBJECT;
42     }
43 
44     return RtcHostReadTime((struct RtcHost *)handle, time);
45 }
46 
RtcWriteTime(DevHandle handle,const struct RtcTime * time)47 int32_t RtcWriteTime(DevHandle handle, const struct RtcTime *time)
48 {
49     if (handle == NULL || time == NULL) {
50         HDF_LOGE("RtcWriteTime: handle or time is null!");
51         return HDF_ERR_INVALID_OBJECT;
52     }
53 
54     if (RtcIsInvalid(time) == RTC_TRUE) {
55         HDF_LOGE("RtcWriteTime: time is invalid!");
56         return HDF_ERR_INVALID_PARAM;
57     }
58 
59     return RtcHostWriteTime((struct RtcHost *)handle, time);
60 }
61 
RtcReadAlarm(DevHandle handle,enum RtcAlarmIndex alarmIndex,struct RtcTime * time)62 int32_t RtcReadAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct RtcTime *time)
63 {
64     if (handle == NULL || time == NULL) {
65         HDF_LOGE("RtcReadAlarm: handle or time is null!");
66         return HDF_ERR_INVALID_OBJECT;
67     }
68 
69     return RtcHostReadAlarm((struct RtcHost *)handle, alarmIndex, time);
70 }
71 
RtcWriteAlarm(DevHandle handle,enum RtcAlarmIndex alarmIndex,const struct RtcTime * time)72 int32_t RtcWriteAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, const struct RtcTime *time)
73 {
74     if (handle == NULL || time == NULL) {
75         HDF_LOGE("RtcWriteAlarm: handle or time is null!");
76         return HDF_ERR_INVALID_OBJECT;
77     }
78 
79     if (RtcIsInvalid(time) == RTC_TRUE) {
80         HDF_LOGE("RtcWriteAlarm: time is invalid!");
81         return HDF_ERR_INVALID_PARAM;
82     }
83 
84     return RtcHostWriteAlarm((struct RtcHost *)handle, alarmIndex, time);
85 }
86 
RtcRegisterAlarmCallback(DevHandle handle,enum RtcAlarmIndex alarmIndex,RtcAlarmCallback cb)87 int32_t RtcRegisterAlarmCallback(DevHandle handle, enum RtcAlarmIndex alarmIndex, RtcAlarmCallback cb)
88 {
89     if (handle == NULL || cb == NULL) {
90         HDF_LOGE("RtcRegisterAlarmCallback: handle or cb is null!");
91         return HDF_ERR_INVALID_OBJECT;
92     }
93 
94     return RtcHostRegisterAlarmCallback((struct RtcHost *)handle, alarmIndex, cb);
95 }
96 
RtcAlarmInterruptEnable(DevHandle handle,enum RtcAlarmIndex alarmIndex,uint8_t enable)97 int32_t RtcAlarmInterruptEnable(DevHandle handle, enum RtcAlarmIndex alarmIndex, uint8_t enable)
98 {
99     if (handle == NULL) {
100         HDF_LOGE("RtcAlarmInterruptEnable: handle is null!");
101         return HDF_ERR_INVALID_OBJECT;
102     }
103 
104     return RtcHostAlarmInterruptEnable((struct RtcHost *)handle, alarmIndex, enable);
105 }
106 
RtcGetFreq(DevHandle handle,uint32_t * freq)107 int32_t RtcGetFreq(DevHandle handle, uint32_t *freq)
108 {
109     if (handle == NULL || freq == NULL) {
110         HDF_LOGE("RtcGetFreq: handle or freq is null!");
111         return HDF_ERR_INVALID_OBJECT;
112     }
113 
114     return RtcHostGetFreq((struct RtcHost *)handle, freq);
115 }
116 
RtcSetFreq(DevHandle handle,uint32_t freq)117 int32_t RtcSetFreq(DevHandle handle, uint32_t freq)
118 {
119     if (handle == NULL) {
120         HDF_LOGE("RtcSetFreq: handle is null!");
121         return HDF_ERR_INVALID_OBJECT;
122     }
123 
124     return RtcHostSetFreq((struct RtcHost *)handle, freq);
125 }
126 
RtcReset(DevHandle handle)127 int32_t RtcReset(DevHandle handle)
128 {
129     if (handle == NULL) {
130         HDF_LOGE("RtcReset: handle is null!");
131         return HDF_ERR_INVALID_OBJECT;
132     }
133 
134     return RtcHostReset((struct RtcHost *)handle);
135 }
136 
RtcReadReg(DevHandle handle,uint8_t usrDefIndex,uint8_t * value)137 int32_t RtcReadReg(DevHandle handle, uint8_t usrDefIndex, uint8_t *value)
138 {
139     if (handle == NULL ||value == NULL) {
140         HDF_LOGE("RtcReadReg: handle or value is null!");
141         return HDF_ERR_INVALID_OBJECT;
142     }
143 
144     return RtcHostReadReg((struct RtcHost *)handle, usrDefIndex, value);
145 }
146 
RtcWriteReg(DevHandle handle,uint8_t usrDefIndex,uint8_t value)147 int32_t RtcWriteReg(DevHandle handle, uint8_t usrDefIndex, uint8_t value)
148 {
149     if (handle == NULL) {
150         HDF_LOGE("RtcWriteReg: handle is null");
151         return HDF_ERR_INVALID_OBJECT;
152     }
153 
154     return RtcHostWriteReg((struct RtcHost *)handle, usrDefIndex, value);
155 }