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:31 UTC

[01/28] incubator-mynewt-core git commit: Add support for halting the cpu for "sim" targets. This is achieved by asking the callout and sched subsystems for the number of ticks until they need to perform some work.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop d2ac2ec10 -> 0f0173365


Add support for halting the cpu for "sim" targets. This is achieved by asking
the callout and sched subsystems for the number of ticks until they need to
perform some work.

'os_arch_idle()' then sets up the interval timer to wake it up after the
specified number of ticks and then calls 'sigsuspend()' to the halt the
process.


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/1d94ef36
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1d94ef36
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1d94ef36

Branch: refs/heads/develop
Commit: 1d94ef36db6756c9c1fb76617ff7867a08ca4ddb
Parents: 963ff4d
Author: Neel Natu <ne...@nahannisys.com>
Authored: Thu Mar 10 10:43:44 2016 -0800
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Thu Mar 10 10:43:44 2016 -0800

----------------------------------------------------------------------
 libs/os/include/os/arch/cortex_m0/os/os_arch.h |  2 +
 libs/os/include/os/arch/cortex_m4/os/os_arch.h |  2 +
 libs/os/include/os/arch/sim/os/os_arch.h       |  2 +
 libs/os/include/os/os_callout.h                |  1 +
 libs/os/include/os/os_sched.h                  |  1 +
 libs/os/src/arch/cortex_m0/os_arch_arm.c       |  9 +++++
 libs/os/src/arch/cortex_m4/os_arch_arm.c       |  9 +++++
 libs/os/src/arch/sim/os_arch_sim.c             | 44 ++++++++++++++++++---
 libs/os/src/os_callout.c                       | 27 +++++++++++++
 libs/os/src/os_sched.c                         | 23 +++++++++++
 10 files changed, 115 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1d94ef36/libs/os/include/os/arch/cortex_m0/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/cortex_m0/os/os_arch.h b/libs/os/include/os/arch/cortex_m0/os/os_arch.h
index cd583d4..59b984d 100755
--- a/libs/os/include/os/arch/cortex_m0/os/os_arch.h
+++ b/libs/os/include/os/arch/cortex_m0/os/os_arch.h
@@ -54,12 +54,14 @@ typedef uint32_t os_stack_t;
 #define OS_ENTER_CRITICAL(__os_sr) (__os_sr = os_arch_save_sr()) 
 /* Exit a critical section, restore processor state and unblock interrupts */
 #define OS_EXIT_CRITICAL(__os_sr) (os_arch_restore_sr(__os_sr))
+#define OS_ASSERT_CRITICAL() (assert(os_arch_in_critical()))
 
 os_stack_t *os_arch_task_stack_init(struct os_task *, os_stack_t *, int);
 void timer_handler(void);
 void os_arch_ctx_sw(struct os_task *);
 os_sr_t os_arch_save_sr(void);
 void os_arch_restore_sr(os_sr_t);
+int os_arch_in_critical(void);
 void os_arch_init(void);
 uint32_t os_arch_start(void);
 os_error_t os_arch_os_init(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1d94ef36/libs/os/include/os/arch/cortex_m4/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/cortex_m4/os/os_arch.h b/libs/os/include/os/arch/cortex_m4/os/os_arch.h
index a88748c..604a57b 100755
--- a/libs/os/include/os/arch/cortex_m4/os/os_arch.h
+++ b/libs/os/include/os/arch/cortex_m4/os/os_arch.h
@@ -54,12 +54,14 @@ typedef uint32_t os_stack_t;
 #define OS_ENTER_CRITICAL(__os_sr) (__os_sr = os_arch_save_sr()) 
 /* Exit a critical section, restore processor state and unblock interrupts */
 #define OS_EXIT_CRITICAL(__os_sr) (os_arch_restore_sr(__os_sr))
+#define OS_ASSERT_CRITICAL() (assert(os_arch_in_critical()))
 
 os_stack_t *os_arch_task_stack_init(struct os_task *, os_stack_t *, int);
 void timer_handler(void);
 void os_arch_ctx_sw(struct os_task *);
 os_sr_t os_arch_save_sr(void);
 void os_arch_restore_sr(os_sr_t);
+int os_arch_in_critical(void);
 void os_arch_init(void);
 uint32_t os_arch_start(void);
 os_error_t os_arch_os_init(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1d94ef36/libs/os/include/os/arch/sim/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/sim/os/os_arch.h b/libs/os/include/os/arch/sim/os/os_arch.h
index cfe737f..bb5f506 100644
--- a/libs/os/include/os/arch/sim/os/os_arch.h
+++ b/libs/os/include/os/arch/sim/os/os_arch.h
@@ -47,6 +47,7 @@ typedef unsigned int os_stack_t;
 #define OS_ENTER_CRITICAL(__os_sr) (__os_sr = os_arch_save_sr())
 /* Exit a critical section, restore processor state and unblock interrupts */
 #define OS_EXIT_CRITICAL(__os_sr) (os_arch_restore_sr(__os_sr))
+#define OS_ASSERT_CRITICAL() (assert(os_arch_in_critical()))
 
 void _Die(char *file, int line);
 
@@ -54,6 +55,7 @@ os_stack_t *os_arch_task_stack_init(struct os_task *, os_stack_t *, int);
 void os_arch_ctx_sw(struct os_task *);
 os_sr_t os_arch_save_sr(void);
 void os_arch_restore_sr(os_sr_t sr);
+int os_arch_in_critical(void);
 os_error_t os_arch_os_init(void);
 void os_arch_os_stop(void);
 os_error_t os_arch_os_start(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1d94ef36/libs/os/include/os/os_callout.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_callout.h b/libs/os/include/os/os_callout.h
index 3e2da75..ce85855 100644
--- a/libs/os/include/os/os_callout.h
+++ b/libs/os/include/os/os_callout.h
@@ -44,6 +44,7 @@ void os_callout_func_init(struct os_callout_func *cf, struct os_eventq *evq,
 void os_callout_stop(struct os_callout *);
 int os_callout_reset(struct os_callout *, int32_t);
 void os_callout_tick(void);
+os_time_t os_callout_wakeup_ticks(os_time_t now);
 
 static inline int
 os_callout_queued(struct os_callout *c)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1d94ef36/libs/os/include/os/os_sched.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_sched.h b/libs/os/include/os/os_sched.h
index 1d1ba31..ac45683 100644
--- a/libs/os/include/os/os_sched.h
+++ b/libs/os/include/os/os_sched.h
@@ -32,5 +32,6 @@ os_error_t os_sched_insert(struct os_task *);
 int os_sched_sleep(struct os_task *, os_time_t nticks);
 int os_sched_wakeup(struct os_task *);
 void os_sched_resort(struct os_task *);
+os_time_t os_sched_wakeup_ticks(os_time_t now);
 
 #endif /* _OS_SCHED_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1d94ef36/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 199d0a7..99f317b 100755
--- a/libs/os/src/arch/cortex_m0/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m0/os_arch_arm.c
@@ -137,6 +137,15 @@ os_arch_restore_sr(os_sr_t isr_ctx)
     }
 }
 
+int
+os_arch_in_critical(void)
+{
+    uint32_t isr_ctx;
+
+    isr_ctx = __get_PRIMASK();
+    return (isr_ctx & 1);
+}
+
 os_stack_t *
 os_arch_task_stack_init(struct os_task *t, os_stack_t *stack_top, int size)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1d94ef36/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 0e6a22a..f0601a1 100755
--- a/libs/os/src/arch/cortex_m4/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m4/os_arch_arm.c
@@ -126,6 +126,15 @@ os_arch_restore_sr(os_sr_t isr_ctx)
     }
 }
 
+int
+os_arch_in_critical(void)
+{
+    uint32_t isr_ctx;
+
+    isr_ctx = __get_PRIMASK();
+    return (isr_ctx & 1);
+}
+
 os_stack_t *
 os_arch_task_stack_init(struct os_task *t, os_stack_t *stack_top, int size)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1d94ef36/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 a0a06d9..b79276e 100644
--- a/libs/os/src/arch/sim/os_arch_sim.c
+++ b/libs/os/src/arch/sim/os_arch_sim.c
@@ -51,11 +51,8 @@ extern void os_arch_frame_init(struct stack_frame *sf);
 #define sim_setjmp(__jb) sigsetjmp(__jb, 0)
 #define sim_longjmp(__jb, __ret) siglongjmp(__jb, __ret) 
 
-#define OS_ASSERT_CRITICAL() (assert(os_arch_in_critical()))
-
 #define OS_USEC_PER_TICK    (1000000 / OS_TICKS_PER_SEC)
 
-static int os_arch_in_critical(void);
 static sigset_t allsigs, nosigs;
 
 /*
@@ -158,7 +155,7 @@ os_arch_restore_sr(os_sr_t osr)
     assert(error == 0);
 }
 
-static int
+int
 os_arch_in_critical(void)
 {
     int error;
@@ -173,9 +170,46 @@ os_arch_in_critical(void)
 void
 os_arch_idle(void)
 {
-    assert(!os_arch_in_critical());
+    int rc;
+    os_sr_t sr;
+    os_time_t now, sticks, cticks, ticks;
+    struct itimerval it;
+
+    OS_ENTER_CRITICAL(sr);
+    assert(sr == 0);
+
+    now = os_time_get();
+    sticks = os_sched_wakeup_ticks(now);
+    cticks = os_callout_wakeup_ticks(now);
+    ticks = min(sticks, cticks);
+    if (ticks > OS_TICKS_PER_SEC) {
+        /*
+         * Wakeup at least once a second (XXX arbitrary).
+         */
+        ticks = OS_TICKS_PER_SEC;
+    }
+
+    if (ticks == 0) {
+        /*
+         * If the wakeup time is in the past then send a SIGALRM to ourselves
+         * rather than wait for the interval timer to fire.
+         */
+        rc = kill(getpid(), SIGALRM);
+    } else {
+        /*
+         * Set the timer to fire after 'ticks' worth of time has elapsed.
+         */
+        it.it_value.tv_sec = ticks / OS_TICKS_PER_SEC;
+        it.it_value.tv_usec = (ticks % OS_TICKS_PER_SEC) * OS_USEC_PER_TICK;
+        it.it_interval.tv_sec = 0;
+        it.it_interval.tv_usec = OS_USEC_PER_TICK;
+        rc = setitimer(ITIMER_REAL, &it, NULL);
+    }
+    assert(rc == 0);
 
     sigsuspend(&nosigs);        /* Wait for a signal to wake us up */
+
+    OS_EXIT_CRITICAL(sr);
 }
 
 static void timer_handler(int sig);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1d94ef36/libs/os/src/os_callout.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_callout.c b/libs/os/src/os_callout.c
index 6eb37ae..cd4a436 100644
--- a/libs/os/src/os_callout.c
+++ b/libs/os/src/os_callout.c
@@ -19,6 +19,7 @@
 
 #include "os/os.h"
 
+#include <assert.h>
 #include <string.h>
 
 TAILQ_HEAD(, os_callout) g_callout_list =
@@ -131,3 +132,29 @@ os_callout_tick(void)
         }
     }
 }
+
+/*
+ * Returns the number of ticks to the first pending callout. If there are no
+ * pending callouts then return OS_TIMEOUT_NEVER instead.
+ */
+os_time_t
+os_callout_wakeup_ticks(os_time_t now)
+{
+    os_time_t rt;
+    struct os_callout *c;
+
+    OS_ASSERT_CRITICAL();
+
+    c = TAILQ_FIRST(&g_callout_list);
+    if (c != NULL) {
+        if (OS_TIME_TICK_GEQ(c->c_ticks, now)) {
+            rt = c->c_ticks - now;
+        } else {
+            rt = 0;     /* callout time is in the past */
+        }
+    } else {
+        rt = OS_TIMEOUT_NEVER;
+    }
+
+    return (rt);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1d94ef36/libs/os/src/os_sched.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_sched.c b/libs/os/src/os_sched.c
index fd30a3e..3d81dba 100644
--- a/libs/os/src/os_sched.c
+++ b/libs/os/src/os_sched.c
@@ -266,6 +266,29 @@ os_sched_os_timer_exp(void)
     OS_EXIT_CRITICAL(sr); 
 }
 
+/*
+ * Return the number of ticks until the first sleep timer expires.If there are
+ * no such tasks then return OS_TIMEOUT_NEVER instead.
+ */
+os_time_t
+os_sched_wakeup_ticks(os_time_t now)
+{
+    os_time_t rt;
+    struct os_task *t;
+
+    OS_ASSERT_CRITICAL();
+
+    t = TAILQ_FIRST(&g_os_sleep_list);
+    if (t == NULL || (t->t_flags & OS_TASK_FLAG_NO_TIMEOUT)) {
+        rt = OS_TIMEOUT_NEVER;
+    } else if (OS_TIME_TICK_GEQ(t->t_next_wakeup, now)) {
+        rt = t->t_next_wakeup - now;   
+    } else {
+        rt = 0;     /* wakeup time was in the past */
+    }
+    return (rt);
+}
+
 /**
  * os sched next task 
  *  


[19/28] incubator-mynewt-core git commit: Cosmetic change to rename CALLOUT to OS_TICK.

Posted by ma...@apache.org.
Cosmetic change to rename CALLOUT to OS_TICK.


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/0e346d02
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/0e346d02
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/0e346d02

Branch: refs/heads/develop
Commit: 0e346d02470a1e6b75acb872535c94b353dc96fb
Parents: 5f4c0ff
Author: Neel Natu <ne...@nahannisys.com>
Authored: Wed Apr 6 15:25:45 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Wed Apr 6 15:25:45 2016 -0700

----------------------------------------------------------------------
 hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c | 60 +++++++++++++--------------
 1 file changed, 30 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0e346d02/hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c b/hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c
index abded0e..ba3f0b3 100644
--- a/hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c
+++ b/hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c
@@ -22,11 +22,11 @@
 #include <mcu/nrf52_bitfields.h>
 #include <bsp/cmsis_nvic.h>
 
-#define CALLOUT_TIMER       NRF_TIMER1
-#define CALLOUT_IRQ         TIMER1_IRQn
-#define CALLOUT_CMPREG      0   /* generate timer interrupt */
-#define CALLOUT_COUNTER     1   /* capture current timer value */
-#define CALLOUT_PRESCALER   4   /* prescaler to generate 1MHz timer freq */
+#define OS_TICK_TIMER       NRF_TIMER1
+#define OS_TICK_IRQ         TIMER1_IRQn
+#define OS_TICK_CMPREG      0   /* generate timer interrupt */
+#define OS_TICK_COUNTER     1   /* capture current timer value */
+#define OS_TICK_PRESCALER   4   /* prescaler to generate 1MHz timer freq */
 #define TIMER_LT(__t1, __t2)    ((int32_t)((__t1) - (__t2)) < 0)
 
 static int timer_ticks_per_ostick;
@@ -34,7 +34,7 @@ static os_time_t nrf52_max_idle_ticks;
 static uint32_t lastocmp;
 
 static inline uint32_t
-nrf52_callout_counter(void)
+nrf52_os_tick_counter(void)
 {
     /*
      * Make sure we are not interrupted between invoking the capture task
@@ -45,19 +45,19 @@ nrf52_callout_counter(void)
     /*
      * Capture the current timer value and return it.
      */
-    CALLOUT_TIMER->TASKS_CAPTURE[CALLOUT_COUNTER] = 1;
-    return (CALLOUT_TIMER->CC[CALLOUT_COUNTER]);
+    OS_TICK_TIMER->TASKS_CAPTURE[OS_TICK_COUNTER] = 1;
+    return (OS_TICK_TIMER->CC[OS_TICK_COUNTER]);
 }
 
 static inline void
-nrf52_callout_set_ocmp(uint32_t ocmp)
+nrf52_os_tick_set_ocmp(uint32_t ocmp)
 {
     uint32_t counter;
 
     OS_ASSERT_CRITICAL();
     while (1) {
-        CALLOUT_TIMER->CC[CALLOUT_CMPREG] = ocmp;
-        counter = nrf52_callout_counter();
+        OS_TICK_TIMER->CC[OS_TICK_CMPREG] = ocmp;
+        counter = nrf52_os_tick_counter();
         if (TIMER_LT(counter, ocmp)) {
             break;
         }
@@ -77,18 +77,18 @@ nrf52_timer_handler(void)
     /*
      * Calculate elapsed ticks and advance OS time.
      */
-    counter = nrf52_callout_counter();
+    counter = nrf52_os_tick_counter();
     ticks = (counter - lastocmp) / timer_ticks_per_ostick;
     os_time_advance(ticks);
 
     /* Clear timer interrupt */
-    CALLOUT_TIMER->EVENTS_COMPARE[CALLOUT_CMPREG] = 0;
+    OS_TICK_TIMER->EVENTS_COMPARE[OS_TICK_CMPREG] = 0;
 
     /* Update the time associated with the most recent tick */
     lastocmp += ticks * timer_ticks_per_ostick;
 
     /* Update the output compare to interrupt at the next tick */
-    nrf52_callout_set_ocmp(lastocmp + timer_ticks_per_ostick);
+    nrf52_os_tick_set_ocmp(lastocmp + timer_ticks_per_ostick);
 
     OS_EXIT_CRITICAL(sr);
 }
@@ -108,7 +108,7 @@ os_tick_idle(os_time_t ticks)
             ticks = nrf52_max_idle_ticks;
         }
         ocmp = lastocmp + ticks * timer_ticks_per_ostick;
-        nrf52_callout_set_ocmp(ocmp);
+        nrf52_os_tick_set_ocmp(ocmp);
     }
 
     __DSB();
@@ -131,28 +131,28 @@ os_tick_init(uint32_t os_ticks_per_sec, int prio)
 
     /*
      * The maximum number of timer ticks allowed to elapse during idle is
-     * limited to 1/4th the number of timer ticks before the counter rolls
-     * over.
+     * limited to 1/4th the number of timer ticks before the 32-bit counter
+     * rolls over.
      */
     nrf52_max_idle_ticks = (1UL << 30) / timer_ticks_per_ostick;
 
     /*
-     * Program CALLOUT_TIMER to operate at 1MHz and trigger an output
+     * Program OS_TICK_TIMER to operate at 1MHz and trigger an output
      * compare interrupt at a rate of 'os_ticks_per_sec'.
      */
-    CALLOUT_TIMER->TASKS_STOP = 1;
-    CALLOUT_TIMER->TASKS_CLEAR = 1;
-    CALLOUT_TIMER->MODE = TIMER_MODE_MODE_Timer;
-    CALLOUT_TIMER->BITMODE = TIMER_BITMODE_BITMODE_32Bit;
-    CALLOUT_TIMER->PRESCALER = CALLOUT_PRESCALER;
+    OS_TICK_TIMER->TASKS_STOP = 1;
+    OS_TICK_TIMER->TASKS_CLEAR = 1;
+    OS_TICK_TIMER->MODE = TIMER_MODE_MODE_Timer;
+    OS_TICK_TIMER->BITMODE = TIMER_BITMODE_BITMODE_32Bit;
+    OS_TICK_TIMER->PRESCALER = OS_TICK_PRESCALER;
 
-    CALLOUT_TIMER->CC[CALLOUT_CMPREG] = timer_ticks_per_ostick;
-    CALLOUT_TIMER->INTENSET = TIMER_COMPARE_INT_MASK(CALLOUT_CMPREG);
-    CALLOUT_TIMER->EVENTS_COMPARE[CALLOUT_CMPREG] = 0;
+    OS_TICK_TIMER->CC[OS_TICK_CMPREG] = timer_ticks_per_ostick;
+    OS_TICK_TIMER->INTENSET = TIMER_COMPARE_INT_MASK(OS_TICK_CMPREG);
+    OS_TICK_TIMER->EVENTS_COMPARE[OS_TICK_CMPREG] = 0;
 
-    NVIC_SetPriority(CALLOUT_IRQ, prio);
-    NVIC_SetVector(CALLOUT_IRQ, (uint32_t)nrf52_timer_handler);
-    NVIC_EnableIRQ(CALLOUT_IRQ);
+    NVIC_SetPriority(OS_TICK_IRQ, prio);
+    NVIC_SetVector(OS_TICK_IRQ, (uint32_t)nrf52_timer_handler);
+    NVIC_EnableIRQ(OS_TICK_IRQ);
 
