1 /* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 * of conditions and the following disclaimer in the documentation and/or other materials 13 * provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 16 * to endorse or promote products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _LOS_SWTMR_PRI_H 33 #define _LOS_SWTMR_PRI_H 34 35 #include "los_swtmr.h" 36 #include "los_spinlock.h" 37 #include "los_sched_pri.h" 38 39 #ifdef LOSCFG_SECURITY_VID 40 #include "vid_api.h" 41 #else 42 #define MAX_INVALID_TIMER_VID OS_SWTMR_MAX_TIMERID 43 #endif 44 45 #ifdef __cplusplus 46 #if __cplusplus 47 extern "C" { 48 #endif /* __cplusplus */ 49 #endif /* __cplusplus */ 50 51 /** 52 * @ingroup los_swtmr_pri 53 * Software timer state 54 */ 55 enum SwtmrState { 56 OS_SWTMR_STATUS_UNUSED, /**< The software timer is not used. */ 57 OS_SWTMR_STATUS_CREATED, /**< The software timer is created. */ 58 OS_SWTMR_STATUS_TICKING /**< The software timer is timing. */ 59 }; 60 61 /** 62 * @ingroup los_swtmr_pri 63 * Structure of the callback function that handles software timer timeout 64 */ 65 typedef struct { 66 SWTMR_PROC_FUNC handler; /**< Callback function that handles software timer timeout */ 67 UINTPTR arg; /**< Parameter passed in when the callback function 68 that handles software timer timeout is called */ 69 LOS_DL_LIST node; 70 #ifdef LOSCFG_SWTMR_DEBUG 71 UINT32 swtmrID; 72 #endif 73 } SwtmrHandlerItem; 74 75 /** 76 * @ingroup los_swtmr_pri 77 * Type of the pointer to the structure of the callback function that handles software timer timeout 78 */ 79 typedef SwtmrHandlerItem *SwtmrHandlerItemPtr; 80 81 extern SWTMR_CTRL_S *g_swtmrCBArray; 82 83 #define OS_SWT_FROM_SID(swtmrID) ((SWTMR_CTRL_S *)g_swtmrCBArray + ((swtmrID) % LOSCFG_BASE_CORE_SWTMR_LIMIT)) 84 85 /** 86 * @ingroup los_swtmr_pri 87 * @brief Scan a software timer. 88 * 89 * @par Description: 90 * <ul> 91 * <li>This API is used to scan a software timer when a Tick interrupt occurs and determine whether 92 * the software timer expires.</li> 93 * </ul> 94 * @attention 95 * <ul> 96 * <li>None.</li> 97 * </ul> 98 * 99 * @param None. 100 * 101 * @retval None. 102 * @par Dependency: 103 * <ul><li>los_swtmr_pri.h: the header file that contains the API declaration.</li></ul> 104 * @see LOS_SwtmrStop 105 */ 106 107 extern UINT32 OsSwtmrGetNextTimeout(VOID); 108 extern BOOL OsIsSwtmrTask(const LosTaskCB *taskCB); 109 extern VOID OsSwtmrResponseTimeReset(UINT64 startTime); 110 extern UINT32 OsSwtmrInit(VOID); 111 extern VOID OsSwtmrRecycle(UINT32 processID); 112 extern BOOL OsSwtmrWorkQueueFind(SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg); 113 extern SPIN_LOCK_S g_swtmrSpin; 114 extern UINT32 OsSwtmrTaskIDGetByCpuid(UINT16 cpuid); 115 116 #ifdef LOSCFG_SWTMR_DEBUG 117 typedef struct { 118 UINT64 startTime; 119 UINT64 waitTimeMax; 120 UINT64 waitTime; 121 UINT64 waitCount; 122 UINT64 readyStartTime; 123 UINT64 readyTime; 124 UINT64 readyTimeMax; 125 UINT64 runTime; 126 UINT64 runTimeMax; 127 UINT64 runCount; 128 UINT32 times; 129 } SwtmrDebugBase; 130 131 typedef struct { 132 SwtmrDebugBase base; 133 SWTMR_PROC_FUNC handler; 134 UINT32 period; 135 UINT32 cpuid; 136 BOOL swtmrUsed; 137 } SwtmrDebugData; 138 139 extern BOOL OsSwtmrDebugDataUsed(UINT32 swtmrID); 140 extern UINT32 OsSwtmrDebugDataGet(UINT32 swtmrID, SwtmrDebugData *data, UINT32 len, UINT8 *mode); 141 #endif 142 143 #ifdef __cplusplus 144 #if __cplusplus 145 } 146 #endif /* __cplusplus */ 147 #endif /* __cplusplus */ 148 149 #endif /* _LOS_SWTMR_PRI_H */ 150