1 /*
2 * Copyright (c) 2022-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 #include "timer_if.h"
9 #include "hdf_log.h"
10 #include "timer_core.h"
11
HwTimerOpen(const uint32_t number)12 DevHandle HwTimerOpen(const uint32_t number)
13 {
14 return (DevHandle)TimerCntrlOpen(number);
15 }
16
HwTimerClose(DevHandle handle)17 void HwTimerClose(DevHandle handle)
18 {
19 struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
20
21 if (cntrl == NULL) {
22 HDF_LOGE("HwTimerClose: cntrl is null!");
23 return;
24 }
25
26 if (TimerCntrlClose(cntrl) != HDF_SUCCESS) {
27 HDF_LOGE("HwTimerClose: timer cnltr close fail!");
28 return;
29 }
30 }
31
HwTimerSet(DevHandle handle,uint32_t useconds,TimerHandleCb cb)32 int32_t HwTimerSet(DevHandle handle, uint32_t useconds, TimerHandleCb cb)
33 {
34 struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
35
36 if (cntrl == NULL || cb == NULL) {
37 HDF_LOGE("HwTimerSet: cntrl or cb is null!");
38 return HDF_FAILURE;
39 }
40
41 if (TimerCntrlSet(cntrl, useconds, cb) != HDF_SUCCESS) {
42 HDF_LOGE("HwTimerSet: timer cnltr set fail!");
43 return HDF_FAILURE;
44 }
45
46 return HDF_SUCCESS;
47 }
48
HwTimerSetOnce(DevHandle handle,uint32_t useconds,TimerHandleCb cb)49 int32_t HwTimerSetOnce(DevHandle handle, uint32_t useconds, TimerHandleCb cb)
50 {
51 struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
52
53 if (cntrl == NULL || cb == NULL) {
54 HDF_LOGE("HwTimerSetOnce: cntrl or cb is null!");
55 return HDF_FAILURE;
56 }
57
58 if (TimerCntrlSetOnce(cntrl, useconds, cb) != HDF_SUCCESS) {
59 HDF_LOGE("HwTimerSetOnce: timer cntlr set once fail!");
60 return HDF_FAILURE;
61 }
62
63 return HDF_SUCCESS;
64 }
65
HwTimerGet(DevHandle handle,uint32_t * useconds,bool * isPeriod)66 int32_t HwTimerGet(DevHandle handle, uint32_t *useconds, bool *isPeriod)
67 {
68 struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
69
70 if (cntrl == NULL || useconds == NULL || isPeriod == NULL) {
71 HDF_LOGE("HwTimerGet: cntlr or useconds or isPeriod is null!");
72 return HDF_FAILURE;
73 }
74
75 if (TimerCntrlGet(cntrl, useconds, isPeriod) != HDF_SUCCESS) {
76 HDF_LOGE("HwTimerGet: timer cntlr get fail!");
77 return HDF_FAILURE;
78 }
79
80 return HDF_SUCCESS;
81 }
82
HwTimerStart(DevHandle handle)83 int32_t HwTimerStart(DevHandle handle)
84 {
85 struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
86
87 if (cntrl == NULL) {
88 HDF_LOGE("HwTimerStart: cntrl is null!");
89 return HDF_FAILURE;
90 }
91
92 if (TimerCntrlStart(cntrl) != HDF_SUCCESS) {
93 HDF_LOGE("HwTimerStart: timer cntlr start fail!");
94 return HDF_FAILURE;
95 }
96
97 return HDF_SUCCESS;
98 }
99
HwTimerStop(DevHandle handle)100 int32_t HwTimerStop(DevHandle handle)
101 {
102 struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
103
104 if (cntrl == NULL) {
105 HDF_LOGE("HwTimerStop: cntrl is null!");
106 return HDF_FAILURE;
107 }
108
109 if (TimerCntrlStop(cntrl) != HDF_SUCCESS) {
110 HDF_LOGE("HwTimerStop: timer cntlr stop fail!");
111 return HDF_FAILURE;
112 }
113
114 return HDF_SUCCESS;
115 }
116