Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions arch/arm/src/armv7-a/arm_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ struct arm_timer_lowerhalf_s
{
struct oneshot_lowerhalf_s lh; /* Lower half operations */
uint32_t freq; /* Timer working clock frequency(Hz) */
oneshot_callback_t callback; /* Current user interrupt callback */
void *arg; /* Argument passed to upper half callback */

/* which cpu timer is running, -1 indicate timer stoppd */

Expand All @@ -78,7 +76,6 @@ struct arm_timer_lowerhalf_s
static int arm_timer_maxdelay(struct oneshot_lowerhalf_s *lower,
struct timespec *ts);
static int arm_timer_start(struct oneshot_lowerhalf_s *lower,
oneshot_callback_t callback, void *arg,
const struct timespec *ts);
static int arm_timer_cancel(struct oneshot_lowerhalf_s *lower,
struct timespec *ts);
Expand Down Expand Up @@ -170,7 +167,6 @@ static int arm_timer_maxdelay(struct oneshot_lowerhalf_s *lower_,
}

static int arm_timer_start(struct oneshot_lowerhalf_s *lower_,
oneshot_callback_t callback, void *arg,
const struct timespec *ts)
{
struct arm_timer_lowerhalf_s *lower =
Expand All @@ -180,9 +176,6 @@ static int arm_timer_start(struct oneshot_lowerhalf_s *lower_,

flags = up_irq_save();

lower->callback = callback;
lower->arg = arg;

lower->running = this_cpu();

count = sec_to_count(ts->tv_sec, lower->freq) +
Expand All @@ -206,8 +199,6 @@ static int arm_timer_cancel(struct oneshot_lowerhalf_s *lower_,

flags = up_irq_save();

lower->callback = NULL;
lower->arg = NULL;
lower->running = -1;

arm_timer_phy_set_irq_mask(true);
Expand All @@ -234,23 +225,14 @@ static int arm_timer_current(struct oneshot_lowerhalf_s *lower_,
static int arm_timer_interrupt(int irq, void *context, void *arg)
{
struct arm_timer_lowerhalf_s *lower = arg;
oneshot_callback_t callback;
void *cbarg;

DEBUGASSERT(lower != NULL);

arm_timer_phy_set_irq_mask(true);

if (lower->callback != NULL && lower->running == this_cpu())
if (lower->running == this_cpu())
{
callback = lower->callback;
cbarg = lower->arg;
lower->callback = NULL;
lower->arg = NULL;

/* Then perform the callback */

callback(&lower->lh, cbarg);
oneshot_process_callback(&lower->lh);
}

return 0;
Expand Down
23 changes: 2 additions & 21 deletions arch/arm/src/armv7-r/arm_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ struct arm_timer_lowerhalf_s
{
struct oneshot_lowerhalf_s lh; /* Lower half operations */
uint32_t freq; /* Timer working clock frequency(Hz) */
oneshot_callback_t callback; /* Current user interrupt callback */
void *arg; /* Argument passed to upper half callback */

/* which cpu timer is running, -1 indicate timer stoppd */

Expand All @@ -77,7 +75,6 @@ struct arm_timer_lowerhalf_s
static int arm_timer_maxdelay(struct oneshot_lowerhalf_s *lower,
struct timespec *ts);
static int arm_timer_start(struct oneshot_lowerhalf_s *lower,
oneshot_callback_t callback, void *arg,
const struct timespec *ts);
static int arm_timer_cancel(struct oneshot_lowerhalf_s *lower,
struct timespec *ts);
Expand Down Expand Up @@ -163,7 +160,6 @@ static int arm_timer_maxdelay(struct oneshot_lowerhalf_s *lower_,
}

static int arm_timer_start(struct oneshot_lowerhalf_s *lower_,
oneshot_callback_t callback, void *arg,
const struct timespec *ts)
{
struct arm_timer_lowerhalf_s *lower =
Expand All @@ -173,9 +169,6 @@ static int arm_timer_start(struct oneshot_lowerhalf_s *lower_,

flags = up_irq_save();

lower->callback = callback;
lower->arg = arg;

lower->running = this_cpu();

count = sec_to_count(ts->tv_sec, arm_timer_get_freq()) +
Expand All @@ -199,8 +192,6 @@ static int arm_timer_cancel(struct oneshot_lowerhalf_s *lower_,

flags = up_irq_save();

lower->callback = NULL;
lower->arg = NULL;
lower->running = -1;

arm_timer_phy_set_irq_mask(true);
Expand All @@ -225,23 +216,13 @@ static int arm_timer_current(struct oneshot_lowerhalf_s *lower_,
static int arm_timer_interrupt(int irq, void *context, void *arg)
{
struct arm_timer_lowerhalf_s *lower = arg;
oneshot_callback_t callback;
void *cbarg;

DEBUGASSERT(lower != NULL);

arm_timer_phy_set_irq_mask(true);

if (lower->callback != NULL && lower->running == this_cpu())
if (lower->running == this_cpu())
{
callback = lower->callback;
cbarg = lower->arg;
lower->callback = NULL;
lower->arg = NULL;

/* Then perform the callback */

callback(&lower->lh, cbarg);
oneshot_process_callback(&lower->lh);
}

return 0;
Expand Down
98 changes: 52 additions & 46 deletions arch/arm/src/armv8-r/arm_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
# define GIC_IRQ_PHY_TIMER GIC_IRQ_NONSEC_PHY_TIMER
#endif

#define ARM_ARCH_TIMER_IRQ GIC_IRQ_VIRT_TIMER
#define ARM_ARCH_TIMER_IRQ GIC_IRQ_PHY_TIMER
#define ARM_ARCH_TIMER_PRIO IRQ_DEFAULT_PRIORITY
#define ARM_ARCH_TIMER_FLAGS IRQ_TYPE_LEVEL

Expand All @@ -80,9 +80,7 @@ struct arm_oneshot_lowerhalf_s

/* Private lower half data follows */

void *arg; /* Argument that is passed to the handler */
uint64_t cycle_per_tick; /* cycle per tick */
oneshot_callback_t callback; /* Internal handler that receives callback */
uint32_t frequency; /* Frequency */
};

/****************************************************************************
Expand Down Expand Up @@ -146,18 +144,15 @@ static int arm_arch_timer_compare_isr(int irq, void *regs, void *arg)

arm_timer_phy_set_irq_mask(true);

if (priv->callback)
{
/* Then perform the callback */
/* Then perform the callback */

priv->callback(&priv->lh, priv->arg);
}
oneshot_process_callback(&priv->lh);

return OK;
}

/****************************************************************************
* Name: arm_tick_max_delay
* Name: arm_max_delay
*
* Description:
* Determine the maximum delay of the one-shot timer (in microseconds)
Expand All @@ -166,26 +161,31 @@ static int arm_arch_timer_compare_isr(int irq, void *regs, void *arg)
* lower An instance of the lower-half oneshot state structure. This
* structure must have been previously initialized via a call to
* oneshot_initialize();
* ticks The location in which to return the maximum delay.
* ts The location in which to return the maximum delay.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned
* on failure.
*
****************************************************************************/

static int arm_tick_max_delay(struct oneshot_lowerhalf_s *lower,
clock_t *ticks)
static int arm_max_delay(struct oneshot_lowerhalf_s *lower,
struct timespec *ts)
{
DEBUGASSERT(ticks != NULL);
struct arm_oneshot_lowerhalf_s *priv =
(struct arm_oneshot_lowerhalf_s *)lower;
uint32_t freq = priv->frequency;

DEBUGASSERT(ts != NULL);

*ticks = (clock_t)UINT64_MAX;
ts->tv_sec = UINT64_MAX / freq;
ts->tv_nsec = UINT64_MAX % freq * NSEC_PER_SEC / freq;

return OK;
}

/****************************************************************************
* Name: arm_tick_cancel
* Name: arm_cancel
*
* Description:
* Cancel the oneshot timer and return the time remaining on the timer.
Expand All @@ -197,7 +197,7 @@ static int arm_tick_max_delay(struct oneshot_lowerhalf_s *lower,
* lower Caller allocated instance of the oneshot state structure. This
* structure must have been previously initialized via a call to
* oneshot_initialize();
* ticks The location in which to return the time remaining on the
* ts The location in which to return the time remaining on the
* oneshot timer.
*
* Returned Value:
Expand All @@ -207,13 +207,13 @@ static int arm_tick_max_delay(struct oneshot_lowerhalf_s *lower,
*
****************************************************************************/

static int arm_tick_cancel(struct oneshot_lowerhalf_s *lower,
clock_t *ticks)
static int arm_cancel(struct oneshot_lowerhalf_s *lower,
struct timespec *ts)
{
struct arm_oneshot_lowerhalf_s *priv =
(struct arm_oneshot_lowerhalf_s *)lower;

DEBUGASSERT(priv != NULL && ticks != NULL);
DEBUGASSERT(priv != NULL && ts != NULL);

/* Disable int */

Expand All @@ -223,7 +223,7 @@ static int arm_tick_cancel(struct oneshot_lowerhalf_s *lower,
}

/****************************************************************************
* Name: arm_tick_start
* Name: arm_start
*
* Description:
* Start the oneshot timer
Expand All @@ -234,32 +234,31 @@ static int arm_tick_cancel(struct oneshot_lowerhalf_s *lower,
* oneshot_initialize();
* handler The function to call when when the oneshot timer expires.
* arg An opaque argument that will accompany the callback.
* ticks Provides the duration of the one shot timer.
* ts Provides the duration of the one shot timer.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned
* on failure.
*
****************************************************************************/

static int arm_tick_start(struct oneshot_lowerhalf_s *lower,
oneshot_callback_t callback, void *arg,
clock_t ticks)
static int arm_start(struct oneshot_lowerhalf_s *lower,
const struct timespec *ts)
{
uint64_t count;
struct arm_oneshot_lowerhalf_s *priv =
(struct arm_oneshot_lowerhalf_s *)lower;
uint64_t freq = priv->frequency;

DEBUGASSERT(priv != NULL && callback != NULL);

/* Save the new handler and its argument */

priv->callback = callback;
priv->arg = arg;
DEBUGASSERT(priv && ts);

/* Set the timeout */

arm_timer_phy_set_absolute(arm_timer_phy_count() +
priv->cycle_per_tick * ticks);
count = arm_timer_phy_count();
count += (uint64_t)ts->tv_sec * freq +
(uint64_t)ts->tv_nsec * freq / NSEC_PER_SEC;

arm_timer_phy_set_absolute(count);

/* Try to unmask the timer irq in timer controller
* in case of arm_tick_cancel is called.
Expand All @@ -271,7 +270,7 @@ static int arm_tick_start(struct oneshot_lowerhalf_s *lower,
}

/****************************************************************************
* Name: arm_tick_current
* Name: arm_current
*
* Description:
* Get the current time.
Expand All @@ -280,23 +279,29 @@ static int arm_tick_start(struct oneshot_lowerhalf_s *lower,
* lower Caller allocated instance of the oneshot state structure. This
* structure must have been previously initialized via a call to
* oneshot_initialize();
* ticks The location in which to return the current time.
* ts The location in which to return the current time.
*
* Returned Value:
* Zero (OK) is returned on success, a negated errno value is returned on
* any failure.
*
****************************************************************************/

static int arm_tick_current(struct oneshot_lowerhalf_s *lower,
clock_t *ticks)
static int arm_current(struct oneshot_lowerhalf_s *lower,
struct timespec *ts)
{
uint64_t count;
uint32_t freq;
struct arm_oneshot_lowerhalf_s *priv =
(struct arm_oneshot_lowerhalf_s *)lower;

DEBUGASSERT(ticks != NULL);
DEBUGASSERT(ts != NULL);

*ticks = arm_timer_phy_count() / priv->cycle_per_tick;
freq = priv->frequency;
count = arm_timer_phy_count();

ts->tv_sec = count / freq;
ts->tv_nsec = (count % freq) * NSEC_PER_SEC / freq;

return OK;
}
Expand All @@ -307,10 +312,10 @@ static int arm_tick_current(struct oneshot_lowerhalf_s *lower,

static const struct oneshot_operations_s g_oneshot_ops =
{
.tick_start = arm_tick_start,
.tick_current = arm_tick_current,
.tick_max_delay = arm_tick_max_delay,
.tick_cancel = arm_tick_cancel,
.start = arm_start,
.current = arm_current,
.max_delay = arm_max_delay,
.cancel = arm_cancel,
};

/****************************************************************************
Expand Down Expand Up @@ -346,9 +351,10 @@ static struct oneshot_lowerhalf_s *arm_oneshot_initialize(void)

/* Initialize the lower-half driver structure */

DEBUGASSERT(arm_timer_get_freq() <= UINT32_MAX);

priv->lh.ops = &g_oneshot_ops;
priv->cycle_per_tick = arm_timer_get_freq() / TICK_PER_SEC;
tmrinfo("cycle_per_tick %" PRIu64 "\n", priv->cycle_per_tick);
priv->frequency = arm_timer_get_freq();

/* Attach handler */

Expand Down Expand Up @@ -411,7 +417,7 @@ void up_timer_initialize(void)
* timer interrupt
****************************************************************************/

void arm_timer_secondary_init(void)
void arm_timer_secondary_init(unsigned int freq)
{
#ifdef CONFIG_SCHED_TICKLESS
tmrinfo("arm_arch_timer_secondary_init\n");
Expand Down
Loading
Loading