feat: 内核提供tick timer框架,支持多架构多平台通用化
背景: 当前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
This commit is contained in:
parent
900f183260
commit
f635450d7c
|
@ -42,8 +42,6 @@ extern "C" {
|
|||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
|
|
@ -47,13 +47,7 @@
|
|||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
HalHwiInit();
|
||||
|
||||
ret = HalTickStart(OsTickHandler);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Tick start failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
|
|
|
@ -29,8 +29,8 @@
|
|||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_timer.h"
|
||||
#include "los_config.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_arch_context.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_reg.h"
|
||||
|
@ -51,14 +51,24 @@
|
|||
#define OS_TIMER_READ_CTL_ADDR (OS_TIMER_REG_BASE + 16)
|
||||
#define OS_TIMER_READ_VAL_ADDR (OS_TIMER_REG_BASE + 20)
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
Input : none
|
||||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = OS_SYS_CLOCK,
|
||||
.irqNum = OS_TIMER_IRQ_NUM,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
UINT32 value;
|
||||
|
@ -83,7 +93,7 @@ WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
|||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID HalClockIrqClear(VOID)
|
||||
STATIC VOID SysTickClockIrqClear(VOID)
|
||||
{
|
||||
UINT32 mask = OS_TIMER_INT_MASK << OS_TIMER_INT_POS;
|
||||
UINT32 status;
|
||||
|
@ -94,15 +104,15 @@ STATIC VOID HalClockIrqClear(VOID)
|
|||
} while (status & mask);
|
||||
}
|
||||
|
||||
WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
ArchTickLock();
|
||||
SysTickLock();
|
||||
WRITE_UINT32(nextResponseTime, OS_TIMER_PERIOD_REG_ADDR);
|
||||
HalClockIrqClear();
|
||||
ArchTickUnlock();
|
||||
SysTickClockIrqClear();
|
||||
SysTickUnlock();
|
||||
}
|
||||
|
||||
WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 val;
|
||||
|
||||
|
@ -118,7 +128,7 @@ WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
|||
return (UINT64)val;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickLock(VOID)
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
UINT32 value;
|
||||
|
||||
|
@ -129,7 +139,7 @@ WEAK VOID ArchTickLock(VOID)
|
|||
WRITE_UINT32(value, OS_TIMER_CTL_REG_ADDR);
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickUnlock(VOID)
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
UINT32 value;
|
||||
|
||||
|
@ -140,6 +150,11 @@ WEAK VOID ArchTickUnlock(VOID)
|
|||
WRITE_UINT32(value, OS_TIMER_CTL_REG_ADDR);
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
dsb();
|
||||
|
|
|
@ -42,8 +42,6 @@ extern "C" {
|
|||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
|
|
@ -48,13 +48,7 @@
|
|||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
HalHwiInit();
|
||||
|
||||
ret = HalTickStart(OsTickHandler);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Tick start failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
|
|
|
@ -34,38 +34,38 @@
|
|||
#include "ARMCM3.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_context.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
Input : none
|
||||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = OS_SYS_CLOCK,
|
||||
.irqNum = SysTick_IRQn,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
if ((OS_SYS_CLOCK == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > OS_SYS_CLOCK)) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler, NULL);
|
||||
OsSetVector(tick->irqNum, handler, NULL);
|
||||
#else
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler);
|
||||
OsSetVector(tick->irqNum, handler);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
g_sysClock = OS_SYS_CLOCK;
|
||||
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
|
||||
ret = SysTick_Config(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
|
||||
if (ret == 1) {
|
||||
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
|
||||
|
@ -74,7 +74,7 @@ WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
|||
return LOS_OK;
|
||||
}
|
||||
|
||||
WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
|
||||
|
@ -83,7 +83,7 @@ WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
|||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 hwCycle = 0;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
|
@ -96,16 +96,21 @@ WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
|||
return (UINT64)hwCycle;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickLock(VOID)
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickUnlock(VOID)
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
__DSB();
|
||||
|
|
|
@ -42,8 +42,6 @@ extern "C" {
|
|||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
|
|
@ -47,13 +47,7 @@
|
|||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
HalHwiInit();
|
||||
|
||||
ret = HalTickStart(OsTickHandler);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Tick start failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
|
|
|
@ -33,38 +33,38 @@
|
|||
#include "los_config.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_context.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
Input : none
|
||||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = OS_SYS_CLOCK,
|
||||
.irqNum = SysTick_IRQn,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
if ((OS_SYS_CLOCK == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > OS_SYS_CLOCK)) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler, NULL);
|
||||
OsSetVector(tick->irqNum, handler, NULL);
|
||||
#else
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler);
|
||||
OsSetVector(tick->irqNum, handler);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
g_sysClock = OS_SYS_CLOCK;
|
||||
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
|
||||
ret = SysTick_Config(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
|
||||
if (ret == 1) {
|
||||
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
|
||||
|
@ -73,7 +73,7 @@ WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
|||
return LOS_OK;
|
||||
}
|
||||
|
||||
WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
|
||||
|
@ -82,7 +82,7 @@ WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
|||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 hwCycle = 0;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
|
@ -95,16 +95,21 @@ WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
|||
return (UINT64)hwCycle;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickLock(VOID)
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickUnlock(VOID)
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
__DSB();
|
||||
|
|
|
@ -42,8 +42,6 @@ extern "C" {
|
|||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
|
|
@ -47,13 +47,7 @@
|
|||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
HalHwiInit();
|
||||
|
||||
ret = HalTickStart(OsTickHandler);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Tick start failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
|
|
|
@ -33,38 +33,37 @@
|
|||
#include "los_config.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_context.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
Input : none
|
||||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = OS_SYS_CLOCK,
|
||||
.irqNum = SysTick_IRQn,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
if ((OS_SYS_CLOCK == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > OS_SYS_CLOCK)) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler, NULL);
|
||||
OsSetVector(tick->irqNum, handler, NULL);
|
||||
#else
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler);
|
||||
OsSetVector(tick->irqNum, handler);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
g_sysClock = OS_SYS_CLOCK;
|
||||
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
|
||||
ret = SysTick_Config(g_cyclesPerTick);
|
||||
if (ret == 1) {
|
||||
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
|
||||
|
@ -73,7 +72,7 @@ WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
|||
return LOS_OK;
|
||||
}
|
||||
|
||||
WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
|
||||
|
@ -82,7 +81,7 @@ WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
|||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 hwCycle = 0;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
|
@ -95,16 +94,21 @@ WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
|||
return (UINT64)hwCycle;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickLock(VOID)
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickUnlock(VOID)
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
__DSB();
|
||||
|
|
|
@ -42,8 +42,6 @@ extern "C" {
|
|||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
|
|
@ -47,13 +47,7 @@
|
|||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
HalHwiInit();
|
||||
|
||||
ret = HalTickStart(OsTickHandler);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Tick start failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
|
|
|
@ -33,38 +33,38 @@
|
|||
#include "los_config.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_context.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
Input : none
|
||||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = OS_SYS_CLOCK,
|
||||
.irqNum = SysTick_IRQn,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
if ((OS_SYS_CLOCK == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > OS_SYS_CLOCK)) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler, NULL);
|
||||
OsSetVector(tick->irqNum, handler, NULL);
|
||||
#else
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler);
|
||||
OsSetVector(tick->irqNum, handler);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
g_sysClock = OS_SYS_CLOCK;
|
||||
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
|
||||
ret = SysTick_Config(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
|
||||
if (ret == 1) {
|
||||
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
|
||||
|
@ -73,7 +73,7 @@ WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
|||
return LOS_OK;
|
||||
}
|
||||
|
||||
WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
|
||||
|
@ -82,7 +82,7 @@ WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
|||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 hwCycle = 0;
|
||||
UINTPTR intSave = LOS_IntLock();
|
||||
|
@ -95,16 +95,21 @@ WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
|||
return (UINT64)hwCycle;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickLock(VOID)
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickUnlock(VOID)
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
__DSB();
|
||||
|
|
|
@ -42,8 +42,6 @@ extern "C" {
|
|||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
|
|
@ -47,13 +47,7 @@
|
|||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
HalHwiInit();
|
||||
|
||||
ret = HalTickStart(OsTickHandler);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Tick start failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
|
|
|
@ -33,38 +33,38 @@
|
|||
#include "los_config.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_context.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
Input : none
|
||||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = OS_SYS_CLOCK,
|
||||
.irqNum = SysTick_IRQn,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
if ((OS_SYS_CLOCK == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > OS_SYS_CLOCK)) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler, NULL);
|
||||
OsSetVector(tick->irqNum, handler, NULL);
|
||||
#else
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler);
|
||||
OsSetVector(tick->irqNum, handler);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
g_sysClock = OS_SYS_CLOCK;
|
||||
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
|
||||
ret = SysTick_Config(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
|
||||
if (ret == 1) {
|
||||
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
|
||||
|
@ -73,7 +73,7 @@ WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
|||
return LOS_OK;
|
||||
}
|
||||
|
||||
WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
|
||||
|
@ -82,7 +82,7 @@ WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
|||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 hwCycle = 0;
|
||||
UINTPTR intSave = LOS_IntLock();
|
||||
|
@ -95,16 +95,21 @@ WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
|||
return (UINT64)hwCycle;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickLock(VOID)
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickUnlock(VOID)
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
__DSB();
|
||||
|
|
|
@ -42,8 +42,6 @@ extern "C" {
|
|||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
|
|
@ -36,8 +36,6 @@
|
|||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_timer.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchInit
|
||||
|
@ -48,14 +46,7 @@
|
|||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
HalHwiInit();
|
||||
|
||||
ret = HalTickStart(OsTickHandler);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Tick start failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
|
|
|
@ -33,39 +33,38 @@
|
|||
#include "los_config.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_context.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
Input : none
|
||||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = OS_SYS_CLOCK,
|
||||
.irqNum = SysTick_IRQn,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
if ((OS_SYS_CLOCK == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > OS_SYS_CLOCK)) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler, NULL);
|
||||
OsSetVector(tick->irqNum, handler, NULL);
|
||||
#else
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler);
|
||||
OsSetVector(tick->irqNum, handler);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
g_sysClock = OS_SYS_CLOCK;
|
||||
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
|
||||
ret = SysTick_Config(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
|
||||
if (ret == 1) {
|
||||
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
|
||||
|
@ -74,7 +73,7 @@ WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
|||
return LOS_OK;
|
||||
}
|
||||
|
||||
WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
|
||||
|
@ -83,7 +82,7 @@ WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
|||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 hwCycle = 0;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
|
@ -96,16 +95,21 @@ WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
|||
return (UINT64)hwCycle;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickLock(VOID)
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickUnlock(VOID)
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
__DSB();
|
||||
|
|
|
@ -42,8 +42,6 @@ extern "C" {
|
|||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
|
|
@ -49,14 +49,7 @@
|
|||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
HalHwiInit();
|
||||
|
||||
ret = HalTickStart(OsTickHandler);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Tick start failed!\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
|
|
|
@ -33,39 +33,38 @@
|
|||
#include "los_config.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_context.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
Input : none
|
||||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = OS_SYS_CLOCK,
|
||||
.irqNum = SysTick_IRQn,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
if ((OS_SYS_CLOCK == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > OS_SYS_CLOCK)) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler, NULL);
|
||||
OsSetVector(tick->irqNum, handler, NULL);
|
||||
#else
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler);
|
||||
OsSetVector(tick->irqNum, handler);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
g_sysClock = OS_SYS_CLOCK;
|
||||
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
|
||||
ret = SysTick_Config(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
|
||||
if (ret == 1) {
|
||||
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
|
||||
|
@ -74,7 +73,7 @@ WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
|||
return LOS_OK;
|
||||
}
|
||||
|
||||
WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
|
||||
|
@ -83,7 +82,7 @@ WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
|||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 hwCycle = 0;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
|
@ -96,16 +95,21 @@ WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
|||
return (UINT64)hwCycle;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickLock(VOID)
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickUnlock(VOID)
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
__DSB();
|
||||
|
|
|
@ -42,8 +42,6 @@ extern "C" {
|
|||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
|
|
@ -47,13 +47,7 @@
|
|||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
HalHwiInit();
|
||||
|
||||
ret = HalTickStart(OsTickHandler);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Tick start failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
|
|
|
@ -33,38 +33,38 @@
|
|||
#include "los_config.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_context.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
Input : none
|
||||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = OS_SYS_CLOCK,
|
||||
.irqNum = SysTick_IRQn,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
if ((OS_SYS_CLOCK == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > OS_SYS_CLOCK)) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler, NULL);
|
||||
OsSetVector(tick->irqNum, handler, NULL);
|
||||
#else
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler);
|
||||
OsSetVector(tick->irqNum, handler);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
g_sysClock = OS_SYS_CLOCK;
|
||||
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
|
||||
ret = SysTick_Config(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
|
||||
if (ret == 1) {
|
||||
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
|
||||
|
@ -73,7 +73,7 @@ WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
|||
return LOS_OK;
|
||||
}
|
||||
|
||||
WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
|
||||
|
@ -82,7 +82,7 @@ WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
|||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 hwCycle = 0;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
|
@ -95,16 +95,21 @@ WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
|||
return (UINT64)hwCycle;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickLock(VOID)
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickUnlock(VOID)
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
__DSB();
|
||||
|
|
|
@ -42,8 +42,6 @@ extern "C" {
|
|||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
|
|
@ -47,13 +47,7 @@
|
|||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
HalHwiInit();
|
||||
|
||||
ret = HalTickStart(OsTickHandler);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Tick start failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
|
|
|
@ -33,38 +33,38 @@
|
|||
#include "los_config.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_context.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
Input : none
|
||||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = OS_SYS_CLOCK,
|
||||
.irqNum = SysTick_IRQn,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
if ((OS_SYS_CLOCK == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > OS_SYS_CLOCK)) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler, NULL);
|
||||
OsSetVector(tick->irqNum, handler, NULL);
|
||||
#else
|
||||
OsSetVector(SysTick_IRQn, (HWI_PROC_FUNC)handler);
|
||||
OsSetVector(tick->irqNum, handler);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
g_sysClock = OS_SYS_CLOCK;
|
||||
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
|
||||
ret = SysTick_Config(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
|
||||
if (ret == 1) {
|
||||
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
|
||||
|
@ -73,7 +73,7 @@ WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
|||
return LOS_OK;
|
||||
}
|
||||
|
||||
WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
|
||||
|
@ -82,7 +82,7 @@ WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
|||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 hwCycle = 0;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
|
@ -95,16 +95,21 @@ WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
|||
return (UINT64)hwCycle;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickLock(VOID)
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickUnlock(VOID)
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
__DSB();
|
||||
|
|
|
@ -42,8 +42,6 @@ extern "C" {
|
|||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
|
|
@ -49,13 +49,7 @@ STATIC UINT32 g_sysNeedSched = FALSE;
|
|||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
HalHwiInit();
|
||||
|
||||
ret = HalTickStart(OsTickHandler);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Tick start failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
|
|
|
@ -33,8 +33,6 @@
|
|||
#include "los_config.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_context.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
typedef struct {
|
||||
|
@ -56,6 +54,23 @@ typedef struct {
|
|||
|
||||
#define TIM_INT_NUM 1
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = OS_SYS_CLOCK,
|
||||
.irqNum = TIM_INT_NUM,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
|
@ -63,15 +78,10 @@ Input : none
|
|||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
if ((OS_SYS_CLOCK == 0) || (LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > OS_SYS_CLOCK)) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
|
||||
g_sysClock = OS_SYS_CLOCK;
|
||||
g_cyclesPerTick = OS_CYCLE_PER_TICK;
|
||||
SysTick->LOAD = (OS_CYCLE_PER_TICK - 1);
|
||||
SysTick->VAL = 0;
|
||||
SysTick->CTRL |= (CORETIM_SOURCE | CORETIM_ENABLE | CORETIM_INTMASK);
|
||||
|
@ -80,15 +90,15 @@ WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
|||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(TIM_INT_NUM, (HWI_PROC_FUNC)handler, NULL);
|
||||
OsSetVector(tick->irqNum, handler, NULL);
|
||||
#else
|
||||
OsSetVector(TIM_INT_NUM, (HWI_PROC_FUNC)handler);
|
||||
OsSetVector(tick->irqNum, handler);
|
||||
#endif
|
||||
#endif
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
SysTick->CTRL &= ~CORETIM_ENABLE;
|
||||
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
|
||||
|
@ -96,7 +106,7 @@ WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
|||
SysTick->CTRL |= CORETIM_ENABLE;
|
||||
}
|
||||
|
||||
WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 hwCycle;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
|
@ -106,16 +116,21 @@ WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
|||
return (UINT64)hwCycle;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickLock(VOID)
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
SysTick->CTRL &= ~CORETIM_ENABLE;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickUnlock(VOID)
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
SysTick->CTRL |= CORETIM_ENABLE;
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
VOID Wfi(VOID)
|
||||
{
|
||||
__asm__ volatile("wait");
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#define _LOS_TIMER_H
|
||||
|
||||
#include "los_compiler.h"
|
||||
#include "los_interrupt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
@ -52,57 +53,36 @@ extern "C" {
|
|||
#define RTC_CALIBRATE_SLEEP_TIME 8
|
||||
#define MACHINE_CYCLE_DEALAY_TIMES (LOSCFG_BASE_CORE_TICK_PER_SECOND << 2)
|
||||
|
||||
typedef VOID (*OS_TICK_HANDLER)(VOID);
|
||||
|
||||
VOID ArchTickLock(VOID);
|
||||
|
||||
VOID ArchTickUnlock(VOID);
|
||||
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 systick cycle.
|
||||
* @brief Get tick timer control block.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get systick cycle and return current tick period.
|
||||
* This API is used to get tick timer control block.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param: period [OUT] current tick period.
|
||||
*
|
||||
* @retval current tick count.
|
||||
* @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
|
||||
* @see None.
|
||||
*/
|
||||
UINT64 ArchGetTickCycle(UINT32 *period);
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_timer
|
||||
* @brief reconfig systick, and clear SysTick_IRQn.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to reconfig systick, and clear SysTick_IRQn.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param nextResponseTime [IN] tick period
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_timer.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None
|
||||
*/
|
||||
VOID ArchSysTickReload(UINT64 nextResponseTime);
|
||||
#define LOS_SysTickTimerGet ArchSysTickTimerGet
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
|
|
@ -43,8 +43,6 @@ extern "C" {
|
|||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
|
|
@ -31,14 +31,7 @@
|
|||
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
HalHwiInit();
|
||||
|
||||
ret = HalTickStart(OsTickHandler);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Tick start failed!\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID ArchSysExit(VOID)
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
#include "los_tick.h"
|
||||
#include "los_reg.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_arch_timer.h"
|
||||
#include "nuclei_sdk_hal.h"
|
||||
|
||||
|
@ -43,11 +42,28 @@
|
|||
|
||||
#define SYSTICK_TICK_CONST (SOC_TIMER_FREQ / LOSCFG_BASE_CORE_TICK_PER_SECOND)
|
||||
|
||||
static OS_TICK_HANDLER systick_handler = (OS_TICK_HANDLER)NULL;
|
||||
STATIC HWI_PROC_FUNC g_sysTickHandler = (HWI_PROC_FUNC)NULL;
|
||||
|
||||
extern UINT32 g_intCount;
|
||||
|
||||
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = OS_SYS_CLOCK,
|
||||
.irqNum = SysTimer_IRQn,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
SysTick_Config(SYSTICK_TICK_CONST);
|
||||
ECLIC_DisableIRQ(SysTimer_IRQn);
|
||||
|
@ -59,31 +75,29 @@ WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
|||
ECLIC_SetShvIRQ(SysTimerSW_IRQn, ECLIC_VECTOR_INTERRUPT);
|
||||
ECLIC_SetLevelIRQ(SysTimerSW_IRQn, configKERNEL_INTERRUPT_PRIORITY);
|
||||
ECLIC_EnableIRQ(SysTimerSW_IRQn);
|
||||
g_sysClock = OS_SYS_CLOCK;
|
||||
g_cyclesPerTick = g_sysClock / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
g_intCount = 0;
|
||||
|
||||
systick_handler = handler;
|
||||
g_sysTickHandler = handler;
|
||||
|
||||
return LOS_OK; /* never return */
|
||||
}
|
||||
|
||||
#define HalTickSysTickHandler eclic_mtip_handler
|
||||
#define ArchTickSysTickHandler eclic_mtip_handler
|
||||
|
||||
void HalTickSysTickHandler( void )
|
||||
void ArchTickSysTickHandler(void)
|
||||
{
|
||||
/* Do systick handler registered in HalTickStart. */
|
||||
if ((void *)systick_handler != NULL) {
|
||||
systick_handler();
|
||||
if ((void *)g_sysTickHandler != NULL) {
|
||||
g_sysTickHandler();
|
||||
}
|
||||
}
|
||||
|
||||
WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
SysTick_Reload(nextResponseTime);
|
||||
}
|
||||
|
||||
WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT64 ticks;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
|
@ -93,16 +107,21 @@ WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
|||
return ticks;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickLock(VOID)
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
SysTimer_Stop();
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickUnlock(VOID)
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
SysTimer_Start();
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
__WFI();
|
||||
|
|
|
@ -45,8 +45,6 @@ extern "C" {
|
|||
#define MTIMER_HI_OFFSET 4
|
||||
#define OS_COMBINED_64(hi, ho) (((UINT64)(hi) << 32) | (ho))
|
||||
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
|
|
@ -35,22 +35,13 @@
|
|||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_timer.h"
|
||||
#include "los_debug.h"
|
||||
#include "soc.h"
|
||||
|
||||
STATIC UINT32 g_sysNeedSched = FALSE;
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
HalHwiInit();
|
||||
|
||||
ret = HalTickStart(OsTickHandler);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Tick start failed!\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
VOID HalIrqEndCheckNeedSched(VOID)
|
||||
|
|
|
@ -34,23 +34,44 @@
|
|||
#include "los_tick.h"
|
||||
#include "los_reg.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_arch_timer.h"
|
||||
#include "riscv_hal.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = OS_SYS_CLOCK,
|
||||
.irqNum = RISCV_MACH_TIMER_IRQ,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
g_sysClock = OS_SYS_CLOCK;
|
||||
g_cyclesPerTick = g_sysClock / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
g_intCount = 0;
|
||||
UINT32 period = (UINT32)LOSCFG_BASE_CORE_TICK_RESPONSE_MAX;
|
||||
UINT32 ret = LOS_HwiCreate(RISCV_MACH_TIMER_IRQ, 0x1, 0, handler, period);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
HalClockInit(handler, (UINT32)LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
|
||||
WRITE_UINT32(0xffffffff, MTIMERCMP + 4); /* The high 4 bits of mtimer */
|
||||
WRITE_UINT32(period, MTIMERCMP);
|
||||
WRITE_UINT32(0x0, MTIMERCMP + 4); /* The high 4 bits of mtimer */
|
||||
|
||||
return LOS_OK; /* never return */
|
||||
HalIrqEnable(RISCV_MACH_TIMER_IRQ);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
UINT64 timeMax = (UINT64)LOSCFG_BASE_CORE_TICK_RESPONSE_MAX - 1;
|
||||
UINT64 timer;
|
||||
|
@ -71,7 +92,7 @@ WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
|||
HalIrqEnable(RISCV_MACH_TIMER_IRQ);
|
||||
}
|
||||
|
||||
WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
(VOID)period;
|
||||
UINT32 timerL, timerH;
|
||||
|
@ -81,6 +102,21 @@ WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
|||
return OS_COMBINED_64(timerH, timerL);
|
||||
}
|
||||
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
HalIrqDisable(RISCV_MACH_TIMER_IRQ);
|
||||
}
|
||||
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
HalIrqEnable(RISCV_MACH_TIMER_IRQ);
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
wfi();
|
||||
|
|
|
@ -43,7 +43,6 @@ extern "C" {
|
|||
#endif /* __cplusplus */
|
||||
|
||||
VOID SysTick_Handler(VOID);
|
||||
UINT32 HalTickStart(OS_TICK_HANDLER handler);
|
||||
|
||||
#define TIM0_GROUP0 0x3FF5F000
|
||||
#define TIM0_GROUP1 0x3FF60000
|
||||
|
@ -64,6 +63,30 @@ typedef struct {
|
|||
UINT32 LOAD_TRI;
|
||||
} Systick_t;
|
||||
|
||||
STATIC INLINE UINT32 GetCcount(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ __volatile__("rsr %0, ccount" : "=a"(intSave) :);
|
||||
return intSave;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ResetCcount(VOID)
|
||||
{
|
||||
__asm__ __volatile__("wsr %0, ccount; rsync" : :"a"(0));
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 GetCcompare(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ __volatile__("rsr %0, ccompare0" : "=a"(intSave) :);
|
||||
return intSave;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID SetCcompare(UINT32 newCompareVal)
|
||||
{
|
||||
__asm__ __volatile__("wsr %0, ccompare0; rsync" : : "a"(newCompareVal));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
|
|
@ -143,15 +143,7 @@ VOID HalStartToRun(VOID)
|
|||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
(VOID)LOS_IntLock();
|
||||
|
||||
ret = HalTickStart(OsTickHandler);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Tick start failed!\n");
|
||||
}
|
||||
|
||||
OsSchedStart();
|
||||
HalStartToRun();
|
||||
return LOS_OK;
|
||||
|
|
|
@ -34,75 +34,48 @@
|
|||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_arch_timer.h"
|
||||
#include "los_context.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
UINT32 GetCcount(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ __volatile__("rsr %0, ccount" : "=a"(intSave) :);
|
||||
return intSave;
|
||||
}
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
VOID ResetCcount(VOID)
|
||||
{
|
||||
__asm__ __volatile__("wsr %0, ccount; rsync" : :"a"(0));
|
||||
}
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = OS_SYS_CLOCK,
|
||||
.irqNum = OS_TICK_INT_NUM,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
UINT32 GetCcompare(VOID)
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ __volatile__("rsr %0, ccompare0" : "=a"(intSave) :);
|
||||
return intSave;
|
||||
}
|
||||
|
||||
VOID SetCcompare(UINT32 newCompareVal)
|
||||
{
|
||||
__asm__ __volatile__("wsr %0, ccompare0; rsync" : : "a"(newCompareVal));
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
Input : none
|
||||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
WEAK UINT32 HalTickStart(OS_TICK_HANDLER handler)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 ccount;
|
||||
UINT32 nextTickCycles;
|
||||
|
||||
if ((OS_SYS_CLOCK == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > OS_SYS_CLOCK)) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(OS_TICK_INT_NUM, (HWI_PROC_FUNC)handler, NULL);
|
||||
OsSetVector(tick->irqNum, handler, NULL);
|
||||
#else
|
||||
OsSetVector(OS_TICK_INT_NUM, (HWI_PROC_FUNC)handler);
|
||||
OsSetVector(tick->irqNum, handler);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
g_sysClock = OS_SYS_CLOCK;
|
||||
g_cyclesPerTick = OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
|
||||
ResetCcount();
|
||||
SetCcompare(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
|
||||
|
||||
__asm__ __volatile__("wsr %0, ccompare1; rsync" : : "a"(0));
|
||||
__asm__ __volatile__("wsr %0, ccompare2; rsync" : : "a"(0));
|
||||
|
||||
HalIrqUnmask(OS_TICK_INT_NUM);
|
||||
HalIrqUnmask(tick->irqNum);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
UINT32 timerL;
|
||||
timerL = GetCcount();
|
||||
|
@ -110,7 +83,7 @@ WEAK VOID ArchSysTickReload(UINT64 nextResponseTime)
|
|||
SetCcompare(timerL);
|
||||
}
|
||||
|
||||
WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 tickCycleH;
|
||||
UINT32 tickCycleL;
|
||||
|
@ -132,16 +105,21 @@ WEAK UINT64 ArchGetTickCycle(UINT32 *period)
|
|||
return tickCycle;
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickLock(VOID)
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
HalIrqMask(OS_TICK_INT_NUM);
|
||||
}
|
||||
|
||||
WEAK VOID ArchTickUnlock(VOID)
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
HalIrqUnmask(OS_TICK_INT_NUM);
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
VOID Wfi(VOID)
|
||||
{
|
||||
__asm__ volatile("waiti 0" : : : "memory");
|
||||
|
|
|
@ -109,7 +109,8 @@ STATIC VOID OsPmTickTimerStart(LosPmCB *pm)
|
|||
currTime = pm->enterSleepTime + realSleepTime;
|
||||
pm->enterSleepTime = 0;
|
||||
|
||||
OsSchedTimerBaseReset(currTime);
|
||||
OsTickTimerBaseReset(currTime);
|
||||
OsSchedResetSchedResponseTime(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -139,7 +140,7 @@ STATIC BOOL OsPmTickTimerStop(LosPmCB *pm)
|
|||
sleepCycle = OS_SYS_NS_TO_CYCLE(sleepCycle, tickTimer->freq);
|
||||
|
||||
/* The main CPU reduces the frequency */
|
||||
pm->enterSleepTime = OsGetCurrSysTimeCycle();
|
||||
pm->enterSleepTime = LOS_SysCycleGet();
|
||||
tickTimer->tickLock();
|
||||
tickTimer->timerStart(sleepCycle);
|
||||
return TRUE;
|
||||
|
@ -262,7 +263,7 @@ STATIC UINT32 OsPmSuspendSleep(LosPmCB *pm)
|
|||
if (!tickTimerStop) {
|
||||
currTime = OsGetCurrSchedTimeCycle();
|
||||
OsSchedResetSchedResponseTime(0);
|
||||
OsSchedUpdateExpireTime(currTime, TRUE);
|
||||
OsSchedUpdateExpireTime(currTime);
|
||||
}
|
||||
|
||||
OsPmCpuSuspend(pm);
|
||||
|
|
|
@ -115,10 +115,6 @@ extern "C" {
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef LOSCFG_BASE_CORE_TICK_HW_TIME
|
||||
#define LOSCFG_BASE_CORE_TICK_HW_TIME 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_config
|
||||
* System timer is a 64/128 bit timer
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
#include "los_task.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_timer.h"
|
||||
#include "los_tick.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
@ -53,15 +53,11 @@ extern UINT64 g_sysSchedStartTime;
|
|||
|
||||
VOID OsSchedResetSchedResponseTime(UINT64 responseTime);
|
||||
|
||||
VOID OsSchedUpdateSchedTimeBase(VOID);
|
||||
|
||||
UINT64 OsGetCurrSysTimeCycle(VOID);
|
||||
|
||||
VOID OsSchedSetIdleTaskSchedParam(LosTaskCB *idleTask);
|
||||
|
||||
UINT32 OsSchedSwtmrScanRegister(SchedScan func);
|
||||
|
||||
VOID OsSchedUpdateExpireTime(UINT64 startTime, BOOL timeUpdate);
|
||||
VOID OsSchedUpdateExpireTime(UINT64 startTime);
|
||||
|
||||
VOID OsSchedTaskDeQueue(LosTaskCB *taskCB);
|
||||
|
||||
|
@ -95,12 +91,10 @@ LosTaskCB *OsGetTopTask(VOID);
|
|||
|
||||
UINT32 OsSchedRealSleepTimeSet(VOID (*func)(UINT64));
|
||||
|
||||
VOID OsSchedTimerBaseReset(UINT64 currTime);
|
||||
|
||||
STATIC INLINE UINT64 OsGetCurrSchedTimeCycle(VOID)
|
||||
{
|
||||
if (g_sysSchedStartTime != OS_64BIT_MAX) {
|
||||
return (OsGetCurrSysTimeCycle() - g_sysSchedStartTime);
|
||||
return (LOS_SysCycleGet() - g_sysSchedStartTime);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#define _LOS_TICK_H
|
||||
|
||||
#include "los_error.h"
|
||||
#include "los_timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
@ -58,7 +59,7 @@ extern "C" {
|
|||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Tick error code: This error code is not in use temporarily.
|
||||
* Tick error code: The system tick timer uninitialized.
|
||||
*
|
||||
* Value: 0x02000401
|
||||
*
|
||||
|
@ -180,6 +181,36 @@ extern UINT64 LOS_SysCycleGet(VOID);
|
|||
*/
|
||||
#define LOS_ERRNO_SYS_HOOK_IS_FULL LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x14)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* System time error code: The Tick Timer must be registered before kernel initialization.
|
||||
*
|
||||
* Value: 0x02000015
|
||||
*
|
||||
* Solution: None.
|
||||
*/
|
||||
#define LOS_ERRNO_SYS_TIMER_IS_RUNNING LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x15)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* System time error code: The tick timer method is NULL.
|
||||
*
|
||||
* Value: 0x02000016
|
||||
*
|
||||
* Solution: None.
|
||||
*/
|
||||
#define LOS_ERRNO_SYS_HOOK_IS_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x16)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* System time error code: The tick timer addr fault.
|
||||
*
|
||||
* Value: 0x02000017
|
||||
*
|
||||
* Solution: None.
|
||||
*/
|
||||
#define LOS_ERRNO_SYS_TIMER_ADDR_FAULT LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x16)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* system time structure.
|
||||
|
@ -194,6 +225,14 @@ typedef struct TagSysTime {
|
|||
UINT8 ucWeek; /**< value 0 - 6 */
|
||||
} SYS_TIME_S;
|
||||
|
||||
VOID OsTickTimerReload(UINT64 responseTime);
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
|
||||
VOID OsTickTimerBaseReset(UINT64 currTime);
|
||||
#endif
|
||||
|
||||
UINT32 OsTickTimerInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief Obtain the number of Ticks.
|
||||
|
@ -276,6 +315,24 @@ extern UINT32 LOS_Tick2MS(UINT32 ticks);
|
|||
*/
|
||||
extern UINT32 LOS_MS2Tick(UINT32 millisec);
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* @brief Re-initializes the system tick timer.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to re-initialize the system Tick timer.
|
||||
* @attention
|
||||
*
|
||||
* @param timer [IN] Specify the tick timer.
|
||||
* @param tickHandler [IN] Tick Interrupts the execution of the hook function.
|
||||
*
|
||||
* @retval LOS_OK or Error code.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
extern UINT32 LOS_TickTimerRegister(const ArchTickTimer *timer, const HWI_PROC_FUNC tickHandler);
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* Ticks per second
|
||||
|
|
|
@ -148,6 +148,12 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID)
|
|||
|
||||
ArchInit();
|
||||
|
||||
ret = OsTickTimerInit();
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("OsTickTimerInit error! 0x%x\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = OsTaskInit();
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("OsTaskInit error\n");
|
||||
|
|
|
@ -90,50 +90,6 @@ VOID OsSchedResetSchedResponseTime(UINT64 responseTime)
|
|||
}
|
||||
}
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
|
||||
STATIC UINT64 g_schedTimerBase;
|
||||
|
||||
VOID OsSchedUpdateSchedTimeBase(VOID)
|
||||
{
|
||||
UINT32 period = 0;
|
||||
|
||||
(VOID)ArchGetTickCycle(&period);
|
||||
g_schedTimerBase += period;
|
||||
}
|
||||
|
||||
VOID OsSchedTimerBaseReset(UINT64 currTime)
|
||||
{
|
||||
LOS_ASSERT(currTime > g_schedTimerBase);
|
||||
|
||||
g_schedTimerBase = currTime;
|
||||
g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
}
|
||||
#endif
|
||||
|
||||
UINT64 OsGetCurrSysTimeCycle(VOID)
|
||||
{
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 1)
|
||||
return ArchGetTickCycle(NULL);
|
||||
#else
|
||||
STATIC UINT64 oldSchedTime = 0;
|
||||
UINT32 period = 0;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
UINT64 time = ArchGetTickCycle(&period);
|
||||
UINT64 schedTime = g_schedTimerBase + time;
|
||||
if (schedTime < oldSchedTime) {
|
||||
/* Turn the timer count */
|
||||
g_schedTimerBase += period;
|
||||
schedTime = g_schedTimerBase + time;
|
||||
}
|
||||
|
||||
LOS_ASSERT(schedTime >= oldSchedTime);
|
||||
|
||||
oldSchedTime = schedTime;
|
||||
LOS_IntRestore(intSave);
|
||||
return schedTime;
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsTimeSliceUpdate(LosTaskCB *taskCB, UINT64 currTime)
|
||||
{
|
||||
LOS_ASSERT(currTime >= taskCB->startTime);
|
||||
|
@ -145,7 +101,7 @@ STATIC INLINE VOID OsTimeSliceUpdate(LosTaskCB *taskCB, UINT64 currTime)
|
|||
taskCB->startTime = currTime;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedTickReload(UINT64 nextResponseTime, UINT32 responseID, BOOL isTimeSlice, BOOL timeUpdate)
|
||||
STATIC INLINE VOID OsSchedTickReload(UINT64 nextResponseTime, UINT32 responseID, BOOL isTimeSlice)
|
||||
{
|
||||
UINT64 currTime, nextExpireTime;
|
||||
UINT32 usedTime;
|
||||
|
@ -169,14 +125,6 @@ STATIC INLINE VOID OsSchedTickReload(UINT64 nextResponseTime, UINT32 responseID,
|
|||
return;
|
||||
}
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
|
||||
if (timeUpdate) {
|
||||
g_schedTimerBase = OsGetCurrSysTimeCycle();
|
||||
}
|
||||
#else
|
||||
(VOID)timeUpdate;
|
||||
#endif
|
||||
|
||||
if (isTimeSlice) {
|
||||
/* The expiration time of the current system is the thread's slice expiration time */
|
||||
g_schedResponseID = responseID;
|
||||
|
@ -184,10 +132,10 @@ STATIC INLINE VOID OsSchedTickReload(UINT64 nextResponseTime, UINT32 responseID,
|
|||
g_schedResponseID = OS_INVALID;
|
||||
}
|
||||
g_schedResponseTime = nextExpireTime;
|
||||
ArchSysTickReload(nextResponseTime);
|
||||
OsTickTimerReload(nextResponseTime);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedSetNextExpireTime(UINT64 startTime, UINT32 responseID, UINT64 taskEndTime, BOOL timeUpdate)
|
||||
STATIC INLINE VOID OsSchedSetNextExpireTime(UINT64 startTime, UINT32 responseID, UINT64 taskEndTime)
|
||||
{
|
||||
UINT64 nextExpireTime;
|
||||
UINT64 nextResponseTime = 0;
|
||||
|
@ -219,10 +167,10 @@ STATIC INLINE VOID OsSchedSetNextExpireTime(UINT64 startTime, UINT32 responseID,
|
|||
return;
|
||||
}
|
||||
|
||||
OsSchedTickReload(nextResponseTime, responseID, isTimeSlice, timeUpdate);
|
||||
OsSchedTickReload(nextResponseTime, responseID, isTimeSlice);
|
||||
}
|
||||
|
||||
VOID OsSchedUpdateExpireTime(UINT64 startTime, BOOL timeUpdate)
|
||||
VOID OsSchedUpdateExpireTime(UINT64 startTime)
|
||||
{
|
||||
UINT64 endTime;
|
||||
BOOL isPmMode = FALSE;
|
||||
|
@ -241,7 +189,7 @@ VOID OsSchedUpdateExpireTime(UINT64 startTime, BOOL timeUpdate)
|
|||
} else {
|
||||
endTime = OS_SCHED_MAX_RESPONSE_TIME - OS_TICK_RESPONSE_PRECISION;
|
||||
}
|
||||
OsSchedSetNextExpireTime(startTime, runTask->taskID, endTime, timeUpdate);
|
||||
OsSchedSetNextExpireTime(startTime, runTask->taskID, endTime);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSchedPriQueueEnHead(LOS_DL_LIST *priqueueItem, UINT32 priority)
|
||||
|
@ -564,14 +512,14 @@ VOID OsSchedStart(VOID)
|
|||
|
||||
/* Initialize the schedule timeline and enable scheduling */
|
||||
g_taskScheduled = TRUE;
|
||||
OsSchedSetStartTime(OsGetCurrSysTimeCycle());
|
||||
OsSchedSetStartTime(LOS_SysCycleGet());
|
||||
|
||||
newTask->startTime = OsGetCurrSchedTimeCycle();
|
||||
OsSchedTaskDeQueue(newTask);
|
||||
|
||||
g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
g_schedResponseID = OS_INVALID;
|
||||
OsSchedSetNextExpireTime(newTask->startTime, newTask->taskID, newTask->startTime + newTask->timeSlice, TRUE);
|
||||
OsSchedSetNextExpireTime(newTask->startTime, newTask->taskID, newTask->startTime + newTask->timeSlice);
|
||||
|
||||
PRINTK("Entering scheduler\n");
|
||||
}
|
||||
|
@ -615,7 +563,7 @@ BOOL OsSchedTaskSwitch(VOID)
|
|||
if (g_schedResponseID == runTask->taskID) {
|
||||
g_schedResponseTime = OS_SCHED_MAX_RESPONSE_TIME;
|
||||
}
|
||||
OsSchedSetNextExpireTime(newTask->startTime, newTask->taskID, endTime, TRUE);
|
||||
OsSchedSetNextExpireTime(newTask->startTime, newTask->taskID, endTime);
|
||||
|
||||
return isTaskSwitch;
|
||||
}
|
||||
|
@ -665,7 +613,7 @@ VOID LOS_SchedTickHandler(VOID)
|
|||
if (LOS_CHECK_SCHEDULE) {
|
||||
ArchTaskSchedule();
|
||||
} else {
|
||||
OsSchedUpdateExpireTime(g_losTask.runTask->startTime, TRUE);
|
||||
OsSchedUpdateExpireTime(g_losTask.runTask->startTime);
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
|
|
@ -238,7 +238,7 @@ LITE_OS_SEC_TEXT VOID OsSwtmrStart(UINT64 currTime, SWTMR_CTRL_S *swtmr)
|
|||
}
|
||||
#endif
|
||||
OsAdd2SortLink(&swtmr->stSortList, swtmr->startTime, swtmr->uwInterval, OS_SORT_LINK_SWTMR);
|
||||
OsSchedUpdateExpireTime(currTime, TRUE);
|
||||
OsSchedUpdateExpireTime(currTime);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
@ -273,7 +273,7 @@ LITE_OS_SEC_TEXT VOID OsSwtmrStop(SWTMR_CTRL_S *swtmr)
|
|||
OsDeleteSortLink(&swtmr->stSortList);
|
||||
swtmr->ucState = OS_SWTMR_STATUS_CREATED;
|
||||
|
||||
OsSchedUpdateExpireTime(OsGetCurrSchedTimeCycle(), TRUE);
|
||||
OsSchedUpdateExpireTime(OsGetCurrSchedTimeCycle());
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_ALIGN == 1)
|
||||
g_swtmrAlignID[swtmr->usTimerID % LOSCFG_BASE_CORE_SWTMR_LIMIT].isAligned = 0;
|
||||
#endif
|
||||
|
|
|
@ -30,37 +30,180 @@
|
|||
*/
|
||||
|
||||
#include "los_tick.h"
|
||||
#include "securec.h"
|
||||
#include "los_config.h"
|
||||
#include "los_task.h"
|
||||
#include "los_swtmr.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
|
||||
LITE_OS_SEC_BSS STATIC ArchTickTimer *g_sysTickTimer = NULL;
|
||||
LITE_OS_SEC_BSS UINT32 g_ticksPerSec;
|
||||
LITE_OS_SEC_BSS UINT32 g_uwCyclePerSec;
|
||||
LITE_OS_SEC_BSS UINT32 g_cyclesPerTick;
|
||||
LITE_OS_SEC_BSS UINT32 g_sysClock;
|
||||
LITE_OS_SEC_BSS BOOL g_sysTimerIsInit = FALSE;
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_HW_TIME == 1)
|
||||
extern VOID platform_tick_handler(VOID);
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
|
||||
STATIC UINT64 g_tickTimerBase;
|
||||
|
||||
LITE_OS_SEC_TEXT STATIC VOID OsUpdateSysTimeBase(VOID)
|
||||
{
|
||||
UINT32 period = 0;
|
||||
|
||||
(VOID)g_sysTickTimer->getCycle(&period);
|
||||
g_tickTimerBase += period;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT VOID OsTickTimerBaseReset(UINT64 currTime)
|
||||
{
|
||||
LOS_ASSERT(currTime > g_tickTimerBase);
|
||||
|
||||
g_tickTimerBase = currTime;
|
||||
}
|
||||
#endif
|
||||
|
||||
LITE_OS_SEC_TEXT VOID OsTickHandler(VOID)
|
||||
{
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
|
||||
OsSchedUpdateSchedTimeBase();
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_HW_TIME == 1)
|
||||
platform_tick_handler();
|
||||
OsUpdateSysTimeBase();
|
||||
#endif
|
||||
|
||||
LOS_SchedTickHandler();
|
||||
}
|
||||
|
||||
UINT64 LOS_SysCycleGet(VOID)
|
||||
LITE_OS_SEC_TEXT VOID OsTickTimerReload(UINT64 responseTime)
|
||||
{
|
||||
return OsGetCurrSysTimeCycle();
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
|
||||
g_tickTimerBase = LOS_SysCycleGet();
|
||||
#endif
|
||||
g_sysTickTimer->reload(responseTime);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT64 LOS_SysCycleGet(VOID)
|
||||
{
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 1)
|
||||
return g_sysTickTimer->getCycle(NULL);
|
||||
#else
|
||||
STATIC UINT64 oldSchedTime = 0;
|
||||
UINT32 period = 0;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
UINT64 time = g_sysTickTimer->getCycle(&period);
|
||||
UINT64 schedTime = g_tickTimerBase + time;
|
||||
if (schedTime < oldSchedTime) {
|
||||
/* Turn the timer count */
|
||||
g_tickTimerBase += period;
|
||||
schedTime = g_tickTimerBase + time;
|
||||
}
|
||||
|
||||
LOS_ASSERT(schedTime >= oldSchedTime);
|
||||
|
||||
oldSchedTime = schedTime;
|
||||
LOS_IntRestore(intSave);
|
||||
return schedTime;
|
||||
#endif
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT STATIC UINT32 TickTimerCheck(const ArchTickTimer *tick)
|
||||
{
|
||||
if (tick == NULL) {
|
||||
return LOS_ERRNO_SYS_PTR_NULL;
|
||||
}
|
||||
|
||||
if ((tick->freq == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND == 0) ||
|
||||
(LOSCFG_BASE_CORE_TICK_PER_SECOND > tick->freq)) {
|
||||
return LOS_ERRNO_SYS_CLOCK_INVALID;
|
||||
}
|
||||
|
||||
if (tick->irqNum > (INT32)LOSCFG_PLATFORM_HWI_LIMIT) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
|
||||
if (tick->init == NULL || tick->reload == NULL ||
|
||||
tick->lock == NULL || tick->unlock == NULL ||
|
||||
tick->getCycle == NULL) {
|
||||
return LOS_ERRNO_SYS_HOOK_IS_NULL;
|
||||
}
|
||||
|
||||
if (g_sysTimerIsInit) {
|
||||
return LOS_ERRNO_SYS_TIMER_IS_RUNNING;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsTickTimerInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
HWI_PROC_FUNC tickHandler = (HWI_PROC_FUNC)OsTickHandler;
|
||||
g_sysTickTimer = LOS_SysTickTimerGet();
|
||||
|
||||
ret = TickTimerCheck(g_sysTickTimer);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("Tick timer param check failed, Error 0x%x\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
g_sysClock = g_sysTickTimer->freq;
|
||||
g_cyclesPerTick = g_sysTickTimer->freq / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
|
||||
if (g_sysTickTimer->tickHandler != NULL) {
|
||||
tickHandler = g_sysTickTimer->tickHandler;
|
||||
}
|
||||
ret = g_sysTickTimer->init(tickHandler);
|
||||
if (ret == LOS_OK) {
|
||||
g_sysTimerIsInit = TRUE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_TickTimerRegister(const ArchTickTimer *timer, const HWI_PROC_FUNC tickHandler)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret;
|
||||
|
||||
if ((timer == NULL) && (tickHandler == NULL)) {
|
||||
return LOS_ERRNO_SYS_PTR_NULL;
|
||||
}
|
||||
|
||||
if (timer != NULL) {
|
||||
ret = TickTimerCheck(timer);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (g_sysTickTimer == NULL) {
|
||||
g_sysTickTimer = LOS_SysTickTimerGet();
|
||||
}
|
||||
|
||||
if (g_sysTickTimer == timer) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_SYS_TIMER_ADDR_FAULT;
|
||||
}
|
||||
|
||||
errno_t errRet = memcpy_s(g_sysTickTimer, sizeof(ArchTickTimer), timer, sizeof(ArchTickTimer));
|
||||
if (errRet != EOK) {
|
||||
PRINT_ERR("%s timer addr fault! errno %d\n", __FUNCTION__, errRet);
|
||||
ret = LOS_ERRNO_SYS_TIMER_ADDR_FAULT;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (g_sysTimerIsInit) {
|
||||
return LOS_ERRNO_SYS_TIMER_IS_RUNNING;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (g_sysTickTimer == NULL) {
|
||||
g_sysTickTimer = LOS_SysTickTimerGet();
|
||||
}
|
||||
|
||||
g_sysTickTimer->tickHandler = tickHandler;
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
@ -72,7 +215,7 @@ Return : current tick
|
|||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_TickCountGet(VOID)
|
||||
{
|
||||
return OsGetCurrSchedTimeCycle() / OS_CYCLE_PER_TICK;
|
||||
return LOS_SysCycleGet() / OS_CYCLE_PER_TICK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
@ -176,5 +319,3 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsCpuTick2US(CpuTick *cpuTick, UINT32 *usHi, UINT32
|
|||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue