• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 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 #ifndef RTC_CORE_H
10 #define RTC_CORE_H
11 
12 #include "hdf_base.h"
13 #include "hdf_device_desc.h"
14 #include "osal_mutex.h"
15 #include "rtc_if.h"
16 
17 #ifdef __cplusplus
18 #if __cplusplus
19 extern "C" {
20 #endif
21 #endif /* __cplusplus */
22 
23 struct RtcHost;
24 struct RtcMethod;
25 
26 struct RtcHost {
27     struct IDeviceIoService service;
28     struct HdfDeviceObject *device;
29     struct RtcMethod *method;
30     void *data;
31 };
32 
33 struct RtcMethod {
34     int32_t (*ReadTime)(struct RtcHost *host, struct RtcTime *time);
35     int32_t (*WriteTime)(struct RtcHost *host, const struct RtcTime *time);
36     int32_t (*ReadAlarm)(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, struct RtcTime *time);
37     int32_t (*WriteAlarm)(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, const struct RtcTime *time);
38     int32_t (*RegisterAlarmCallback)(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, RtcAlarmCallback cb);
39     int32_t (*AlarmInterruptEnable)(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, uint8_t enable);
40     int32_t (*GetFreq)(struct RtcHost *host, uint32_t *freq);
41     int32_t (*SetFreq)(struct RtcHost *host, uint32_t freq);
42     int32_t (*Reset)(struct RtcHost *host);
43     int32_t (*ReadReg)(struct RtcHost *host, uint8_t usrDefIndex, uint8_t *value);
44     int32_t (*WriteReg)(struct RtcHost *host, uint8_t usrDefIndex, uint8_t value);
45 };
46 
47 struct RtcHost *RtcHostCreate(struct HdfDeviceObject *device);
48 void RtcHostDestroy(struct RtcHost *host);
49 
RtcHostFromDevice(const struct HdfDeviceObject * device)50 static inline struct RtcHost *RtcHostFromDevice(const struct HdfDeviceObject *device)
51 {
52     return (device == NULL) ? NULL : (struct RtcHost *)device->service;
53 }
54 
55 int32_t RtcHostReadTime(struct RtcHost *host, struct RtcTime *time);
56 
57 int32_t RtcHostWriteTime(struct RtcHost *host, const struct RtcTime *time);
58 
59 int32_t RtcHostReadAlarm(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, struct RtcTime *time);
60 
61 int32_t RtcHostWriteAlarm(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, const struct RtcTime *time);
62 
63 int32_t RtcHostRegisterAlarmCallback(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, RtcAlarmCallback cb);
64 
65 int32_t RtcHostAlarmInterruptEnable(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, uint8_t enable);
66 
67 int32_t RtcHostGetFreq(struct RtcHost *host, uint32_t *freq);
68 
69 int32_t RtcHostSetFreq(struct RtcHost *host, uint32_t freq);
70 
71 int32_t RtcHostReset(struct RtcHost *host);
72 
73 int32_t RtcHostReadReg(struct RtcHost *host, uint8_t usrDefIndex, uint8_t *value);
74 
75 int32_t RtcHostWriteReg(struct RtcHost *host, uint8_t usrDefIndex, uint8_t value);
76 
77 int32_t RtcIoDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply);
78 
79 #ifdef __cplusplus
80 #if __cplusplus
81 }
82 #endif
83 #endif /* __cplusplus */
84 
85 #endif /* RTC_CORE_H */
86