Skip to content

Commit

Permalink
Convert the 64-bit usec limit to a 32-bit tick limit
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory-nutt committed Feb 3, 2015
1 parent cabaf73 commit 1d534ff
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 22 deletions.
5 changes: 2 additions & 3 deletions arch/arm/src/sam34/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ endif # SAM34_GPIO_IRQ
endmenu # AT91SAM3/4 GPIO Interrupt Configuration

menu "AT91SAM3/4 Timer/Counter Configuration"
depends on SAM34_TC
depends on SAM34_TC && ARCH_CHIP_SAM4CM

config SAM34_TC0_CLK
bool "Enable TC channel 0 clock input pin"
Expand Down Expand Up @@ -1058,8 +1058,7 @@ config SAM34_TICKLESS_FREERUN
If the Tickless OS feature is enabled, the one clock must be
assigned to provided the free-running timer needed by the OS.

endif

endif # SCHED_TICKLESS
endmenu # AT91SAM3/4 Timer/Counter Configuration

if SAM34_SPI0 || SAM34_SPI1
Expand Down
19 changes: 18 additions & 1 deletion arch/arm/src/sam34/sam4cm_tickless.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ static void sam_oneshot_handler(void *arg)

void up_timer_initialize(void)
{
#ifdef CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP
uint64_t max_delay;
#endif
int ret;

/* Initialize the one-shot timer */
Expand All @@ -245,12 +248,26 @@ void up_timer_initialize(void)
}

#ifdef CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP
ret = sam_oneshot_max_delay(&g_tickless.oneshot, &g_oneshot_max_delay_usec);
/* Get the maximum delay of the one-shot timer in microseconds */

ret = sam_oneshot_max_delay(&g_tickless.oneshot, &max_delay);
if (ret < 0)
{
tclldbg("ERROR: sam_oneshot_max_delay failed\n");
PANIC();
}

/* Convert this to configured clock ticks for use by the OS timer logic */

max_delay /= CONFIG_USEC_PER_TICK;
if (max_delay > UINT32_MAX)
{
g_oneshot_maxticks = UINT32_MAX
}
else
{
g_oneshot_maxticks = max_delay;
}
#endif

/* Initialize the free-running timer */
Expand Down
25 changes: 15 additions & 10 deletions include/nuttx/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,32 +119,36 @@ typedef CODE void (*phy_enable_t)(bool enable);
* Public Variables
****************************************************************************/

#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif

#ifdef CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP
/* By default, the RTOS tickless logic assumes that range of times that can
* be represented by the underlying hardware time is so large that no special
* precautions need to taken. That is not always the case. If there is a
* limit to the maximum timing interval that be represented by the timer,
* then that limit must be respected.
*
* If CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP is defined, then a 64-bit global
* variable called g_oneshot_max_delay_usec variable is enabled. The variable
* If CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP is defined, then use a 32-bit
* global variable called g_oneshot_maxticks variable is enabled. This variable
* is initialized by platform-specific logic at runtime to the maximum delay
* that the timer can wait (in microseconds). The RTOS tickless logic will
* then limit all requested delays to this value (in ticks).
* that the timer can wait (in configured clock ticks). The RTOS tickless
* logic will then limit all requested delays to this value (in ticks).
*/

extern uint64_t g_oneshot_max_delay_usec;
EXTERN uint32_t g_oneshot_maxticks;
#endif

/****************************************************************************
* Public Function Prototypes
****************************************************************************/

#ifdef __cplusplus
extern "C"
{
#endif

/****************************************************************************
* These are standard interfaces that must be exported to the base RTOS
* logic from architecture-specific code.
Expand Down Expand Up @@ -1946,6 +1950,7 @@ int up_getc(void);

void up_puts(FAR const char *str);

#undef EXTERN
#ifdef __cplusplus
}
#endif
Expand Down
7 changes: 4 additions & 3 deletions sched/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ config SCHED_TICKLESS_LIMIT_MAX_SLEEP
bool "Max sleep period (in microseconds)"
default n
---help---
Enables g_oneshot_max_delay_usec variable. The variable is
Enables use of the g_oneshot_maxticks variable. This variable is
initialized by platform-specific logic at runtime to the maximum
delay that the timer can wait (in microseconds). The RTOS tickless
logic will then limit all requested delays to this value (in ticks).
delay that the timer can wait (in configured clock ticks). The
RTOS tickless logic will then limit all requested delays to this
value.

endif

Expand Down
10 changes: 5 additions & 5 deletions sched/sched/sched_timerexpiration.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@
* limit to the maximum timing interval that be represented by the timer,
* then that limit must be respected.
*
* If CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP is defined, then a 64-bit global
* variable called g_oneshot_max_delay_usec variable is enabled. The variable
* If CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP is defined, then a 32-bit global
* variable called g_oneshot_maxticks variable is enabled. The variable
* is initialized by platform-specific logic at runtime to the maximum delay
* that the timer can wait (in microseconds). The RTOS tickless logic will
* then limit all requested delays to this value (in ticks).
*/

uint64_t g_oneshot_max_delay_usec;
uint32_t g_oneshot_maxticks = UINT32_MAX;
#endif

/************************************************************************
Expand Down Expand Up @@ -445,9 +445,9 @@ static void sched_timer_start(unsigned int ticks)
struct timespec ts;

#if CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP
if (ticks > (g_oneshot_max_delay_usec / CONFIG_USEC_PER_TICK))
if (ticks > g_oneshot_maxticks)
{
ticks = (g_oneshot_max_delay_usec / CONFIG_USEC_PER_TICK);
ticks = g_oneshot_maxticks;
}
#endif

Expand Down

0 comments on commit 1d534ff

Please sign in to comment.