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: swtmr模块的模块内头文件 14 */ 15 #ifndef PRT_SWTMR_INTERNAL_H 16 #define PRT_SWTMR_INTERNAL_H 17 18 #include "prt_lib_external.h" 19 #include "prt_err_external.h" 20 #include "prt_sys_external.h" 21 #include "prt_cpu_external.h" 22 #include "prt_swtmr_external.h" 23 #include "prt_sys_external.h" 24 #include "prt_timer_external.h" 25 #include "prt_err_external.h" 26 #include "prt_tick_external.h" 27 #include "prt_mem_external.h" 28 #include "prt_list_external.h" 29 #include "prt_cpu_external.h" 30 31 /* 32 * 模块内宏定义 33 */ 34 #define OS_SWTMR_SORTLINK_LEN 64 /* SortLink数组长度 */ 35 #define OS_SWTMR_SORTLINK_MASK 0x3FUL 36 37 #define OS_TICK_SWTMR_GROUP_ID 0 /* 软件定时器组ID号 */ 38 39 #define OS_SWTMR_STATUS_DEFAULT 0 40 #define OS_SWTMR_STATUS_MASK 0xfU 41 #define OS_SWTMR_PRE_STATUS_MASK 0xf0U 42 43 /* 44 * @brief 获取低位的值。 45 * 46 * @par 描述 47 * 宏定义,定义完成从一个32位的数获取低26位的值 48 * 49 * @attention 无 50 * @param num [IN] 源数。 51 * 52 * @retval 无 53 * @par 依赖 54 * <li>prt_swtmr_external.h: 该宏定义所在的头文件。</li></ul> 55 * @see UWROLLNUMSUB | UWROLLNUMADD | EVALUATE_L | EVALUATE_H | UWROLLNUM | UWSORTINDEX。 56 */ 57 #define UWROLLNUM(num) ((num) & 0x03ffffffU) 58 /* 59 * @brief 获取高位的值。 60 * 61 * @par 描述 62 * 宏定义,定义完成从一个32位的数获取高位的值 63 * 64 * @attention 无 65 * @param num [IN] 源数。 66 * 67 * @retval 无 68 * @par 依赖 69 * <li>prt_swtmr_external.h: 该宏定义所在的头文件。</li></ul> 70 * @see UWROLLNUMSUB | UWROLLNUMADD | EVALUATE_L | EVALUATE_H | UWROLLNUM | UWSORTINDEX。 71 */ 72 #define UWSORTINDEX(num) ((num) >> 26) 73 /* 74 * @brief 定义高位赋值。 75 * 76 * @par 描述 77 * 宏定义,屏蔽高6位,把值与到高6位 78 * 79 * @attention 无 80 * @param num [IN] 被赋值的变量。 81 * @param value [IN] 待赋的值或变量。 82 * 83 * @retval 无 84 * @par 依赖 85 * <li>prt_swtmr_external.h: 该宏定义所在的头文件。</li></ul> 86 * @see UWROLLNUMSUB | UWROLLNUMADD | EVALUATE_L | EVALUATE_H | UWROLLNUM | UWSORTINDEX。 87 */ 88 #define EVALUATE_H(num, value) ((num) = (((num) & 0x03ffffffU) | ((value) << 26))) 89 90 /* 91 * @brief 定义低位赋值。 92 * 93 * @par 描述 94 * 宏定义,定义完成一个32位的数低位赋值的功能,高位不变。 95 * 96 * @attention 无 97 * @param num [IN] 被赋值的变量。 98 * @param value [IN] 待赋的值或变量。 99 * 100 * @retval 无 101 * @par 依赖 102 * <li>prt_swtmr_external.h: 该宏定义所在的头文件。</li></ul> 103 * @see UWROLLNUMSUB | UWROLLNUMADD | EVALUATE_L | EVALUATE_H | UWROLLNUM | UWSORTINDEX。 104 */ 105 #define EVALUATE_L(num, value) ((num) = (((num) & 0xfc000000U) | (value))) 106 107 /* 108 * @brief 定义两个数低位相减的功能。 109 * 110 * @par 描述 111 * 宏定义,定义完成一个32位的数低位相加,结果存放到第一个参数,H(num1) = H(num1) - H(num2)。 112 * 如 两个定时器控制块中sortData低位的rollNum进行相加。 113 * 114 * @attention 无 115 * @param num1 [IN] 被加数。 116 * @param num2 [IN] 加数。 117 * 118 * @retval 无 119 * @par 依赖 120 * <li>prt_swtmr_external.h: 该宏定义所在的头文件。</li></ul> 121 * @see UWROLLNUMSUB | UWROLLNUMADD | EVALUATE_L | EVALUATE_H | UWROLLNUM | UWSORTINDEX。 122 */ 123 #define UWROLLNUMADD(num1, num2) ((num1) = (((num1) & 0xfc000000U) | (UWROLLNUM(num1) + UWROLLNUM(num2)))) 124 125 /* 126 * @brief 定义两个数低位相减的功能。 127 * 128 * @par 描述 129 * 宏定义,定义完成一个32位的数低位相减,结果存放到第一个参数,H(num1) = H(num1) - H(num2)。 130 * 如 两个定时器控制块中sortData低位的rollNum进行相减。 131 * 132 * @attention 无 133 * @param num1 [IN] 被减数。 134 * @param num2 [IN] 减数。 135 * 136 * @retval 无 137 * @par 依赖 138 * <li>prt_swtmr_external.h: 该宏定义所在的头文件。</li></ul> 139 * @see UWROLLNUMSUB | UWROLLNUMADD | EVALUATE_L | EVALUATE_H | UWROLLNUM | UWSORTINDEX。 140 */ 141 #define UWROLLNUMSUB(num1, num2) ((num1) = (((num1) & 0xfc000000U) | (UWROLLNUM(num1) - UWROLLNUM(num2)))) 142 143 /* 144 * @brief 定义低位减1的功能。 145 * 146 * @par 描述 147 * 宏定义,定义完成一个32位的数低位自减1。 148 * 如 定时器控制块中sortData低位的rollNum进行自减1操作 149 * 150 * @attention 无 151 * @param num [IN] 低为待自减1的数。 152 * 153 * @retval 无 154 * @par 依赖 155 * <li>prt_swtmr_external.h: 该宏定义所在的头文件。</li></ul> 156 * @see UWROLLNUMSUB | UWROLLNUMADD | EVALUATE_L | EVALUATE_H | UWROLLNUM | UWSORTINDEX。 157 */ 158 #define UWROLLNUMDEC(num) ((num) = ((num) - 1)) 159 160 /* 161 * 模块内全局变量声明 162 */ 163 /* 软件定时器Sortlink */ 164 extern struct TagSwTmrSortLinkAttr g_tmrSortLink; 165 /* 软件定时器空闲链表 */ 166 extern struct TagSwTmrCtrl *g_tmrFreeList; 167 168 /* 169 * 模块内函数声明 170 */ 171 /* 172 * Function : OsSwTmrResInit 173 * Description: 软件定时器模块的初始化接口 174 * Input : none 175 * Output : none 176 * Return : OS_OK -- 初始化成功 177 * OS_ERRNO_SWTMR_NO_MEMORY -- 初始化内存不足 178 */ 179 extern U32 OsSwTmrResInit(void); 180 181 /* 182 * Function : OsSwTmrRun 183 * Description: 软件定时器模块的Tick中断运行接口 184 * Input : none 185 * Output : none 186 * Return : OS_OK -- 成功 187 */ 188 extern void OsSwTmrScan(void); 189 190 /* 191 * Function : OsSwTmrGetRemainTick 192 * Description: 获取软件定时器剩余Tick数的内部接口 193 * Input : swtmr [IN] 类型#struct TagSwTmrCtrl *,定时器指针 194 * Output : none 195 * Return : 软件定时器剩余TICK数 196 */ 197 extern U32 OsSwTmrGetRemainTick(struct TagSwTmrCtrl *swtmr); 198 199 /* 200 * Function : OsSwTmrCreateTimer 201 * Description: 软件定时器创建函数 202 * Input : none 203 * Output : none 204 * Return : OS_OK -- 初始化成功 205 * OS_ERRNO_SWTMR_NO_MEMORY -- 初始化内存不足 206 */ 207 extern U32 OsSwTmrCreateTimer(struct TimerCreatePara *createPara, TimerHandle *tmrHandle); 208 209 /* 210 * Function : OsSwTmrStartTimer 211 * Description: 软件定时器启动函数 212 * Input : none 213 * Output : none 214 * Return : OS_OK -- 初始化成功 215 * OS_ERRNO_SWTMR_NO_MEMORY -- 初始化内存不足 216 */ 217 extern U32 OsSwTmrStartTimer(TimerHandle tmrHandle); 218 219 /* 220 * Function : OsSwTmrStopTimer 221 * Description: 软件定时器停止函数 222 * Input : none 223 * Output : none 224 * Return : OS_OK -- 初始化成功 225 * OS_ERRNO_SWTMR_NO_MEMORY -- 初始化内存不足 226 */ 227 extern U32 OsSwTmrStopTimer(TimerHandle tmrHandle); 228 229 /* 230 * Function : OsSwTmrRestartTimer 231 * Description: 软件定时器重启函数 232 * Input : none 233 * Output : none 234 * Return : OS_OK -- 初始化成功 235 * OS_ERRNO_SWTMR_NO_MEMORY -- 初始化内存不足 236 */ 237 extern U32 OsSwTmrRestartTimer(TimerHandle tmrHandle); 238 239 /* 240 * Function : OsSwTmrDeleteTimer 241 * Description: 软件定时器删除函数 242 * Input : none 243 * Output : none 244 * Return : OS_OK -- 初始化成功 245 * OS_ERRNO_SWTMR_NO_MEMORY -- 初始化内存不足 246 */ 247 extern U32 OsSwTmrDeleteTimer(TimerHandle tmrHandle); 248 249 /* 250 * Function : OsSwTmrStart 251 * Description: 软件定时器的启动接口 252 * Input : swtmr [IN] 类型#struct TagSwTmrCtrl*, 需要启动的定时器 253 * interval[IN] 类型#U32, 定时器计时时长 254 * Output : none 255 * Return : none 256 * Other : None 257 */ 258 extern void OsSwTmrStart(struct TagSwTmrCtrl *swtmr, U32 interval); 259 260 /* 261 * Function : OsSwTmrStop 262 * Description: 软件定时器的暂停内部接口 263 * Input : swtmr [IN] 类型#struct TagSwTmrCtrl*, 需要启动的定时器 264 * reckonOff [IN] 类型#UINT16 计算剩余时间开关 265 * Output : none 266 * Return : OS_OK -- 暂停定时器成功 267 * Other : None 268 */ 269 extern void OsSwTmrStop(struct TagSwTmrCtrl *swtmr, bool reckonOff); 270 271 /* 272 * 模块内内联函数定义 273 */ 274 /* 275 * Function : OsSwTmrDelete 276 * Description: 软件定时器的删除内部接口 277 * Input : swtmr [IN] 类型#struct TagSwTmrCtrl*, 需要删除的定时器 278 * Output : none 279 * Return : none 280 * Other : None 281 */ 282 extern void OsSwTmrDelete(struct TagSwTmrCtrl *swtmr); 283 284 #define OsSwtmrIqrSplLock(a) OsIntLock() 285 #define OsSwtmrIqrSplUnlock(a, b) OsIntRestore(b) 286 287 #endif /* PRT_SWTMR_INTERNAL_H */ 288