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
8 changes: 4 additions & 4 deletions arch/arm/src/stm32/stm32_tickless.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ int up_timer_gettime(struct timespec *ts)
#ifdef CONFIG_CLOCK_TIMEKEEPING

/****************************************************************************
* Name: up_timer_getcounter
* Name: up_timer_gettick
*
* Description:
* To be provided
Expand All @@ -698,9 +698,9 @@ int up_timer_gettime(struct timespec *ts)
*
****************************************************************************/

int up_timer_getcounter(uint64_t *cycles)
int up_timer_gettick(clock_t *ticks)
{
*cycles = (uint64_t)STM32_TIM_GETCOUNTER(g_tickless.tch);
*ticks = (clock_t)STM32_TIM_GETCOUNTER(g_tickless.tch);
return OK;
}

Expand All @@ -718,7 +718,7 @@ int up_timer_getcounter(uint64_t *cycles)
*
****************************************************************************/

void up_timer_getmask(uint64_t *mask)
void up_timer_getmask(clock_t *mask)
{
DEBUGASSERT(mask != NULL);
#ifdef HAVE_32BIT_TICKLESS
Expand Down
8 changes: 4 additions & 4 deletions arch/arm/src/stm32f7/stm32_tickless.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ int up_timer_gettime(struct timespec *ts)
#ifdef CONFIG_CLOCK_TIMEKEEPING

/****************************************************************************
* Name: up_timer_getcounter
* Name: up_timer_gettick
*
* Description:
* To be provided
Expand All @@ -756,9 +756,9 @@ int up_timer_gettime(struct timespec *ts)
*
****************************************************************************/

int up_timer_getcounter(uint64_t *cycles)
int up_timer_gettick(clock_t *ticks)
{
*cycles = (uint64_t)STM32_TIM_GETCOUNTER(g_tickless.tch);
*ticks = (clock_t)STM32_TIM_GETCOUNTER(g_tickless.tch);
return OK;
}

Expand All @@ -776,7 +776,7 @@ int up_timer_getcounter(uint64_t *cycles)
*
****************************************************************************/

void up_timer_getmask(uint64_t *mask)
void up_timer_getmask(clock_t *mask)
{
DEBUGASSERT(mask != NULL);
#ifdef HAVE_32BIT_TICKLESS
Expand Down
8 changes: 4 additions & 4 deletions arch/arm/src/stm32h7/stm32_tickless.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ int up_timer_gettime(struct timespec *ts)
#ifdef CONFIG_CLOCK_TIMEKEEPING

/****************************************************************************
* Name: up_timer_getcounter
* Name: up_timer_gettick
*
* Description:
* To be provided
Expand All @@ -729,9 +729,9 @@ int up_timer_gettime(struct timespec *ts)
*
****************************************************************************/

int up_timer_getcounter(uint64_t *cycles)
int up_timer_gettick(clock_t *ticks)
{
*cycles = (uint64_t)STM32_TIM_GETCOUNTER(g_tickless.tch);
*ticks = (clock_t)STM32_TIM_GETCOUNTER(g_tickless.tch);
return OK;
}

Expand All @@ -749,7 +749,7 @@ int up_timer_getcounter(uint64_t *cycles)
*
****************************************************************************/

void up_timer_getmask(uint64_t *mask)
void up_timer_getmask(clock_t *mask)
{
DEBUGASSERT(mask != NULL);
#ifdef HAVE_32BIT_TICKLESS
Expand Down
8 changes: 4 additions & 4 deletions arch/arm/src/stm32wb/stm32wb_tickless.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ int up_timer_gettime(struct timespec *ts)
#ifdef CONFIG_CLOCK_TIMEKEEPING

/****************************************************************************
* Name: up_timer_getcounter
* Name: up_timer_gettick
*
* Description:
* To be provided
Expand All @@ -572,9 +572,9 @@ int up_timer_gettime(struct timespec *ts)
*
****************************************************************************/

int up_timer_getcounter(uint64_t *cycles)
int up_timer_gettick(clock_t *ticks)
{
*cycles = (uint64_t)STM32WB_TIM_GETCOUNTER(g_tickless.tch);
*ticks = (clock_t)STM32WB_TIM_GETCOUNTER(g_tickless.tch);
return OK;
}

Expand All @@ -592,7 +592,7 @@ int up_timer_getcounter(uint64_t *cycles)
*
****************************************************************************/

void up_timer_getmask(uint64_t *mask)
void up_timer_getmask(clock_t *mask)
{
DEBUGASSERT(mask != NULL);
#ifdef HAVE_32BIT_TICKLESS
Expand Down
1 change: 1 addition & 0 deletions drivers/timers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ config ALARM_ARCH
select ARCH_HAVE_TIMEKEEPING
select SCHED_TICKLESS_ALARM if SCHED_TICKLESS
select SCHED_TICKLESS_LIMIT_MAX_SLEEP if SCHED_TICKLESS
select SCHED_TICKLESS_TICK_ARGUMENT if SCHED_TICKLESS
---help---
Implement alarm arch API on top of oneshot driver interface.

Expand Down
97 changes: 40 additions & 57 deletions drivers/timers/arch_alarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,27 @@ static void udelay_coarse(useconds_t microseconds)
static void oneshot_callback(FAR struct oneshot_lowerhalf_s *lower,
FAR void *arg)
{
struct timespec now;
clock_t now = 0;

#ifdef CONFIG_SCHED_TICKLESS
ONESHOT_CURRENT(g_oneshot_lower, &now);
nxsched_alarm_expiration(&now);
ONESHOT_TICK_CURRENT(g_oneshot_lower, &now);
nxsched_alarm_tick_expiration(now);
#else
struct timespec delta;
clock_t delta;

do
{
static uint64_t tick = 1;
struct timespec next;
static clock_t tick = 1;
clock_t next;

nxsched_process_timer();
timespec_from_usec(&next, ++tick * USEC_PER_TICK);
ONESHOT_CURRENT(g_oneshot_lower, &now);
clock_timespec_subtract(&next, &now, &delta);
next = ++tick;
ONESHOT_TICK_CURRENT(g_oneshot_lower, &now);
delta = next - now;
}
while (delta.tv_sec == 0 && delta.tv_nsec == 0);
while ((sclock_t)delta <= 0);

ONESHOT_START(g_oneshot_lower, oneshot_callback, NULL, &delta);
ONESHOT_TICK_START(g_oneshot_lower, oneshot_callback, NULL, delta);
#endif
}

Expand All @@ -154,19 +154,16 @@ static void oneshot_callback(FAR struct oneshot_lowerhalf_s *lower,
void up_alarm_set_lowerhalf(FAR struct oneshot_lowerhalf_s *lower)
{
#ifdef CONFIG_SCHED_TICKLESS
struct timespec maxts;
uint64_t maxticks;
clock_t ticks;
#endif

g_oneshot_lower = lower;
ONESHOT_MAX_DELAY(g_oneshot_lower, &maxts);
maxticks = timespec_to_usec(&maxts) / USEC_PER_TICK;
g_oneshot_maxticks = maxticks < UINT32_MAX ? maxticks : UINT32_MAX;
#else
struct timespec ts;

g_oneshot_lower = lower;
timespec_from_usec(&ts, USEC_PER_TICK);
ONESHOT_START(g_oneshot_lower, oneshot_callback, NULL, &ts);
#ifdef CONFIG_SCHED_TICKLESS
ONESHOT_TICK_MAX_DELAY(g_oneshot_lower, &ticks);
g_oneshot_maxticks = ticks < UINT32_MAX ? ticks : UINT32_MAX;
#else
ONESHOT_TICK_START(g_oneshot_lower, oneshot_callback, NULL, 1);
#endif
}

Expand Down Expand Up @@ -204,39 +201,19 @@ void up_alarm_set_lowerhalf(FAR struct oneshot_lowerhalf_s *lower)
****************************************************************************/

#ifdef CONFIG_CLOCK_TIMEKEEPING
int weak_function up_timer_getcounter(FAR uint64_t *cycles)
{
int ret = -EAGAIN;

if (g_oneshot_lower != NULL)
{
struct timespec now;

ret = ONESHOT_CURRENT(g_oneshot_lower, &now);
if (ret == 0)
{
*cycles = timespec_to_usec(&now) / USEC_PER_TICK;
}
}

return ret;
}

void weak_function up_timer_getmask(FAR uint64_t *mask)
void weak_function up_timer_getmask(FAR clock_t *mask)
{
*mask = 0;

if (g_oneshot_lower != NULL)
{
struct timespec maxts;
uint64_t maxticks;
clock_t maxticks;

ONESHOT_MAX_DELAY(g_oneshot_lower, &maxts);
maxticks = timespec_to_usec(&maxts) / USEC_PER_TICK;
ONESHOT_TICK_MAX_DELAY(g_oneshot_lower, &maxticks);

for (; ; )
{
uint64_t next = (*mask << 1) | 1;
clock_t next = (*mask << 1) | 1;
if (next > maxticks)
{
break;
Expand All @@ -248,14 +225,14 @@ void weak_function up_timer_getmask(FAR uint64_t *mask)
}
#endif

#if defined(CONFIG_SCHED_TICKLESS)
int weak_function up_timer_gettime(FAR struct timespec *ts)
#if defined(CONFIG_SCHED_TICKLESS) || defined(CONFIG_CLOCK_TIMEKEEPING)
int weak_function up_timer_gettick(FAR clock_t *ticks)
{
int ret = -EAGAIN;

if (g_oneshot_lower != NULL)
{
ret = ONESHOT_CURRENT(g_oneshot_lower, ts);
ret = ONESHOT_TICK_CURRENT(g_oneshot_lower, ticks);
}

return ret;
Expand Down Expand Up @@ -297,14 +274,14 @@ int weak_function up_timer_gettime(FAR struct timespec *ts)
****************************************************************************/

#ifdef CONFIG_SCHED_TICKLESS
int weak_function up_alarm_cancel(FAR struct timespec *ts)
int weak_function up_alarm_tick_cancel(FAR clock_t *ticks)
{
int ret = -EAGAIN;

if (g_oneshot_lower != NULL)
{
ret = ONESHOT_CANCEL(g_oneshot_lower, ts);
ONESHOT_CURRENT(g_oneshot_lower, ts);
ret = ONESHOT_TICK_CANCEL(g_oneshot_lower, ticks);
ONESHOT_TICK_CURRENT(g_oneshot_lower, ticks);
}

return ret;
Expand Down Expand Up @@ -336,18 +313,24 @@ int weak_function up_alarm_cancel(FAR struct timespec *ts)
****************************************************************************/

#ifdef CONFIG_SCHED_TICKLESS
int weak_function up_alarm_start(FAR const struct timespec *ts)
int weak_function up_alarm_tick_start(clock_t ticks)
{
int ret = -EAGAIN;

if (g_oneshot_lower != NULL)
{
struct timespec now;
struct timespec delta;
clock_t now = 0;
clock_t delta;

ONESHOT_CURRENT(g_oneshot_lower, &now);
clock_timespec_subtract(ts, &now, &delta);
ret = ONESHOT_START(g_oneshot_lower, oneshot_callback, NULL, &delta);
ONESHOT_TICK_CURRENT(g_oneshot_lower, &now);
delta = ticks - now;
if ((sclock_t)delta < 0)
{
delta = 0;
}

ret = ONESHOT_TICK_START(g_oneshot_lower, oneshot_callback,
NULL, delta);
}

return ret;
Expand Down
40 changes: 21 additions & 19 deletions drivers/timers/arch_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,27 +269,14 @@ void up_timer_set_lowerhalf(FAR struct timer_lowerhalf_s *lower)
****************************************************************************/

#ifdef CONFIG_CLOCK_TIMEKEEPING
int weak_function up_timer_getcounter(FAR uint64_t *cycles)
{
int ret = -EAGAIN;

if (g_timer.lower != NULL)
{
*cycles = current_usec() / USEC_PER_TICK;
ret = 0;
}

return ret;
}

void weak_function up_timer_getmask(FAR uint64_t *mask)
void weak_function up_timer_getmask(FAR clock_t *mask)
{
uint32_t maxticks = g_timer.maxtimeout / USEC_PER_TICK;

*mask = 0;
while (1)
{
uint64_t next = (*mask << 1) | 1;
clock_t next = (*mask << 1) | 1;
if (next > maxticks)
{
break;
Expand All @@ -300,15 +287,30 @@ void weak_function up_timer_getmask(FAR uint64_t *mask)
}
#endif

#if defined(CONFIG_SCHED_TICKLESS)
#if defined(CONFIG_SCHED_TICKLESS) && !defined(CONFIG_SCHED_TICKLESS_TICK_ARGUMENT)
int weak_function up_timer_gettime(FAR struct timespec *ts)
{
int ret = -EAGAIN;

if (g_timer.lower != NULL)
{
timespec_from_usec(ts, current_usec());
ret = 0;
ret = OK;
}

return ret;
}
#endif

#if defined(CONFIG_SCHED_TICKLESS_TICK_ARGUMENT) || defined(CONFIG_CLOCK_TIMEKEEPING)
int weak_function up_timer_gettick(FAR clock_t *ticks)
{
int ret = -EAGAIN;

if (g_timer.lower != NULL)
{
*ticks = current_usec() / USEC_PER_TICK;
ret = OK;
}

return ret;
Expand Down Expand Up @@ -359,7 +361,7 @@ int weak_function up_timer_cancel(FAR struct timespec *ts)
if (g_timer.lower != NULL)
{
timespec_from_usec(ts, update_timeout(g_timer.maxtimeout));
ret = 0;
ret = OK;
}

return ret;
Expand Down Expand Up @@ -399,7 +401,7 @@ int weak_function up_timer_start(FAR const struct timespec *ts)
if (g_timer.lower != NULL)
{
update_timeout(timespec_to_usec(ts));
ret = 0;
ret = OK;
}

return ret;
Expand Down
Loading