更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_swtmr_pri.h 文件参考

浏览源代码.

结构体

struct  SwtmrHandlerItem
 
struct  SwtmrDebugBase
 
struct  SwtmrDebugData
 

类型定义

typedef SwtmrHandlerItemSwtmrHandlerItemPtr
 

枚举

enum  SwtmrState { OS_SWTMR_STATUS_UNUSED , OS_SWTMR_STATUS_CREATED , OS_SWTMR_STATUS_TICKING }
 

函数

UINT32 OsSwtmrGetNextTimeout (VOID)
 Scan a software timer. 更多...
 
BOOL OsIsSwtmrTask (const LosTaskCB *taskCB)
 
VOID OsSwtmrResponseTimeReset (UINT64 startTime)
 
UINT32 OsSwtmrInit (VOID)
 
VOID OsSwtmrRecycle (UINT32 processID)
 回收指定进程的软时钟 更多...
 
BOOL OsSwtmrWorkQueueFind (SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg)
 
UINT32 OsSwtmrTaskIDGetByCpuid (UINT16 cpuid)
 
BOOL OsSwtmrDebugDataUsed (UINT32 swtmrID)
 
UINT32 OsSwtmrDebugDataGet (UINT32 swtmrID, SwtmrDebugData *data, UINT32 len, UINT8 *mode)
 

变量

SWTMR_CTRL_Sg_swtmrCBArray
 
SPIN_LOCK_S g_swtmrSpin
 

类型定义说明

◆ SwtmrHandlerItemPtr

Type of the pointer to the structure of the callback function that handles software timer timeout

在文件 los_swtmr_pri.h79 行定义.

枚举类型说明

◆ SwtmrState

enum SwtmrState

Software timer state

枚举值
OS_SWTMR_STATUS_UNUSED 

The software timer is not used. | 定时器未使用,系统在定时器模块初始化时,会将系统中所有定时器资源初始化成该状态。

OS_SWTMR_STATUS_CREATED 

The software timer is created. | 定时器创建后未启动,或已停止.定时器创建后,不处于计数状态时,定时器将变成该状态。

OS_SWTMR_STATUS_TICKING 

The software timer is timing. | 定时器处于计数状态,在定时器创建后调用LOS_SwtmrStart接口启动,定时器将变成该状态,是定时器运行时的状态。

在文件 los_swtmr_pri.h55 行定义.

55 { //定时器状态
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. | 定时器处于计数状态,在定时器创建后调用LOS_SwtmrStart接口启动,定时器将变成该状态,是定时器运行时的状态。 */
59};
@ OS_SWTMR_STATUS_UNUSED
Definition: los_swtmr_pri.h:56
@ OS_SWTMR_STATUS_CREATED
Definition: los_swtmr_pri.h:57
@ OS_SWTMR_STATUS_TICKING
Definition: los_swtmr_pri.h:58

函数说明

◆ OsIsSwtmrTask()

BOOL OsIsSwtmrTask ( const LosTaskCB taskCB)

在文件 los_swtmr.c383 行定义.

384{
385 if (taskCB->taskEntry == (TSK_ENTRY_FUNC)SwtmrTask) {
386 return TRUE;
387 }
388 return FALSE;
389}
VOID *(* TSK_ENTRY_FUNC)(UINTPTR param1, UINTPTR param2, UINTPTR param3, UINTPTR param4)
Define the type of a task entrance function.
Definition: los_task.h:480
STATIC VOID SwtmrTask(VOID)
软时钟的入口函数,拥有任务的最高优先级 0 级!
Definition: los_swtmr.c:325
TSK_ENTRY_FUNC taskEntry
函数调用图:
这是这个函数的调用关系图:

◆ OsSwtmrDebugDataGet()

UINT32 OsSwtmrDebugDataGet ( UINT32  swtmrID,
SwtmrDebugData data,
UINT32  len,
UINT8 mode 
)

在文件 los_swtmr.c142 行定义.

