You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/04/11 23:25:33 UTC
[03/28] incubator-mynewt-core git commit: Add a helper function
'os_time_advance()' that is called from arch-specific timer ISR to advance
the os time. The OS might preempt the interrupted task if a higher priority
task is now runnable (unless the 'resch
Add a helper function 'os_time_advance()' that is called from arch-specific
timer ISR to advance the os time. The OS might preempt the interrupted task
if a higher priority task is now runnable (unless the 'resched' parameter
is false).
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/67ab7fe8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/67ab7fe8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/67ab7fe8
Branch: refs/heads/develop
Commit: 67ab7fe81d7f9e1b4788a523963a71fa6225504b
Parents: 589bc4b
Author: Neel Natu <ne...@nahannisys.com>
Authored: Fri Mar 18 13:58:38 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Fri Mar 18 13:58:38 2016 -0700
----------------------------------------------------------------------
libs/os/include/os/os_time.h | 3 +-
libs/os/src/arch/cortex_m0/os_arch_arm.c | 5 +--
libs/os/src/arch/cortex_m4/os_arch_arm.c | 5 +--
libs/os/src/arch/sim/os_arch_sim.c | 8 +----
libs/os/src/os_time.c | 46 ++++++++++++++++++---------
5 files changed, 36 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/67ab7fe8/libs/os/include/os/os_time.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_time.h b/libs/os/include/os/os_time.h
index d3cb028..5992374 100644
--- a/libs/os/include/os/os_time.h
+++ b/libs/os/include/os/os_time.h
@@ -52,6 +52,7 @@
#ifndef _OS_TIME_H
#define _OS_TIME_H
+#include <stdbool.h>
#include <stdint.h>
typedef uint32_t os_time_t;
@@ -64,7 +65,7 @@ typedef uint32_t os_time_t;
#define OS_TIMEOUT_NEVER (UINT32_MAX)
os_time_t os_time_get(void);
-void os_time_tick(void);
+void os_time_advance(int ticks, bool resched);
void os_time_delay(int32_t osticks);
#define OS_TIME_TICK_LT(__t1, __t2) ((int32_t) ((__t1) - (__t2)) < 0)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/67ab7fe8/libs/os/src/arch/cortex_m0/os_arch_arm.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m0/os_arch_arm.c b/libs/os/src/arch/cortex_m0/os_arch_arm.c
index 99f317b..b70481a 100755
--- a/libs/os/src/arch/cortex_m0/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m0/os_arch_arm.c
@@ -104,10 +104,7 @@ uint32_t os_flags = OS_RUN_PRIV;
void
timer_handler(void)
{
- os_time_tick();
- os_callout_tick();
- os_sched_os_timer_exp();
- os_sched(NULL);
+ os_time_advance(1, true);
}
void
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/67ab7fe8/libs/os/src/arch/cortex_m4/os_arch_arm.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/os_arch_arm.c b/libs/os/src/arch/cortex_m4/os_arch_arm.c
index f0601a1..3117af9 100755
--- a/libs/os/src/arch/cortex_m4/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m4/os_arch_arm.c
@@ -93,10 +93,7 @@ uint32_t os_flags = OS_RUN_PRIV;
void
timer_handler(void)
{
- os_time_tick();
- os_callout_tick();
- os_sched_os_timer_exp();
- os_sched(NULL);
+ os_time_advance(1, true);
}
void
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/67ab7fe8/libs/os/src/arch/sim/os_arch_sim.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/sim/os_arch_sim.c b/libs/os/src/arch/sim/os_arch_sim.c
index 33455b1..6831094 100644
--- a/libs/os/src/arch/sim/os_arch_sim.c
+++ b/libs/os/src/arch/sim/os_arch_sim.c
@@ -294,11 +294,6 @@ timer_handler(int sig)
ticks = time_diff.tv_sec * OS_TICKS_PER_SEC;
ticks += time_diff.tv_usec / OS_USEC_PER_TICK;
- while (--ticks >= 0) {
- os_time_tick();
- os_callout_tick();
- }
-
/*
* Update 'time_last' but account for the remainder usecs that did not
* contribute towards whole 'ticks'.
@@ -307,8 +302,7 @@ timer_handler(int sig)
time_diff.tv_usec %= OS_USEC_PER_TICK;
timersub(&time_now, &time_diff, &time_last);
- os_sched_os_timer_exp();
- os_sched(NULL);
+ os_time_advance(ticks, true);
}
static void
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/67ab7fe8/libs/os/src/os_time.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_time.c b/libs/os/src/os_time.c
index fe7de8b..dc70dec 100644
--- a/libs/os/src/os_time.c
+++ b/libs/os/src/os_time.c
@@ -17,9 +17,14 @@
* under the License.
*/
+#include <util/util.h>
+#include <assert.h>
+
#include "os/os.h"
#include "os/queue.h"
+CTASSERT(sizeof(os_time_t) == 4);
+
#define OS_USEC_PER_TICK (1000000 / OS_TICKS_PER_SEC)
os_time_t g_os_time;
@@ -51,31 +56,42 @@ os_time_get(void)
return (g_os_time);
}
-/**
- * Called for every single tick by the architecture specific functions.
- *
- * Increases the os_time by 1 tick.
- */
-void
-os_time_tick(void)
+static void
+os_time_tick(int ticks)
{
- os_sr_t sr;
- os_time_t delta;
+ os_time_t delta, prev_os_time;
- OS_ENTER_CRITICAL(sr);
- ++g_os_time;
+ assert(ticks >= 0);
+
+ OS_ASSERT_CRITICAL();
+ prev_os_time = g_os_time;
+ g_os_time += ticks;
/*
- * Update 'basetod' when the lowest 31 bits of 'g_os_time' are all zero,
- * i.e. at 0x00000000 and 0x80000000.
+ * Update 'basetod' when 'g_os_time' crosses the 0x00000000 and
+ * 0x80000000 thresholds.
*/
- if ((g_os_time << 1) == 0) { /* XXX use __unlikely() here */
+ if ((prev_os_time ^ g_os_time) >> 31) {
delta = g_os_time - basetod.ostime;
os_deltatime(delta, &basetod.uptime, &basetod.uptime);
os_deltatime(delta, &basetod.utctime, &basetod.utctime);
basetod.ostime = g_os_time;
}
- OS_EXIT_CRITICAL(sr);
+}
+
+void
+os_time_advance(int ticks, bool resched)
+{
+ assert(ticks >= 0);
+
+ if (ticks > 0) {
+ os_time_tick(ticks);
+ os_callout_tick();
+ os_sched_os_timer_exp();
+ if (resched) {
+ os_sched(NULL);
+ }
+ }
}
/**