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: 定时器模块
14 */
15 #include "prt_attr_external.h"
16 #include "prt_timer_external.h"
17 #include "prt_err_external.h"
18
19 OS_SEC_BSS struct TagFuncsLibTimer g_timerApi[TIMER_TYPE_INVALID];
20
21 /*
22 * 描述:创建硬件或者软件定时器
23 */
PRT_TimerCreate(struct TimerCreatePara * createPara,TimerHandle * tmrHandle)24 OS_SEC_L4_TEXT U32 PRT_TimerCreate(struct TimerCreatePara *createPara, TimerHandle *tmrHandle)
25 {
26 U32 ret;
27 U32 timerType = TIMER_TYPE_SWTMR;
28
29 if ((createPara == NULL) || (tmrHandle == NULL)) {
30 return OS_ERRNO_TIMER_INPUT_PTR_NULL;
31 }
32
33 if (createPara->interval == 0) {
34 return OS_ERRNO_TIMER_INTERVAL_INVALID;
35 }
36
37 if ((createPara->mode != OS_TIMER_LOOP) && (createPara->mode != OS_TIMER_ONCE)) {
38 return OS_ERRNO_TIMER_MODE_INVALID;
39 }
40
41 switch (createPara->type) {
42 case OS_TIMER_HARDWARE:
43 timerType = TIMER_TYPE_HWTMR;
44 break;
45
46 case OS_TIMER_SOFTWARE:
47 timerType = TIMER_TYPE_SWTMR;
48 break;
49
50 default:
51 ret = OS_ERRNO_TIMER_TYPE_INVALID;
52 goto OS_TIMER_CREATE_ERR;
53 }
54
55 if (g_timerApi[timerType].createTimer == NULL) {
56 ret = OS_ERRNO_TIMER_NOT_INIT_OR_GROUP_NOT_CREATED;
57 goto OS_TIMER_CREATE_ERR;
58 }
59
60 ret = g_timerApi[timerType].createTimer(createPara, tmrHandle);
61 return ret;
62
63 OS_TIMER_CREATE_ERR:
64 OS_ERROR_LOG_REPORT(OS_ERR_LEVEL_HIGH, "timer create error, timer type is 0x%x\n", createPara->type);
65 return ret;
66 }
67
68 /*
69 * 描述:定时器删除函数
70 */
PRT_TimerDelete(U32 mid,TimerHandle tmrHandle)71 OS_SEC_L4_TEXT U32 PRT_TimerDelete(U32 mid, TimerHandle tmrHandle)
72 {
73 U32 ret;
74 U32 timerType;
75 (void)mid;
76
77 timerType = OS_TIMER_GET_TYPE(tmrHandle);
78 if (timerType >= TIMER_TYPE_INVALID) {
79 ret = OS_ERRNO_TIMER_HANDLE_INVALID;
80 goto OS_TIMER_DEL_ERR;
81 }
82
83 if (g_timerApi[timerType].deleteTimer == NULL) {
84 ret = OS_ERRNO_TIMER_NOT_INIT_OR_GROUP_NOT_CREATED;
85 goto OS_TIMER_DEL_ERR;
86 }
87
88 ret = g_timerApi[timerType].deleteTimer(tmrHandle);
89 return ret;
90
91 OS_TIMER_DEL_ERR:
92 OS_ERROR_LOG_REPORT(OS_ERR_LEVEL_HIGH, "timer del error handle 0x%x\n", tmrHandle);
93 return ret;
94 }
95
96 /*
97 * 描述:重新启动定时器
98 */
PRT_TimerRestart(U32 mid,TimerHandle tmrHandle)99 OS_SEC_L2_TEXT U32 PRT_TimerRestart(U32 mid, TimerHandle tmrHandle)
100 {
101 U32 ret;
102 U32 timerType;
103 (void)mid;
104
105 timerType = OS_TIMER_GET_TYPE(tmrHandle);
106 if (timerType >= TIMER_TYPE_INVALID) {
107 ret = OS_ERRNO_TIMER_HANDLE_INVALID;
108 goto OS_TIMER_RESTART_ERR;
109 }
110
111 if (g_timerApi[timerType].restartTimer == NULL) {
112 ret = OS_ERRNO_TIMER_NOT_INIT_OR_GROUP_NOT_CREATED;
113 goto OS_TIMER_RESTART_ERR;
114 }
115
116 ret = g_timerApi[timerType].restartTimer(tmrHandle);
117 return ret;
118
119 OS_TIMER_RESTART_ERR:
120 OS_ERROR_LOG_REPORT(OS_ERR_LEVEL_HIGH, "timer restart error handle 0x%x\n", tmrHandle);
121 return ret;
122 }
123