!724 fix: 修复系统时间比RTC时间过快的问题
Merge pull request !724 from zhushengle/tick_3.0.0
This commit is contained in:
commit
887a845874
|
@ -130,6 +130,10 @@ extern UINT64 LOS_SysCycleGet(VOID);
|
|||
#define OS_SYS_NS_TO_CYCLE(time, freq) (((time) / OS_SYS_NS_PER_SECOND) * (freq) + \
|
||||
(time % OS_SYS_NS_PER_SECOND) * (freq) / OS_SYS_NS_PER_SECOND)
|
||||
|
||||
#define OS_SYS_TICK_TO_CYCLE(ticks) (((UINT64)(ticks) * g_sysClock) / LOSCFG_BASE_CORE_TICK_PER_SECOND)
|
||||
|
||||
#define OS_SYS_CYCLE_TO_TICK(cycle) ((((UINT64)(cycle)) * LOSCFG_BASE_CORE_TICK_PER_SECOND) / g_sysClock)
|
||||
|
||||
/**
|
||||
* @ingroup los_tick
|
||||
* System time basic function error code: Null pointer.
|
||||
|
|
|
@ -92,13 +92,17 @@ VOID OsSchedResetSchedResponseTime(UINT64 responseTime)
|
|||
|
||||
#if (LOSCFG_BASE_CORE_TICK_WTIMER == 0)
|
||||
STATIC UINT64 g_schedTimerBase;
|
||||
STATIC BOOL g_tickTimerBaseUpdate = FALSE;
|
||||
|
||||
VOID OsSchedUpdateSchedTimeBase(VOID)
|
||||
{
|
||||
UINT32 period = 0;
|
||||
|
||||
(VOID)HalGetTickCycle(&period);
|
||||
g_schedTimerBase += period;
|
||||
if (g_tickTimerBaseUpdate == FALSE) {
|
||||
(VOID)HalGetTickCycle(&period);
|
||||
g_schedTimerBase += period;
|
||||
}
|
||||
g_tickTimerBaseUpdate = FALSE;
|
||||
}
|
||||
|
||||
VOID OsSchedTimerBaseReset(UINT64 currTime)
|
||||
|
@ -124,6 +128,7 @@ UINT64 OsGetCurrSysTimeCycle(VOID)
|
|||
/* Turn the timer count */
|
||||
g_schedTimerBase += period;
|
||||
schedTime = g_schedTimerBase + time;
|
||||
g_tickTimerBaseUpdate = TRUE;
|
||||
}
|
||||
|
||||
LOS_ASSERT(schedTime >= oldSchedTime);
|
||||
|
@ -145,22 +150,11 @@ 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 currTime, UINT64 nextResponseTime, UINT32 responseID,
|
||||
BOOL isTimeSlice, BOOL timeUpdate)
|
||||
{
|
||||
UINT64 currTime, nextExpireTime;
|
||||
UINT32 usedTime;
|
||||
|
||||
currTime = OsGetCurrSchedTimeCycle();
|
||||
if (g_tickStartTime != 0) {
|
||||
usedTime = currTime - g_tickStartTime;
|
||||
g_tickStartTime = 0;
|
||||
} else {
|
||||
usedTime = 0;
|
||||
}
|
||||
|
||||
if ((nextResponseTime > usedTime) && ((nextResponseTime - usedTime) > OS_TICK_RESPONSE_PRECISION)) {
|
||||
nextResponseTime -= usedTime;
|
||||
} else {
|
||||
UINT64 nextExpireTime;
|
||||
if (nextResponseTime < OS_TICK_RESPONSE_PRECISION) {
|
||||
nextResponseTime = OS_TICK_RESPONSE_PRECISION;
|
||||
}
|
||||
|
||||
|
@ -190,8 +184,10 @@ STATIC INLINE VOID OsSchedSetNextExpireTime(UINT64 startTime, UINT32 responseID,
|
|||
UINT64 nextExpireTime;
|
||||
UINT64 nextResponseTime = 0;
|
||||
BOOL isTimeSlice = FALSE;
|
||||
(VOID)startTime;
|
||||
|
||||
nextExpireTime = OsGetNextExpireTime(startTime);
|
||||
UINT64 currTime = OsGetCurrSchedTimeCycle();
|
||||
nextExpireTime = OsGetNextExpireTime(currTime);
|
||||
/* The response time of the task time slice is aligned to the next response time in the delay queue */
|
||||
if ((nextExpireTime > taskEndTime) && ((nextExpireTime - taskEndTime) > OS_SCHED_MINI_PERIOD)) {
|
||||
nextExpireTime = taskEndTime;
|
||||
|
@ -200,7 +196,7 @@ STATIC INLINE VOID OsSchedSetNextExpireTime(UINT64 startTime, UINT32 responseID,
|
|||
|
||||
if ((g_schedResponseTime > nextExpireTime) &&
|
||||
((g_schedResponseTime - nextExpireTime) >= OS_TICK_RESPONSE_PRECISION)) {
|
||||
nextResponseTime = nextExpireTime - startTime;
|
||||
nextResponseTime = nextExpireTime - currTime;
|
||||
if (nextResponseTime > OS_TICK_RESPONSE_TIME_MAX) {
|
||||
if (SchedRealSleepTimeSet != NULL) {
|
||||
SchedRealSleepTimeSet(nextResponseTime);
|
||||
|
@ -217,7 +213,7 @@ STATIC INLINE VOID OsSchedSetNextExpireTime(UINT64 startTime, UINT32 responseID,
|
|||
return;
|
||||
}
|
||||
|
||||
OsSchedTickReload(nextResponseTime, responseID, isTimeSlice, timeUpdate);
|
||||
OsSchedTickReload(currTime, nextResponseTime, responseID, isTimeSlice, timeUpdate);
|
||||
}
|
||||
|
||||
VOID OsSchedUpdateExpireTime(UINT64 startTime, BOOL timeUpdate)
|
||||
|
|
|
@ -115,7 +115,7 @@ VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, Sort
|
|||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
SET_SORTLIST_VALUE(node, startTime + (UINT64)waitTicks * OS_CYCLE_PER_TICK);
|
||||
SET_SORTLIST_VALUE(node, startTime + OS_SYS_TICK_TO_CYCLE(waitTicks));
|
||||
OsAddNode2SortLink(sortLinkHeader, node);
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
|
|
@ -123,8 +123,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrTaskCreate(VOID)
|
|||
STATIC UINT64 OsSwtmrCalcStartTime(UINT64 currTime, SWTMR_CTRL_S *swtmr, const SWTMR_CTRL_S *alignSwtmr)
|
||||
{
|
||||
UINT64 usedTime, startTime;
|
||||
UINT64 alignEnd = (UINT64)alignSwtmr->uwInterval * OS_CYCLE_PER_TICK;
|
||||
UINT64 swtmrTime = (UINT64)swtmr->uwInterval * OS_CYCLE_PER_TICK;
|
||||
UINT64 alignEnd = OS_SYS_TICK_TO_CYCLE(alignSwtmr->uwInterval);
|
||||
UINT64 swtmrTime = OS_SYS_TICK_TO_CYCLE(swtmr->uwInterval);
|
||||
UINT64 remainTime = OsSortLinkGetRemainTime(currTime, &alignSwtmr->stSortList);
|
||||
if (remainTime == 0) {
|
||||
startTime = GET_SORTLIST_VALUE(&alignSwtmr->stSortList);
|
||||
|
|
|
@ -72,7 +72,7 @@ Return : current tick
|
|||
*****************************************************************************/
|
||||
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_TickCountGet(VOID)
|
||||
{
|
||||
return OsGetCurrSchedTimeCycle() / OS_CYCLE_PER_TICK;
|
||||
return OS_SYS_CYCLE_TO_TICK(OsGetCurrSchedTimeCycle());
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
|
Loading…
Reference in New Issue