• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
3  *
4  * UniProton is licensed under Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *          http://license.coscl.org.cn/MulanPSL2
8  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11  * See the Mulan PSL v2 for more details.
12  * Create: 2009-12-22
13  * Description: Hardware timer implementation
14  */
15 #include "prt_timer_external.h"
16 #include "prt_err_external.h"
17 #include "prt_attr_external.h"
18 
19 /*
20  * 描述:启动硬件定时器计时
21  */
PRT_TimerStart(U32 mid,TimerHandle tmrHandle)22 OS_SEC_L2_TEXT U32 PRT_TimerStart(U32 mid, TimerHandle tmrHandle)
23 {
24     U32 ret;
25     U32 timerType;
26 
27     (void)mid;
28 
29     timerType = OS_TIMER_GET_TYPE(tmrHandle);
30     if (timerType >= TIMER_TYPE_INVALID) {
31         ret = OS_ERRNO_TIMER_HANDLE_INVALID;
32         goto OS_TIMER_START_ERR;
33     }
34 
35     if (g_timerApi[timerType].startTimer == NULL) {
36         ret = OS_ERRNO_TIMER_NOT_INIT_OR_GROUP_NOT_CREATED;
37         goto OS_TIMER_START_ERR;
38     }
39 
40     ret = g_timerApi[timerType].startTimer(tmrHandle);
41     return ret;
42 
43 OS_TIMER_START_ERR:
44     OS_ERROR_LOG_REPORT(OS_ERR_LEVEL_HIGH, "timer start error handle 0x%x\n", tmrHandle);
45     return ret;
46 }
47 
48 /*
49  * 描述:停止定时器计时
50  */
PRT_TimerStop(U32 mid,TimerHandle tmrHandle)51 OS_SEC_L2_TEXT U32 PRT_TimerStop(U32 mid, TimerHandle tmrHandle)
52 {
53     U32 ret;
54     U32 timerType;
55 
56     (void)mid;
57 
58     timerType = OS_TIMER_GET_TYPE(tmrHandle);
59     if (timerType >= TIMER_TYPE_INVALID) {
60         ret = OS_ERRNO_TIMER_HANDLE_INVALID;
61         goto OS_TIMER_STOP_ERR;
62     }
63 
64     if (g_timerApi[timerType].stopTimer == NULL) {
65         ret = OS_ERRNO_TIMER_NOT_INIT_OR_GROUP_NOT_CREATED;
66         goto OS_TIMER_STOP_ERR;
67     }
68 
69     ret = g_timerApi[timerType].stopTimer(tmrHandle);
70     return ret;
71 
72 OS_TIMER_STOP_ERR:
73     OS_ERROR_LOG_REPORT(OS_ERR_LEVEL_HIGH, "timer stop error handle 0x%x\n", tmrHandle);
74     return ret;
75 }
76 
77 /*
78  * 描述:查询定时器剩余超时时间
79  */
PRT_TimerQuery(U32 mid,TimerHandle tmrHandle,U32 * expireTime)80 OS_SEC_L2_TEXT U32 PRT_TimerQuery(U32 mid, TimerHandle tmrHandle, U32 *expireTime)
81 {
82     U32 ret;
83     U32 timerType;
84     (void)mid;
85 
86     // 检查指针是否为NULL
87     if (expireTime == NULL) {
88         return OS_ERRNO_TIMER_INPUT_PTR_NULL;
89     }
90 
91     timerType = OS_TIMER_GET_TYPE(tmrHandle);
92     if (timerType >= TIMER_TYPE_INVALID) {
93         ret = OS_ERRNO_TIMER_HANDLE_INVALID;
94         goto OS_TIMER_QUERY_ERR;
95     }
96 
97     // 检查钩子是否为NULL
98     if (g_timerApi[timerType].timerQuery == NULL) {
99         ret = OS_ERRNO_TIMER_NOT_INIT_OR_GROUP_NOT_CREATED;
100         goto OS_TIMER_QUERY_ERR;
101     }
102 
103     ret = g_timerApi[timerType].timerQuery(tmrHandle, expireTime);
104     return ret;
105 
106 OS_TIMER_QUERY_ERR:
107     OS_ERROR_LOG_REPORT(OS_ERR_LEVEL_HIGH, "timer query error handle 0x%x\n", tmrHandle);
108     return ret;
109 }
110