You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2016/07/01 01:18:09 UTC

incubator-mynewt-core git commit: MYNEWT-329: More efficient cputime when using 1MHZ clock

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop baee9cd05 -> bcfe3fd05


MYNEWT-329: More efficient cputime when using 1MHZ clock

You can now define a target variable named HAL_CPUTIME_1MHZ. If you include
this in your target the cputime will assume a 1MHZ clock is being used
and the routines for converting usecs to ticks (and vice versa) will
basically become "no-ops".


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

Branch: refs/heads/develop
Commit: bcfe3fd05384ca07d65352bbfcbf02ce3195b383
Parents: baee9cd
Author: William San Filippo <wi...@runtime.io>
Authored: Thu Jun 30 18:11:40 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Thu Jun 30 18:13:57 2016 -0700

----------------------------------------------------------------------
 apps/bletest/src/main.c                  |  2 +-
 hw/hal/include/hal/hal_cputime.h         |  5 +++++
 hw/hal/src/hal_cputime.c                 | 11 ++++++++++-
 hw/mcu/native/src/hal_cputime.c          |  7 +++++++
 hw/mcu/nordic/nrf51xxx/src/hal_cputime.c |  6 ++++++
 hw/mcu/nordic/nrf52xxx/src/hal_cputime.c | 13 +++++++------
 hw/mcu/stm/stm32f4xx/src/hal_cputime.c   |  6 ++++++
 7 files changed, 42 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bcfe3fd0/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index e132f32..d9efe7e 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -104,7 +104,7 @@ os_membuf_t g_mbuf_buffer[MBUF_MEMPOOL_SIZE];
 //#define BLETEST_CFG_ROLE                (BLETEST_ROLE_SCANNER)
 
 /* Advertiser config */
-#define BLETEST_CFG_ADV_OWN_ADDR_TYPE   (BLE_HCI_ADV_OWN_ADDR_PRIV_PUB)
+#define BLETEST_CFG_ADV_OWN_ADDR_TYPE   (BLE_HCI_ADV_OWN_ADDR_PUBLIC)
 #define BLETEST_CFG_ADV_PEER_ADDR_TYPE  (BLE_HCI_ADV_PEER_ADDR_PUBLIC)
 #define BLETEST_CFG_ADV_ITVL            (60000 / BLE_HCI_ADV_ITVL)
 #define BLETEST_CFG_ADV_TYPE            BLE_HCI_ADV_TYPE_ADV_IND

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bcfe3fd0/hw/hal/include/hal/hal_cputime.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_cputime.h b/hw/hal/include/hal/hal_cputime.h
index 001bac5..7932de6 100644
--- a/hw/hal/include/hal/hal_cputime.h
+++ b/hw/hal/include/hal/hal_cputime.h
@@ -108,6 +108,10 @@ uint32_t cputime_nsecs_to_ticks(uint32_t nsecs);
  */
 uint32_t cputime_ticks_to_nsecs(uint32_t ticks);
 
+#if defined(HAL_CPUTIME_1MHZ)
+#define cputime_usecs_to_ticks(x)       (x)
+#define cputime_ticks_to_usecs(x)       (x)
+#else
 /**
  * cputime usecs to ticks
  *
@@ -129,6 +133,7 @@ uint32_t cputime_usecs_to_ticks(uint32_t usecs);
  * @return uint32_t The number of microseconds corresponding to 'ticks'
  */
 uint32_t cputime_ticks_to_usecs(uint32_t ticks);