-    CALLOUT_TIMER->TASKS_START = 1;     /* start the callout timer */
+    OS_TICK_TIMER->TASKS_START = 1;     /* start the os tick timer */
 }


[07/28] incubator-mynewt-core git commit: Merge branch 'develop' into tickless

Posted by ma...@apache.org.
Merge branch 'develop' into tickless


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/4a7ff051
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4a7ff051
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4a7ff051

Branch: refs/heads/develop
Commit: 4a7ff05166d9a6c8ebdecd1316caaa1907f78825
Parents: b387dc6 c36b804
Author: Neel Natu <ne...@nahannisys.com>
Authored: Thu Mar 24 13:43:56 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Thu Mar 24 13:43:56 2016 -0700

----------------------------------------------------------------------
 .rat-excludes                                   |   5 +
 LICENSE                                         |  20 +-
 README.md                                       | 193 +++++--
 RELEASE_NOTES.md                                |  35 ++
 apps/bleprph/src/main.c                         |  11 +-
 apps/bletest/pkg.yml                            |   7 +-
 apps/bletest/src/main.c                         |  68 ++-
 apps/bletiny/pkg.yml                            |   7 +-
 apps/bletiny/src/cmd.c                          |   2 +-
 apps/bletiny/src/main.c                         |  11 +-
 apps/blinky/pkg.yml                             |   7 +-
 apps/boot/pkg.yml                               |   7 +-
 apps/ffs2native/pkg.yml                         |   7 +-
 apps/luatest/pkg.yml                            |   7 +-
 apps/slinky/pkg.yml                             |   7 +-
 apps/test/pkg.yml                               |   7 +-
 apps/test/src/test.c                            |   2 +-
 compiler/arm-none-eabi-m0/pkg.yml               |   7 +-
 compiler/arm-none-eabi-m4/pkg.yml               |   7 +-
 compiler/sim/compiler.yml                       |  34 +-
 compiler/sim/linux-compiler.yml                 |  35 --
 compiler/sim/osx-compiler.yml                   |  31 -
 compiler/sim/pkg.yml                            |   7 +-
 fs/fs/pkg.yml                                   |   6 +-
 fs/nffs/README.md                               |  22 -
 fs/nffs/pkg.yml                                 |   6 +-
 hw/bsp/bmd300eval/bmd300eval.ld                 | 195 +++++++
 hw/bsp/bmd300eval/bmd300eval_debug.sh           |  47 ++
 hw/bsp/bmd300eval/bmd300eval_dowload.sh         |  70 +++
 hw/bsp/bmd300eval/include/bsp/bsp.h             |  49 ++
 hw/bsp/bmd300eval/include/bsp/cmsis_nvic.h      |  29 +
 hw/bsp/bmd300eval/pkg.yml                       |  39 ++
 .../src/arch/cortex_m4/gcc_startup_nrf52.s      | 284 ++++++++++
 hw/bsp/bmd300eval/src/hal_bsp.c                 |  46 ++
 hw/bsp/bmd300eval/src/libc_stubs.c              |  84 +++
 hw/bsp/bmd300eval/src/os_bsp.c                  |  80 +++
 hw/bsp/bmd300eval/src/sbrk.c                    |  54 ++
 hw/bsp/bmd300eval/src/system_nrf52.c            | 183 ++++++
 hw/bsp/native/README.md                         |  22 -
 hw/bsp/native/pkg.yml                           |   7 +-
 hw/bsp/nrf51dk-16kbram/boot-nrf51dk-16kbram.ld  |   2 +-
 hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram.ld       |   2 +-
 hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_debug.sh |   2 +-
 .../nrf51dk-16kbram/nrf51dk-16kbram_download.sh |   2 +-
 hw/bsp/nrf51dk-16kbram/pkg.yml                  |   7 +-
 hw/bsp/nrf51dk-16kbram/src/os_bsp.c             |  10 +-
 hw/bsp/nrf51dk/boot-nrf51dk.ld                  |   2 +-
 hw/bsp/nrf51dk/nrf51dk.ld                       |   2 +-
 hw/bsp/nrf51dk/nrf51dk_debug.sh                 |   2 +-
 hw/bsp/nrf51dk/nrf51dk_download.sh              |   2 +-
 hw/bsp/nrf51dk/pkg.yml                          |   7 +-
 hw/bsp/nrf51dk/src/os_bsp.c                     |  10 +-
 hw/bsp/nrf52pdk/boot-nrf52pdk.ld                | 196 +++++++
 hw/bsp/nrf52pdk/nrf52pdk.ld                     |   7 +-
 hw/bsp/nrf52pdk/nrf52pdk_debug.sh               |   2 +-
 hw/bsp/nrf52pdk/nrf52pdk_download.sh            |  54 +-
 hw/bsp/nrf52pdk/nrf52pdk_no_boot.ld             | 196 +++++++
 hw/bsp/nrf52pdk/pkg.yml                         |   7 +-
 hw/bsp/nrf52pdk/src/os_bsp.c                    |   8 +-
 hw/bsp/olimex_stm32-e407_devboard/pkg.yml       |   7 +-
 hw/hal/README.MD                                |  22 -
 hw/hal/include/hal/flash_map.h                  |   5 +
 hw/hal/pkg.yml                                  |   6 +-
 hw/hal/src/flash_map.c                          |   6 +
 hw/mcu/README.md                                |  22 -
 hw/mcu/native/pkg.yml                           |   6 +-
 hw/mcu/native/src/hal_gpio.c                    |   4 +-
 hw/mcu/nordic/nrf51xxx/pkg.yml                  |   6 +-
 hw/mcu/nordic/nrf52xxx/pkg.yml                  |   6 +-
 hw/mcu/nordic/nrf52xxx/src/hal_system_start.c   |  48 ++
 hw/mcu/stm/stm32f4xx/pkg.yml                    |   6 +-
 libs/baselibc/pkg.yml                           |   6 +-
 libs/bootutil/README.md                         |  22 -
 libs/bootutil/pkg.yml                           |   6 +-
 libs/cmsis-core/pkg.yml                         |   6 +-
 libs/console/README.md                          |  24 +-
 libs/console/full/pkg.yml                       |   6 +-
 libs/console/stub/pkg.yml                       |   6 +-
 libs/elua/elua_base/pkg.yml                     |  10 +-
 libs/flash_test/pkg.yml                         |   4 +-
 libs/imgmgr/pkg.yml                             |   6 +-
 libs/json/include/json/json.h                   |   6 +
 libs/json/pkg.yml                               |   8 +-
 libs/json/src/test/test_json.c                  |  41 ++
 libs/json/src/test/test_json.h                  |  27 +
 libs/json/src/test/test_json_simple.c           | 208 +++++++
 libs/mbedtls/pkg.yml                            |   6 +-
 libs/newtmgr/pkg.yml                            |   6 +-
 libs/os/README.md                               |  24 -
 libs/os/pkg.yml                                 |   6 +-
 libs/os/src/arch/sim/os_arch_stack_frame.s      |  19 +
 libs/os/src/os_mbuf.c                           |   4 +
 libs/shell/pkg.yml                              |   6 +-
 libs/testreport/pkg.yml                         |   6 +-
 libs/testutil/README.md                         |  22 -
 libs/testutil/include/testutil/testutil.h       |   4 +
 libs/testutil/pkg.yml                           |   6 +-
 libs/util/pkg.yml                               |   6 +-
 net/nimble/README.md                            |  22 -
 .../controller/include/controller/ble_ll.h      |  34 +-
 .../controller/include/controller/ble_ll_conn.h |  18 +-
 .../controller/include/controller/ble_ll_hci.h  |  13 +-
 .../controller/include/controller/ble_ll_scan.h |  18 -
 .../include/controller/ble_ll_whitelist.h       |   2 -
 net/nimble/controller/pkg.yml                   |   6 +-
 net/nimble/controller/src/ble_ll.c              | 127 ++++-
 net/nimble/controller/src/ble_ll_adv.c          |  12 +-
 net/nimble/controller/src/ble_ll_conn.c         | 349 ++++++------
 net/nimble/controller/src/ble_ll_conn_hci.c     |  10 +-
 net/nimble/controller/src/ble_ll_ctrl.c         |   3 +-
 net/nimble/controller/src/ble_ll_hci.c          | 150 ++++-
 net/nimble/controller/src/ble_ll_scan.c         |  32 +-
 net/nimble/controller/src/ble_ll_supp_cmd.c     | 197 +++++++
 net/nimble/controller/src/ble_ll_whitelist.c    |  12 +-
 net/nimble/drivers/native/pkg.yml               |   6 +-
 net/nimble/drivers/nrf51/pkg.yml                |   6 +-
 net/nimble/drivers/nrf52/pkg.yml                |   6 +-
 net/nimble/host/include/host/host_hci.h         |   6 +-
 net/nimble/host/pkg.yml                         |   6 +-
 net/nimble/host/src/ble_hs.c                    |   2 +-
 net/nimble/host/src/host_dbg.c                  |  87 ++-
 net/nimble/host/src/host_hci.c                  |   2 +
 net/nimble/host/src/host_hci_cmd.c              |  58 ++
 net/nimble/include/nimble/ble.h                 |  20 +-
 net/nimble/include/nimble/hci_common.h          | 110 ++--
 net/nimble/include/nimble/nimble_opt.h          |  90 +++
 net/nimble/pkg.yml                              |   6 +-
 net/nimble/src/hci_common.c                     |   4 +-
 scripts/hatch_tadpole.sh                        |  43 --
 sys/config/include/config/config.h              |  28 +-
 sys/config/include/config/config_fcb.h          |  36 ++
 sys/config/include/config/config_file.h         |  36 ++
 sys/config/include/config/config_test.h         |  24 -
 sys/config/pkg.yml                              |  17 +-
 sys/config/src/config.c                         |  15 +-
 sys/config/src/config_fcb.c                     |  38 ++
 sys/config/src/config_file.c                    | 186 ++++++
 sys/config/src/config_nmgr.c                    |  28 +-
 sys/config/src/config_parse_line.c              |  54 ++
 sys/config/src/config_priv.h                    |   6 +-
 sys/config/src/config_store.c                   |  70 +++
 sys/config/src/test/conf_test.c                 | 124 +++-
 sys/config/src/test/conf_test.h                 |  25 +
 sys/config/src/test/conf_test_suite.c           |  39 ++
 sys/config/src/test/config_test.h               |  24 +
 sys/fcb/README.md                               |  58 ++
 sys/fcb/include/fcb/fcb.h                       |  96 ++++
 sys/fcb/pkg.yml                                 |  23 +
 sys/fcb/src/fcb.c                               | 172 ++++++
 sys/fcb/src/fcb_append.c                        | 106 ++++
 sys/fcb/src/fcb_elem_info.c                     |  99 ++++
 sys/fcb/src/fcb_getnext.c                       | 132 +++++
 sys/fcb/src/fcb_priv.h                          |  60 ++
 sys/fcb/src/fcb_rotate.c                        |  56 ++
 sys/fcb/src/fcb_walk.c                          |  53 ++
 sys/fcb/src/test/fcb_test.c                     | 562 +++++++++++++++++++
 sys/log/pkg.yml                                 |   6 +-
 sys/stats/pkg.yml                               |   6 +-
 targets/unittest/pkg.yml                        |  20 +-
 targets/unittest/target.yml                     |  20 +
 160 files changed, 5497 insertions(+), 1091 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4a7ff051/hw/bsp/nrf51dk/src/os_bsp.c
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4a7ff051/hw/bsp/nrf52pdk/src/os_bsp.c
----------------------------------------------------------------------


[18/28] incubator-mynewt-core git commit: Assert that the OS tick frequency divides cleanly into the RTC frequency.

Posted by ma...@apache.org.
Assert that the OS tick frequency divides cleanly into the RTC frequency.


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/5f4c0ff5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5f4c0ff5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5f4c0ff5

Branch: refs/heads/develop
Commit: 5f4c0ff5bb471e31c8dd90154e8788722efd7511
Parents: 9b8540f
Author: Neel Natu <ne...@nahannisys.com>
Authored: Wed Apr 6 12:17:21 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Wed Apr 6 12:17:21 2016 -0700

----------------------------------------------------------------------
 hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5f4c0ff5/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c b/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
index 72cc358..c0579e1 100644
--- a/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
+++ b/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
@@ -25,6 +25,8 @@
 #include <mcu/nrf51_bitfields.h>
 #include <mcu/nrf51_hal.h>
 
+#define NRF51_RTC_FREQ  32768
+
 void
 os_tick_idle(os_time_t ticks)
 {
@@ -50,6 +52,8 @@ os_tick_init(uint32_t os_ticks_per_sec, int prio)
     uint32_t mask;
     uint32_t pre_scaler;
 
+    assert(NRF51_RTC_FREQ % os_ticks_per_sec == 0);
+
     /* Turn on the LFCLK */
     NRF_CLOCK->XTALFREQ = CLOCK_XTALFREQ_XTALFREQ_16MHz;
     NRF_CLOCK->TASKS_LFCLKSTOP = 1;
@@ -68,7 +72,7 @@ os_tick_init(uint32_t os_ticks_per_sec, int prio)
     }
 
     /* Is this exact frequency obtainable? */
-    pre_scaler = (32768 / os_ticks_per_sec) - 1;
+    pre_scaler = (NRF51_RTC_FREQ / os_ticks_per_sec) - 1;
 
     /* disable interrupts */
     __HAL_DISABLE_INTERRUPTS(ctx);


[09/28] incubator-mynewt-core git commit: Explicitly program output compare register to generate a periodic timer interrupt. This is in preparation for doing long sleeps when cpu is idle.

Posted by ma...@apache.org.
Explicitly program output compare register to generate a periodic timer
interrupt. This is in preparation for doing long sleeps when cpu is idle.


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/79e9e9ba
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/79e9e9ba
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/79e9e9ba

Branch: refs/heads/develop
Commit: 79e9e9ba132a1e3b27da781f5c4758252a60cd61
Parents: a9b6d9e
Author: Neel Natu <ne...@nahannisys.com>
Authored: Fri Mar 25 15:25:04 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Fri Mar 25 15:25:04 2016 -0700

----------------------------------------------------------------------
 hw/bsp/nrf52pdk/src/os_bsp.c | 55 ++++++++++++++++++++++++++++++++-------
 1 file changed, 46 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/79e9e9ba/hw/bsp/nrf52pdk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/src/os_bsp.c b/hw/bsp/nrf52pdk/src/os_bsp.c
index 0295100..f26460f 100644
--- a/hw/bsp/nrf52pdk/src/os_bsp.c
+++ b/hw/bsp/nrf52pdk/src/os_bsp.c
@@ -16,6 +16,8 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+#include <assert.h>
+
 #include <os/os.h>
 #include <bsp/cmsis_nvic.h>
 #include <mcu/nrf52.h>
@@ -84,24 +86,62 @@ os_bsp_init(void)
 
 #define CALLOUT_TIMER       NRF_TIMER1
 #define CALLOUT_IRQ         TIMER1_IRQn
-#define CALLOUT_CMPREG      0
+#define CALLOUT_CMPREG      0   /* generate timer interrupt */
+#define CALLOUT_COUNTER     1   /* capture current timer value */
 #define CALLOUT_PRESCALER   4   /* prescaler to generate 1MHz timer freq */
+#define TIMER_GEQ(__t1, __t2)   ((int32_t)((__t1) - (__t2)) >= 0)
+
+static int timer_ticks_per_ostick;
+static uint32_t lastocmp;
+
+static inline uint32_t
+nrf52_callout_counter(void)
+{
+    /*
+     * Capture the current timer value and return it.
+     */
+    CALLOUT_TIMER->TASKS_CAPTURE[CALLOUT_COUNTER] = 1;
+    return (CALLOUT_TIMER->CC[CALLOUT_COUNTER]);
+}
 
 static void
 nrf52_timer_handler(void)
 {
+    int ticks;
+    os_sr_t sr;
+    uint32_t counter, ocmp;
+
+    assert(CALLOUT_TIMER->EVENTS_COMPARE[CALLOUT_CMPREG]);
+
+    OS_ENTER_CRITICAL(sr);
+
     /* Clear interrupt */
     CALLOUT_TIMER->EVENTS_COMPARE[CALLOUT_CMPREG] = 0;
 
-    os_time_advance(1, true);
+    /* Capture the timer value */
+    counter = nrf52_callout_counter();
+
+    /* Calculate elapsed ticks */
+    ticks = (counter - lastocmp) / timer_ticks_per_ostick;
+    lastocmp += ticks * timer_ticks_per_ostick;
+
+    ocmp = lastocmp;
+    do {
+        ocmp += timer_ticks_per_ostick;
+        CALLOUT_TIMER->CC[CALLOUT_CMPREG] = ocmp;
+        counter = nrf52_callout_counter();
+    } while (TIMER_GEQ(counter, ocmp));
+
+    OS_EXIT_CRITICAL(sr);
+
+    os_time_advance(ticks, true);
 }
 
 void
 os_bsp_systick_init(uint32_t os_ticks_per_sec, int prio)
 {
-    uint32_t usecs_per_os_tick;
-
-    usecs_per_os_tick = 1000000 / os_ticks_per_sec;
+    lastocmp = 0;
+    timer_ticks_per_ostick = 1000000 / os_ticks_per_sec;
 
     /*
      * Program CALLOUT_TIMER to operate at 1MHz and trigger an output
@@ -113,13 +153,10 @@ os_bsp_systick_init(uint32_t os_ticks_per_sec, int prio)
     CALLOUT_TIMER->BITMODE = TIMER_BITMODE_BITMODE_32Bit;
     CALLOUT_TIMER->PRESCALER = CALLOUT_PRESCALER;
 
-    CALLOUT_TIMER->CC[CALLOUT_CMPREG] = usecs_per_os_tick;
+    CALLOUT_TIMER->CC[CALLOUT_CMPREG] = timer_ticks_per_ostick;
     CALLOUT_TIMER->INTENSET = TIMER_COMPARE_INT_MASK(CALLOUT_CMPREG);
     CALLOUT_TIMER->EVENTS_COMPARE[CALLOUT_CMPREG] = 0;
 
-    /* Enable shortcut to clear the timer on output compare */
-    CALLOUT_TIMER->SHORTS = TIMER_SHORTS_COMPARE_CLEAR(CALLOUT_CMPREG);
-
     NVIC_SetPriority(CALLOUT_IRQ, prio);
     NVIC_SetVector(CALLOUT_IRQ, (uint32_t)nrf52_timer_handler);
     NVIC_EnableIRQ(CALLOUT_IRQ);


[21/28] incubator-mynewt-core git commit: Implement tickless support for nRF51 microcontrollers using RTC0 for OS ticks.

Posted by ma...@apache.org.
Implement tickless support for nRF51 microcontrollers using RTC0 for OS ticks.


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/b0c6fbff
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b0c6fbff
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b0c6fbff

Branch: refs/heads/develop
Commit: b0c6fbffce26bef7b4f78a0c3030850e823f86b4
Parents: 3444a55
Author: Neel Natu <ne...@nahannisys.com>
Authored: Wed Apr 6 16:05:03 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Wed Apr 6 16:05:03 2016 -0700

----------------------------------------------------------------------
 hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b0c6fbff/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c b/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
index 85c1eef..e0e5be1 100644
--- a/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
+++ b/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
@@ -30,7 +30,7 @@
 
 static uint32_t lastocmp;
 static uint32_t timer_ticks_per_ostick;
-static uint32_t max_idle_ticks;
+static uint32_t nrf51_max_idle_ticks;
 
 /*
  * Implement (x - y) where the range of both 'x' and 'y' is limited to 24-bits.
@@ -125,9 +125,31 @@ rtc0_timer_handler(void)
 void
 os_tick_idle(os_time_t ticks)
 {
+    uint32_t ocmp;
+
     OS_ASSERT_CRITICAL();
+
+    if (ticks > 0) {
+        /*
+         * Enter tickless regime during long idle durations.
+         */
+        if (ticks > nrf51_max_idle_ticks) {
+            ticks = nrf51_max_idle_ticks;
+        }
+        ocmp = lastocmp + ticks * timer_ticks_per_ostick;
+        nrf51_os_tick_set_ocmp(ocmp);
+    }
+
     __DSB();
     __WFI();