143{
144 UINT32 intSave;
145 errno_t ret;
146
147 if ((swtmrID > LOSCFG_BASE_CORE_SWTMR_LIMIT) || (data == NULL) ||
148 (mode == NULL) || (len < sizeof(SwtmrDebugData))) {
149 return LOS_NOK;
150 }
151
152 SWTMR_CTRL_S *swtmr = &g_swtmrCBArray[swtmrID];
153 SWTMR_LOCK(intSave);
154 ret = memcpy_s(data, len, &g_swtmrDebugData[swtmrID], sizeof(SwtmrDebugData));
155 *mode = swtmr->ucMode;
156 SWTMR_UNLOCK(intSave);
157 if (ret != EOK) {
158 return LOS_NOK;
159 }
160 return LOS_OK;
161}
LITE_OS_SEC_BSS SWTMR_CTRL_S * g_swtmrCBArray
Definition: los_swtmr.c:112
STATIC SwtmrDebugData * g_swtmrDebugData
Definition: los_swtmr.c:131
unsigned int UINT32
Definition: los_typedef.h:57
UINT8 ucMode
Definition: los_swtmr.h:270
这是这个函数的调用关系图:

◆ OsSwtmrDebugDataUsed()

BOOL OsSwtmrDebugDataUsed ( UINT32  swtmrID)

在文件 los_swtmr.c133 行定义.

134{
135 if (swtmrID > LOSCFG_BASE_CORE_SWTMR_LIMIT) {
136 return FALSE;
137 }
138
139 return g_swtmrDebugData[swtmrID].swtmrUsed;
140}
这是这个函数的调用关系图:

◆ OsSwtmrGetNextTimeout()

UINT32 OsSwtmrGetNextTimeout ( VOID  )

Scan a software timer.

Description:
  • This API is used to scan a software timer when a Tick interrupt occurs and determine whether the software timer expires.
注意
  • None.
参数
None.
返回值
None.
Dependency:
参见
LOS_SwtmrStop

在文件 los_swtmr.c675 行定义.

676{
677 UINT64 currTime = OsGetCurrSchedTimeCycle();
679 UINT64 time = (OsSortLinkGetNextExpireTime(currTime, &srq->swtmrSortLink) / OS_CYCLE_PER_TICK);
680 if (time > OS_INVALID_VALUE) {
681 time = OS_INVALID_VALUE;
682 }
683 return (UINT32)time;
684}
STATIC INLINE UINT32 ArchCurrCpuid(VOID)
Definition: los_hw_cpu.h:168
STATIC INLINE UINT64 OsGetCurrSchedTimeCycle(VOID)
Definition: los_sched_pri.h:75
STATIC SwtmrRunqueue g_swtmrRunqueue[LOSCFG_KERNEL_CORE_NUM]
Definition: los_swtmr.c:127
long unsigned int UINT64
Definition: los_typedef.h:66
SortLinkAttribute swtmrSortLink
Definition: los_swtmr.c:122
time_t time(time_t *t)
Definition: time.c:1224
函数调用图:

◆ OsSwtmrInit()

UINT32 OsSwtmrInit ( VOID  )

在文件 los_swtmr.c441 行定义.

442{
443 UINT32 ret;
444 UINT32 cpuid = ArchCurrCpuid();
445 UINT32 swtmrTaskID;
446
447 if (cpuid == 0) {
448 ret = SwtmrBaseInit();
449 if (ret != LOS_OK) {
450 goto ERROR;
451 }
452 }
453
454 ret = SwtmrTaskCreate(cpuid, &swtmrTaskID);
455 if (ret != LOS_OK) {
456 ret = LOS_ERRNO_SWTMR_TASK_CREATE_FAILED;
457 goto ERROR;
458 }
459
460 SwtmrRunqueue *srq = &g_swtmrRunqueue[cpuid];
461 srq->swtmrTask = OsGetTaskCB(swtmrTaskID);
462 return LOS_OK;
463
464ERROR:
465 PRINT_ERR("OsSwtmrInit error! ret = %u\n", ret);
467 g_swtmrCBArray = NULL;
469 g_swtmrHandlerPool = NULL;
470 return ret;
471}
UINT8 * m_aucSysMem1
系统动态内存池地址的起始地址 @note_thinking 能否不要用 0,1来命名核心变量 ???
Definition: los_memory.c:108
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
Definition: los_memory.c:1369
UINT8 * m_aucSysMem0
异常交互动态内存池地址的起始地址,当不支持异常交互特性时,m_aucSysMem0等于m_aucSysMem1。
Definition: los_memory.c:107
STATIC UINT32 SwtmrBaseInit(VOID)
软时钟初始化 ,注意函数在多CPU情况下会执行多次
Definition: los_swtmr.c:400
STATIC UINT32 SwtmrTaskCreate(UINT16 cpuid, UINT32 *swtmrTaskID)
创建软时钟任务,每个cpu core都可以拥有自己的软时钟任务
Definition: los_swtmr.c:356
LITE_OS_SEC_BSS UINT8 * g_swtmrHandlerPool
Definition: los_swtmr.c:113
STATIC INLINE LosTaskCB * OsGetTaskCB(UINT32 taskID)
通过任务ID获取任务实体,task由任务池分配,本质是个数组,彼此都挨在一块
Definition: los_task_pri.h:250
LosTaskCB * swtmrTask
Definition: los_swtmr.c:123
函数调用图:
这是这个函数的调用关系图:

◆ OsSwtmrRecycle()

VOID OsSwtmrRecycle ( UINT32  processID)

回收指定进程的软时钟

在文件 los_swtmr.c391 行定义.

392{
393 for (UINT16 index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++) {//一个进程往往会有多个定时器
394 if (g_swtmrCBArray[index].uwOwnerPid == processID) {//找到一个
395 LOS_SwtmrDelete(index);//删除定时器
396 }
397 }
398}
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT16 swtmrID)
接口函数 删除定时器
Definition: los_swtmr.c:889
unsigned short UINT16
Definition: los_typedef.h:56
函数调用图:
这是这个函数的调用关系图:

◆ OsSwtmrResponseTimeReset()

VOID OsSwtmrResponseTimeReset ( UINT64  startTime)

在文件 los_swtmr.c610 行定义.

611{
612 UINT16 cpuid = ArchCurrCpuid();
613 SortLinkAttribute *swtmrSortLink = &g_swtmrRunqueue[cpuid].swtmrSortLink;
614 LOS_DL_LIST *listHead = &swtmrSortLink->sortLink;
615 LOS_DL_LIST *listNext = listHead->pstNext;
616
617 LOS_SpinLock(&swtmrSortLink->spinLock);
618 while (listNext != listHead) {
619 SortLinkList *sortList = LOS_DL_LIST_ENTRY(listNext, SortLinkList, sortLinkNode);
620 OsDeleteNodeSortLink(swtmrSortLink, sortList);
621 LOS_SpinUnlock(&swtmrSortLink->spinLock);
622
623 SwtmrRestart(startTime, sortList, cpuid);
624
625 LOS_SpinLock(&swtmrSortLink->spinLock);
626 listNext = listNext->pstNext;
627 }
628 LOS_SpinUnlock(&swtmrSortLink->spinLock);
629}
VOID LOS_SpinLock(SPIN_LOCK_S *lock)
Definition: los_spinlock.c:50
VOID LOS_SpinUnlock(SPIN_LOCK_S *lock)
Definition: los_spinlock.c:84
STATIC INLINE VOID SwtmrRestart(UINT64 startTime, SortLinkList *sortList, UINT16 cpuid)
Definition: los_swtmr.c:599
struct LOS_DL_LIST * pstNext
Definition: los_list.h:84
函数调用图:
这是这个函数的调用关系图:

◆ OsSwtmrTaskIDGetByCpuid()

UINT32 OsSwtmrTaskIDGetByCpuid ( UINT16  cpuid)

在文件 los_swtmr.c378 行定义.

379{
380 return g_swtmrRunqueue[cpuid].swtmrTask->taskID;
381}
UINT32 taskID

◆ OsSwtmrWorkQueueFind()

BOOL OsSwtmrWorkQueueFind ( SCHED_TL_FIND_FUNC  checkFunc,
UINTPTR  arg 
)

在文件 los_swtmr.c661 行定义.

662{
663 UINT32 intSave;
664
665 SWTMR_LOCK(intSave);
666 BOOL find = SwtmrTimeListFind(checkFunc, arg);
667 SWTMR_UNLOCK(intSave);
668 return find;
669}
STATIC BOOL SwtmrTimeListFind(SCHED_TL_FIND_FUNC checkFunc, UINTPTR arg)
Definition: los_swtmr.c:650
size_t BOOL
Definition: los_typedef.h:88
函数调用图:

变量说明

◆ g_swtmrCBArray

SWTMR_CTRL_S* g_swtmrCBArray
extern

First address in Timer memory space
定时器池

在文件 los_swtmr.c112 行定义.

◆ g_swtmrSpin

SPIN_LOCK_S g_swtmrSpin
extern