+#endif
 
 /**
  * cputime delay ticks

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bcfe3fd0/hw/hal/src/hal_cputime.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_cputime.c b/hw/hal/src/hal_cputime.c
index 980b3e1..69e0407 100644
--- a/hw/hal/src/hal_cputime.c
+++ b/hw/hal/src/hal_cputime.c
@@ -90,7 +90,6 @@ cputime_init(uint32_t clock_freq)
     return rc;
 }
 
-
 /**
  * cputime nsecs to ticks
  *
@@ -105,7 +104,11 @@ cputime_nsecs_to_ticks(uint32_t nsecs)
 {
     uint32_t ticks;
 
+#if defined(HAL_CPUTIME_1MHZ)
+    ticks = (nsecs + 999) / 1000;
+#else
     ticks = ((nsecs * g_cputime.ticks_per_usec) + 999) / 1000;
+#endif
     return ticks;
 }
 
@@ -123,12 +126,17 @@ cputime_ticks_to_nsecs(uint32_t ticks)
 {
     uint32_t nsecs;
 
+#if defined(HAL_CPUTIME_1MHZ)
+    nsecs = ticks * 1000;
+#else
     nsecs = ((ticks * 1000) + (g_cputime.ticks_per_usec - 1)) /
             g_cputime.ticks_per_usec;
+#endif
 
     return nsecs;
 }
 
+#if !defined(HAL_CPUTIME_1MHZ)
 /**
  * cputime usecs to ticks
  *
@@ -164,6 +172,7 @@ cputime_ticks_to_usecs(uint32_t ticks)
     us =  (ticks + (g_cputime.ticks_per_usec - 1)) / g_cputime.ticks_per_usec;
     return us;
 }
+#endif
 
 /**
  * cputime delay ticks

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bcfe3fd0/hw/mcu/native/src/hal_cputime.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_cputime.c b/hw/mcu/native/src/hal_cputime.c
index e310415..ad49d07 100644
--- a/hw/mcu/native/src/hal_cputime.c
+++ b/hw/mcu/native/src/hal_cputime.c
@@ -129,6 +129,13 @@ native_cputime_task_handler(void *arg)
 int
 cputime_hw_init(uint32_t clock_freq)
 {
+
+#if defined(HAL_CPUTIME_1MHZ)
+    if (clock_freq != 1000000) {
+        return -1;
+    }
+#endif
+
     /* Clock frequency must be at least 1 MHz */
     if (clock_freq < 1000000U) {
         return -1;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bcfe3fd0/hw/mcu/nordic/nrf51xxx/src/hal_cputime.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_cputime.c b/hw/mcu/nordic/nrf51xxx/src/hal_cputime.c
index 8f2815d..f0c67fb 100644
--- a/hw/mcu/nordic/nrf51xxx/src/hal_cputime.c
+++ b/hw/mcu/nordic/nrf51xxx/src/hal_cputime.c
@@ -154,6 +154,12 @@ cputime_hw_init(uint32_t clock_freq)
     uint32_t max_freq;
     uint32_t pre_scaler;
 
+#if defined(HAL_CPUTIME_1MHZ)
+    if (clock_freq != 1000000) {
+        return -1;
+    }
+#endif
+
     /* Clock frequency must be at least 1 MHz */
     if (clock_freq < 1000000U) {
         return -1;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bcfe3fd0/hw/mcu/nordic/nrf52xxx/src/hal_cputime.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_cputime.c b/hw/mcu/nordic/nrf52xxx/src/hal_cputime.c
index d58fee3..ce82242 100644
--- a/hw/mcu/nordic/nrf52xxx/src/hal_cputime.c
+++ b/hw/mcu/nordic/nrf52xxx/src/hal_cputime.c
@@ -43,12 +43,7 @@
 /* Interrupt mask for interrupt enable/clear */
 #define CPUTIMER_INT_MASK(x)    ((1 << (uint32_t)(x)) << 16)
 
-/* XXX:
- *  - Must determine how to set priority of cpu timer interrupt
- *  - Determine if we should use a mutex as opposed to disabling interrupts
- *  - Should I use macro for compare channel?
- *  - Sync to OSTIME.
- */
+/* Disable output compare used for cputimer */
 void
 cputime_disable_ocmp(void)
 {
@@ -152,6 +147,12 @@ cputime_hw_init(uint32_t clock_freq)
     uint32_t max_freq;
     uint32_t pre_scaler;
 
+#if defined(HAL_CPUTIME_1MHZ)
+    if (clock_freq != 1000000) {
+        return -1;
+    }
+#endif
+
     /* Clock frequency must be at least 1 MHz */
     if (clock_freq < 1000000U) {
         return -1;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bcfe3fd0/hw/mcu/stm/stm32f4xx/src/hal_cputime.c
----------------------------------------------------------------------
diff --git a/hw/mcu/stm/stm32f4xx/src/hal_cputime.c b/hw/mcu/stm/stm32f4xx/src/hal_cputime.c
index 0025670..e6324c6 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_cputime.c
+++ b/hw/mcu/stm/stm32f4xx/src/hal_cputime.c
@@ -107,6 +107,12 @@ cputime_hw_init(uint32_t clock_freq)
     uint32_t max_freq;
     uint32_t pre_scalar;
 
+#if defined(HAL_CPUTIME_1MHZ)
+    if (clock_freq != 1000000) {
+        return -1;
+    }
+#endif
+
     /* Clock frequency must be at least 1 MHz */
     if (clock_freq < 1000000U) {
         return -1;