+
+    if (ticks > 0) {
+        /*
+         * Update OS time before anything else when coming out of
+         * the tickless regime.
+         */
+        rtc0_timer_handler();
+    }
 }
 
 void
@@ -146,7 +168,7 @@ os_tick_init(uint32_t os_ticks_per_sec, int prio)
      * limited to 1/4th the number of timer ticks before the 24-bit counter
      * rolls over.
      */
-    max_idle_ticks = (1UL << 22) / timer_ticks_per_ostick;
+    nrf51_max_idle_ticks = (1UL << 22) / timer_ticks_per_ostick;
 
     /* Turn on the LFCLK */
     NRF_CLOCK->XTALFREQ = CLOCK_XTALFREQ_XTALFREQ_16MHz;


[14/28] incubator-mynewt-core git commit: Remove unused function declaration.

Posted by ma...@apache.org.
Remove unused function declaration.


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/1dcc28c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1dcc28c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1dcc28c7

Branch: refs/heads/develop
Commit: 1dcc28c70e81dc7897ac40a32f5f05ec1046f740
Parents: f3f5777
Author: Neel Natu <ne...@nahannisys.com>
Authored: Wed Apr 6 11:13:22 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Wed Apr 6 11:13:22 2016 -0700

----------------------------------------------------------------------
 libs/os/src/arch/cortex_m0/os_arch_arm.c | 3 ---
 1 file changed, 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1dcc28c7/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 36377ba..e8cf44f 100755
--- a/libs/os/src/arch/cortex_m0/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m0/os_arch_arm.c
@@ -22,9 +22,6 @@
 
 #include <bsp/cmsis_nvic.h>
 
-/* XXX*/
-extern void system_os_tick_init(uint32_t os_ticks_per_sec);
-
 /*
  * From HAL_CM0.s
  */


[23/28] incubator-mynewt-core git commit: Make task context switches in sim behave similarly to real hardware.

Posted by ma...@apache.org.
Make task context switches in sim behave similarly to real hardware.

Prior to the change context switching in sim happened "inline" as opposed
to on hardware where it would trigger a special interrupt and the context
switching happened in context of the interrupt handler.

This causes subtle differences in how tasks are scheduled inside sim.
For e.g. 'os_callout_tick()' is called from the timer handler with
interrupts disabled. If a callout fires this function will post to an
eventq and if a task is sleeping on it then it will be made runnable.

On 'sim' the context switch happened immediately (i.e. from the timer
handler context to the task that became runnable) whereas on real hardware
all it would do is trigger the special interrupt. Note that the interrupt
will not be recognized until the timer handler re-enables interrupts.

The context switching behavior is now done similarly on sim by posting
a signal to ourselves. The signal used is SIGURG because gdb treats this
signal specially and forwards it to the process without any additional
configuration (as opposed to gdb's treatment of SIGUSR1 which stops the
process).


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/dcdcfb4a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/dcdcfb4a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/dcdcfb4a

Branch: refs/heads/develop
Commit: dcdcfb4a1cc4352f19d9852ab6462b6f6aed8cb2
Parents: b51a0ee
Author: Neel Natu <ne...@nahannisys.com>
Authored: Wed Apr 6 18:54:08 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Wed Apr 6 18:54:08 2016 -0700

----------------------------------------------------------------------
 libs/os/src/arch/sim/os_arch_sim.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dcdcfb4a/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 521d51a..7a3b27d 100644
--- a/libs/os/src/arch/sim/os_arch_sim.c
+++ b/libs/os/src/arch/sim/os_arch_sim.c
@@ -53,6 +53,7 @@ extern void os_arch_frame_init(struct stack_frame *sf);
 
 #define OS_USEC_PER_TICK    (1000000 / OS_TICKS_PER_SEC)
 
+static pid_t mypid;
 static sigset_t allsigs, nosigs;
 static void timer_handler(int sig);
 
@@ -96,14 +97,32 @@ os_arch_task_stack_init(struct os_task *t, os_stack_t *stack_top, int size)
 }
 
 void
