• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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     if (cntrl == NULL) {
21         HDF_LOGE("%s: cntrl is null", __func__);
22         return;
23     }
24 
25     if (TimerCntrlClose(cntrl) != HDF_SUCCESS) {
26         HDF_LOGE("%s: TimerCntrlClose fail", __func__);
27         return;
28     }
29 }
30 
HwTimerSet(DevHandle handle,uint32_t useconds,TimerHandleCb cb)31 int32_t HwTimerSet(DevHandle handle, uint32_t useconds, TimerHandleCb cb)
32 {
33     struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
34     if (cntrl == NULL || cb == NULL) {
35         HDF_LOGE("%s: cntrl is null", __func__);
36         return HDF_FAILURE;
37     }
38 
39     if (TimerCntrlSet(cntrl, useconds, cb) != HDF_SUCCESS) {
40         HDF_LOGE("%s: TimerCntrlSet fail", __func__);
41         return HDF_FAILURE;
42     }
43 
44     return HDF_SUCCESS;
45 }
46 
HwTimerSetOnce(DevHandle handle,uint32_t useconds,TimerHandleCb cb)47 int32_t HwTimerSetOnce(DevHandle handle, uint32_t useconds, TimerHandleCb cb)
48 {
49     struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
50     if (cntrl == NULL || cb == NULL) {
51         HDF_LOGE("%s: cntrl is null", __func__);
52         return HDF_FAILURE;
53     }
54 
55     if (TimerCntrlSetOnce(cntrl, useconds, cb) != HDF_SUCCESS) {
56         HDF_LOGE("%s: TimerCntrlSetOnce fail", __func__);
57         return HDF_FAILURE;
58     }
59 
60     return HDF_SUCCESS;
61 }
62 
HwTimerGet(DevHandle handle,uint32_t * useconds,bool * isPeriod)63 int32_t HwTimerGet(DevHandle handle, uint32_t *useconds, bool *isPeriod)
64 {
65     struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
66     if (cntrl == NULL || useconds == NULL || isPeriod == NULL) {
67         HDF_LOGE("%s: param is null", __func__);
68         return HDF_FAILURE;
69     }
70 
71     if (TimerCntrlGet(cntrl, useconds, isPeriod) != HDF_SUCCESS) {
72         HDF_LOGE("%s: TimerCntrlGet fail", __func__);
73         return HDF_FAILURE;
74     }
75 
76     return HDF_SUCCESS;
77 }
78 
HwTimerStart(DevHandle handle)79 int32_t HwTimerStart(DevHandle handle)
80 {
81     struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
82     if (cntrl == NULL) {
83         HDF_LOGE("%s: cntrl is null", __func__);
84         return HDF_FAILURE;
85     }
86 
87     if (TimerCntrlStart(cntrl) != HDF_SUCCESS) {
88         HDF_LOGE("%s: TimerCntrlStart fail", __func__);
89         return HDF_FAILURE;
90     }
91 
92     return HDF_SUCCESS;
93 }
94 
HwTimerStop(DevHandle handle)95 int32_t HwTimerStop(DevHandle handle)
96 {
97     struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
98     if (cntrl == NULL) {
99         HDF_LOGE("%s: cntrl is null", __func__);
100         return HDF_FAILURE;
101     }
102 
103     if (TimerCntrlStop(cntrl) != HDF_SUCCESS) {
104         HDF_LOGE("%s: TimerCntrlStop fail", __func__);
105         return HDF_FAILURE;
106     }
107 
108     return HDF_SUCCESS;
109 }
110