背景:
当前Arch下tick timer的实现依赖于弱函数机制,三方适配时出错及限制较大,且tick
timer作为内核必须模块,未模块化,当前散落在tick和调度等模块中,且当前存在arch依赖
内核,内核也依赖arch的情况,为了解决上述问题,将tick timer模块化,通过提供tick
timer框架实现内核依赖Arch而Arch不依赖内核,并且可以减少对外暴漏的接口,使得三方
适配时更加明确需要实现的接口。
方案描述:
1.tick timer结构
在kernel_liteos_m/arch/include/los_timer.h,中定义结构:
typedef struct {
UINT32 freq;
INT32 irqNum;
UINT32 (*init)(HWI_PROC_FUNC tickHandler);
UINT64 (*getCycle)(UINT32 *period);
VOID (*reload)(UINT64 time);
VOID (*lock)(VOID);
VOID (*unlock)(VOID);
HWI_PROC_FUNC tickHandler;
} ArchTickTimer;
并声明对外获取tick timer的接口:
ArchTickTimer *ArchSysTickTimerGet(VOID)
define LOS_SysTickTimerGet ArchSysTickTimerGet
2.在每个架构下提供默认的tick timer操作:
STATIC ArchTickTimer g_archTickTimer = {
.freq = xxx, 必填
.irqNum = xxx, 必填
.init = xxx, 必填
.getCycle = xxx, 必填
.reload = xxx, 必填
.lock = xxx, 必填
.unlock = xxx, 必填
.tickHandler = NULL, 可选
}
并实现:ArchTickTimer *ArchSysTickTimerGet(VOID) 接口
3.内核los_tick.c中提供对外(其它模块)和公共的tick timer初始化操作函数,
如果用户不想启用系统默认的tick timer,则需要在 "内核初始化之前" 调用接口:
LOS_TickTimerRegister(const ArchTickTimer *timer, const HWI_PROC_FUNC tickHandler)
将用户自己的tick timer或中断处理函数 注册进去。
用户也可以注册自己的中断处理函数(用户不提供,默认使用系统提供的)。
BREAKING CHANGE:
原来版本中每个架构下提供的tick timer相关操作函数为弱函数:
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler);
WEAK VOID HalSysTickReload(UINT64 nextResponseTime);
WEAK UINT64 HalGetTickCycle(UINT32 *period);
WEAK VOID HalTickLock(VOID);
WEAK VOID HalTickUnlock(VOID);
用户如果需要启用自己的tick timer需要自己实现相关接口(强属性),在 "内核初始化之前" 通过调用:
LOS_TickTimerRegister 接口替换系统默认提供的tick timer相关接口。
无论用户提供的tick timer 还是系统默认提供的,均在内核初始化时启动。
Close #I4N7XV:arch 重构
Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I83ad0bdf303904f0e73f808b57b60183619fddcd
94 lines
3.2 KiB
C
94 lines
3.2 KiB
C
/*
|
|
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
|
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
* are permitted provided that the following conditions are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
* conditions and the following disclaimer.
|
|
*
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
* of conditions and the following disclaimer in the documentation and/or other materials
|
|
* provided with the distribution.
|
|
*
|
|
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
|
* to endorse or promote products derived from this software without specific prior written
|
|
* permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#ifndef _LOS_TIMER_H
|
|
#define _LOS_TIMER_H
|
|
|
|
#include "los_compiler.h"
|
|
#include "los_interrupt.h"
|
|
|
|
#ifdef __cplusplus
|
|
#if __cplusplus
|
|
extern "C" {
|
|
#endif /* __cplusplus */
|
|
#endif /* __cplusplus */
|
|
|
|
#define TICK_CHECK 0x4000000
|
|
#define CYCLE_CHECK 0xFFFFFFFFU
|
|
#define SHIFT_32_BIT 32
|
|
#define MAX_HOUR 24
|
|
#define MAX_MINUTES 60
|
|
#define MAX_SECONDS 60
|
|
#define MILSEC 1000
|
|
#define RTC_WAKEUPCLOCK_RTCCLK 32768
|
|
#define RTC_WAKEUPCLOCK_RTCCLK_DIV 16
|
|
#define RTC_CALIBRATE_SLEEP_TIME 8
|
|
#define MACHINE_CYCLE_DEALAY_TIMES (LOSCFG_BASE_CORE_TICK_PER_SECOND << 2)
|
|
|
|
typedef struct {
|
|
UINT32 freq;
|
|
INT32 irqNum;
|
|
UINT32 (*init)(HWI_PROC_FUNC tickHandler);
|
|
UINT64 (*getCycle)(UINT32 *period);
|
|
VOID (*reload)(UINT64 time);
|
|
VOID (*lock)(VOID);
|
|
VOID (*unlock)(VOID);
|
|
HWI_PROC_FUNC tickHandler;
|
|
} ArchTickTimer;
|
|
|
|
UINT32 ArchEnterSleep(VOID);
|
|
|
|
/**
|
|
* @ingroup los_timer
|
|
* @brief Get tick timer control block.
|
|
*
|
|
* @par Description:
|
|
* This API is used to get tick timer control block.
|
|
*
|
|
* @param None
|
|
*
|
|
* @retval #tick timer control block
|
|
* @par Dependency:
|
|
* <ul><li>los_timer.h: the header file that contains the API declaration.</li></ul>
|
|
* @see None.
|
|
*/
|
|
ArchTickTimer *ArchSysTickTimerGet(VOID);
|
|
|
|
#define LOS_SysTickTimerGet ArchSysTickTimerGet
|
|
|
|
#ifdef __cplusplus
|
|
#if __cplusplus
|
|
}
|
|
#endif /* __cplusplus */
|
|
#endif /* __cplusplus */
|
|
|
|
#endif /* _LOS_TIMER_H */
|