-os_arch_ctx_sw(struct os_task *next_t)  
+os_arch_ctx_sw(struct os_task *next_t)
 {
-    struct os_task *t;
+    /*
+     * gdb will stop execution of the program on most signals (e.g. SIGUSR1)
+     * whereas it passes SIGURG to the process without any special settings.
+     */
+    kill(mypid, SIGURG);
+}
+
+static void
+ctxsw_handler(int sig)
+{
+    struct os_task *t, *next_t;
     struct stack_frame *sf; 
     int rc;
 
     OS_ASSERT_CRITICAL();
     t = os_sched_get_current_task();
+    next_t = os_sched_next_task();
+    if (t == next_t) {
+        /*
+         * Context switch not needed - just return.
+         */
+        return;
+    }
+
     if (t) {
         sf = (struct stack_frame *) t->t_stackptr;
 
@@ -223,6 +242,7 @@ static struct {
     void (*handler)(int sig);
 } signals[] = {
     { SIGALRM, timer_handler },
+    { SIGURG, ctxsw_handler },
 };
 
 #define NUMSIGS     (sizeof(signals)/sizeof(signals[0]))
@@ -332,6 +352,7 @@ stop_timer(void)
 os_error_t 
 os_arch_os_init(void)
 {
+    mypid = getpid();
     g_current_task = NULL;
 
     TAILQ_INIT(&g_os_task_list);


[24/28] incubator-mynewt-core git commit: Get rid of unused include file.

Posted by ma...@apache.org.
Get rid of unused include file.


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/71234464
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/71234464
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/71234464

Branch: refs/heads/develop
Commit: 712344646fcef4f830c0807bb595b0f7b1808e1e
Parents: dcdcfb4
Author: Neel Natu <ne...@nahannisys.com>
Authored: Thu Apr 7 11:15:21 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Thu Apr 7 11:15:21 2016 -0700

----------------------------------------------------------------------
 hw/bsp/nrf52pdk/src/os_bsp.c | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/71234464/hw/bsp/nrf52pdk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/src/os_bsp.c b/hw/bsp/nrf52pdk/src/os_bsp.c
index d1e8809..1c5a7a9 100644
--- a/hw/bsp/nrf52pdk/src/os_bsp.c
+++ b/hw/bsp/nrf52pdk/src/os_bsp.c
@@ -16,7 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-#include <util/util.h>
 #include <hal/flash_map.h>
 
 static struct flash_area bsp_flash_areas[] = {


[17/28] incubator-mynewt-core git commit: Rename 'os_bsp_systick_init()' to 'os_tick_init()' for Cortex-M0 processors.

Posted by ma...@apache.org.
Rename 'os_bsp_systick_init()' to 'os_tick_init()' for Cortex-M0 processors.


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/9b8540fd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/9b8540fd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/9b8540fd

Branch: refs/heads/develop
Commit: 9b8540fda7ebdf93275778f3649aa8b24d48b2ac
Parents: c9eef76
Author: Neel Natu <ne...@nahannisys.com>
Authored: Wed Apr 6 12:12:49 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Wed Apr 6 12:12:49 2016 -0700

----------------------------------------------------------------------
 hw/bsp/nrf51dk-16kbram/src/os_bsp.c      | 64 ---------------------------
 hw/bsp/nrf51dk/src/os_bsp.c              | 62 --------------------------
 hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c | 62 ++++++++++++++++++++++++++
 libs/os/src/arch/cortex_m0/os_arch_arm.c |  6 +--
 4 files changed, 65 insertions(+), 129 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b8540fd/hw/bsp/nrf51dk-16kbram/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/src/os_bsp.c b/hw/bsp/nrf51dk-16kbram/src/os_bsp.c
index 906bc81..2b88f27 100644
--- a/hw/bsp/nrf51dk-16kbram/src/os_bsp.c
+++ b/hw/bsp/nrf51dk-16kbram/src/os_bsp.c
@@ -17,12 +17,6 @@
  * under the License.
  */
 #include <hal/flash_map.h>
-#include "bsp/cmsis_nvic.h"
-#include "mcu/nrf51.h"
-#include "mcu/nrf51_bitfields.h"
-#include "mcu/nrf51_hal.h"
-
-#define BSP_LOWEST_PRIO     ((1 << __NVIC_PRIO_BITS) - 1)
 
 static struct flash_area bsp_flash_areas[] = {
     [FLASH_AREA_BOOTLOADER] = {
@@ -82,61 +76,3 @@ os_bsp_init(void)
       sizeof(bsp_flash_areas) / sizeof(bsp_flash_areas[0]));
 
 }
-
-extern void timer_handler(void);
-static void
-rtc0_timer_handler(void)
-{
-    if (NRF_RTC0->EVENTS_TICK) {
-        NRF_RTC0->EVENTS_TICK = 0;
-        timer_handler();
-    }
-}
-
-void
-os_bsp_systick_init(uint32_t os_ticks_per_sec)
-{
-    uint32_t ctx;
-    uint32_t mask;
-    uint32_t pre_scaler;
-
-    /* Turn on the LFCLK */
-    NRF_CLOCK->XTALFREQ = CLOCK_XTALFREQ_XTALFREQ_16MHz;
-    NRF_CLOCK->TASKS_LFCLKSTOP = 1;
-    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
-    NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal;
-    NRF_CLOCK->TASKS_LFCLKSTART = 1;
-
-    /* Wait here till started! */
-    mask = CLOCK_LFCLKSTAT_STATE_Msk | CLOCK_LFCLKSTAT_SRC_Xtal;
-    while (1) {
-        if (NRF_CLOCK->EVENTS_LFCLKSTARTED) {
-            if ((NRF_CLOCK->LFCLKSTAT & mask) == mask) {
-                break;
-            }
-        }
-    }
-
-    /* Is this exact frequency obtainable? */
-    pre_scaler = (32768 / os_ticks_per_sec) - 1;
-
-    /* disable interrupts */
-    __HAL_DISABLE_INTERRUPTS(ctx);
-
-    NRF_RTC0->TASKS_STOP = 1;
-    NRF_RTC0->EVENTS_TICK = 0;
-    NRF_RTC0->PRESCALER = pre_scaler;
-    NRF_RTC0->INTENCLR = 0xffffffff;
-    NRF_RTC0->TASKS_CLEAR = 1;
-
-    /* Set isr in vector table and enable interrupt */
-    NVIC_SetPriority(RTC0_IRQn, BSP_LOWEST_PRIO - 1);
-    NVIC_SetVector(RTC0_IRQn, (uint32_t)rtc0_timer_handler);
-    NVIC_EnableIRQ(RTC0_IRQn);
-
-    NRF_RTC0->INTENSET = RTC_INTENSET_TICK_Msk;
-    NRF_RTC0->TASKS_START = 1;
-
-    __HAL_ENABLE_INTERRUPTS(ctx);
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b8540fd/hw/bsp/nrf51dk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/src/os_bsp.c b/hw/bsp/nrf51dk/src/os_bsp.c
index 8e9855f..2b88f27 100644
--- a/hw/bsp/nrf51dk/src/os_bsp.c
+++ b/hw/bsp/nrf51dk/src/os_bsp.c
@@ -17,10 +17,6 @@
  * under the License.
  */
 #include <hal/flash_map.h>
-#include "bsp/cmsis_nvic.h"
-#include "mcu/nrf51.h"
-#include "mcu/nrf51_bitfields.h"
-#include "mcu/nrf51_hal.h"
 
 static struct flash_area bsp_flash_areas[] = {
     [FLASH_AREA_BOOTLOADER] = {
@@ -80,61 +76,3 @@ os_bsp_init(void)
       sizeof(bsp_flash_areas) / sizeof(bsp_flash_areas[0]));
 
 }
-
-extern void timer_handler(void);
-static void
-rtc0_timer_handler(void)
-{
-    if (NRF_RTC0->EVENTS_TICK) {
-        NRF_RTC0->EVENTS_TICK = 0;
-        timer_handler();
-    }
-}
-
-void
-os_bsp_systick_init(uint32_t os_ticks_per_sec, int prio)
-{
-    uint32_t ctx;
-    uint32_t mask;
-    uint32_t pre_scaler;
-
-    /* Turn on the LFCLK */
-    NRF_CLOCK->XTALFREQ = CLOCK_XTALFREQ_XTALFREQ_16MHz;
-    NRF_CLOCK->TASKS_LFCLKSTOP = 1;
-    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
-    NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal;
-    NRF_CLOCK->TASKS_LFCLKSTART = 1;
-
-    /* Wait here till started! */
-    mask = CLOCK_LFCLKSTAT_STATE_Msk | CLOCK_LFCLKSTAT_SRC_Xtal;
-    while (1) {
-        if (NRF_CLOCK->EVENTS_LFCLKSTARTED) {
-            if ((NRF_CLOCK->LFCLKSTAT & mask) == mask) {
-                break;
-            }
-        }
-    }
-
-    /* Is this exact frequency obtainable? */
-    pre_scaler = (32768 / os_ticks_per_sec) - 1;
-
-    /* disable interrupts */
-    __HAL_DISABLE_INTERRUPTS(ctx);
-
-    NRF_RTC0->TASKS_STOP = 1;
-    NRF_RTC0->EVENTS_TICK = 0;
-    NRF_RTC0->PRESCALER = pre_scaler;
-    NRF_RTC0->INTENCLR = 0xffffffff;
-    NRF_RTC0->TASKS_CLEAR = 1;
-
-    /* Set isr in vector table and enable interrupt */
-    NVIC_SetPriority(RTC0_IRQn, prio);
-    NVIC_SetVector(RTC0_IRQn, (uint32_t)rtc0_timer_handler);
-    NVIC_EnableIRQ(RTC0_IRQn);
-
-    NRF_RTC0->INTENSET = RTC_INTENSET_TICK_Msk;
-    NRF_RTC0->TASKS_START = 1;
-
-    __HAL_ENABLE_INTERRUPTS(ctx);
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b8540fd/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c b/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
index 665abd9..72cc358 100644
--- a/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
+++ b/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
@@ -20,6 +20,11 @@
 #include <os/os.h>
 #include <hal/hal_os_tick.h>
 
+#include <bsp/cmsis_nvic.h>
+#include <mcu/nrf51.h>
+#include <mcu/nrf51_bitfields.h>
+#include <mcu/nrf51_hal.h>
+
 void
 os_tick_idle(os_time_t ticks)
 {
@@ -27,3 +32,60 @@ os_tick_idle(os_time_t ticks)
     __DSB();
     __WFI();
 }
+
+extern void timer_handler(void);
+static void
+rtc0_timer_handler(void)
+{
+    if (NRF_RTC0->EVENTS_TICK) {
+        NRF_RTC0->EVENTS_TICK = 0;
+        timer_handler();
+    }
+}
+
+void
+os_tick_init(uint32_t os_ticks_per_sec, int prio)
+{
+    uint32_t ctx;
+    uint32_t mask;
+    uint32_t pre_scaler;
+
+    /* Turn on the LFCLK */
+    NRF_CLOCK->XTALFREQ = CLOCK_XTALFREQ_XTALFREQ_16MHz;
+    NRF_CLOCK->TASKS_LFCLKSTOP = 1;
+    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
+    NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal;
+    NRF_CLOCK->TASKS_LFCLKSTART = 1;
+
+    /* Wait here till started! */
+    mask = CLOCK_LFCLKSTAT_STATE_Msk | CLOCK_LFCLKSTAT_SRC_Xtal;
+    while (1) {
+        if (NRF_CLOCK->EVENTS_LFCLKSTARTED) {
+            if ((NRF_CLOCK->LFCLKSTAT & mask) == mask) {
+                break;
+            }
+        }
+    }
+
+    /* Is this exact frequency obtainable? */
+    pre_scaler = (32768 / os_ticks_per_sec) - 1;
+
+    /* disable interrupts */
+    __HAL_DISABLE_INTERRUPTS(ctx);
+
+    NRF_RTC0->TASKS_STOP = 1;
+    NRF_RTC0->EVENTS_TICK = 0;
+    NRF_RTC0->PRESCALER = pre_scaler;
+    NRF_RTC0->INTENCLR = 0xffffffff;
+    NRF_RTC0->TASKS_CLEAR = 1;
+
+    /* Set isr in vector table and enable interrupt */
+    NVIC_SetPriority(RTC0_IRQn, prio);
+    NVIC_SetVector(RTC0_IRQn, (uint32_t)rtc0_timer_handler);
+    NVIC_EnableIRQ(RTC0_IRQn);
+
+    NRF_RTC0->INTENSET = RTC_INTENSET_TICK_Msk;
+    NRF_RTC0->TASKS_START = 1;
+
+    __HAL_ENABLE_INTERRUPTS(ctx);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b8540fd/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 8a2015c..f5403f3 100755
--- a/libs/os/src/arch/cortex_m0/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m0/os_arch_arm.c
@@ -19,7 +19,7 @@
 
 #include "os/os.h"
 #include "os/os_arch.h"
-
+#include <hal/hal_os_tick.h>
 #include <bsp/cmsis_nvic.h>
 
 /*
@@ -38,7 +38,7 @@ extern void SysTick_Handler(void);
  * higher priority exception will interrupt a lower priority exception.
  */
 #define PEND_SV_PRIO    ((1 << __NVIC_PRIO_BITS) - 1)
-#define SYSTICK_PRIO    (PEND_SV_PRIO - 1)
+#define OS_TICK_PRIO    (PEND_SV_PRIO - 1)
 
 /* Make the SVC instruction highest priority */
 #define SVC_PRIO        (1)
@@ -253,7 +253,7 @@ os_arch_start(void)
     __set_PSP((uint32_t)t->t_stackptr + offsetof(struct stack_frame, r0));
 
     /* Intitialize and start system clock timer */
-    os_bsp_systick_init(OS_TICKS_PER_SEC, SYSTICK_PRIO);
+    os_tick_init(OS_TICKS_PER_SEC, OS_TICK_PRIO);
 
     /* Mark the OS as started, right before we run our first task */
     g_os_started = 1;


[15/28] incubator-mynewt-core git commit: Get rid of 'os_arch_idle()' in favor of calling 'os_tick_idle()' directly from the idle task. This was motivated by the fact that on most platforms the OS tick will be generated by a MCU-specific timer which impl

Posted by ma...@apache.org.
Get rid of 'os_arch_idle()' in favor of calling 'os_tick_idle()' directly
from the idle task. This was motivated by the fact that on most platforms
the OS tick will be generated by a MCU-specific timer which implies that
the idle function will also be MCU-specific.


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/f59995ec
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f59995ec
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f59995ec

Branch: refs/heads/develop
Commit: f59995ecd33ed99997cffd6e04884fc69bf875c4
Parents: 1dcc28c
Author: Neel Natu <ne...@nahannisys.com>
Authored: Wed Apr 6 11:57:17 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Wed Apr 6 11:57:17 2016 -0700

----------------------------------------------------------------------
 hw/bsp/nrf52pdk/src/os_bsp.c                   | 141 -----------------
 hw/hal/include/hal/hal_os_tick.h               |  35 +++++
 hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c       |  29 ++++
 hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c       | 158 ++++++++++++++++++++
 libs/os/include/os/arch/cortex_m0/os/os_arch.h |   1 -
 libs/os/include/os/arch/cortex_m4/os/os_arch.h |   1 -
 libs/os/include/os/arch/sim/os/os_arch.h       |   1 -
 libs/os/src/arch/cortex_m0/os_arch_arm.c       |  13 --
 libs/os/src/arch/cortex_m4/os_arch_arm.c       |  10 +-
 libs/os/src/arch/sim/os_arch_sim.c             |   2 +-
 libs/os/src/os.c                               |   4 +-
 11 files changed, 228 insertions(+), 167 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f59995ec/hw/bsp/nrf52pdk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/src/os_bsp.c b/hw/bsp/nrf52pdk/src/os_bsp.c
index f386137..d1e8809 100644
--- a/hw/bsp/nrf52pdk/src/os_bsp.c
+++ b/hw/bsp/nrf52pdk/src/os_bsp.c
@@ -16,12 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-#include <assert.h>
-
-#include <os/os.h>
-#include <bsp/cmsis_nvic.h>
-#include <mcu/nrf52.h>
-#include <mcu/nrf52_bitfields.h>
 #include <util/util.h>
 #include <hal/flash_map.h>
 
@@ -83,138 +77,3 @@ os_bsp_init(void)
     flash_area_init(bsp_flash_areas,
       sizeof(bsp_flash_areas) / sizeof(bsp_flash_areas[0]));
 }
-
-#define CALLOUT_TIMER       NRF_TIMER1
-#define CALLOUT_IRQ         TIMER1_IRQn
-#define CALLOUT_CMPREG      0   /* generate timer interrupt */
-#define CALLOUT_COUNTER     1   /* capture current timer value */
-#define CALLOUT_PRESCALER   4   /* prescaler to generate 1MHz timer freq */
-#define TIMER_LT(__t1, __t2)    ((int32_t)((__t1) - (__t2)) < 0)
-
-static int timer_ticks_per_ostick;
-static os_time_t nrf52_max_idle_ticks;
-static uint32_t lastocmp;
-
-static inline uint32_t
-nrf52_callout_counter(void)
-{
-    /*
-     * Make sure we are not interrupted between invoking the capture task
-     * and reading the value.
-     */
-    OS_ASSERT_CRITICAL();
-
-    /*
-     * Capture the current timer value and return it.
-     */
-    CALLOUT_TIMER->TASKS_CAPTURE[CALLOUT_COUNTER] = 1;
-    return (CALLOUT_TIMER->CC[CALLOUT_COUNTER]);
-}
-
-static inline void
-nrf52_callout_set_ocmp(uint32_t ocmp)
-{
-    uint32_t counter;
-
-    OS_ASSERT_CRITICAL();
-    while (1) {
-        CALLOUT_TIMER->CC[CALLOUT_CMPREG] = ocmp;
-        counter = nrf52_callout_counter();
-        if (TIMER_LT(counter, ocmp)) {
-            break;
-        }
-        ocmp += timer_ticks_per_ostick;
-    }
-}
-
-static void
-nrf52_timer_handler(void)
-{
-    int ticks;
-    os_sr_t sr;
-    uint32_t counter;
-
-    OS_ENTER_CRITICAL(sr);
-
-    /*
-     * Calculate elapsed ticks and advance OS time.
-     */
-    counter = nrf52_callout_counter();
-    ticks = (counter - lastocmp) / timer_ticks_per_ostick;
-    os_time_advance(ticks);
-
-    /* Clear timer interrupt */
-    CALLOUT_TIMER->EVENTS_COMPARE[CALLOUT_CMPREG] = 0;
-
-    /* Update the time associated with the most recent tick */
-    lastocmp += ticks * timer_ticks_per_ostick;
-
-    /* Update the output compare to interrupt at the next tick */
-    nrf52_callout_set_ocmp(lastocmp + timer_ticks_per_ostick);
-
-    OS_EXIT_CRITICAL(sr);
-}
-
-void
-os_bsp_idle(os_time_t ticks)
-{
-    uint32_t ocmp;
-
-    OS_ASSERT_CRITICAL();
-
-    if (ticks > 0) {
-        /*
-         * Enter tickless regime during long idle durations.
-         */
-        if (ticks > nrf52_max_idle_ticks) {
-            ticks = nrf52_max_idle_ticks;
-        }
-        ocmp = lastocmp + ticks * timer_ticks_per_ostick;
-        nrf52_callout_set_ocmp(ocmp);
-    }
-
-    __DSB();
-    __WFI();
-
-    if (ticks > 0) {
-        /*
-         * Update OS time before anything else when coming out of
-         * the tickless regime.
-         */
-        nrf52_timer_handler();
-    }
-}
-
-void
-os_bsp_systick_init(uint32_t os_ticks_per_sec, int prio)
-{
-    lastocmp = 0;
-    timer_ticks_per_ostick = 1000000 / os_ticks_per_sec;
-
-    /*
-     * The maximum number of timer ticks allowed to elapse during idle is
-     * limited to 1/4th the number of timer ticks before the counter rolls
-     * over.
-     */
-    nrf52_max_idle_ticks = (1UL << 30) / timer_ticks_per_ostick;
-
-    /*
-     * Program CALLOUT_TIMER to operate at 1MHz and trigger an output
-     * compare interrupt at a rate of 'os_ticks_per_sec'.
-     */
-    CALLOUT_TIMER->TASKS_STOP = 1;
-    CALLOUT_TIMER->TASKS_CLEAR = 1;
-    CALLOUT_TIMER->MODE = TIMER_MODE_MODE_Timer;
-    CALLOUT_TIMER->BITMODE = TIMER_BITMODE_BITMODE_32Bit;
-    CALLOUT_TIMER->PRESCALER = CALLOUT_PRESCALER;
-
-    CALLOUT_TIMER->CC[CALLOUT_CMPREG] = timer_ticks_per_ostick;
-    CALLOUT_TIMER->INTENSET = TIMER_COMPARE_INT_MASK(CALLOUT_CMPREG);
-    CALLOUT_TIMER->EVENTS_COMPARE[CALLOUT_CMPREG] = 0;
-
-    NVIC_SetPriority(CALLOUT_IRQ, prio);
-    NVIC_SetVector(CALLOUT_IRQ, (uint32_t)nrf52_timer_handler);
-    NVIC_EnableIRQ(CALLOUT_IRQ);
-
-    CALLOUT_TIMER->TASKS_START = 1;     /* start the callout timer */
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f59995ec/hw/hal/include/hal/hal_os_tick.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_os_tick.h b/hw/hal/include/hal/hal_os_tick.h
new file mode 100644
index 0000000..dce419e
--- /dev/null
+++ b/hw/hal/include/hal/hal_os_tick.h
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#ifndef _HAL_OS_TICK_H_
+#define _HAL_OS_TICK_H_
+
+#include <os/os_time.h>
+
+/*
+ * Set up the periodic timer to interrupt at a frequency of 'os_ticks_per_sec'.
+ * 'prio' is the cpu-specific priority of the periodic timer interrupt.
+ */
+void os_tick_init(uint32_t os_ticks_per_sec, int prio);
+
+/*
+ * Halt CPU for up to 'n' ticks.
+ */
+void os_tick_idle(os_time_t n);
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f59995ec/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c b/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
new file mode 100644
index 0000000..665abd9
--- /dev/null
+++ b/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <assert.h>
+#include <os/os.h>
+#include <hal/hal_os_tick.h>
+
+void
+os_tick_idle(os_time_t ticks)
+{
+    OS_ASSERT_CRITICAL();
+    __DSB();
+    __WFI();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f59995ec/hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c b/hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c
new file mode 100644
index 0000000..abded0e
--- /dev/null
+++ b/hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c
@@ -0,0 +1,158 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <assert.h>
+#include <os/os.h>
+#include <hal/hal_os_tick.h>
+#include <mcu/nrf52_bitfields.h>
+#include <bsp/cmsis_nvic.h>
+
+#define CALLOUT_TIMER       NRF_TIMER1
+#define CALLOUT_IRQ         TIMER1_IRQn
+#define CALLOUT_CMPREG      0   /* generate timer interrupt */
+#define CALLOUT_COUNTER     1   /* capture current timer value */
+#define CALLOUT_PRESCALER   4   /* prescaler to generate 1MHz timer freq */
+#define TIMER_LT(__t1, __t2)    ((int32_t)((__t1) - (__t2)) < 0)
+
+static int timer_ticks_per_ostick;
+static os_time_t nrf52_max_idle_ticks;
+static uint32_t lastocmp;
+
+static inline uint32_t
+nrf52_callout_counter(void)
+{
+    /*
+     * Make sure we are not interrupted between invoking the capture task
+     * and reading the value.
+     */
+    OS_ASSERT_CRITICAL();
+
+    /*
+     * Capture the current timer value and return it.
+     */
+    CALLOUT_TIMER->TASKS_CAPTURE[CALLOUT_COUNTER] = 1;
+    return (CALLOUT_TIMER->CC[CALLOUT_COUNTER]);
+}
+
+static inline void
+nrf52_callout_set_ocmp(uint32_t ocmp)
+{
+    uint32_t counter;
+
+    OS_ASSERT_CRITICAL();
+    while (1) {
+        CALLOUT_TIMER->CC[CALLOUT_CMPREG] = ocmp;
+        counter = nrf52_callout_counter();
+        if (TIMER_LT(counter, ocmp)) {
+            break;
+        }
+        ocmp += timer_ticks_per_ostick;
+    }
+}
+
+static void
+nrf52_timer_handler(void)
+{
+    int ticks;
+    os_sr_t sr;
+    uint32_t counter;
+
+    OS_ENTER_CRITICAL(sr);
+
+    /*
+     * Calculate elapsed ticks and advance OS time.
+     */
+    counter = nrf52_callout_counter();
+    ticks = (counter - lastocmp) / timer_ticks_per_ostick;
+    os_time_advance(ticks);
+
+    /* Clear timer interrupt */
+    CALLOUT_TIMER->EVENTS_COMPARE[CALLOUT_CMPREG] = 0;
+
+    /* Update the time associated with the most recent tick */
+    lastocmp += ticks * timer_ticks_per_ostick;
+
+    /* Update the output compare to interrupt at the next tick */
+    nrf52_callout_set_ocmp(lastocmp + timer_ticks_per_ostick);
+
+    OS_EXIT_CRITICAL(sr);
+}
+
+void
+os_tick_idle(os_time_t ticks)
+{
+    uint32_t ocmp;
+
+    OS_ASSERT_CRITICAL();
+
+    if (ticks > 0) {
+        /*
+         * Enter tickless regime during long idle durations.
+         */
+        if (ticks > nrf52_max_idle_ticks) {
+            ticks = nrf52_max_idle_ticks;
+        }
+        ocmp = lastocmp + ticks * timer_ticks_per_ostick;
+        nrf52_callout_set_ocmp(ocmp);
+    }
+
+    __DSB();
+    __WFI();
+
+    if (ticks > 0) {
+        /*
+         * Update OS time before anything else when coming out of
+         * the tickless regime.
+         */
+        nrf52_timer_handler();
+    }
+}
+
+void
+os_tick_init(uint32_t os_ticks_per_sec, int prio)
+{
+    lastocmp = 0;
+    timer_ticks_per_ostick = 1000000 / os_ticks_per_sec;
+
+    /*
+     * The maximum number of timer ticks allowed to elapse during idle is
+     * limited to 1/4th the number of timer ticks before the counter rolls
+     * over.
+     */
+    nrf52_max_idle_ticks = (1UL << 30) / timer_ticks_per_ostick;
+
+    /*
+     * Program CALLOUT_TIMER to operate at 1MHz and trigger an output
+     * compare interrupt at a rate of 'os_ticks_per_sec'.
+     */
+    CALLOUT_TIMER->TASKS_STOP = 1;
+    CALLOUT_TIMER->TASKS_CLEAR = 1;
+    CALLOUT_TIMER->MODE = TIMER_MODE_MODE_Timer;
+    CALLOUT_TIMER->BITMODE = TIMER_BITMODE_BITMODE_32Bit;
+    CALLOUT_TIMER->PRESCALER = CALLOUT_PRESCALER;
+
+    CALLOUT_TIMER->CC[CALLOUT_CMPREG] = timer_ticks_per_ostick;
+    CALLOUT_TIMER->INTENSET = TIMER_COMPARE_INT_MASK(CALLOUT_CMPREG);
+    CALLOUT_TIMER->EVENTS_COMPARE[CALLOUT_CMPREG] = 0;
+
+    NVIC_SetPriority(CALLOUT_IRQ, prio);
+    NVIC_SetVector(CALLOUT_IRQ, (uint32_t)nrf52_timer_handler);
+    NVIC_EnableIRQ(CALLOUT_IRQ);
+
+    CALLOUT_TIMER->TASKS_START = 1;     /* start the callout timer */
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f59995ec/libs/os/include/os/arch/cortex_m0/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/cortex_m0/os/os_arch.h b/libs/os/include/os/arch/cortex_m0/os/os_arch.h
index 23016c7..7231cb7 100755
--- a/libs/os/include/os/arch/cortex_m0/os/os_arch.h
+++ b/libs/os/include/os/arch/cortex_m0/os/os_arch.h
@@ -66,7 +66,6 @@ os_error_t os_arch_os_start(void);
 void os_set_env(void);
 void os_arch_init_task_stack(os_stack_t *sf);
 void os_default_irq_asm(void);
-void os_arch_idle(os_time_t ticks);
 
 /* External function prototypes supplied by BSP */
 void os_bsp_systick_init(uint32_t os_ticks_per_sec, int prio);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f59995ec/libs/os/include/os/arch/cortex_m4/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/cortex_m4/os/os_arch.h b/libs/os/include/os/arch/cortex_m4/os/os_arch.h
index a68f38a..590542a 100755
--- a/libs/os/include/os/arch/cortex_m4/os/os_arch.h
+++ b/libs/os/include/os/arch/cortex_m4/os/os_arch.h
@@ -66,7 +66,6 @@ os_error_t os_arch_os_start(void);
 void os_set_env(void);
 void os_arch_init_task_stack(os_stack_t *sf);
 void os_default_irq_asm(void);
-void os_arch_idle(os_time_t ticks);
 
 /* External function prototypes supplied by BSP */
 void os_bsp_systick_init(uint32_t os_tick_per_sec, int prio);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f59995ec/libs/os/include/os/arch/sim/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/sim/os/os_arch.h b/libs/os/include/os/arch/sim/os/os_arch.h
index b1368ee..6b98b8e 100644
--- a/libs/os/include/os/arch/sim/os/os_arch.h
+++ b/libs/os/include/os/arch/sim/os/os_arch.h
@@ -70,7 +70,6 @@ int os_arch_in_critical(void);
 os_error_t os_arch_os_init(void);
 void os_arch_os_stop(void);
 os_error_t os_arch_os_start(void);
-void os_arch_idle(os_time_t ticks);
 
 void os_bsp_init(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f59995ec/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 e8cf44f..8a2015c 100755
--- a/libs/os/src/arch/cortex_m0/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m0/os_arch_arm.c
@@ -329,16 +329,3 @@ os_arch_os_start(void)
 
     return err;
 }
-
-void
-os_arch_idle(os_time_t ticks)
-{
-    os_sr_t sr;
-
-    OS_ENTER_CRITICAL(sr);
-    __DSB();
-    __WFI();
-    OS_EXIT_CRITICAL(sr);
-
-    return;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f59995ec/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 dc91e84..b9c0c1d 100755
--- a/libs/os/src/arch/cortex_m4/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m4/os_arch_arm.c
@@ -19,7 +19,7 @@
 
 #include "os/os.h"
 #include "os/os_arch.h"
-
+#include <hal/hal_os_tick.h>
 #include <bsp/cmsis_nvic.h>
 
 /* Initial program status register */
@@ -246,7 +246,7 @@ os_arch_start(void)
     __set_PSP((uint32_t)t->t_stackptr + offsetof(struct stack_frame, r0));
 
     /* Intitialize and start system clock timer */
-    os_bsp_systick_init(OS_TICKS_PER_SEC, SYSTICK_PRIO);
+    os_tick_init(OS_TICKS_PER_SEC, SYSTICK_PRIO);
 
     /* Mark the OS as started, right before we run our first task */
     g_os_started = 1;
@@ -322,9 +322,3 @@ os_arch_os_start(void)
 
     return err;
 }
-
-void
-os_arch_idle(os_time_t ticks)
-{
-    os_bsp_idle(ticks);
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f59995ec/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 bbdc641..521d51a 100644
--- a/libs/os/src/arch/sim/os_arch_sim.c
+++ b/libs/os/src/arch/sim/os_arch_sim.c
@@ -177,7 +177,7 @@ os_arch_in_critical(void)
 }
 
 void
-os_arch_idle(os_time_t ticks)
+os_tick_idle(os_time_t ticks)
 {
     int rc;
     struct itimerval it;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f59995ec/libs/os/src/os.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os.c b/libs/os/src/os.c
index 4310178..963fc40 100644
--- a/libs/os/src/os.c
+++ b/libs/os/src/os.c
@@ -20,6 +20,8 @@
 #include "os/os.h"
 #include "os/queue.h"
 
+#include "hal/hal_os_tick.h"
+
 #include <assert.h> 
 
 struct os_task g_idle_task; 
@@ -59,7 +61,7 @@ os_idle_task(void *arg)
         } else {
             /* NOTHING */
         }
-        os_arch_idle(iticks);
+        os_tick_idle(iticks);
         OS_EXIT_CRITICAL(sr);
     }
 }


[20/28] incubator-mynewt-core git commit: Implement OS tick on nRF51 microcontrollers using output compare rather than the tick feature.

Posted by ma...@apache.org.
Implement OS tick on nRF51 microcontrollers using output compare rather than
the tick feature.

This is in preparation for tickless support when idle.


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/3444a55a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3444a55a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3444a55a

Branch: refs/heads/develop
Commit: 3444a55a5f003355ddbf1daf8302ea03c09efc6c
Parents: 0e346d0
Author: Neel Natu <ne...@nahannisys.com>
Authored: Wed Apr 6 15:50:43 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Wed Apr 6 15:50:43 2016 -0700

----------------------------------------------------------------------
 .../nrf51xxx/include/mcu/nrf51_bitfields.h      |   2 +
 hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c        | 142 ++++++++++++++++---
 2 files changed, 122 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3444a55a/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_bitfields.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_bitfields.h b/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_bitfields.h
index bf7682b..934e1dd 100755
--- a/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_bitfields.h
+++ b/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_bitfields.h
@@ -5432,6 +5432,8 @@
 /* Register: RTC_INTENSET */
 /* Description: Interrupt enable set register. */
 
+#define RTC_COMPARE_INT_MASK(ccreg) (1UL << ((ccreg) + 16))
+
 /* Bit 19 : Enable interrupt on COMPARE[3] event. */
 #define RTC_INTENSET_COMPARE3_Pos (19UL) /*!< Position of COMPARE3 field. */
 #define RTC_INTENSET_COMPARE3_Msk (0x1UL << RTC_INTENSET_COMPARE3_Pos) /*!< Bit mask of COMPARE3 field. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3444a55a/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c b/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
index c0579e1..85c1eef 100644
--- a/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
+++ b/hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c
@@ -25,24 +25,109 @@
 #include <mcu/nrf51_bitfields.h>
 #include <mcu/nrf51_hal.h>
 
-#define NRF51_RTC_FREQ  32768
+#define OS_TICK_CMPREG  0
+#define RTC_FREQ        32768
 
-void
-os_tick_idle(os_time_t ticks)
+static uint32_t lastocmp;
+static uint32_t timer_ticks_per_ostick;
+static uint32_t max_idle_ticks;
+
+/*
+ * Implement (x - y) where the range of both 'x' and 'y' is limited to 24-bits.
+ *
+ * For example:
+ *
+ * sub24(0, 0xffffff) = 1
+ * sub24(0xffffff, 0xfffffe) = 1
+ * sub24(0xffffff, 0) = -1
+ * sub24(0x7fffff, 0) = 8388607
+ * sub24(0x800000, 0) = -8388608
+ */
+static inline int
+sub24(uint32_t x, uint32_t y)
 {
+    int result;
+
+    assert(x <= 0xffffff);
+    assert(y <= 0xffffff);
+
+    result = x - y;
+    if (result & 0x800000) {
+        return (result | 0xff800000);
+    } else {
+        return (result & 0x007fffff);
+    }
+}
+
+static inline uint32_t
+nrf51_os_tick_counter(void)
+{
+    return (NRF_RTC0->COUNTER);
+}
+
+static inline void
+nrf51_os_tick_set_ocmp(uint32_t ocmp)
+{
+    int delta;
+    uint32_t counter;
+
     OS_ASSERT_CRITICAL();
-    __DSB();
-    __WFI();
+    while (1) {
+        ocmp &= 0xffffff;
+        NRF_RTC0->CC[OS_TICK_CMPREG] = ocmp;
+        counter = nrf51_os_tick_counter();
+        /*
+         * From section 19.1.7 "Compare Feature" nRF51 Reference Manual 3.0:
+         *
+         * - If Counter is 'N' writing (N) or (N + 1) to CC register
+         *   may not trigger a compare event.
+         *
+         * - If Counter is 'N' writing (N + 2) to CC register is guaranteed
+         *   to trigger a compare event at 'N + 2'.
+         */
+        delta = sub24(ocmp, counter);
+        if (delta > 2) {
+            break;
+        }
+        ocmp += timer_ticks_per_ostick;
+    }
 }
 
-extern void timer_handler(void);
 static void
 rtc0_timer_handler(void)
 {
-    if (NRF_RTC0->EVENTS_TICK) {
-        NRF_RTC0->EVENTS_TICK = 0;
-        timer_handler();
-    }
+    int ticks, delta;
+    os_sr_t sr;
+    uint32_t counter;
+
+    OS_ENTER_CRITICAL(sr);
+
+    /*
+     * Calculate elapsed ticks and advance OS time.
+     */
+    counter = nrf51_os_tick_counter();
+    delta = sub24(counter, lastocmp);
+    ticks = delta / timer_ticks_per_ostick;
+    os_time_advance(ticks);
+
+    /* Clear timer interrupt */
+    NRF_RTC0->EVENTS_COMPARE[OS_TICK_CMPREG] = 0;
+
+    /* Update the time associated with the most recent tick */
+    lastocmp = (lastocmp + ticks * timer_ticks_per_ostick) & 0xffffff;
+
+    /* Update the output compare to interrupt at the next tick */
+    nrf51_os_tick_set_ocmp(lastocmp + timer_ticks_per_ostick);
+
+    OS_EXIT_CRITICAL(sr);
+}
+
+void
+os_tick_idle(os_time_t ticks)
+{
+    OS_ASSERT_CRITICAL();
+    __DSB();
+    __WFI();
 }
 
 void
@@ -50,9 +135,18 @@ os_tick_init(uint32_t os_ticks_per_sec, int prio)
 {
     uint32_t ctx;
     uint32_t mask;
-    uint32_t pre_scaler;
 
-    assert(NRF51_RTC_FREQ % os_ticks_per_sec == 0);
+    assert(RTC_FREQ % os_ticks_per_sec == 0);
+
+    lastocmp = 0;
+    timer_ticks_per_ostick = RTC_FREQ / os_ticks_per_sec;
+
+    /*
+     * The maximum number of OS ticks allowed to elapse during idle is
+     * limited to 1/4th the number of timer ticks before the 24-bit counter
+     * rolls over.
+     */
+    max_idle_ticks = (1UL << 22) / timer_ticks_per_ostick;
 
     /* Turn on the LFCLK */
     NRF_CLOCK->XTALFREQ = CLOCK_XTALFREQ_XTALFREQ_16MHz;
@@ -71,24 +165,28 @@ os_tick_init(uint32_t os_ticks_per_sec, int prio)
         }
     }
 
-    /* Is this exact frequency obtainable? */
-    pre_scaler = (NRF51_RTC_FREQ / os_ticks_per_sec) - 1;
-
     /* disable interrupts */
     __HAL_DISABLE_INTERRUPTS(ctx);
 
-    NRF_RTC0->TASKS_STOP = 1;
-    NRF_RTC0->EVENTS_TICK = 0;
-    NRF_RTC0->PRESCALER = pre_scaler;
-    NRF_RTC0->INTENCLR = 0xffffffff;
-    NRF_RTC0->TASKS_CLEAR = 1;
-
     /* Set isr in vector table and enable interrupt */
     NVIC_SetPriority(RTC0_IRQn, prio);
     NVIC_SetVector(RTC0_IRQn, (uint32_t)rtc0_timer_handler);
     NVIC_EnableIRQ(RTC0_IRQn);
 
-    NRF_RTC0->INTENSET = RTC_INTENSET_TICK_Msk;
+    /*
+     * Program the OS_TICK_TIMER to operate at 32KHz and trigger an output
+     * compare interrupt at a rate of 'os_ticks_per_sec'.
+     */
+    NRF_RTC0->TASKS_STOP = 1;
+    NRF_RTC0->TASKS_CLEAR = 1;
+
+    NRF_RTC0->EVTENCLR = 0xffffffff;
+    NRF_RTC0->INTENCLR = 0xffffffff;
+    NRF_RTC0->INTENSET = RTC_COMPARE_INT_MASK(OS_TICK_CMPREG);
+
+    NRF_RTC0->EVENTS_COMPARE[OS_TICK_CMPREG] = 0;
+    NRF_RTC0->CC[OS_TICK_CMPREG] = timer_ticks_per_ostick;
+
     NRF_RTC0->TASKS_START = 1;
 
     __HAL_ENABLE_INTERRUPTS(ctx);


[28/28] incubator-mynewt-core git commit: This close pull request #34.

Posted by ma...@apache.org.
This close pull request #34.

Merge branch 'tickless' of https://github.com/neelnatu/incubator-mynewt-larva into develop


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/0f017336
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/0f017336
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/0f017336

Branch: refs/heads/develop
Commit: 0f0173365915b0ba93c6fc5c91c727a1136c8170
Parents: d2ac2ec dda6cb4
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Apr 11 14:17:14 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Apr 11 14:17:14 2016 -0700

----------------------------------------------------------------------
 hw/bsp/nrf51dk-16kbram/src/os_bsp.c             |  64 ------
 hw/bsp/nrf51dk/src/os_bsp.c                     |  64 ------
 hw/hal/include/hal/hal_os_tick.h                |  35 +++
 hw/mcu/native/include/mcu/mcu_sim.h             |   2 +
 hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h  |   7 +
 .../nrf51xxx/include/mcu/nrf51_bitfields.h      |   5 +
 hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c        | 215 +++++++++++++++++++
 hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h  |   2 +
 .../nrf52xxx/include/mcu/nrf52_bitfields.h      |   4 +
 hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c        | 158 ++++++++++++++
 hw/mcu/stm/stm32f4xx/include/mcu/cortex_m4.h    |   2 +
 hw/mcu/stm/stm32f4xx/src/hal_os_tick.c          |  49 +++++
 libs/os/include/os/arch/cortex_m0/os/os_arch.h  |  10 +-
 libs/os/include/os/arch/cortex_m4/os/os_arch.h  |  11 +-
 libs/os/include/os/arch/sim/os/os_arch.h        |   8 +-
 libs/os/include/os/os_callout.h                 |   1 +
 libs/os/include/os/os_sched.h                   |   1 +
 libs/os/include/os/os_time.h                    |   3 +-
 libs/os/src/arch/cortex_m0/os_arch_arm.c        |  29 ++-
 libs/os/src/arch/cortex_m4/os_arch_arm.c        |  49 ++---
 libs/os/src/arch/sim/os_arch_sim.c              |  79 +++++--
 libs/os/src/os.c                                |  27 ++-
 libs/os/src/os_callout.c                        |  27 +++
 libs/os/src/os_sched.c                          |  23 ++
 libs/os/src/os_time.c                           |  40 ++--
 25 files changed, 689 insertions(+), 226 deletions(-)
----------------------------------------------------------------------



[22/28] incubator-mynewt-core git commit: Cut over to using 'hal_os_tick.c' APIs for periodic OS timer.

Posted by ma...@apache.org.
Cut over to using 'hal_os_tick.c' APIs for periodic OS timer.


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/b51a0ee2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b51a0ee2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b51a0ee2

Branch: refs/heads/develop
Commit: b51a0ee289cc8a4d7c54507e4a43f48a35337b21
Parents: b0c6fbf
Author: Neel Natu <ne...@nahannisys.com>
Authored: Wed Apr 6 17:41:47 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Wed Apr 6 17:41:47 2016 -0700

----------------------------------------------------------------------
 hw/mcu/stm/stm32f4xx/include/mcu/cortex_m4.h |  2 +
 hw/mcu/stm/stm32f4xx/src/hal_os_tick.c       | 49 +++++++++++++++++++++++
 2 files changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b51a0ee2/hw/mcu/stm/stm32f4xx/include/mcu/cortex_m4.h
----------------------------------------------------------------------
diff --git a/hw/mcu/stm/stm32f4xx/include/mcu/cortex_m4.h b/hw/mcu/stm/stm32f4xx/include/mcu/cortex_m4.h
index 674f749..f9c2109 100644
--- a/hw/mcu/stm/stm32f4xx/include/mcu/cortex_m4.h
+++ b/hw/mcu/stm/stm32f4xx/include/mcu/cortex_m4.h
@@ -22,4 +22,6 @@
 
 #include "mcu/stm32f4xx.h"
 
+#define OS_TICKS_PER_SEC    (1000)
+
 #endif /* __MCU_CORTEX_M4_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b51a0ee2/hw/mcu/stm/stm32f4xx/src/hal_os_tick.c
----------------------------------------------------------------------
diff --git a/hw/mcu/stm/stm32f4xx/src/hal_os_tick.c b/hw/mcu/stm/stm32f4xx/src/hal_os_tick.c
new file mode 100644
index 0000000..0f0ce77
--- /dev/null
+++ b/hw/mcu/stm/stm32f4xx/src/hal_os_tick.c
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <assert.h>
+#include <os/os.h>
+#include <hal/hal_os_tick.h>
+
+/*
+ * XXX implement tickless mode.
+ */
+void
+os_tick_idle(os_time_t ticks)
+{
+    OS_ASSERT_CRITICAL();
+    __DSB();
+    __WFI();
+}
+
+void
+os_tick_init(uint32_t os_ticks_per_sec, int prio)
+{
+    uint32_t reload_val;
+
+    reload_val = ((uint64_t)SystemCoreClock / os_ticks_per_sec) - 1;
+
+    /* Set the system time ticker up */
+    SysTick->LOAD = reload_val;
+    SysTick->VAL = 0;
+    SysTick->CTRL = 0x0007;
+
+    /* Set the system tick priority */
+    NVIC_SetPriority(SysTick_IRQn, prio);
+}


[08/28] incubator-mynewt-core git commit: Enter low power state in the idle loop by using the "WFI" instruction.

Posted by ma...@apache.org.
Enter low power state in the idle loop by using the "WFI" instruction.


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/a9b6d9eb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a9b6d9eb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a9b6d9eb

Branch: refs/heads/develop
Commit: a9b6d9eb99ed91d7f9a4fb80f5ea65da863ba950
Parents: 4a7ff05
Author: Neel Natu <ne...@nahannisys.com>
Authored: Fri Mar 25 12:51:51 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Fri Mar 25 12:51:51 2016 -0700

----------------------------------------------------------------------
 libs/os/src/arch/cortex_m0/os_arch_arm.c | 7 +++++++
 libs/os/src/arch/cortex_m4/os_arch_arm.c | 7 +++++++
 2 files changed, 14 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a9b6d9eb/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 224c045..7e6e433 100755
--- a/libs/os/src/arch/cortex_m0/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m0/os_arch_arm.c
@@ -336,5 +336,12 @@ os_arch_os_start(void)
 void
 os_arch_idle(void)
 {
+    os_sr_t sr;
+
+    OS_ENTER_CRITICAL(sr);
+    __DSB();
+    __WFI();
+    OS_EXIT_CRITICAL(sr);
+
     return;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a9b6d9eb/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 a819e43..72b9f45 100755
--- a/libs/os/src/arch/cortex_m4/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m4/os_arch_arm.c
@@ -326,5 +326,12 @@ os_arch_os_start(void)
 void
 os_arch_idle(void)
 {
+    os_sr_t sr;
+
+    OS_ENTER_CRITICAL(sr);
+    __DSB();
+    __WFI();
+    OS_EXIT_CRITICAL(sr);
+
     return;
 }


[27/28] incubator-mynewt-core git commit: Get rid of unused functions.

Posted by ma...@apache.org.
Get rid of unused functions.


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/dda6cb4e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/dda6cb4e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/dda6cb4e

Branch: refs/heads/develop
Commit: dda6cb4e1cccb94c0843db08b81797849f220159
Parents: a2648de
Author: Neel Natu <ne...@nahannisys.com>
Authored: Thu Apr 7 11:54:26 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Thu Apr 7 11:54:26 2016 -0700

----------------------------------------------------------------------
 libs/os/src/os_callout.c | 14 --------------
 1 file changed, 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dda6cb4e/libs/os/src/os_callout.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_callout.c b/libs/os/src/os_callout.c
index d8dbf61..cd4a436 100644
--- a/libs/os/src/os_callout.c
+++ b/libs/os/src/os_callout.c
@@ -25,20 +25,6 @@
 TAILQ_HEAD(, os_callout) g_callout_list =
   TAILQ_HEAD_INITIALIZER(g_callout_list);
 
-static int callout_drift;
-
-void
-callout_drift_set(int drift)
-{
-    callout_drift = drift;
-}
-
-int
-callout_drift_get(void)
-{
-    return (callout_drift);
-}
-
 void
 os_callout_init(struct os_callout *c, struct os_eventq *evq, void *ev_arg)
 {


[13/28] incubator-mynewt-core git commit: OS_TICKS_PER_SEC is heavily influenced by the capabilities and frequency of the timer used to generate periodic interrupts. For example, it is important to choose a value for OS_TICKS_PER_SEC that divides cleanly

Posted by ma...@apache.org.
OS_TICKS_PER_SEC is heavily influenced by the capabilities and frequency of
the timer used to generate periodic interrupts. For example, it is important
to choose a value for OS_TICKS_PER_SEC that divides cleanly into the underlying
timer frequency to avoid a systemic time drift.

MCU     Timer       Frequency       OS_TICKS_PER_SEC
nrf52   TIMER1      1000000         1000
nrf51   RTC         32768           1024

Move the definition of OS_TICKS_PER_SEC in the mcu-specific header file.


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/f3f5777e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f3f5777e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f3f5777e

Branch: refs/heads/develop
Commit: f3f5777e7b9341f72731024df244eb33b9860fea
Parents: e44429d
Author: Neel Natu <ne...@nahannisys.com>
Authored: Wed Apr 6 10:59:38 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Wed Apr 6 10:59:38 2016 -0700

----------------------------------------------------------------------
 hw/mcu/native/include/mcu/mcu_sim.h            | 2 ++
 hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h | 2 ++
 hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h | 2 ++
 libs/os/include/os/arch/cortex_m0/os/os_arch.h | 3 ---
 libs/os/include/os/arch/cortex_m4/os/os_arch.h | 3 ---
 libs/os/include/os/arch/sim/os/os_arch.h       | 5 ++---
 6 files changed, 8 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f3f5777e/hw/mcu/native/include/mcu/mcu_sim.h
----------------------------------------------------------------------
diff --git a/hw/mcu/native/include/mcu/mcu_sim.h b/hw/mcu/native/include/mcu/mcu_sim.h
index 15ff8da..5aab337 100644
--- a/hw/mcu/native/include/mcu/mcu_sim.h
+++ b/hw/mcu/native/include/mcu/mcu_sim.h
@@ -19,6 +19,8 @@
 #ifndef __MCU_SIM_H__
 #define __MCU_SIM_H__
 
+#define OS_TICKS_PER_SEC    (1000)
+
 extern char *native_flash_file;
 extern char *native_uart_log_file;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f3f5777e/hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h b/hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h
index dc97f10..c7314fc 100644
--- a/hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h
+++ b/hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h
@@ -22,4 +22,6 @@
 
 #include "mcu/nrf51.h"
 
+#define OS_TICKS_PER_SEC    (1024)
+
 #endif /* __MCU_CORTEX_M0_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f3f5777e/hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h b/hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h
index d93153c..d7661c7 100644
--- a/hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h
+++ b/hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h
@@ -22,4 +22,6 @@
 
 #include "mcu/nrf52.h"
 
+#define OS_TICKS_PER_SEC    (1000)
+
 #endif /* __MCU_CORTEX_M4_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f3f5777e/libs/os/include/os/arch/cortex_m0/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/cortex_m0/os/os_arch.h b/libs/os/include/os/arch/cortex_m0/os/os_arch.h
index 7259288..23016c7 100755
--- a/libs/os/include/os/arch/cortex_m0/os/os_arch.h
+++ b/libs/os/include/os/arch/cortex_m0/os/os_arch.h
@@ -29,9 +29,6 @@ struct os_task;
 #define OS_RUN_PRIV         (0)
 #define OS_RUN_UNPRIV       (1)
 
-/* Time tick in miliseconds that the OS runs */
-#define OS_TICKS_PER_SEC    (1000)
-
 /* CPU status register */
 typedef uint32_t os_sr_t;
 /* Stack type, aligned to a 32-bit word. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f3f5777e/libs/os/include/os/arch/cortex_m4/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/cortex_m4/os/os_arch.h b/libs/os/include/os/arch/cortex_m4/os/os_arch.h
index 7b51c0d..a68f38a 100755
--- a/libs/os/include/os/arch/cortex_m4/os/os_arch.h
+++ b/libs/os/include/os/arch/cortex_m4/os/os_arch.h
@@ -29,9 +29,6 @@ struct os_task;
 #define OS_RUN_PRIV         (0)
 #define OS_RUN_UNPRIV       (1)
 
-/* Time tick in miliseconds that the OS runs */
-#define OS_TICKS_PER_SEC    (1000)
-
 /* CPU status register */
 typedef uint32_t os_sr_t;
 /* Stack type, aligned to a 32-bit word. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f3f5777e/libs/os/include/os/arch/sim/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/sim/os/os_arch.h b/libs/os/include/os/arch/sim/os/os_arch.h
index 4a33458..b1368ee 100644
--- a/libs/os/include/os/arch/sim/os/os_arch.h
+++ b/libs/os/include/os/arch/sim/os/os_arch.h
@@ -20,10 +20,9 @@
 #ifndef _OS_ARCH_SIM_H
 #define _OS_ARCH_SIM_H
 
-struct os_task;
+#include <mcu/mcu_sim.h>
 
-/* Time tick in miliseconds that the OS runs */
-#define OS_TICKS_PER_SEC (1000)
+struct os_task;
 
 /* CPU status register */
 typedef unsigned int os_sr_t;


[25/28] incubator-mynewt-core git commit: Add comment explaining the periodic frequency chosen on nRF51 MCUs.

Posted by ma...@apache.org.
Add comment explaining the periodic frequency chosen on nRF51 MCUs.


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/40aefccd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/40aefccd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/40aefccd

Branch: refs/heads/develop
Commit: 40aefccd454ead8e4228e9b1ddf1367957271d19
Parents: 7123446
Author: Neel Natu <ne...@nahannisys.com>
Authored: Thu Apr 7 11:30:28 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Thu Apr 7 11:30:28 2016 -0700

----------------------------------------------------------------------
 hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/40aefccd/hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h b/hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h
index c7314fc..b8c91a9 100644
--- a/hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h
+++ b/hw/mcu/nordic/nrf51xxx/include/mcu/cortex_m0.h
@@ -22,6 +22,11 @@
 
 #include "mcu/nrf51.h"
 
+/*
+ * The nRF51 microcontroller uses RTC0 for periodic interrupts and it is
+ * clocked at 32768Hz. The tick frequency is chosen such that it divides
+ * cleanly into 32768 to avoid a systemic bias in the actual tick frequency.
+ */
 #define OS_TICKS_PER_SEC    (1024)
 
 #endif /* __MCU_CORTEX_M0_H__ */


[11/28] incubator-mynewt-core git commit: Enter tickless regime during idle on NRF52.

Posted by ma...@apache.org.
Enter tickless regime during idle on NRF52.

'os_arch_idle(ticks)' now takes an argument to indicate how long before
the OS has anything useful to schedule. The architecture specific function
is allowed to suspend execution for up to those many ticks. Note that
this function may return earlier if another interrupt wakes up the CPU.
Note that 'ticks' may be zero in which case the CPU stays in the periodic
timer regime.

The idle stack size needed a bump to account for the increase in stack
depth.


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/5b5abc88
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5b5abc88
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5b5abc88

Branch: refs/heads/develop
Commit: 5b5abc887e70a513a0fde8480b2f4f9daabe0d05
Parents: 8e31a9e
Author: Neel Natu <ne...@nahannisys.com>
Authored: Mon Apr 4 19:27:21 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Mon Apr 4 19:27:21 2016 -0700

----------------------------------------------------------------------
 hw/bsp/nrf52pdk/src/os_bsp.c                   | 89 +++++++++++++++++----
 libs/os/include/os/arch/cortex_m0/os/os_arch.h |  4 +-
 libs/os/include/os/arch/cortex_m4/os/os_arch.h |  5 +-
 libs/os/include/os/arch/sim/os/os_arch.h       |  2 +-
 libs/os/src/arch/cortex_m0/os_arch_arm.c       |  2 +-
 libs/os/src/arch/cortex_m4/os_arch_arm.c       | 11 +--
 libs/os/src/arch/sim/os_arch_sim.c             | 50 ++++++------
 libs/os/src/os.c                               | 25 +++++-
 8 files changed, 128 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5b5abc88/hw/bsp/nrf52pdk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/src/os_bsp.c b/hw/bsp/nrf52pdk/src/os_bsp.c
index 255f16f..f386137 100644
--- a/hw/bsp/nrf52pdk/src/os_bsp.c
+++ b/hw/bsp/nrf52pdk/src/os_bsp.c
@@ -89,52 +89,100 @@ os_bsp_init(void)
 #define CALLOUT_CMPREG      0   /* generate timer interrupt */
 #define CALLOUT_COUNTER     1   /* capture current timer value */
 #define CALLOUT_PRESCALER   4   /* prescaler to generate 1MHz timer freq */
-#define TIMER_GEQ(__t1, __t2)   ((int32_t)((__t1) - (__t2)) >= 0)
+#define TIMER_LT(__t1, __t2)    ((int32_t)((__t1) - (__t2)) < 0)
 
 static int timer_ticks_per_ostick;
+static os_time_t nrf52_max_idle_ticks;
 static uint32_t lastocmp;
 
 static inline uint32_t
 nrf52_callout_counter(void)
 {
     /*
+     * Make sure we are not interrupted between invoking the capture task
+     * and reading the value.
+     */
+    OS_ASSERT_CRITICAL();
+
+    /*
      * Capture the current timer value and return it.
      */
     CALLOUT_TIMER->TASKS_CAPTURE[CALLOUT_COUNTER] = 1;
     return (CALLOUT_TIMER->CC[CALLOUT_COUNTER]);
 }
 
+static inline void
+nrf52_callout_set_ocmp(uint32_t ocmp)
+{
+    uint32_t counter;
+
+    OS_ASSERT_CRITICAL();
+    while (1) {
+        CALLOUT_TIMER->CC[CALLOUT_CMPREG] = ocmp;
+        counter = nrf52_callout_counter();
+        if (TIMER_LT(counter, ocmp)) {
+            break;
+        }
+        ocmp += timer_ticks_per_ostick;
+    }
+}
+
 static void
 nrf52_timer_handler(void)
 {
     int ticks;
     os_sr_t sr;
-    uint32_t counter, ocmp;
-
-    assert(CALLOUT_TIMER->EVENTS_COMPARE[CALLOUT_CMPREG]);
+    uint32_t counter;
 
     OS_ENTER_CRITICAL(sr);
 
-    /* Clear interrupt */
-    CALLOUT_TIMER->EVENTS_COMPARE[CALLOUT_CMPREG] = 0;
-
-    /* Capture the timer value */
+    /*
+     * Calculate elapsed ticks and advance OS time.
+     */
     counter = nrf52_callout_counter();
-
-    /* Calculate elapsed ticks */
     ticks = (counter - lastocmp) / timer_ticks_per_ostick;
+    os_time_advance(ticks);
+
+    /* Clear timer interrupt */
+    CALLOUT_TIMER->EVENTS_COMPARE[CALLOUT_CMPREG] = 0;
+
+    /* Update the time associated with the most recent tick */
     lastocmp += ticks * timer_ticks_per_ostick;
 
-    ocmp = lastocmp;
-    do {
-        ocmp += timer_ticks_per_ostick;
-        CALLOUT_TIMER->CC[CALLOUT_CMPREG] = ocmp;
-        counter = nrf52_callout_counter();
-    } while (TIMER_GEQ(counter, ocmp));
+    /* Update the output compare to interrupt at the next tick */
+    nrf52_callout_set_ocmp(lastocmp + timer_ticks_per_ostick);
 
     OS_EXIT_CRITICAL(sr);
+}
 
-    os_time_advance(ticks);
+void
+os_bsp_idle(os_time_t ticks)
+{
+    uint32_t ocmp;
+
+    OS_ASSERT_CRITICAL();
+
+    if (ticks > 0) {
+        /*
+         * Enter tickless regime during long idle durations.
+         */
+        if (ticks > nrf52_max_idle_ticks) {
+            ticks = nrf52_max_idle_ticks;
+        }
+        ocmp = lastocmp + ticks * timer_ticks_per_ostick;
+        nrf52_callout_set_ocmp(ocmp);
+    }
+
+    __DSB();
+    __WFI();
+
+    if (ticks > 0) {
+        /*
+         * Update OS time before anything else when coming out of
+         * the tickless regime.
+         */
+        nrf52_timer_handler();
+    }
 }
 
 void
@@ -144,6 +192,13 @@ os_bsp_systick_init(uint32_t os_ticks_per_sec, int prio)
     timer_ticks_per_ostick = 1000000 / os_ticks_per_sec;
 
     /*
+     * The maximum number of timer ticks allowed to elapse during idle is
+     * limited to 1/4th the number of timer ticks before the counter rolls
+     * over.
+     */
+    nrf52_max_idle_ticks = (1UL << 30) / timer_ticks_per_ostick;
+
+    /*
      * Program CALLOUT_TIMER to operate at 1MHz and trigger an output
      * compare interrupt at a rate of 'os_ticks_per_sec'.
      */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5b5abc88/libs/os/include/os/arch/cortex_m0/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/cortex_m0/os/os_arch.h b/libs/os/include/os/arch/cortex_m0/os/os_arch.h
index 23f6131..7259288 100755
--- a/libs/os/include/os/arch/cortex_m0/os/os_arch.h
+++ b/libs/os/include/os/arch/cortex_m0/os/os_arch.h
@@ -45,7 +45,7 @@ typedef uint32_t os_stack_t;
  * Stack sizes for common OS tasks
  */
 #define OS_SANITY_STACK_SIZE (64)
-#define OS_IDLE_STACK_SIZE (32)
+#define OS_IDLE_STACK_SIZE (64)
 
 #define OS_STACK_ALIGN(__nmemb) \
     (OS_ALIGN((__nmemb), OS_STACK_ALIGNMENT))
@@ -69,7 +69,7 @@ os_error_t os_arch_os_start(void);
 void os_set_env(void);
 void os_arch_init_task_stack(os_stack_t *sf);
 void os_default_irq_asm(void);
-void os_arch_idle(void);
+void os_arch_idle(os_time_t ticks);
 
 /* External function prototypes supplied by BSP */
 void os_bsp_systick_init(uint32_t os_ticks_per_sec, int prio);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5b5abc88/libs/os/include/os/arch/cortex_m4/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/cortex_m4/os/os_arch.h b/libs/os/include/os/arch/cortex_m4/os/os_arch.h
index ab0f95f..7b51c0d 100755
--- a/libs/os/include/os/arch/cortex_m4/os/os_arch.h
+++ b/libs/os/include/os/arch/cortex_m4/os/os_arch.h
@@ -45,7 +45,7 @@ typedef uint32_t os_stack_t;
  * Stack sizes for common OS tasks
  */
 #define OS_SANITY_STACK_SIZE (64)
-#define OS_IDLE_STACK_SIZE (32)
+#define OS_IDLE_STACK_SIZE (64)
 
 #define OS_STACK_ALIGN(__nmemb) \
     (OS_ALIGN((__nmemb), OS_STACK_ALIGNMENT))
@@ -69,11 +69,12 @@ os_error_t os_arch_os_start(void);
 void os_set_env(void);
 void os_arch_init_task_stack(os_stack_t *sf);
 void os_default_irq_asm(void);
-void os_arch_idle(void);
+void os_arch_idle(os_time_t ticks);
 
 /* External function prototypes supplied by BSP */
 void os_bsp_systick_init(uint32_t os_tick_per_sec, int prio);
 void os_bsp_init(void);
+void os_bsp_idle(os_time_t ticks);
 void os_bsp_ctx_sw(void);
 
 #endif /* _OS_ARCH_X86_H */ 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5b5abc88/libs/os/include/os/arch/sim/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/sim/os/os_arch.h b/libs/os/include/os/arch/sim/os/os_arch.h
index dd12cfd..4a33458 100644
--- a/libs/os/include/os/arch/sim/os/os_arch.h
+++ b/libs/os/include/os/arch/sim/os/os_arch.h
@@ -71,7 +71,7 @@ int os_arch_in_critical(void);
 os_error_t os_arch_os_init(void);
 void os_arch_os_stop(void);
 os_error_t os_arch_os_start(void);
-void os_arch_idle(void);
+void os_arch_idle(os_time_t ticks);
 
 void os_bsp_init(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5b5abc88/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 82603da..36377ba 100755
--- a/libs/os/src/arch/cortex_m0/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m0/os_arch_arm.c
@@ -334,7 +334,7 @@ os_arch_os_start(void)
 }
 
 void
-os_arch_idle(void)
+os_arch_idle(os_time_t ticks)
 {
     os_sr_t sr;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5b5abc88/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 5c4ad88..dc91e84 100755
--- a/libs/os/src/arch/cortex_m4/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m4/os_arch_arm.c
@@ -324,14 +324,7 @@ os_arch_os_start(void)
 }
 
 void
-os_arch_idle(void)
+os_arch_idle(os_time_t ticks)
 {
-    os_sr_t sr;
-
-    OS_ENTER_CRITICAL(sr);
-    __DSB();
-    __WFI();
-    OS_EXIT_CRITICAL(sr);
-
-    return;
+    os_bsp_idle(ticks);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5b5abc88/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 cb36df8..bbdc641 100644
--- a/libs/os/src/arch/sim/os_arch_sim.c
+++ b/libs/os/src/arch/sim/os_arch_sim.c
@@ -54,6 +54,7 @@ extern void os_arch_frame_init(struct stack_frame *sf);
 #define OS_USEC_PER_TICK    (1000000 / OS_TICKS_PER_SEC)
 
 static sigset_t allsigs, nosigs;
+static void timer_handler(int sig);
 
 /*
  * Called from 'os_arch_frame_init()' when setjmp returns indirectly via
@@ -176,52 +177,47 @@ os_arch_in_critical(void)
 }
 
 void
-os_arch_idle(void)
+os_arch_idle(os_time_t ticks)
 {
     int rc;
-    os_sr_t sr;
-    os_time_t now, sticks, cticks, ticks;
     struct itimerval it;
 
-    OS_ENTER_CRITICAL(sr);
-    assert(sr == 0);
+    OS_ASSERT_CRITICAL();
 
-    now = os_time_get();
-    sticks = os_sched_wakeup_ticks(now);
-    cticks = os_callout_wakeup_ticks(now);
-    ticks = min(sticks, cticks);
-    if (ticks > OS_TICKS_PER_SEC) {
+    if (ticks > 0) {
         /*
-         * Wakeup at least once a second (XXX arbitrary).
+         * Enter tickless regime and set the timer to fire after 'ticks'
+         * worth of time has elapsed.
          */
-        ticks = OS_TICKS_PER_SEC;
+        it.it_value.tv_sec = ticks / OS_TICKS_PER_SEC;
+        it.it_value.tv_usec = (ticks % OS_TICKS_PER_SEC) * OS_USEC_PER_TICK;
+        it.it_interval.tv_sec = 0;
+        it.it_interval.tv_usec = OS_USEC_PER_TICK;
+        rc = setitimer(ITIMER_REAL, &it, NULL);
+        assert(rc == 0);
     }
 
-    if (ticks == 0) {
+    sigsuspend(&nosigs);        /* Wait for a signal to wake us up */
+
+    if (ticks > 0) {
         /*
-         * If the wakeup time is in the past then send a SIGALRM to ourselves
-         * rather than wait for the interval timer to fire.
+         * Update OS time before anything else when coming out of
+         * the tickless regime.
          */
-        rc = kill(getpid(), SIGALRM);
-    } else {
+        timer_handler(SIGALRM);
+
         /*
-         * Set the timer to fire after 'ticks' worth of time has elapsed.
+         * Enable the periodic timer interrupt.
          */
-        it.it_value.tv_sec = ticks / OS_TICKS_PER_SEC;
-        it.it_value.tv_usec = (ticks % OS_TICKS_PER_SEC) * OS_USEC_PER_TICK;
+        it.it_value.tv_sec = 0;
+        it.it_value.tv_usec = OS_USEC_PER_TICK;
         it.it_interval.tv_sec = 0;
         it.it_interval.tv_usec = OS_USEC_PER_TICK;
         rc = setitimer(ITIMER_REAL, &it, NULL);
+        assert(rc == 0);
     }
-    assert(rc == 0);
-
-    sigsuspend(&nosigs);        /* Wait for a signal to wake us up */
-
-    OS_EXIT_CRITICAL(sr);
 }
 
-static void timer_handler(int sig);
-
 static struct {
     int num;
     void (*handler)(int sig);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5b5abc88/libs/os/src/os.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os.c b/libs/os/src/os.c
index 078800a..4310178 100644
--- a/libs/os/src/os.c
+++ b/libs/os/src/os.c
@@ -30,14 +30,37 @@ uint32_t g_os_idle_ctr;
  */
 int g_os_started; 
 
+#ifdef ARCH_sim
+#define MIN_IDLE_TICKS  1
+#else
+#define MIN_IDLE_TICKS  (100 * OS_TICKS_PER_SEC / 1000) /* 100 msec */
+#endif
+#define MAX_IDLE_TICKS  (600 * OS_TICKS_PER_SEC)        /* 10 minutes */
 
 void
 os_idle_task(void *arg)
 {
+    os_sr_t sr;
+    os_time_t now;
+    os_time_t iticks, sticks, cticks;
+
     /* For now, idle task simply increments a counter to show it is running. */
     while (1) {
         ++g_os_idle_ctr;
-        os_arch_idle();
+        OS_ENTER_CRITICAL(sr);
+        now = os_time_get();
+        sticks = os_sched_wakeup_ticks(now);
+        cticks = os_callout_wakeup_ticks(now);
+        iticks = min(sticks, cticks);
+        if (iticks < MIN_IDLE_TICKS) {
+            iticks = 0;
+        } else if (iticks > MAX_IDLE_TICKS) {
+            iticks = MAX_IDLE_TICKS;
+        } else {
+            /* NOTHING */
+        }
+        os_arch_idle(iticks);
+        OS_EXIT_CRITICAL(sr);
     }
 }
 


[16/28] incubator-mynewt-core git commit: Replace SYSTICK_PRIO with OS_TICK_PRIO.

Posted by ma...@apache.org.
Replace SYSTICK_PRIO with OS_TICK_PRIO.

It is not required that the periodic timer be based on the ARM's systick.


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/c9eef76a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/c9eef76a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/c9eef76a

Branch: refs/heads/develop
Commit: c9eef76ab94d6423ceba45b42d640018fe06693f
Parents: f59995e
Author: Neel Natu <ne...@nahannisys.com>
Authored: Wed Apr 6 12:00:01 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Wed Apr 6 12:00:01 2016 -0700

----------------------------------------------------------------------
 libs/os/src/arch/cortex_m4/os_arch_arm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c9eef76a/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 b9c0c1d..6023eca 100755
--- a/libs/os/src/arch/cortex_m4/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m4/os_arch_arm.c
@@ -30,7 +30,7 @@
  * higher priority exception will interrupt a lower priority exception.
  */
 #define PEND_SV_PRIO    ((1 << __NVIC_PRIO_BITS) - 1)
-#define SYSTICK_PRIO    (PEND_SV_PRIO - 1)
+#define OS_TICK_PRIO    (PEND_SV_PRIO - 1)
 
 /* Make the SVC instruction highest priority */
 #define SVC_PRIO        (1)
@@ -246,7 +246,7 @@ os_arch_start(void)
     __set_PSP((uint32_t)t->t_stackptr + offsetof(struct stack_frame, r0));
 
     /* Intitialize and start system clock timer */
-    os_tick_init(OS_TICKS_PER_SEC, SYSTICK_PRIO);
+    os_tick_init(OS_TICKS_PER_SEC, OS_TICK_PRIO);
 
     /* Mark the OS as started, right before we run our first task */
     g_os_started = 1;


[06/28] incubator-mynewt-core git commit: Pass the interrupt priority as a parameter to 'os_bsp_systick_init()' instead of hardcoding it in the BSP.

Posted by ma...@apache.org.
Pass the interrupt priority as a parameter to 'os_bsp_systick_init()'
instead of hardcoding it in the BSP.

Configure TIMER1 to run at a frequency of 1MHz and generate a periodic
timer interrupt to drive the OS tick.


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/b387dc65
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b387dc65
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b387dc65

Branch: refs/heads/develop
Commit: b387dc6525656ff77a17f9adb0c34be2e170ae5f
Parents: bb403e7
Author: Neel Natu <ne...@nahannisys.com>
Authored: Thu Mar 24 13:18:49 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Thu Mar 24 13:18:49 2016 -0700

----------------------------------------------------------------------
 hw/bsp/nrf51dk/src/os_bsp.c                     |  6 +--
 hw/bsp/nrf52pdk/src/os_bsp.c                    | 50 ++++++++++++++++++++
 .../nrf51xxx/include/mcu/nrf51_bitfields.h      |  3 ++
 .../nrf52xxx/include/mcu/nrf52_bitfields.h      |  4 ++
 libs/os/include/os/arch/cortex_m0/os/os_arch.h  |  2 +-
 libs/os/include/os/arch/cortex_m4/os/os_arch.h  |  2 +-
 libs/os/src/arch/cortex_m0/os_arch_arm.c        |  2 +-
 libs/os/src/arch/cortex_m4/os_arch_arm.c        | 25 +---------
 8 files changed, 63 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b387dc65/hw/bsp/nrf51dk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/src/os_bsp.c b/hw/bsp/nrf51dk/src/os_bsp.c
index e09bdee..b8e3608 100644
--- a/hw/bsp/nrf51dk/src/os_bsp.c
+++ b/hw/bsp/nrf51dk/src/os_bsp.c
@@ -22,8 +22,6 @@
 #include "mcu/nrf51_bitfields.h"
 #include "mcu/nrf51_hal.h"
 
-#define BSP_LOWEST_PRIO     ((1 << __NVIC_PRIO_BITS) - 1)
-
 static struct flash_area bsp_flash_areas[] = {
     [FLASH_AREA_BOOTLOADER] = {
         .fa_flash_id = 0,       /* internal flash */
@@ -94,7 +92,7 @@ rtc0_timer_handler(void)
 }
 
 void
-os_bsp_systick_init(uint32_t os_ticks_per_sec)
+os_bsp_systick_init(uint32_t os_ticks_per_sec, int prio)
 {
     uint32_t ctx;
     uint32_t mask;
@@ -130,7 +128,7 @@ os_bsp_systick_init(uint32_t os_ticks_per_sec)
     NRF_RTC0->TASKS_CLEAR = 1;
 
     /* Set isr in vector table and enable interrupt */
-    NVIC_SetPriority(RTC0_IRQn, BSP_LOWEST_PRIO - 1);
+    NVIC_SetPriority(RTC0_IRQn, prio);
     NVIC_SetVector(RTC0_IRQn, (uint32_t)rtc0_timer_handler);
     NVIC_EnableIRQ(RTC0_IRQn);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b387dc65/hw/bsp/nrf52pdk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/src/os_bsp.c b/hw/bsp/nrf52pdk/src/os_bsp.c
index 92bd69c..0957c22 100644
--- a/hw/bsp/nrf52pdk/src/os_bsp.c
+++ b/hw/bsp/nrf52pdk/src/os_bsp.c
@@ -16,6 +16,11 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+#include <os/os.h>
+#include <bsp/cmsis_nvic.h>
+#include <mcu/nrf52.h>
+#include <mcu/nrf52_bitfields.h>
+#include <util/util.h>
 #include <hal/flash_map.h>
 
 static struct flash_area bsp_flash_areas[] = {
@@ -78,3 +83,48 @@ os_bsp_init(void)
     flash_area_init(bsp_flash_areas,
       sizeof(bsp_flash_areas) / sizeof(bsp_flash_areas[0]));
 }
+
+#define CALLOUT_TIMER       NRF_TIMER1
+#define CALLOUT_IRQ         TIMER1_IRQn
+#define CALLOUT_CMPREG      0
+#define CALLOUT_PRESCALER   4   /* prescaler to generate 1MHz timer freq */
+
+static void
+nrf52_timer_handler(void)
+{
+    /* Clear interrupt */
+    CALLOUT_TIMER->EVENTS_COMPARE[CALLOUT_CMPREG] = 0;
+
+    os_time_advance(1, true);
+}
+
+void
+os_bsp_systick_init(uint32_t os_ticks_per_sec, int prio)
+{
+    uint32_t usecs_per_os_tick;
+
+    usecs_per_os_tick = 1000000 / os_ticks_per_sec;
+
+    /*
+     * Program CALLOUT_TIMER to operate at 1MHz and trigger an output
+     * compare interrupt at a rate of 'os_ticks_per_sec'.
+     */
+    CALLOUT_TIMER->TASKS_STOP = 1;
+    CALLOUT_TIMER->TASKS_CLEAR = 1;
+    CALLOUT_TIMER->MODE = TIMER_MODE_MODE_Timer;
+    CALLOUT_TIMER->BITMODE = TIMER_BITMODE_BITMODE_32Bit;
+    CALLOUT_TIMER->PRESCALER = CALLOUT_PRESCALER;
+
+    CALLOUT_TIMER->CC[CALLOUT_CMPREG] = usecs_per_os_tick;
+    CALLOUT_TIMER->INTENSET = TIMER_COMPARE_INT_MASK(CALLOUT_CMPREG);
+    CALLOUT_TIMER->EVENTS_COMPARE[CALLOUT_CMPREG] = 0;
+
+    /* Enable shortcut to clear the timer on output compare */
+    CALLOUT_TIMER->SHORTS = TIMER_SHORTS_COMPARE_CLEAR(CALLOUT_CMPREG);
+
+    NVIC_SetPriority(CALLOUT_IRQ, prio);
+    NVIC_SetVector(CALLOUT_IRQ, (uint32_t)nrf52_timer_handler);
+    NVIC_EnableIRQ(CALLOUT_IRQ);
+
+    CALLOUT_TIMER->TASKS_START = 1;     /* start the callout timer */
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b387dc65/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_bitfields.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_bitfields.h b/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_bitfields.h
index 5c877d9..bf7682b 100755
--- a/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_bitfields.h
+++ b/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_bitfields.h
@@ -6133,6 +6133,9 @@
 /* Register: TIMER_SHORTS */
 /* Description: Shortcuts for Timer. */
 
+#define TIMER_SHORTS_COMPARE_CLEAR(ccreg)   (1UL << (ccreg))
+#define TIMER_SHORTS_COMPARE_STOP(ccreg)    (1UL << ((ccreg) + 8))
+
 /* Bit 11 : Shortcut between CC[3] event and the STOP task. */
 #define TIMER_SHORTS_COMPARE3_STOP_Pos (11UL) /*!< Position of COMPARE3_STOP field. */
 #define TIMER_SHORTS_COMPARE3_STOP_Msk (0x1UL << TIMER_SHORTS_COMPARE3_STOP_Pos) /*!< Bit mask of COMPARE3_STOP field. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b387dc65/hw/mcu/nordic/nrf52xxx/include/mcu/nrf52_bitfields.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/include/mcu/nrf52_bitfields.h b/hw/mcu/nordic/nrf52xxx/include/mcu/nrf52_bitfields.h
index a7c4db8..6d7de32 100755
--- a/hw/mcu/nordic/nrf52xxx/include/mcu/nrf52_bitfields.h
+++ b/hw/mcu/nordic/nrf52xxx/include/mcu/nrf52_bitfields.h
@@ -10347,6 +10347,9 @@
 /* Register: TIMER_SHORTS */
 /* Description: Shortcut register */
 
+#define TIMER_SHORTS_COMPARE_CLEAR(ccreg)   (1UL << (ccreg))
+#define TIMER_SHORTS_COMPARE_STOP(ccreg)    (1UL << ((ccreg) + 8))
+
 /* Bit 13 : Shortcut between EVENTS_COMPARE[5] event and TASKS_STOP task */
 #define TIMER_SHORTS_COMPARE5_STOP_Pos (13UL) /*!< Position of COMPARE5_STOP field. */
 #define TIMER_SHORTS_COMPARE5_STOP_Msk (0x1UL << TIMER_SHORTS_COMPARE5_STOP_Pos) /*!< Bit mask of COMPARE5_STOP field. */
@@ -10421,6 +10424,7 @@
 
 /* Register: TIMER_INTENSET */
 /* Description: Enable interrupt */
+#define TIMER_COMPARE_INT_MASK(ccreg)   (1UL << ((ccreg) + 16))
 
 /* Bit 21 : Write '1' to Enable interrupt on EVENTS_COMPARE[5] event */
 #define TIMER_INTENSET_COMPARE5_Pos (21UL) /*!< Position of COMPARE5 field. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b387dc65/libs/os/include/os/arch/cortex_m0/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/cortex_m0/os/os_arch.h b/libs/os/include/os/arch/cortex_m0/os/os_arch.h
index 59b984d..23f6131 100755
--- a/libs/os/include/os/arch/cortex_m0/os/os_arch.h
+++ b/libs/os/include/os/arch/cortex_m0/os/os_arch.h
@@ -72,7 +72,7 @@ void os_default_irq_asm(void);
 void os_arch_idle(void);
 
 /* External function prototypes supplied by BSP */
-void os_bsp_systick_init(uint32_t os_ticks_per_sec);
+void os_bsp_systick_init(uint32_t os_ticks_per_sec, int prio);
 void os_bsp_init(void);
 void os_bsp_ctx_sw(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b387dc65/libs/os/include/os/arch/cortex_m4/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/cortex_m4/os/os_arch.h b/libs/os/include/os/arch/cortex_m4/os/os_arch.h
index 604a57b..ab0f95f 100755
--- a/libs/os/include/os/arch/cortex_m4/os/os_arch.h
+++ b/libs/os/include/os/arch/cortex_m4/os/os_arch.h
@@ -72,7 +72,7 @@ void os_default_irq_asm(void);
 void os_arch_idle(void);
 
 /* External function prototypes supplied by BSP */
-void os_bsp_systick_init(uint32_t os_tick_per_sec);
+void os_bsp_systick_init(uint32_t os_tick_per_sec, int prio);
 void os_bsp_init(void);
 void os_bsp_ctx_sw(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b387dc65/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 b70481a..224c045 100755
--- a/libs/os/src/arch/cortex_m0/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m0/os_arch_arm.c
@@ -256,7 +256,7 @@ os_arch_start(void)
     __set_PSP((uint32_t)t->t_stackptr + offsetof(struct stack_frame, r0));
 
     /* Intitialize and start system clock timer */
-    os_bsp_systick_init(OS_TICKS_PER_SEC);
+    os_bsp_systick_init(OS_TICKS_PER_SEC, SYSTICK_PRIO);
 
     /* Mark the OS as started, right before we run our first task */
     g_os_started = 1;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b387dc65/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 3117af9..a819e43 100755
--- a/libs/os/src/arch/cortex_m4/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m4/os_arch_arm.c
@@ -233,29 +233,6 @@ os_arch_os_init(void)
     return err;
 }
 
-/**
- * os systick init
- *
- * Initializes systick for the MCU
- *
- * @param os_tick_usecs The number of microseconds in an os time tick
- */
-static void
-os_systick_init(uint32_t os_tick_usecs)
-{
-    uint32_t reload_val;
-
-    reload_val = (((uint64_t)SystemCoreClock * os_tick_usecs) / 1000000) - 1;
-
-    /* Set the system time ticker up */
-    SysTick->LOAD = reload_val;
-    SysTick->VAL = 0;
-    SysTick->CTRL = 0x0007;
-
-    /* Set the system tick priority */
-    NVIC_SetPriority(SysTick_IRQn, SYSTICK_PRIO);
-}
-
 uint32_t
 os_arch_start(void)
 {
@@ -269,7 +246,7 @@ os_arch_start(void)
     __set_PSP((uint32_t)t->t_stackptr + offsetof(struct stack_frame, r0));
 
     /* Intitialize and start system clock timer */
-    os_systick_init(1000000 / OS_TICKS_PER_SEC);
+    os_bsp_systick_init(OS_TICKS_PER_SEC, SYSTICK_PRIO);
 
     /* Mark the OS as started, right before we run our first task */
     g_os_started = 1;


[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

Posted by ma...@apache.org.
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);
+        }
+    }
 }
 
 /**


[12/28] incubator-mynewt-core git commit: Merge branch 'develop' into tickless

Posted by ma...@apache.org.
Merge branch 'develop' into tickless


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/e44429d3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/e44429d3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/e44429d3

Branch: refs/heads/develop
Commit: e44429d3ff8426b6791fe95d021528a35c649b65
Parents: 5b5abc8 2fef21d
Author: Neel Natu <ne...@nahannisys.com>
Authored: Mon Apr 4 19:33:53 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Mon Apr 4 19:33:53 2016 -0700

----------------------------------------------------------------------
 README.md                                       |   86 +-
 apps/bleprph/pkg.yml                            |   31 +
 apps/bleprph/src/main.c                         |    2 +-
 apps/bletest/pkg.yml                            |    1 -
 apps/bletest/src/main.c                         |   71 +-
 apps/bletiny/pkg.yml                            |    1 -
 apps/bletiny/src/cmd.c                          |    7 +-
 apps/bletiny/src/main.c                         |    9 +-
 apps/bletiny/src/parse.c                        |   44 +-
 apps/boot/pkg.yml                               |    1 -
 apps/slinky/pkg.yml                             |    3 +-
 compiler/arm-none-eabi-m0/compiler.yml          |    4 +-
 compiler/arm-none-eabi-m4/compiler.yml          |    4 +-
 fs/nffs/src/nffs_inode.c                        |   57 +-
 fs/nffs/src/test/arch/sim/nffs_test.c           |   10 +
 hw/bsp/bmd300eval/bmd300eval_dowload.sh         |   70 -
 hw/bsp/bmd300eval/bmd300eval_download.sh        |   70 +
 hw/bsp/bmd300eval/include/bsp/bsp_sysid.h       |   37 +
 hw/bsp/bmd300eval/pkg.yml                       |    1 +
 hw/bsp/native/include/bsp/bsp.h                 |    1 -
 hw/bsp/native/include/bsp/bsp_sysid.h           |   48 +
 hw/bsp/native/pkg.yml                           |    2 +-
 hw/bsp/native/src/hal_bsp.c                     |   81 ++
 hw/bsp/nrf51dk-16kbram/include/bsp/bsp_sysid.h  |   36 +
 hw/bsp/nrf51dk-16kbram/pkg.yml                  |    1 +
 hw/bsp/nrf51dk/include/bsp/bsp_sysid.h          |   36 +
 hw/bsp/nrf51dk/pkg.yml                          |    7 +-
 hw/bsp/nrf52pdk/include/bsp/bsp_sysid.h         |   36 +
 hw/bsp/nrf52pdk/pkg.yml                         |    1 +
 .../include/bsp/bsp_sysid.h                     |   36 +
 hw/bsp/olimex_stm32-e407_devboard/pkg.yml       |    5 +-
 hw/hal/include/hal/hal_adc.h                    |   60 +
 hw/hal/include/hal/hal_adc_int.h                |   62 +
 hw/hal/include/hal/hal_dac.h                    |   77 ++
 hw/hal/include/hal/hal_dac_int.h                |   63 +
 hw/hal/include/hal/hal_pwm.h                    |   87 ++
 hw/hal/include/hal/hal_pwm_int.h                |   51 +
 hw/hal/src/hal_adc.c                            |   78 ++
 hw/hal/src/hal_dac.c                            |   88 ++
 hw/hal/src/hal_pwm.c                            |   85 ++
 hw/mcu/native/include/mcu/hal_dac.h             |   36 +
 hw/mcu/native/include/mcu/hal_pwm.h             |   52 +
 hw/mcu/native/include/mcu/mcu_hal.h             |   60 +
 hw/mcu/native/pkg.yml                           |    3 +
 hw/mcu/native/src/hal_adc.c                     |  239 ++++
 hw/mcu/native/src/hal_dac.c                     |  113 ++
 hw/mcu/native/src/hal_pwm.c                     |  157 +++
 libs/baselibc/pkg.yml                           |    2 +
 libs/baselibc/src/tinyprintf.c                  |   16 +-
 libs/bootutil/include/bootutil/image.h          |   13 +-
 libs/bootutil/src/image_validate.c              |  311 ++++-
 libs/bootutil/src/test/boot_test.c              |   40 +-
 libs/console/full/include/console/console.h     |    1 -
 libs/console/full/pkg.yml                       |    1 +
 libs/console/full/src/cons_fmt.c                |   41 +-
 libs/console/full/src/cons_tty.c                |   12 +-
 libs/console/stub/include/console/console.h     |    6 -
 libs/flash_test/pkg.yml                         |    1 -
 libs/flash_test/src/flash_test/flash_test.c     |    1 +
 libs/mbedtls/include/mbedtls/cmac.h             |  141 ++
 libs/mbedtls/include/mbedtls/config.h           |   14 +-
 libs/mbedtls/include/mbedtls/error.h            |    1 +
 libs/mbedtls/src/cmac.c                         |  529 ++++++++
 libs/mbedtls/src/error.c                        |   11 +
 libs/mbedtls/src/version_features.c             |    3 +
 libs/shell/src/shell.c                          |    6 +-
 libs/testutil/src/testutil.c                    |    2 -
 .../controller/include/controller/ble_hw.h      |   29 +
 .../controller/include/controller/ble_ll.h      |   20 +
 .../controller/include/controller/ble_ll_hci.h  |    2 +-
 net/nimble/controller/src/ble_ll.c              |   47 +-
 net/nimble/controller/src/ble_ll_adv.c          |    4 +-
 net/nimble/controller/src/ble_ll_conn.c         |   11 +
 net/nimble/controller/src/ble_ll_conn_hci.c     |   51 +-
 net/nimble/controller/src/ble_ll_conn_priv.h    |    6 +-
 net/nimble/controller/src/ble_ll_ctrl.c         |  100 +-
 net/nimble/controller/src/ble_ll_hci.c          |  151 ++-
 net/nimble/controller/src/ble_ll_rand.c         |  133 ++
 net/nimble/controller/src/ble_ll_rng.c          |   60 +
 net/nimble/controller/src/ble_ll_scan.c         |    4 +
 net/nimble/controller/src/ble_ll_supp_cmd.c     |   20 +-
 net/nimble/drivers/native/src/ble_hw.c          |   57 +
 net/nimble/drivers/nrf51/src/ble_hw.c           |  155 +++
 net/nimble/drivers/nrf51/src/ble_phy.c          |    9 +-
 net/nimble/drivers/nrf52/src/ble_hw.c           |  155 +++
 net/nimble/host/include/host/ble_gap.h          |   19 +-
 net/nimble/host/include/host/ble_hs.h           |   76 +-
 net/nimble/host/include/host/ble_hs_test.h      |    1 +
 net/nimble/host/include/host/ble_l2cap.h        |   30 +-
 net/nimble/host/include/host/host_hci.h         |    8 +
 net/nimble/host/pkg.yml                         |    6 +-
 net/nimble/host/src/ble_att.c                   |    1 -
 net/nimble/host/src/ble_att_clt.c               |  231 ++--
 net/nimble/host/src/ble_att_cmd.c               |  987 ++++++--------
 net/nimble/host/src/ble_att_cmd.h               |  168 +--
 net/nimble/host/src/ble_att_priv.h              |   16 +-
 net/nimble/host/src/ble_att_svr.c               |  348 ++---
 net/nimble/host/src/ble_fsm.c                   |   38 +-
 net/nimble/host/src/ble_fsm_priv.h              |    4 +-
 net/nimble/host/src/ble_gap.c                   |  309 +++--
 net/nimble/host/src/ble_gap_priv.h              |    3 +
 net/nimble/host/src/ble_gatt_priv.h             |    2 -
 net/nimble/host/src/ble_gattc.c                 |   23 +-
 net/nimble/host/src/ble_gatts.c                 |   43 +-
 net/nimble/host/src/ble_hci_sched.c             |   22 +-
 net/nimble/host/src/ble_hs.c                    |   23 +-
 net/nimble/host/src/ble_hs_adv.c                |    3 +-
 net/nimble/host/src/ble_hs_cfg.c                |    9 +
 net/nimble/host/src/ble_hs_conn.c               |   13 +-
 net/nimble/host/src/ble_hs_conn.h               |    2 +
 net/nimble/host/src/ble_hs_endian.h             |   57 +
 net/nimble/host/src/ble_hs_misc.c               |   12 +-
 net/nimble/host/src/ble_hs_priv.h               |   36 +-
 net/nimble/host/src/ble_hs_startup.c            |   30 +-
 net/nimble/host/src/ble_l2cap.c                 |   10 +-
 net/nimble/host/src/ble_l2cap_priv.h            |   41 +-
 net/nimble/host/src/ble_l2cap_sig.c             |   21 +-
 net/nimble/host/src/ble_l2cap_sig_cmd.c         |  318 ++---
 net/nimble/host/src/ble_l2cap_sm.c              | 1219 +++++++++++++++++-
 net/nimble/host/src/ble_l2cap_sm.h              |  137 ++
 net/nimble/host/src/ble_l2cap_sm_alg.c          |  168 +++
 net/nimble/host/src/ble_l2cap_sm_cmd.c          |  276 ++++
 net/nimble/host/src/ble_uuid.c                  |    5 +-
 net/nimble/host/src/host_dbg.c                  |   29 +
 net/nimble/host/src/host_hci.c                  |   96 +-
 net/nimble/host/src/host_hci_cmd.c              |  165 ++-
 net/nimble/host/src/test/ble_att_clt_test.c     |   33 +-
 net/nimble/host/src/test/ble_att_svr_test.c     |  180 +--
 net/nimble/host/src/test/ble_gap_test.c         |    4 +-
 net/nimble/host/src/test/ble_gatt_disc_c_test.c |    3 +-
 net/nimble/host/src/test/ble_gatt_disc_d_test.c |    3 +-
 net/nimble/host/src/test/ble_gatt_disc_s_test.c |    5 +-
 net/nimble/host/src/test/ble_gatt_find_s_test.c |   12 +-
 net/nimble/host/src/test/ble_gatt_read_test.c   |    3 +-
 net/nimble/host/src/test/ble_gatt_write_test.c  |    9 +-
 .../host/src/test/ble_gatts_notify_test.c       |   12 +-
 net/nimble/host/src/test/ble_hs_adv_test.c      |    6 +-
 net/nimble/host/src/test/ble_hs_test.c          |    5 +-
 net/nimble/host/src/test/ble_hs_test_util.c     |   46 +-
 net/nimble/host/src/test/ble_hs_test_util.h     |    5 +
 net/nimble/host/src/test/ble_l2cap_sm_test.c    |  820 ++++++++++++
 net/nimble/host/src/test/ble_l2cap_test.c       |   74 +-
 net/nimble/include/nimble/ble.h                 |   15 +-
 net/nimble/include/nimble/hci_common.h          |   67 +-
 net/nimble/include/nimble/nimble_opt.h          |   19 +-
 net/nimble/src/hci_common.c                     |   14 +-
 net/nimble/src/util.c                           |   30 +
 sys/config/include/config/config.h              |   24 +-
 sys/config/include/config/config_fcb.h          |   12 +-
 sys/config/include/config/config_file.h         |   12 +-
 sys/config/pkg.yml                              |    2 +-
 sys/config/src/config.c                         |   14 +-
 sys/config/src/config_fcb.c                     |  250 +++-
 sys/config/src/config_file.c                    |  196 +--
 sys/config/src/config_json_line.c               |   56 +
 sys/config/src/config_line.c                    |  105 ++
 sys/config/src/config_nmgr.c                    |    2 +-
 sys/config/src/config_parse_line.c              |   54 -
 sys/config/src/config_priv.h                    |   27 +-
 sys/config/src/config_store.c                   |   51 +-
 sys/config/src/test/conf_test.c                 |  567 +++++++-
 sys/fcb/include/fcb/fcb.h                       |   16 +-
 sys/fcb/pkg.yml                                 |    8 +
 sys/fcb/src/fcb.c                               |   20 +-
 sys/fcb/src/fcb_append.c                        |   45 +-
 sys/fcb/src/fcb_priv.h                          |   11 +-
 sys/fcb/src/test/fcb_test.c                     |  148 ++-
 167 files changed, 9759 insertions(+), 2507 deletions(-)
----------------------------------------------------------------------



[04/28] incubator-mynewt-core git commit: Interrupts are not disabled when the Cortex-M is inside an ISR so replace OS_ASSERT_CRITICAL() with a OS_ENTER_CRITICAL/OS_EXIT_CRITICAL in os_time_tick().

Posted by ma...@apache.org.
Interrupts are not disabled when the Cortex-M is inside an ISR so replace
OS_ASSERT_CRITICAL() with a OS_ENTER_CRITICAL/OS_EXIT_CRITICAL in
os_time_tick().


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/e4185fd8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/e4185fd8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/e4185fd8

Branch: refs/heads/develop
Commit: e4185fd83a99fb0bd086e8896540f5a6e64b0754
Parents: 67ab7fe
Author: Neel Natu <ne...@nahannisys.com>
Authored: Mon Mar 21 14:54:00 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Mon Mar 21 14:54:00 2016 -0700

----------------------------------------------------------------------
 libs/os/src/os_time.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4185fd8/libs/os/src/os_time.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_time.c b/libs/os/src/os_time.c
index dc70dec..825fc13 100644
--- a/libs/os/src/os_time.c
+++ b/libs/os/src/os_time.c
@@ -59,11 +59,12 @@ os_time_get(void)
 static void
 os_time_tick(int ticks)
 {
+    os_sr_t sr;
     os_time_t delta, prev_os_time;
 
     assert(ticks >= 0);
 
-    OS_ASSERT_CRITICAL();
+    OS_ENTER_CRITICAL(sr);
     prev_os_time = g_os_time;
     g_os_time += ticks;
 
@@ -77,6 +78,7 @@ os_time_tick(int ticks)
         os_deltatime(delta, &basetod.utctime, &basetod.utctime);
         basetod.ostime = g_os_time;
     }
+    OS_EXIT_CRITICAL(sr);
 }
 
 void


[26/28] incubator-mynewt-core git commit: Get rid of unimplemented function declarations.

Posted by ma...@apache.org.
Get rid of unimplemented function declarations.


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/a2648def
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a2648def
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a2648def

Branch: refs/heads/develop
Commit: a2648def138c4b66ccfd674baf9bb41197a7f612
Parents: 40aefcc
Author: Neel Natu <ne...@nahannisys.com>
Authored: Thu Apr 7 11:48:51 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Thu Apr 7 11:48:51 2016 -0700

----------------------------------------------------------------------
 libs/os/include/os/os_callout.h | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a2648def/libs/os/include/os/os_callout.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_callout.h b/libs/os/include/os/os_callout.h
index 7aab7c9..ce85855 100644
--- a/libs/os/include/os/os_callout.h
+++ b/libs/os/include/os/os_callout.h
@@ -45,8 +45,6 @@ void os_callout_stop(struct os_callout *);
 int os_callout_reset(struct os_callout *, int32_t);
 void os_callout_tick(void);
 os_time_t os_callout_wakeup_ticks(os_time_t now);
-void os_callout_drift_set(int drift);
-int os_callout_drift_get(void);
 
 static inline int
 os_callout_queued(struct os_callout *c)


[05/28] incubator-mynewt-core git commit: Add API for the system ticker to initialize the drift. This should include the drift of the underlying physical clock source as well as the "drift" due to the finite granularity of each tick.

Posted by ma...@apache.org.
Add API for the system ticker to initialize the drift. This should include
the drift of the underlying physical clock source as well as the "drift"
due to the finite granularity of each tick.


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/bb403e72
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/bb403e72
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/bb403e72

Branch: refs/heads/develop
Commit: bb403e72daab5eb4b31a3439a64e2d6572e1ab4e
Parents: e4185fd
Author: Neel Natu <ne...@nahannisys.com>
Authored: Mon Mar 21 16:37:38 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Mon Mar 21 16:37:38 2016 -0700

----------------------------------------------------------------------
 libs/os/include/os/os_callout.h |  2 ++
 libs/os/src/os_callout.c        | 14 ++++++++++++++
 2 files changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bb403e72/libs/os/include/os/os_callout.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_callout.h b/libs/os/include/os/os_callout.h
index ce85855..7aab7c9 100644
--- a/libs/os/include/os/os_callout.h
+++ b/libs/os/include/os/os_callout.h
@@ -45,6 +45,8 @@ void os_callout_stop(struct os_callout *);
 int os_callout_reset(struct os_callout *, int32_t);
 void os_callout_tick(void);
 os_time_t os_callout_wakeup_ticks(os_time_t now);
+void os_callout_drift_set(int drift);
+int os_callout_drift_get(void);
 
 static inline int
 os_callout_queued(struct os_callout *c)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bb403e72/libs/os/src/os_callout.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_callout.c b/libs/os/src/os_callout.c
index cd4a436..d8dbf61 100644
--- a/libs/os/src/os_callout.c
+++ b/libs/os/src/os_callout.c
@@ -25,6 +25,20 @@
 TAILQ_HEAD(, os_callout) g_callout_list =
   TAILQ_HEAD_INITIALIZER(g_callout_list);
 
+static int callout_drift;
+
+void
+callout_drift_set(int drift)
+{
+    callout_drift = drift;
+}
+
+int
+callout_drift_get(void)
+{
+    return (callout_drift);
+}
+
 void
 os_callout_init(struct os_callout *c, struct os_eventq *evq, void *ev_arg)
 {


[10/28] incubator-mynewt-core git commit: Remove 'resched' parameter to 'os_time_advance()' because 'os_callout_tick()' calls it implicitly via 'os_eventq_put()'.

Posted by ma...@apache.org.
Remove 'resched' parameter to 'os_time_advance()' because 'os_callout_tick()'
calls it implicitly via 'os_eventq_put()'.


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/8e31a9e1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/8e31a9e1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/8e31a9e1

Branch: refs/heads/develop
Commit: 8e31a9e184d0ac97ba98c7a3264475b45da2c172
Parents: 79e9e9b
Author: Neel Natu <ne...@nahannisys.com>
Authored: Fri Mar 25 16:57:39 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Fri Mar 25 16:57:39 2016 -0700

----------------------------------------------------------------------
 hw/bsp/nrf52pdk/src/os_bsp.c             | 2 +-
 libs/os/include/os/os_time.h             | 2 +-
 libs/os/src/arch/cortex_m0/os_arch_arm.c | 2 +-
 libs/os/src/arch/cortex_m4/os_arch_arm.c | 2 +-
 libs/os/src/arch/sim/os_arch_sim.c       | 2 +-
 libs/os/src/os_time.c                    | 6 ++----
 6 files changed, 7 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e31a9e1/hw/bsp/nrf52pdk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/src/os_bsp.c b/hw/bsp/nrf52pdk/src/os_bsp.c
index f26460f..255f16f 100644
--- a/hw/bsp/nrf52pdk/src/os_bsp.c
+++ b/hw/bsp/nrf52pdk/src/os_bsp.c
@@ -134,7 +134,7 @@ nrf52_timer_handler(void)
 
     OS_EXIT_CRITICAL(sr);
 
-    os_time_advance(ticks, true);
+    os_time_advance(ticks);
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e31a9e1/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 5992374..c187112 100644
--- a/libs/os/include/os/os_time.h
+++ b/libs/os/include/os/os_time.h
@@ -65,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_advance(int ticks, bool resched);
+void os_time_advance(int ticks);
 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/8e31a9e1/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 7e6e433..82603da 100755
--- a/libs/os/src/arch/cortex_m0/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m0/os_arch_arm.c
@@ -104,7 +104,7 @@ uint32_t os_flags = OS_RUN_PRIV;
 void
 timer_handler(void)
 {
-    os_time_advance(1, true);
+    os_time_advance(1);
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e31a9e1/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 72b9f45..5c4ad88 100755
--- a/libs/os/src/arch/cortex_m4/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m4/os_arch_arm.c
@@ -93,7 +93,7 @@ uint32_t os_flags = OS_RUN_PRIV;
 void
 timer_handler(void)
 {
-    os_time_advance(1, true);
+    os_time_advance(1);
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e31a9e1/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 6831094..cb36df8 100644
--- a/libs/os/src/arch/sim/os_arch_sim.c
+++ b/libs/os/src/arch/sim/os_arch_sim.c
@@ -302,7 +302,7 @@ timer_handler(int sig)
     time_diff.tv_usec %= OS_USEC_PER_TICK;
     timersub(&time_now, &time_diff, &time_last);
 
-    os_time_advance(ticks, true);
+    os_time_advance(ticks);
 }
 
 static void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e31a9e1/libs/os/src/os_time.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_time.c b/libs/os/src/os_time.c
index 825fc13..7b2f310 100644
--- a/libs/os/src/os_time.c
+++ b/libs/os/src/os_time.c
@@ -82,7 +82,7 @@ os_time_tick(int ticks)
 }
 
 void
-os_time_advance(int ticks, bool resched)
+os_time_advance(int ticks)
 {
     assert(ticks >= 0);
 
@@ -90,9 +90,7 @@ os_time_advance(int ticks, bool resched)
         os_time_tick(ticks);
         os_callout_tick();
         os_sched_os_timer_exp();
-        if (resched) {
-            os_sched(NULL);
-        }
+        os_sched(NULL);
     }
 }
 


[02/28] incubator-mynewt-core git commit: Merge branch 'develop' into tickless

Posted by ma...@apache.org.
Merge branch 'develop' into tickless


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/589bc4bc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/589bc4bc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/589bc4bc

Branch: refs/heads/develop
Commit: 589bc4bc0097c6ae0c0e982642a8424ef90f17bc
Parents: 1d94ef3 473f5a8
Author: Neel Natu <ne...@nahannisys.com>
Authored: Mon Mar 14 12:25:33 2016 -0700
Committer: Neel Natu <ne...@nahannisys.com>
Committed: Mon Mar 14 12:25:33 2016 -0700

----------------------------------------------------------------------
 app.yml                                         |   20 -
 apps/bleprph/src/bleprph.h                      |   43 +
 apps/bleprph/src/gatt_svr.c                     |  342 ++++
 apps/bleprph/src/main.c                         |  299 ++++
 apps/bletest/pkg.yml                            |   42 +
 apps/bletest/src/main.c                         |  972 ++++++++++++
 apps/bletiny/pkg.yml                            |   35 +
 apps/bletiny/src/bletiny_priv.h                 |  169 ++
 apps/bletiny/src/cmd.c                          | 1479 ++++++++++++++++++
 apps/bletiny/src/main.c                         | 1467 +++++++++++++++++
 apps/bletiny/src/parse.c                        |  435 ++++++
 apps/bletiny/src/periph.c                       |  344 ++++
 apps/blinky/pkg.yml                             |   37 +
 apps/blinky/src/main.c                          |  200 +++
 apps/boot/pkg.yml                               |   39 +
 apps/boot/src/boot.c                            |  110 ++
 apps/ffs2native/pkg.yml                         |   34 +
 apps/ffs2native/src/main.c                      |  366 +++++
 apps/luatest/pkg.yml                            |   34 +
 apps/luatest/src/main.c                         |  115 ++
 apps/slinky/pkg.yml                             |   42 +
 apps/slinky/src/main.c                          |  296 ++++
 apps/test/pkg.yml                               |   41 +
 apps/test/src/test.c                            |   44 +
 compiler/arm-none-eabi-m0/compiler.yml          |   33 +
 compiler/arm-none-eabi-m0/pkg.yml               |   19 +-
 compiler/arm-none-eabi-m4/compiler.yml          |   33 +
 compiler/arm-none-eabi-m4/pkg.yml               |   19 +-
 compiler/sim/compiler.yml                       |   32 +
 compiler/sim/linux-compiler.yml                 |   13 +-
 compiler/sim/osx-compiler.yml                   |   12 -
 compiler/sim/pkg.yml                            |   18 +-
 fs/fs/pkg.yml                                   |    6 +-
 fs/nffs/pkg.yml                                 |    4 +-
 fs/nffs/src/test/arch/sim/nffs_test.c           |    2 +-
 hw/bsp/native/native_debug.sh                   |    7 +-
 hw/bsp/native/pkg.yml                           |    6 +-
 hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_debug.sh |   11 +-
 .../nrf51dk-16kbram/nrf51dk-16kbram_download.sh |   12 +-
 hw/bsp/nrf51dk-16kbram/pkg.yml                  |    6 +-
 hw/bsp/nrf51dk/nrf51dk_debug.sh                 |   11 +-
 hw/bsp/nrf51dk/nrf51dk_download.sh              |   14 +-
 hw/bsp/nrf51dk/pkg.yml                          |    6 +-
 hw/bsp/nrf52pdk/nrf52pdk_debug.sh               |    9 +-
 hw/bsp/nrf52pdk/nrf52pdk_download.sh            |   11 +-
 hw/bsp/nrf52pdk/pkg.yml                         |    6 +-
 .../olimex_stm32-e407_devboard_debug.sh         |   11 +-
 .../olimex_stm32-e407_devboard_download.sh      |   17 +-
 hw/bsp/olimex_stm32-e407_devboard/pkg.yml       |    6 +-
 hw/hal/pkg.yml                                  |    2 +-
 hw/hal/src/test/flash_map_test.c                |    2 +-
 hw/mcu/native/pkg.yml                           |    2 +-
 hw/mcu/native/src/hal_uart.c                    |    4 +-
 hw/mcu/nordic/nrf51xxx/pkg.yml                  |    2 +-
 hw/mcu/nordic/nrf52xxx/pkg.yml                  |    2 +-
 hw/mcu/stm/stm32f4xx/pkg.yml                    |    2 +-
 libs/baselibc/pkg.yml                           |    6 +-
 .../baselibc_test/printf_tests.c.donotcompile   |   22 +
 .../src/baselibc_test/tests_glue.c.donotcompile |   33 +
 libs/baselibc/src/baselibc_test/unittests.h     |   14 +
 libs/baselibc/src/test/printf_tests.c           |   22 -
 libs/baselibc/src/test/tests_glue.c             |   33 -
 libs/baselibc/src/test/unittests.h              |   14 -
 libs/bootutil/pkg.yml                           |    2 +-
 libs/bootutil/src/test/boot_test.c              |    2 +-
 libs/cmsis-core/pkg.yml                         |    2 +-
 libs/console/full/pkg.yml                       |    4 +-
 libs/console/stub/pkg.yml                       |    4 +-
 libs/elua/elua_base/pkg.yml                     |    4 +-
 libs/flash_test/pkg.yml                         |    9 +-
 libs/imgmgr/pkg.yml                             |    2 +-
 libs/json/pkg.yml                               |    2 +-
 libs/mbedtls/pkg.yml                            |    4 +-
 libs/mbedtls/src/test/mbedtls_test.c            |    2 +-
 libs/newtmgr/pkg.yml                            |    4 +-
 libs/os/include/os/arch/sim/os/os_arch.h        |   14 +-
 libs/os/pkg.yml                                 |    8 +-
 libs/os/src/arch/sim/os_arch_sim.c              |   32 +-
 libs/os/src/arch/sim/os_arch_stack_frame.s      |   17 +-
 libs/os/src/os_priv.h                           |    1 +
 libs/os/src/test/os_test.c                      |    2 +-
 libs/shell/pkg.yml                              |    6 +-
 libs/testreport/pkg.yml                         |    2 +-
 libs/testutil/include/testutil/testutil.h       |    2 +-
 libs/testutil/pkg.yml                           |    4 +-
 libs/testutil/src/case.c                        |    2 +
 libs/testutil/src/testutil.c                    |    3 +
 libs/util/pkg.yml                               |    2 +-
 libs/util/src/test/util_test.c                  |    2 +-
 .../controller/include/controller/ble_ll_conn.h |    1 +
 .../include/controller/ble_ll_sched.h           |   19 +
 net/nimble/controller/pkg.yml                   |    4 +-
 net/nimble/controller/src/ble_ll_conn.c         |  181 ++-
 net/nimble/controller/src/ble_ll_ctrl.c         |    3 -
 net/nimble/controller/src/ble_ll_sched.c        |   53 +-
 net/nimble/drivers/native/pkg.yml               |    4 +-
 net/nimble/drivers/nrf51/pkg.yml                |    4 +-
 net/nimble/drivers/nrf52/pkg.yml                |    4 +-
 net/nimble/drivers/nrf52/src/ble_phy.c          |    4 +-
 net/nimble/host/pkg.yml                         |   10 +-
 net/nimble/host/src/test/ble_hs_test.c          |    2 +-
 net/nimble/host/src/test/ble_hs_test_util.c     |    2 +
 net/nimble/host/src/test/ble_os_test.c          |    6 -
 net/nimble/include/nimble/ble.h                 |    6 +
 net/nimble/pkg.yml                              |    2 +-
 pkg-list.yml                                    |  384 -----
 project.yml                                     |   20 +
 project/bleprph/src/bleprph.h                   |   43 -
 project/bleprph/src/gatt_svr.c                  |  342 ----
 project/bleprph/src/main.c                      |  299 ----
 project/bletest/pkg.yml                         |   40 -
 project/bletest/src/main.c                      |  969 ------------
 project/bletiny/pkg.yml                         |   33 -
 project/bletiny/src/bletiny_priv.h              |  169 --
 project/bletiny/src/cmd.c                       | 1479 ------------------
 project/bletiny/src/main.c                      | 1467 -----------------
 project/bletiny/src/parse.c                     |  435 ------
 project/bletiny/src/periph.c                    |  344 ----
 project/blinky/pkg.yml                          |   35 -
 project/blinky/src/main.c                       |  200 ---
 project/boot/pkg.yml                            |   37 -
 project/boot/src/boot.c                         |  110 --
 project/ffs2native/pkg.yml                      |   32 -
 project/ffs2native/src/main.c                   |  366 -----
 project/luatest/pkg.yml                         |   32 -
 project/luatest/src/main.c                      |  115 --
 project/slinky/pkg.yml                          |   40 -
 project/slinky/src/main.c                       |  296 ----
 project/test/pkg.yml                            |   40 -
 project/test/src/test.c                         |   44 -
 sys/config/pkg.yml                              |    4 +-
 sys/config/src/test/conf_test.c                 |    2 +-
 sys/log/pkg.yml                                 |    4 +-
 sys/stats/pkg.yml                               |    4 +-
 targets/unittest/pkg.yml                        |    7 +
 targets/unittest/target.yml                     |    3 +
 136 files changed, 7620 insertions(+), 7707 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/589bc4bc/libs/os/include/os/arch/sim/os/os_arch.h
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/589bc4bc/libs/os/src/arch/sim/os_arch_sim.c
----------------------------------------------------------------------