diff --git a/Documentation/NuttxPortingGuide.html b/Documentation/NuttxPortingGuide.html index 386f1d5668..5ff6b55748 100644 --- a/Documentation/NuttxPortingGuide.html +++ b/Documentation/NuttxPortingGuide.html @@ -12,7 +12,7 @@
Last Updated: August 10, 2014
+Last Updated: August 12, 2014
@@ -2460,8 +2460,17 @@ config ARCH_SIM
- CONFIG_SCHED_TICKLESS
:
- If CONFIG_ARCH_HAVE_TICKLESS
is selected, then it will enable the Tickless OS features in NuttX.
+ CONFIG_SCHED_TICKLESS
:
+ If CONFIG_ARCH_HAVE_TICKLESS
is selected, then it will enable the Tickless OS features in NuttX.
+
+ CONFIG_SCHED_TICKLESS_ALARM
:
+ The tickless option can be supported either via a simple interval timer (plus elapsed time) or via an alarm. The interval timer allows programming events to occur after an interval. With the alarm, you can set a time in the future and get an event when that alarm goes off. This option selects the use of an alarm.
+
+ The advantage of an alarm is that it avoids some small timing errors; the advantage of the use of the interval timer is that the hardware requirement may be less.
up_timer_gettime()
:
Returns the current time from the platform specific time source.
+ The tickless option can be supported either via a simple interval timer (plus elapsed time) or via an alarm. The interval timer allows programming events to occur after an interval. With the alarm, you can set a time in* the future and get an event when that alarm goes off. +
+
+ If CONFIG_SCHED_TICKLESS_ALARM
is defined, then the platform code must provide the following:
+
+
up_alarm_cancel()
:
+ Cancels the alarm.
+ up_alarm_start()
:
+ Enables (or re-enables) the alaram.
+
+ If CONFIG_SCHED_TICKLESS_ALARM
is notdefined, then the platform code must provide the following verify similar functions:
+
+
up_timer_cancel()
:
Cancels the interval timer.
@@ -2555,7 +2585,8 @@ int up_timer_gettime(FAR struct timespec *ts);
Input Parameters:
ts
: Provides the location in which to return the up-time.ts
: Provides the location in which to return the up-time..
+Returned Value:
up_timer_cancel()
up_alarm_cancel()
Prototype:
+
+#include <nuttx/arch.h> +int up_alarm_cancel(FAR struct timespec *ts); + +Description:
+ Cancel the alarm and return the time of cancellation of the alarm. These two steps need to be as nearly atomic as possible.sched_timer_expiration()
will not be called unless the alarm is restarted withup_alarm_start()
. If, as a race condition, the alarm has already expired when this function is called, then time returned is the current time. +
Input Parameters:
+ts
: Location to return the expiration time. The current time should be returned if the timer is not active. ts
may be NULL
in which case the time is not returnedReturned Value:
+OK
) on success; a negated errno
value on failure.
+Assumptions:
+up_alarm_start()
Prototype:
+
+#include <nuttx/arch.h> +int up_alarm_start(FAR const struct timespec *ts); + +Description:
+ Start the alarm.sched_timer_expiration()
will be called when the alarm occurs (unlessup_alaram_cancel
is called to stop it). +
Input Parameters:
+ts
: The time in the future at the alarm is expected to occur. When the alarm occurs the timer logic will call sched_timer_expiration()
.Returned Value:
+OK
) on success; a negated errno
value on failure.
+Assumptions:
+up_timer_cancel()
Prototype:
#include <nuttx/arch.h> @@ -2589,7 +2666,7 @@ int up_timer_cancel(FAR struct timespec *ts); May be called from interrupt level handling or from the normal tasking level. iterrupts may need to be disabled internally to assure non-reentrancy. -4.3.4.4.4
+up_timer_start()
4.3.4.4.6
up_timer_start()
Prototype:
#include <nuttx/arch.h> diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index d1f2b739cb..495e9fa9b3 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -950,9 +950,21 @@ int up_prioritize_irq(int irq, int priority); * early in the intialization sequence (by up_intialize()). * int up_timer_gettime(FAR struct timespec *ts): Returns the current * time from the platform specific time source. + * + * The tickless option can be supported either via a simple interval timer + * (plus elapsed time) or via an alarm. The interval timer allows programming + * events to occur after an interval. With the alarm, you can set a time in + * the future and get an event when that alarm goes off. + * + * #ifdef CONFIG_SCHED_TICKLESS_ALARM + * int up_alarm_cancel(void): Cancel the alarm. + * int up_alarm_start(FAR const struct timespec *ts): Enable (or re-anable + * the alarm. + * #else * int up_timer_cancel(void): Cancels the interval timer. * int up_timer_start(FAR const struct timespec *ts): Start (or re-starts) * the interval timer. + * #endif * * The RTOS will provide the following interfaces for use by the platform- * specific interval timer implementation: @@ -1028,6 +1040,72 @@ void up_timer_initialize(void); int up_timer_gettime(FAR struct timespec *ts); #endif +/**************************************************************************** + * Name: up_alarm_cancel + * + * Description: + * Cancel the alarm and return the time of cancellation of the alarm. + * These two steps need to be as nearly atomic as possible. + * sched_timer_expiration() will not be called unless the alarm is + * restarted with up_alarm_start(). + * + * If, as a race condition, the alarm has already expired when this + * function is called, then time returned is the current time. + * + * NOTE: This function may execute at a high rate with no timer running (as + * when pre-emption is enabled and disabled). + * + * Provided by platform-specific code and called from the RTOS base code. + * + * Input Parameters: + * ts - Location to return the expiration time. The current time should + * returned if the alarm is not active. ts may be NULL in which + * case the time is not returned. + * + * Returned Value: + * Zero (OK) is returned on success. A call to up_alarm_cancel() when + * the timer is not active should also return success; a negated errno + * value is returned on any failure. + * + * Assumptions: + * May be called from interrupt level handling or from the normal tasking + * level. Interrupts may need to be disabled internally to assure + * non-reentrancy. + * + ****************************************************************************/ + +#if defined(CONFIG_SCHED_TICKLESS) && defined(CONFIG_SCHED_TICKLESS_ALARM) +int up_alarm_cancel(FAR struct timespec *ts); +#endif + +/**************************************************************************** + * Name: up_alarm_start + * + * Description: + * Start the alarm. sched_timer_expiration() will be called when the + * alarm occurs (unless up_alaram_cancel is called to stop it). + * + * Provided by platform-specific code and called from the RTOS base code. + * + * Input Parameters: + * ts - The time at the alarm is expected to occur. When the alarm occurs + * the timer logic will call sched_timer_expiration(). + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure. + * + * Assumptions: + * May be called from interrupt level handling or from the normal tasking + * level. Interrupts may need to be disabled internally to assure + * non-reentrancy. + * + ****************************************************************************/ + +#if defined(CONFIG_SCHED_TICKLESS) && defined(CONFIG_SCHED_TICKLESS_ALARM) +int up_alarm_start(FAR const struct timespec *ts); +#endif + /**************************************************************************** * Name: up_timer_cancel * @@ -1064,7 +1142,7 @@ int up_timer_gettime(FAR struct timespec *ts); * ****************************************************************************/ -#ifdef CONFIG_SCHED_TICKLESS +#if defined(CONFIG_SCHED_TICKLESS) && !defined(CONFIG_SCHED_TICKLESS_ALARM) int up_timer_cancel(FAR struct timespec *ts); #endif @@ -1093,7 +1171,7 @@ int up_timer_cancel(FAR struct timespec *ts); * ****************************************************************************/ -#ifdef CONFIG_SCHED_TICKLESS +#if defined(CONFIG_SCHED_TICKLESS) && !defined(CONFIG_SCHED_TICKLESS_ALARM) int up_timer_start(FAR const struct timespec *ts); #endif diff --git a/sched/Kconfig b/sched/Kconfig index c13a47a551..31d4f31b2a 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -57,7 +57,7 @@ config SCHED_TICKLESS default n depends on ARCH_HAVE_TICKLESS ---help--- - Be default, system time is driven by a periodic timer interrupt. An + By default, system time is driven by a periodic timer interrupt. An alternative configurations is a tick-less configuration in which there is no periodic timer interrupt. Instead and interval timer is used to schedule the next OS time event. This option selects that @@ -65,6 +65,23 @@ config SCHED_TICKLESS additional platform specific interfaces that must be provided as defined include/nuttx/arch.h +if SCHED_TICKLESS +conf SCHED_TICKLESS_ALARM + bool "Tickless alarm" + default n + ---help--- + The tickless option can be supported either via a simple interval + timer (plus elapsed time) or via an alarm. The interval timer allows + programming events to occur after an interval. With the alarm, + you can set a time in the future and get an event when that alarm + goes off. This option selects the use of an alarm. + + The advantage of an alarm is that it avoids some small timing + errors; the advantage of the use of the interval timer is that + the hardware requirement may be less. + +endif + config USEC_PER_TICK int "System timer tick period (microseconds)" default 10000 if !SCHED_TICKLESS