On my platform I have just 16-bit timer clocked at 32kHz. As result oneshot timer max delay is 2s. The patch adds limit of maximum ticks in sched_timer_start (nuttx/sched/sched/sched_timerexpiration.c). From Macs N.

This commit is contained in:
Gregory Nutt 2015-02-03 06:25:19 -06:00
parent d89073ae13
commit a448e0f69f
3 changed files with 53 additions and 6 deletions

View File

@ -1,7 +1,7 @@
/****************************************************************************
* include/nuttx/arch.h
*
* Copyright (C) 2007-2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -119,6 +119,23 @@ typedef CODE void (*phy_enable_t)(bool enable);
* Public Variables
****************************************************************************/
#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
* 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).
*/
extern uint64_t g_oneshot_max_delay_usec;
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/

View File

@ -66,6 +66,7 @@ config SCHED_TICKLESS
defined include/nuttx/arch.h
if SCHED_TICKLESS
config SCHED_TICKLESS_ALARM
bool "Tickless alarm"
default n
@ -80,6 +81,15 @@ config SCHED_TICKLESS_ALARM
errors; the advantage of the use of the interval timer is that
the hardware requirement may be less.
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
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).
endif
config USEC_PER_TICK

View File

@ -1,7 +1,7 @@
/************************************************************************
* sched/sched/sched_timerexpiration.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2014-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -84,12 +84,25 @@
#endif
/************************************************************************
* Private Type Declarations
* Public Data
************************************************************************/
/************************************************************************
* Public Variables
************************************************************************/
#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
* 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;
#endif
/************************************************************************
* Private Variables
@ -431,6 +444,13 @@ 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))
{
ticks = (g_oneshot_max_delay_usec / CONFIG_USEC_PER_TICK);
}
#endif
/* Save new timer interval */
g_timer_interval = ticks;