armv7a/r: use register cval to set timer

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2023-12-26 22:53:32 +08:00 committed by Xiang Xiao
parent dabed3c7fb
commit 8eddf00212
2 changed files with 32 additions and 4 deletions

View File

@ -129,6 +129,18 @@ static inline void arm_timer_set_tval(uint32_t tval)
ARM_ISB(); ARM_ISB();
} }
static inline uint64_t arm_timer_get_cval(void)
{
ARM_ISB();
return CP15_GET64(CNTP_CVAL);
}
static inline void arm_timer_set_cval(uint64_t cval)
{
CP15_SET64(CNTP_CVAL, cval);
ARM_ISB();
}
static inline uint64_t nsec_from_count(uint64_t count, uint32_t freq) static inline uint64_t nsec_from_count(uint64_t count, uint32_t freq)
{ {
return (uint64_t)count * NSEC_PER_SEC / freq; return (uint64_t)count * NSEC_PER_SEC / freq;
@ -165,7 +177,7 @@ static int arm_timer_start(struct oneshot_lowerhalf_s *lower_,
struct arm_timer_lowerhalf_s *lower = struct arm_timer_lowerhalf_s *lower =
(struct arm_timer_lowerhalf_s *)lower_; (struct arm_timer_lowerhalf_s *)lower_;
irqstate_t flags; irqstate_t flags;
uint32_t count; uint64_t count;
uint32_t ctrl; uint32_t ctrl;
flags = up_irq_save(); flags = up_irq_save();
@ -175,7 +187,7 @@ static int arm_timer_start(struct oneshot_lowerhalf_s *lower_,
count = sec_to_count(ts->tv_sec, lower->freq) + count = sec_to_count(ts->tv_sec, lower->freq) +
nsec_to_count(ts->tv_nsec, lower->freq); nsec_to_count(ts->tv_nsec, lower->freq);
arm_timer_set_tval(count); arm_timer_set_cval(arm_timer_get_count() + count);
ctrl = arm_timer_get_ctrl(); ctrl = arm_timer_get_ctrl();
ctrl &= ~ARM_TIMER_CTRL_INT_MASK; ctrl &= ~ARM_TIMER_CTRL_INT_MASK;
@ -230,6 +242,8 @@ static int arm_timer_interrupt(int irq, void *context, void *arg)
DEBUGASSERT(lower != NULL); DEBUGASSERT(lower != NULL);
arm_timer_set_ctrl(arm_timer_get_ctrl() | ARM_TIMER_CTRL_INT_MASK);
if (lower->callback != NULL) if (lower->callback != NULL)
{ {
callback = lower->callback; callback = lower->callback;

View File

@ -129,6 +129,18 @@ static inline void arm_timer_set_tval(uint32_t tval)
ARM_ISB(); ARM_ISB();
} }
static inline uint64_t arm_timer_get_cval(void)
{
ARM_ISB();
return CP15_GET64(CNTP_CVAL);
}
static inline void arm_timer_set_cval(uint64_t cval)
{
CP15_SET64(CNTP_CVAL, cval);
ARM_ISB();
}
static inline uint64_t nsec_from_count(uint64_t count, uint32_t freq) static inline uint64_t nsec_from_count(uint64_t count, uint32_t freq)
{ {
return (uint64_t)count * NSEC_PER_SEC / freq; return (uint64_t)count * NSEC_PER_SEC / freq;
@ -165,7 +177,7 @@ static int arm_timer_start(struct oneshot_lowerhalf_s *lower_,
struct arm_timer_lowerhalf_s *lower = struct arm_timer_lowerhalf_s *lower =
(struct arm_timer_lowerhalf_s *)lower_; (struct arm_timer_lowerhalf_s *)lower_;
irqstate_t flags; irqstate_t flags;
uint32_t count; uint64_t count;
uint32_t ctrl; uint32_t ctrl;
flags = up_irq_save(); flags = up_irq_save();
@ -175,7 +187,7 @@ static int arm_timer_start(struct oneshot_lowerhalf_s *lower_,
count = sec_to_count(ts->tv_sec, lower->freq) + count = sec_to_count(ts->tv_sec, lower->freq) +
nsec_to_count(ts->tv_nsec, lower->freq); nsec_to_count(ts->tv_nsec, lower->freq);
arm_timer_set_tval(count); arm_timer_set_cval(arm_timer_get_count() + count);
ctrl = arm_timer_get_ctrl(); ctrl = arm_timer_get_ctrl();
ctrl &= ~ARM_TIMER_CTRL_INT_MASK; ctrl &= ~ARM_TIMER_CTRL_INT_MASK;
@ -230,6 +242,8 @@ static int arm_timer_interrupt(int irq, void *context, void *arg)
DEBUGASSERT(lower != NULL); DEBUGASSERT(lower != NULL);
arm_timer_set_ctrl(arm_timer_get_ctrl() | ARM_TIMER_CTRL_INT_MASK);
if (lower->callback != NULL) if (lower->callback != NULL)
{ {
callback = lower->callback; callback = lower->callback;