You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2017/05/17 09:55:17 UTC

[01/43] incubator-mynewt-core git commit: bsp: wifire: Implement hal_bsp_hw_id

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/bluetooth5 958bce0a5 -> 2446dcb64


bsp: wifire: Implement hal_bsp_hw_id

This function reads the DEVID register which
contains the revision (upper 4 bits) and the
device id (lower 28 bits).

Signed-off-by: Francois Berder <fb...@outlook.fr>


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

Branch: refs/heads/bluetooth5
Commit: e278c351183310a3883f5255c856b6184e6d9cec
Parents: debf64f
Author: Francois Berder <fb...@outlook.fr>
Authored: Mon May 8 11:31:17 2017 +0200
Committer: Francois Berder <fb...@outlook.fr>
Committed: Mon May 8 11:34:13 2017 +0200

----------------------------------------------------------------------
 hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e278c351/hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c b/hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c
index 87fcfa6..ae78a1d 100644
--- a/hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c
+++ b/hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c
@@ -19,9 +19,21 @@
 #include "hal/hal_bsp.h"
 #include "bsp/bsp.h"
 #include <assert.h>
+#include <xc.h>
 
 const struct hal_flash *
 hal_bsp_flash_dev(uint8_t id)
 {
     return 0;
 }
+
+int
+hal_bsp_hw_id(uint8_t *id, int max_len)
+{
+    if (max_len > sizeof(DEVID)) {
+        max_len = sizeof(DEVID);
+    }
+
+    memcpy(id, &DEVID, max_len);
+    return max_len;
+}
\ No newline at end of file


[39/43] incubator-mynewt-core git commit: MYNEWT-748 SensorAPI: Add BME280 support

Posted by an...@apache.org.
MYNEWT-748 SensorAPI: Add BME280 support

- Make OIC observe rate configurable
- Use the OIC observe rate as the LED blink rate in the app


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

Branch: refs/heads/bluetooth5
Commit: f2a8e66af0947699269814ff13fa562fc27323d5
Parents: c9ca827
Author: Vipul Rahane <vi...@apache.org>
Authored: Fri May 12 17:13:38 2017 -0700
Committer: Vipul Rahane <vi...@apache.org>
Committed: Fri May 12 17:13:38 2017 -0700

----------------------------------------------------------------------
 apps/sensors_test/src/main.c | 2 +-
 hw/sensor/src/sensor_oic.c   | 2 +-
 hw/sensor/syscfg.yml         | 4 ++++
 3 files changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f2a8e66a/apps/sensors_test/src/main.c
----------------------------------------------------------------------
diff --git a/apps/sensors_test/src/main.c b/apps/sensors_test/src/main.c
index 3c07e21..585a230 100755
--- a/apps/sensors_test/src/main.c
+++ b/apps/sensors_test/src/main.c
@@ -323,7 +323,7 @@ task1_handler(void *arg)
         ++g_task1_loops;
 
         /* Wait one second */
-        os_time_delay(OS_TICKS_PER_SEC);
+        os_time_delay(OS_TICKS_PER_SEC * MYNEWT_VAL(SENSOR_OIC_OBS_RATE));
 
         /* Toggle the LED */
         (void)hal_gpio_toggle(g_led_pin);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f2a8e66a/hw/sensor/src/sensor_oic.c
----------------------------------------------------------------------
diff --git a/hw/sensor/src/sensor_oic.c b/hw/sensor/src/sensor_oic.c
index 53c5406..651e0ff 100644
--- a/hw/sensor/src/sensor_oic.c
+++ b/hw/sensor/src/sensor_oic.c
@@ -598,7 +598,7 @@ sensor_oic_init(void)
                 oc_resource_set_default_interface(res, OC_IF_R);
 
                 oc_resource_set_discoverable(res);
-                oc_resource_set_periodic_observable(res, 1);
+                oc_resource_set_periodic_observable(res, MYNEWT_VAL(SENSOR_OIC_OBS_RATE));
                 oc_resource_set_request_handler(res, OC_GET,
                                                 sensor_oic_get_data);
                 oc_add_resource(res);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f2a8e66a/hw/sensor/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/sensor/syscfg.yml b/hw/sensor/syscfg.yml
index 761d62b..581802f 100644
--- a/hw/sensor/syscfg.yml
+++ b/hw/sensor/syscfg.yml
@@ -36,3 +36,7 @@ syscfg.defs:
     MATHLIB_SUPPORT:
         description: 'Is MATHLIB support present'
         value: 0
+
+    SENSOR_OIC_OBS_RATE:
+        description: 'Set OIC server observation rate in seconds'
+        value: 1


[12/43] incubator-mynewt-core git commit: This closes pull request #263.

Posted by an...@apache.org.
This closes pull request #263.


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

Branch: refs/heads/bluetooth5
Commit: 850b9cb988ad64bed8a5f6e6fb58e9908a6beb6a
Parents: d5cfc5c 8c999d5
Author: julian <ju...@imgtec.com>
Authored: Wed May 10 11:54:26 2017 +0100
Committer: julian <ju...@imgtec.com>
Committed: Wed May 10 11:54:26 2017 +0100

----------------------------------------------------------------------
 hw/mcu/microchip/pic32mz2048efg100/src/hal_gpio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------



[33/43] incubator-mynewt-core git commit: This closes #274

Posted by an...@apache.org.
This closes #274

Merge remote-tracking branch 'jacobrosenthal/sensors-fix'

* jacobrosenthal/sensors-fix:
  various fixes


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

Branch: refs/heads/bluetooth5
Commit: 5ac00053bb26534bbcf29b03fb8228edc74bad7c
Parents: 5ccaebb 56e5f25
Author: Vipul Rahane <vi...@apache.org>
Authored: Thu May 11 11:41:45 2017 -0700
Committer: Vipul Rahane <vi...@apache.org>
Committed: Thu May 11 11:41:45 2017 -0700

----------------------------------------------------------------------
 hw/drivers/sensors/bno055/src/bno055.c     | 10 +++++-----
 hw/drivers/sensors/tcs34725/src/tcs34725.c | 14 +++++++-------
 2 files changed, 12 insertions(+), 12 deletions(-)
----------------------------------------------------------------------



[17/43] incubator-mynewt-core git commit: hw: mcu: pic32mz2048efg100: Configure pins in hal_uart_config

Posted by an...@apache.org.
hw: mcu: pic32mz2048efg100: Configure pins in hal_uart_config

Signed-off-by: Francois Berder <fb...@outlook.fr>


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

Branch: refs/heads/bluetooth5
Commit: bdd92f700f438385f9499d6569f6bb8c581f5354
Parents: 2bdc9c1
Author: Francois Berder <fb...@outlook.fr>
Authored: Tue May 9 11:29:13 2017 +0200
Committer: Francois Berder <fb...@outlook.fr>
Committed: Wed May 10 13:54:43 2017 +0200

----------------------------------------------------------------------
 .../pic32mz2048efg100/include/mcu/mips_hal.h    |  6 +++
 .../microchip/pic32mz2048efg100/src/hal_uart.c  | 44 ++++++++++++++++++++
 2 files changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bdd92f70/hw/mcu/microchip/pic32mz2048efg100/include/mcu/mips_hal.h
----------------------------------------------------------------------
diff --git a/hw/mcu/microchip/pic32mz2048efg100/include/mcu/mips_hal.h b/hw/mcu/microchip/pic32mz2048efg100/include/mcu/mips_hal.h
index f29bd2a..a031fb8 100644
--- a/hw/mcu/microchip/pic32mz2048efg100/include/mcu/mips_hal.h
+++ b/hw/mcu/microchip/pic32mz2048efg100/include/mcu/mips_hal.h
@@ -26,6 +26,12 @@
 extern "C" {
 #endif
 
+/* I/O pins for UART */
+struct mips_uart_cfg {
+    uint8_t tx;
+    uint8_t rx;
+};
+
 /* Helper functions to enable/disable interrupts. */
 #define __HAL_DISABLE_INTERRUPTS(__os_sr) do {__os_sr = __builtin_get_isr_state(); \
         __builtin_disable_interrupts();} while(0)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bdd92f70/hw/mcu/microchip/pic32mz2048efg100/src/hal_uart.c
----------------------------------------------------------------------
diff --git a/hw/mcu/microchip/pic32mz2048efg100/src/hal_uart.c b/hw/mcu/microchip/pic32mz2048efg100/src/hal_uart.c
index aa33c2c..2c7c434 100644
--- a/hw/mcu/microchip/pic32mz2048efg100/src/hal_uart.c
+++ b/hw/mcu/microchip/pic32mz2048efg100/src/hal_uart.c
@@ -21,6 +21,7 @@
 #include "bsp/bsp.h"
 #include "syscfg/syscfg.h"
 #include "mcu/mips_hal.h"
+#include "mcu/pps.h"
 #include <assert.h>
 #include <stdlib.h>
 
@@ -33,6 +34,7 @@ struct hal_uart {
     hal_uart_tx_char u_tx_func;
     hal_uart_tx_done u_tx_done;
     void *u_func_arg;
+    const struct mips_uart_cfg *u_pins;
 };
 static struct hal_uart uarts[UART_CNT];
 
@@ -376,6 +378,12 @@ hal_uart_blocking_tx(int port, uint8_t data)
 int
 hal_uart_init(int port, void *arg)
 {
+    if (port >= UART_CNT) {
+        return -1;
+    }
+
+    uarts[port].u_pins = arg;
+
     return 0;
 }
 
@@ -417,6 +425,42 @@ hal_uart_config(int port, int32_t baudrate, uint8_t databits, uint8_t stopbits,
         return -1;
     }
 
+    /* Configure TX/RX pins */
+    if (uarts[port].u_pins) {
+        int ret = 0;
+        switch(port) {
+        case 0:
+            ret += pps_configure_output(uarts[port].u_pins->tx, U1TX_OUT_FUNC);
+            ret += pps_configure_input(uarts[port].u_pins->rx, U1RX_IN_FUNC);
+            break;
+        case 1:
+            ret += pps_configure_output(uarts[port].u_pins->tx, U2TX_OUT_FUNC);
+            ret += pps_configure_input(uarts[port].u_pins->rx, U2RX_IN_FUNC);
+            break;
+        case 2:
+            ret += pps_configure_output(uarts[port].u_pins->tx, U3TX_OUT_FUNC);
+            ret += pps_configure_input(uarts[port].u_pins->rx, U3RX_IN_FUNC);
+            break;
+        case 3:
+            ret += pps_configure_output(uarts[port].u_pins->tx, U4TX_OUT_FUNC);
+            ret += pps_configure_input(uarts[port].u_pins->rx, U4RX_IN_FUNC);
+            break;
+        case 4:
+            ret += pps_configure_output(uarts[port].u_pins->tx, U5TX_OUT_FUNC);
+            ret += pps_configure_input(uarts[port].u_pins->rx, U5RX_IN_FUNC);
+            break;
+        case 5:
+            ret += pps_configure_output(uarts[port].u_pins->tx, U6TX_OUT_FUNC);
+            ret += pps_configure_input(uarts[port].u_pins->rx, U6RX_IN_FUNC);
+            break;
+        default:
+            return -1;
+        }
+        if (ret) {
+            return -1;
+        }
+    }
+
     uint16_t divisor = peripheral_clk / (4 * baudrate) - 1;
 
     switch (port) {


[34/43] incubator-mynewt-core git commit: Merge branch 'windows_debug_script' of https://github.com/cwanda/incubator-mynewt-core

Posted by an...@apache.org.
Merge branch 'windows_debug_script' of https://github.com/cwanda/incubator-mynewt-core

This closes #268.


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

Branch: refs/heads/bluetooth5
Commit: afc404f836bf9935386d96c1ba06ccb27dd7f24e
Parents: 5ac0005 39212f4
Author: aditihilbert <ad...@runtime.io>
Authored: Fri May 12 14:36:14 2017 -0700
Committer: aditihilbert <ad...@runtime.io>
Committed: Fri May 12 14:36:14 2017 -0700

----------------------------------------------------------------------
 hw/scripts/jlink.sh   | 4 ++--
 hw/scripts/openocd.sh | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------



[40/43] incubator-mynewt-core git commit: This closes #273

Posted by an...@apache.org.
This closes #273

Merge remote-tracking branch 'fork/sensor_bme280'

* fork/sensor_bme280:
  MYNEWT-748 SensorAPI: Add BME280 support
  MYNEWT-748 SensorAPI: Add BME280 support
  MYNEWT-748 SensorAPI: Add BME280 support
  MYNEWT-748 SensorAPI: Add BME280 support
  MYNEWT-748 SensorAPI: Add BME280 support


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

Branch: refs/heads/bluetooth5
Commit: b26a78d8f040968512a082335fce372f924acb22
Parents: afc404f f2a8e66
Author: Vipul Rahane <vi...@apache.org>
Authored: Fri May 12 17:31:45 2017 -0700
Committer: Vipul Rahane <vi...@apache.org>
Committed: Fri May 12 17:31:45 2017 -0700

----------------------------------------------------------------------
 apps/sensors_test/pkg.yml                       |    1 +
 apps/sensors_test/src/main.c                    |   38 +-
 apps/sensors_test/syscfg.yml                    |    4 +
 hw/bsp/nrf52840pdk/src/hal_bsp.c                |   20 +
 hw/bsp/nrf52dk/src/hal_bsp.c                    |   12 +
 hw/bsp/ruuvi_tag_revb2/src/hal_bsp.c            |   33 +-
 .../sensors/bme280/include/bme280/bme280.h      |  259 ++++
 hw/drivers/sensors/bme280/pkg.yml               |   32 +
 hw/drivers/sensors/bme280/src/bme280.c          | 1360 ++++++++++++++++++
 hw/drivers/sensors/bme280/src/bme280_priv.h     |  111 ++
 hw/drivers/sensors/bme280/src/bme280_shell.c    |  414 ++++++
 hw/drivers/sensors/bme280/syscfg.yml            |   41 +
 .../sensors/bno055/include/bno055/bno055.h      |    2 +-
 hw/drivers/sensors/bno055/src/bno055.c          |   32 +-
 hw/sensor/include/sensor/humidity.h             |   45 +
 hw/sensor/include/sensor/pressure.h             |   45 +
 hw/sensor/include/sensor/temperature.h          |   45 +
 hw/sensor/src/sensor_oic.c                      |   54 +-
 hw/sensor/src/sensor_shell.c                    |   35 +-
 hw/sensor/syscfg.yml                            |    8 +
 20 files changed, 2561 insertions(+), 30 deletions(-)
----------------------------------------------------------------------



[22/43] incubator-mynewt-core git commit: nimble/ll: Add option to schedule connection with non-zero WindowOffset

Posted by an...@apache.org.
nimble/ll: Add option to schedule connection with non-zero WindowOffset

Devices based on TI CC254x with older stack version have bug where
connection parameters are not updated properly on slave device if
transmitWindowOffset in CONNECT_IND was set to 0 (and apparently this
applies to 1 as well).

To workaround this, we allow to use larger transmitWindowOffset in
CONNECT_IND - by default this is set to 0, for old TI CC254x IOP should
be set to at least 2.

This also fixes MYNEWT-526.


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

Branch: refs/heads/bluetooth5
Commit: 9f3452cab921043743b9512c55e248acdb676d5d
Parents: baa74ed
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Tue Apr 25 08:08:10 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Thu May 11 10:47:11 2017 +0200

----------------------------------------------------------------------
 net/nimble/controller/src/ble_ll_sched.c |  7 ++++---
 net/nimble/controller/syscfg.yml         | 10 ++++++++++
 2 files changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9f3452ca/net/nimble/controller/src/ble_ll_sched.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_sched.c b/net/nimble/controller/src/ble_ll_sched.c
index 4713f3d..6939a96 100644
--- a/net/nimble/controller/src/ble_ll_sched.c
+++ b/net/nimble/controller/src/ble_ll_sched.c
@@ -365,12 +365,13 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm,
      * request transmission. Note that adv_rxend is the end of the received
      * advertisement, so we need to add an IFS plus the time it takes to send
      * the connection request. The 1.25 msecs starts from the end of the conn
-     * request.
+     * request. Also include minimum WindowOffset value if configured.
      */
     dur = os_cputime_usecs_to_ticks(req_slots * BLE_LL_SCHED_USECS_PER_SLOT);
     earliest_start = adv_rxend +
         os_cputime_usecs_to_ticks(BLE_LL_IFS + BLE_LL_CONN_REQ_DURATION +
-                                  BLE_LL_CONN_INITIAL_OFFSET);
+                                  BLE_LL_CONN_INITIAL_OFFSET +
+                                  MYNEWT_VAL(BLE_LL_CONN_INIT_MIN_WIN_OFFSET) * BLE_LL_CONN_TX_OFF_USECS);
     earliest_end = earliest_start + dur;
     itvl_t = os_cputime_usecs_to_ticks(connsm->conn_itvl * BLE_LL_CONN_ITVL_USECS);
 #endif
@@ -385,7 +386,7 @@ ble_ll_sched_master_new(struct ble_ll_conn_sm *connsm,
     if (!ble_ll_sched_insert_if_empty(sch)) {
         /* Nothing in schedule. Schedule as soon as possible */
         rc = 0;
-        connsm->tx_win_off = 0;
+        connsm->tx_win_off = MYNEWT_VAL(BLE_LL_CONN_INIT_MIN_WIN_OFFSET);
     } else {
         os_cputime_timer_stop(&g_ble_ll_sched_timer);
         TAILQ_FOREACH(entry, &g_ble_ll_sched_q, link) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9f3452ca/net/nimble/controller/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/controller/syscfg.yml b/net/nimble/controller/syscfg.yml
index fd4f48a..9af7d96 100644
--- a/net/nimble/controller/syscfg.yml
+++ b/net/nimble/controller/syscfg.yml
@@ -128,6 +128,16 @@ syscfg.defs:
             scheduled items will be at least this far apart
         value: '4'
 
+    BLE_LL_CONN_INIT_MIN_WIN_OFFSET:
+        description: >
+            This is the minimum number of "slots" for WindowOffset value used for
+            CONNECT_IND when creating new connection as a master. Each slot is 1.25
+            msecs long. Increasing this value will delay first connection event after
+            connection is created. However, older TI CC254x controllers cannot change
+            connection parameters later if WindowOffset was set to 0 in CONNECT_IND. To
+            ensure interoperability with such devices set this value to 2 (or more).
+        value: '0'
+
     # The number of random bytes to store
     BLE_LL_RNG_BUFSIZE:
         description: >


[10/43] incubator-mynewt-core git commit: hal: nrf51 spi1 fix

Posted by an...@apache.org.
hal: nrf51 spi1 fix


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

Branch: refs/heads/bluetooth5
Commit: f42bc724c0218d31f58bf6ce9ca1bd68551948d5
Parents: cb23f34
Author: Jacob Rosenthal <ja...@gmail.com>
Authored: Tue May 9 20:53:32 2017 -0700
Committer: Jacob Rosenthal <ja...@gmail.com>
Committed: Tue May 9 20:53:32 2017 -0700

----------------------------------------------------------------------
 hw/mcu/nordic/nrf51xxx/src/hal_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f42bc724/hw/mcu/nordic/nrf51xxx/src/hal_spi.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_spi.c b/hw/mcu/nordic/nrf51xxx/src/hal_spi.c
index 21ae640..ab88ae3 100644
--- a/hw/mcu/nordic/nrf51xxx/src/hal_spi.c
+++ b/hw/mcu/nordic/nrf51xxx/src/hal_spi.c
@@ -512,7 +512,7 @@ hal_spi_init(int spi_num, void *cfg, uint8_t spi_type)
         irq_handler = nrf51_spi1_irq_handler;
         if (spi_type == HAL_SPI_TYPE_MASTER) {
 #if MYNEWT_VAL(SPI_1_MASTER)
-            spi->nhs_spi.spim = NRF_SPIM1;
+            spi->nhs_spi.spim = NRF_SPI1;
 #else
             assert(0);
 #endif


[09/43] incubator-mynewt-core git commit: MYNEWT-745 Make native sockets nonblocking.

Posted by an...@apache.org.
MYNEWT-745 Make native sockets nonblocking.

This prevents deadlock in the "no-signals" sim implementation.


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

Branch: refs/heads/bluetooth5
Commit: 71811d438c1c4722c09419646c4e6f198da1d1b2
Parents: cc1acfe
Author: Christopher Collins <cc...@apache.org>
Authored: Tue May 9 18:05:53 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue May 9 18:05:53 2017 -0700

----------------------------------------------------------------------
 net/ip/native_sockets/src/native_sock.c | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/71811d43/net/ip/native_sockets/src/native_sock.c
----------------------------------------------------------------------
diff --git a/net/ip/native_sockets/src/native_sock.c b/net/ip/native_sockets/src/native_sock.c
index 9e2d3d6..e0ecd79 100644
--- a/net/ip/native_sockets/src/native_sock.c
+++ b/net/ip/native_sockets/src/native_sock.c
@@ -250,6 +250,7 @@ native_sock_create(struct mn_socket **sp, uint8_t domain,
     struct native_sock_state *nss = &native_sock_state;
     struct native_sock *ns;
     int idx;
+    int rc;
 
     switch (domain) {
     case MN_PF_INET:
@@ -283,6 +284,11 @@ native_sock_create(struct mn_socket **sp, uint8_t domain,
     }
     os_sem_init(&ns->ns_sem, 0);
     idx = socket(domain, type, proto);
+
+    /* Make the socket nonblocking. */
+    rc = fcntl(idx, F_SETFL, fcntl(idx, F_GETFL, 0) | O_NONBLOCK);
+    assert(rc == 0);
+
     ns->ns_fd = idx;
     ns->ns_pf = domain;
     ns->ns_type = type;


[35/43] incubator-mynewt-core git commit: MYNEWT-748 SensorAPI: Add BME280 support

Posted by an...@apache.org.
MYNEWT-748 SensorAPI: Add BME280 support

- SensorAPI pressure, temperature and humidity support
- Compiles


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

Branch: refs/heads/bluetooth5
Commit: ad7cdf093a9cf325df02b4a27bcf1d70529dce9f
Parents: afc404f
Author: Vipul Rahane <vi...@apache.org>
Authored: Mon Apr 24 11:54:02 2017 -0700
Committer: Vipul Rahane <vi...@apache.org>
Committed: Fri May 12 17:08:08 2017 -0700

----------------------------------------------------------------------
 apps/sensors_test/pkg.yml                       |   1 +
 apps/sensors_test/src/main.c                    |  20 +
 apps/sensors_test/syscfg.yml                    |  10 +-
 hw/bsp/nrf52dk/src/hal_bsp.c                    |  12 +
 .../sensors/bme280/include/bme280/bme280.h      | 245 +++++++
 hw/drivers/sensors/bme280/pkg.yml               |  32 +
 hw/drivers/sensors/bme280/src/bme280.c          | 714 +++++++++++++++++++
 hw/drivers/sensors/bme280/src/bme280_priv.h     | 110 +++
 hw/drivers/sensors/bme280/src/bme280_shell.c    | 364 ++++++++++
 hw/drivers/sensors/bme280/syscfg.yml            |  38 +
 hw/sensor/src/sensor_shell.c                    |  14 +-
 11 files changed, 1554 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad7cdf09/apps/sensors_test/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/sensors_test/pkg.yml b/apps/sensors_test/pkg.yml
index 4f8e25c..9f56e7b 100644
--- a/apps/sensors_test/pkg.yml
+++ b/apps/sensors_test/pkg.yml
@@ -33,6 +33,7 @@ pkg.deps:
     - hw/drivers/sensors/tsl2561
     - hw/drivers/sensors/bno055
     - hw/drivers/sensors/tcs34725
+    - hw/drivers/sensors/bme280
     - boot/bootutil
     - sys/shell
     - sys/config

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad7cdf09/apps/sensors_test/src/main.c
----------------------------------------------------------------------
diff --git a/apps/sensors_test/src/main.c b/apps/sensors_test/src/main.c
index d05cb94..152d48e 100755
--- a/apps/sensors_test/src/main.c
+++ b/apps/sensors_test/src/main.c
@@ -34,6 +34,7 @@
 #include <tsl2561/tsl2561.h>
 #include <tcs34725/tcs34725.h>
 #include <bno055/bno055.h>
+#include <bme280/bme280.h>
 #include "flash_map/flash_map.h"
 #include <hal/hal_system.h>
 #if MYNEWT_VAL(SPLIT_LOADER)
@@ -386,6 +387,25 @@ config_sensor(void)
     struct os_dev *dev;
     int rc;
 
+#if MYNEWT_VAL(BME280_PRESENT)
+    struct bme280_cfg bmecfg;
+
+    dev = (struct os_dev *) os_dev_open("bme280", OS_TIMEOUT_NEVER, NULL);
+    assert(dev != NULL);
+    rc = bme280_init(dev, NULL);
+    if (rc) {
+        os_dev_close(dev);
+        goto err;
+    }
+
+    rc = bme280_config((struct bme280 *)dev, &bmecfg);
+    if (rc) {
+        os_dev_close(dev);
+        goto err;
+    }
+    os_dev_close(dev);
+#endif
+
 #if MYNEWT_VAL(TCS34725_PRESENT)
     struct tcs34725_cfg tcscfg;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad7cdf09/apps/sensors_test/syscfg.yml
----------------------------------------------------------------------
diff --git a/apps/sensors_test/syscfg.yml b/apps/sensors_test/syscfg.yml
index 81876bc..8172a62 100644
--- a/apps/sensors_test/syscfg.yml
+++ b/apps/sensors_test/syscfg.yml
@@ -42,8 +42,9 @@ syscfg.vals:
     CONFIG_NEWTMGR: 0
 
     TSL2561_CLI: 0
-    BNO055_CLI: 1
-    TCS34725_CLI: 1
+    BNO055_CLI: 0
+    TCS34725_CLI: 0
+    BME280_CLI: 0
 
     # Setup Sensor BLE OIC GATT Server
     SENSOR_OIC: 1
@@ -65,10 +66,13 @@ syscfg.defs:
         value : 0
     BNO055_PRESENT:
         description: 'BNO055 is present'
+        value : 0
+    BME280_PRESENT:
+        description: 'BME280 is present'
         value : 1
     TCS34725_PRESENT:
         description: 'TCS34725 is present'
-        value : 1
+        value : 0
     SIM_ACCEL_PRESENT:
         description: 'SIM ACCEL is present'
         value : 0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad7cdf09/hw/bsp/nrf52dk/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/src/hal_bsp.c b/hw/bsp/nrf52dk/src/hal_bsp.c
index c0031b1..46c084d 100644
--- a/hw/bsp/nrf52dk/src/hal_bsp.c
+++ b/hw/bsp/nrf52dk/src/hal_bsp.c
@@ -55,6 +55,9 @@ static struct lsm303dlhc lsm303dlhc;
 #if MYNEWT_VAL(TCS34725_PRESENT)
 #include <tcs34725/tcs34725.h>
 #endif
+#if MYNEWT_VAL(BME280_PRESENT)
+#include <bme280/bme280.h>
+#endif
 
 #if MYNEWT_VAL(LSM303DLHC_PRESENT)
 static struct lsm303dlhc lsm303dlhc;
@@ -72,6 +75,10 @@ static struct tsl2561 tsl2561;
 static struct tcs34725 tcs34725;
 #endif
 
+#if MYNEWT_VAL(BME280_PRESENT)
+static struct bme280 bme280;
+#endif
+
 #if MYNEWT_VAL(UART_0)
 static struct uart_dev os_bsp_uart0;
 static const struct nrf52_uart_cfg os_bsp_uart0_cfg = {
@@ -234,6 +241,11 @@ sensor_dev_create(void)
     assert(rc == 0);
 #endif
 
+#if MYNEWT_VAL(BME280_PRESENT)
+    rc = os_dev_create((struct os_dev *) &bme280, "bme280",
+      OS_DEV_INIT_PRIMARY, 0, color_init, NULL);
+    assert(rc == 0);
+#endif
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad7cdf09/hw/drivers/sensors/bme280/include/bme280/bme280.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/include/bme280/bme280.h b/hw/drivers/sensors/bme280/include/bme280/bme280.h
new file mode 100644
index 0000000..f5ea131
--- /dev/null
+++ b/hw/drivers/sensors/bme280/include/bme280/bme280.h
@@ -0,0 +1,245 @@
+/*
+ * 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 __BME280_H__
+#define __BME280_H__
+
+#include <os/os.h>
+#include "os/os_dev.h"
+#include "sensor/sensor.h"
+
+#define BME280_SPI_READ_CMD_BIT 0x80
+
+/* Sampling */
+#define BME280_SAMPLING_NONE     0x0
+#define BME280_SAMPLING_X1       0x1
+#define BME280_SAMPLING_X2       0x2
+#define BME280_SAMPLING_X4       0x3
+#define BME280_SAMPLING_X8       0x4
+#define BME280_SAMPLING_X16      0x5
+
+/* Operating modes */
+#define BME280_MODE_SLEEP        0x0
+#define BME280_MODE_FORCED       0x1
+#define BME280_MODE_NORMAL       0x3
+
+/* Filter settings */
+#define BME280_FILTER_OFF        0x0
+#define BME280_FILTER_X2         0x1
+#define BME280_FILTER_X4         0x2
+#define BME280_FILTER_X8         0x3
+#define BME280_FILTER_X16        0x4
+
+/* Standby durations in ms */
+#define BME280_STANDBY_MS_0_5    0x0
+#define BME280_STANDBY_MS_10     0x6
+#define BME280_STANDBY_MS_20     0x7
+#define BME280_STANDBY_MS_62_5   0x1
+#define BME280_STANDBY_MS_125    0x2
+#define BME280_STANDBY_MS_250    0x3
+#define BME280_STANDBY_MS_500    0x4
+#define BME280_STANDBY_MS_1000   0x5
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct bme280_calib_data {
+    uint16_t bcd_dig_T1;
+    int16_t  bcd_dig_T2;
+    int16_t  bcd_dig_T3;
+
+    uint16_t bcd_dig_P1;
+    int16_t  bcd_dig_P2;
+    int16_t  bcd_dig_P3;
+    int16_t  bcd_dig_P4;
+    int16_t  bcd_dig_P5;
+    int16_t  bcd_dig_P6;
+    int16_t  bcd_dig_P7;
+    int16_t  bcd_dig_P8;
+    int16_t  bcd_dig_P9;
+
+    uint8_t  bcd_dig_H1;
+    int16_t  bcd_dig_H2;
+    uint8_t  bcd_dig_H3;
+    int16_t  bcd_dig_H4;
+    int16_t  bcd_dig_H5;
+    int8_t   bcd_dig_H6;
+};
+
+struct bme280_over_cfg {
+    sensor_type_t boc_type;
+    uint8_t boc_oversample;
+};
+
+struct bme280_cfg {
+    uint8_t bc_iir;
+    struct bme280_over_cfg bc_boc[3];
+    uint8_t bc_mode;
+};
+
+struct bme280 {
+    struct os_dev dev;
+    struct sensor sensor;
+    struct bme280_cfg cfg;
+    os_time_t last_read_time;
+};
+
+/**
+ * Initialize the bme280.
+ *
+ * @param dev  Pointer to the bme280_dev device descriptor
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int bme280_init(struct os_dev *dev, void *arg);
+
+/**
+ * Sets IIR filter
+ *
+ * @param filter setting
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int bme280_set_iir(uint8_t iir);
+
+/**
+ * Get IIR filter setting
+ *
+ * @param ptr to fill up iir setting into
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int bme280_get_iir(uint8_t *iir);
+
+/**
+ * Gets a new data sample from the sensor.
+ *
+ * @param temperature sensor output
+ * @param pressure sensor output
+ * @param humidity sensor output
+ * @param bme280 config and OS device structure
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int bme280_get_data(uint32_t *temp, uint32_t *press, uint32_t *humidity,
+                    struct bme280 *bme280);
+
+/**
+ * Gets temperature
+ *
+ * @param temperature
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int bme280_get_temperature(uint32_t *temp);
+
+/**
+ * Gets pressure
+ *
+ * @param pressure
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int bme280_get_pressure(uint32_t *press);
+
+/**
+ * Gets humidity
+ *
+ * @param humidity
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int bme280_get_humidity(uint32_t *humidity);
+
+/**
+ * Sets the sampling rate
+ *
+ * @param sensor type
+ * @param sampling rate
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int bme280_set_oversample(sensor_type_t type, uint8_t rate);
+
+/**
+ * Gets the current sampling rate for the type of sensor
+ *
+ * @param Type of sensor to return sampling rate
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int bme280_get_oversample(sensor_type_t type, uint8_t *rate);
+
+/**
+ * Sets the operating mode
+ *
+ * @param mode
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int bme280_set_mode(uint8_t mode);
+
+/**
+ * Gets the operating mode
+ *
+ * @param ptr to the mode variable to be filled up
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int bme280_get_mode(uint8_t *mode);
+
+/**
+ * Resets the BME280 chip
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+bme280_reset(void);
+
+/**
+ * Configure BME280 sensor
+ *
+ * @param Sensor device BME280 structure
+ * @param Sensor device BME280 config
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int bme280_config(struct bme280 *bme280, struct bme280_cfg *cfg);
+
+/**
+ * Get the chip id
+ *
+ * @param ptr to fill up the chip id
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int
+bme280_get_chipid(uint8_t *chipid);
+
+#if MYNEWT_VAL(BME280_CLI)
+int bme280_shell_init(void);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BME280_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad7cdf09/hw/drivers/sensors/bme280/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/pkg.yml b/hw/drivers/sensors/bme280/pkg.yml
new file mode 100644
index 0000000..496e35e
--- /dev/null
+++ b/hw/drivers/sensors/bme280/pkg.yml
@@ -0,0 +1,32 @@
+#
+# 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.
+#
+
+pkg.name: hw/drivers/sensors/bme280
+pkg.description: Driver for the BME280 light to digital sensor
+pkg.author: "Vipul Rahane <vi...@runtime.io>"
+pkg.homepage: "http://www.runtime.io/"
+pkg.keywords:
+    - adafruit
+    - bme280
+    - spi
+    - sensor
+
+pkg.deps:
+    - "@apache-mynewt-core/kernel/os"
+    - "@apache-mynewt-core/hw/hal"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad7cdf09/hw/drivers/sensors/bme280/src/bme280.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/src/bme280.c b/hw/drivers/sensors/bme280/src/bme280.c
new file mode 100644
index 0000000..ca5ee0a
--- /dev/null
+++ b/hw/drivers/sensors/bme280/src/bme280.c
@@ -0,0 +1,714 @@
+/*
+ * 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 <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#include "defs/error.h"
+#include "os/os.h"
+#include "sysinit/sysinit.h"
+#include "hal/hal_spi.h"
+#include "sensor/sensor.h"
+#include "bme280/bme280.h"
+#include "bme280_priv.h"
+#include "hal/hal_gpio.h"
+
+#if MYNEWT_VAL(BME280_LOG)
+#include "log/log.h"
+#endif
+
+#if MYNEWT_VAL(BME280_STATS)
+#include "stats/stats.h"
+#endif
+
+static struct hal_spi_settings spi_bme280_settings = {
+    .data_order = HAL_SPI_MSB_FIRST,
+    .data_mode  = HAL_SPI_MODE0,
+    .baudrate   = 500,
+    .word_size  = HAL_SPI_WORD_SIZE_8BIT,
+};
+
+#if MYNEWT_VAL(BME280_STATS)
+/* Define the stats section and records */
+STATS_SECT_START(bme280_stat_section)
+    STATS_SECT_ENTRY(errors)
+STATS_SECT_END
+
+/* Define stat names for querying */
+STATS_NAME_START(bme280_stat_section)
+    STATS_NAME(bme280_stat_section, errors)
+STATS_NAME_END(bme280_stat_section)
+
+/* Global variable used to hold stats data */
+STATS_SECT_DECL(bme280_stat_section) g_bme280stats;
+#endif
+
+#if MYNEWT_VAL(BME280_LOG)
+#define LOG_MODULE_BME280    (2561)
+#define BME280_INFO(...)     LOG_INFO(&_log, LOG_MODULE_BME280, __VA_ARGS__)
+#define BME280_ERR(...)      LOG_ERROR(&_log, LOG_MODULE_BME280, __VA_ARGS__)
+static struct log _log;
+#else
+#define BME280_INFO(...)
+#define BME280_ERR(...)
+#endif
+
+/* Exports for the sensor interface.
+ */
+static void *bme280_sensor_get_interface(struct sensor *, sensor_type_t);
+static int bme280_sensor_read(struct sensor *, sensor_type_t,
+        sensor_data_func_t, void *, uint32_t);
+static int bme280_sensor_get_config(struct sensor *, sensor_type_t,
+        struct sensor_cfg *);
+
+static const struct sensor_driver g_bme280_sensor_driver = {
+    bme280_sensor_get_interface,
+    bme280_sensor_read,
+    bme280_sensor_get_config
+};
+
+static int
+bme280_default_cfg(struct bme280_cfg *cfg)
+{
+    cfg->bc_iir = BME280_FILTER_OFF;
+    cfg->bc_mode = BME280_MODE_NORMAL;
+
+    cfg->bc_boc[0].boc_type = SENSOR_TYPE_TEMPERATURE;
+    cfg->bc_boc[0].boc_oversample = BME280_SAMPLING_NONE;
+    cfg->bc_boc[1].boc_type = SENSOR_TYPE_PRESSURE;
+    cfg->bc_boc[1].boc_oversample = BME280_SAMPLING_NONE;
+    cfg->bc_boc[2].boc_type = SENSOR_TYPE_RELATIVE_HUMIDITY;
+    cfg->bc_boc[2].boc_oversample = BME280_SAMPLING_NONE;
+
+    return 0;
+}
+
+/**
+ * Expects to be called back through os_dev_create().
+ *
+ * @param The device object associated with bme280
+ * @param Argument passed to OS device init, unused
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int
+bme280_init(struct os_dev *dev, void *arg)
+{
+    struct bme280 *bme280;
+    struct sensor *sensor;
+    int rc;
+
+    bme280 = (struct bme280 *) dev;
+
+    rc = bme280_default_cfg(&bme280->cfg);
+    if (rc) {
+        goto err;
+    }
+
+#if MYNEWT_VAL(BME280_LOG)
+    log_register("bme280", &_log, &log_console_handler, NULL, LOG_SYSLEVEL);
+#endif
+
+    sensor = &bme280->sensor;
+
+#if MYNEWT_VAL(BME280_STATS)
+    /* Initialise the stats entry */
+    rc = stats_init(
+        STATS_HDR(g_bme280stats),
+        STATS_SIZE_INIT_PARMS(g_bme280stats, STATS_SIZE_32),
+        STATS_NAME_INIT_PARMS(bme280_stat_section));
+    SYSINIT_PANIC_ASSERT(rc == 0);
+    /* Register the entry with the stats registry */
+    rc = stats_register("bme280", STATS_HDR(g_bme280stats));
+    SYSINIT_PANIC_ASSERT(rc == 0);
+#endif
+    rc = sensor_init(sensor, dev);
+    if (rc != 0) {
+        goto err;
+    }
+
+    /* Add the driver */
+    rc = sensor_set_driver(sensor, SENSOR_TYPE_TEMPERATURE |
+                           SENSOR_TYPE_PRESSURE            |
+                           SENSOR_TYPE_RELATIVE_HUMIDITY,
+                           (struct sensor_driver *) &g_bme280_sensor_driver);
+    if (rc != 0) {
+        goto err;
+    }
+
+    rc = sensor_mgr_register(sensor);
+    if (rc != 0) {
+        goto err;
+    }
+
+    rc = hal_spi_config(MYNEWT_VAL(BME280_SPINUM), &spi_bme280_settings);
+    if (rc) {
+        goto err;
+    }
+
+    rc = hal_spi_enable(MYNEWT_VAL(BME280_SPINUM));
+    if (rc) {
+        goto err;
+    }
+
+    rc = hal_gpio_init_out(MYNEWT_VAL(BME280_CSPIN), 1);
+    if (rc) {
+        goto err;
+    }
+
+    return (0);
+err:
+    return (rc);
+
+}
+
+static void *
+bme280_sensor_get_interface(struct sensor *sensor, sensor_type_t type)
+{
+    return (NULL);
+}
+
+static int
+bme280_sensor_read(struct sensor *sensor, sensor_type_t type,
+        sensor_data_func_t data_func, void *data_arg, uint32_t timeout)
+{
+    uint32_t temp;
+    uint32_t press;
+    uint32_t humid;
+    int rc;
+
+    if (!(type & SENSOR_TYPE_PRESSURE)    ||
+        !(type & SENSOR_TYPE_TEMPERATURE) ||
+        !(type & SENSOR_TYPE_RELATIVE_HUMIDITY)) {
+        rc = SYS_EINVAL;
+        goto err;
+    }
+
+    temp = press = humid = 0;
+
+    /* Get a new pressure sample */
+    if (type & SENSOR_TYPE_PRESSURE) {
+        rc = bme280_get_pressure(&press);
+        if (rc) {
+            goto err;
+        }
+
+        //lux = bme280_calculate_lux(full, ir, &(bme280->cfg));
+
+        /* Call data function */
+        rc = data_func(sensor, data_arg, &press);
+        if (rc) {
+            goto err;
+        }
+    }
+
+    /* Get a new temperature sample */
+    if (type & SENSOR_TYPE_TEMPERATURE) {
+        rc = bme280_get_temperature(&temp);
+        if (rc) {
+            goto err;
+        }
+
+        //lux = bme280_calculate_lux(full, ir, &(bme280->cfg));
+
+        /* Call data function */
+        rc = data_func(sensor, data_arg, &temp);
+        if (rc) {
+            goto err;
+        }
+    }
+
+    /* Get a new relative humidity sample */
+    if (type & SENSOR_TYPE_RELATIVE_HUMIDITY) {
+        rc = bme280_get_humidity(&humid);
+        if (rc) {
+            goto err;
+        }
+
+        //lux = bme280_calculate_lux(full, ir, &(bme280->cfg));
+
+        /* Call data function */
+        rc = data_func(sensor, data_arg, &humid);
+        if (rc) {
+            goto err;
+        }
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+static int
+bme280_sensor_get_config(struct sensor *sensor, sensor_type_t type,
+        struct sensor_cfg *cfg)
+{
+    int rc;
+
+    if (!(type & SENSOR_TYPE_PRESSURE)    ||
+        !(type & SENSOR_TYPE_TEMPERATURE) ||
+        !(type & SENSOR_TYPE_RELATIVE_HUMIDITY)) {
+        rc = SYS_EINVAL;
+        goto err;
+    }
+
+    cfg->sc_valtype = SENSOR_VALUE_TYPE_INT32;
+
+    return (0);
+err:
+    return (rc);
+}
+
+/**
+ * Configure BME280 sensor
+ *
+ * @param Sensor device BME280 structure
+ * @param Sensor device BME280 config
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+bme280_config(struct bme280 *bme280, struct bme280_cfg *cfg)
+{
+    int rc;
+
+    rc = bme280_set_iir(cfg->bc_iir);
+
+    rc |= bme280_set_mode(cfg->bc_mode);
+
+    rc |= bme280_set_oversample(cfg->bc_boc[0].boc_type,
+                                cfg->bc_boc[0].boc_oversample);
+
+    rc |= bme280_set_oversample(cfg->bc_boc[1].boc_type,
+                                cfg->bc_boc[1].boc_oversample);
+
+    rc |= bme280_set_oversample(cfg->bc_boc[2].boc_type,
+                                cfg->bc_boc[2].boc_oversample);
+
+    if (rc) {
+        goto err;
+    }
+
+    /* Overwrite the configuration data. */
+    memcpy(&bme280->cfg, cfg, sizeof(*cfg));
+
+err:
+    return (rc);
+}
+
+/**
+ * Read multiple length data from BME280 sensor over SPI
+ *
+ * @param register address
+ * @param variable length payload
+ * @param length of the payload to read
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+bme280_readlen(uint8_t addr, uint8_t *payload, uint8_t len)
+{
+    int i;
+    int rc;
+    uint8_t txdata;
+    uint8_t rxdata;
+
+    /* Select the device */
+    hal_gpio_write(MYNEWT_VAL(BME280_CSPIN), 0);
+
+    /* Send the address */
+    rc = hal_spi_tx_val(MYNEWT_VAL(BME280_SPINUM), addr | BME280_SPI_READ_CMD_BIT);
+    if (rc) {
+        goto err;
+    }
+
+    txdata = 0;
+
+    for (i = 0; i < len; i++) {
+        /* Read data */
+        rc = hal_spi_txrx(MYNEWT_VAL(BME280_SPINUM), &txdata, &rxdata, 1);
+        if (rc) {
+            goto err;
+        }
+
+        payload[i] = rxdata;
+    }
+
+    /* De-select the device */
+    hal_gpio_write(MYNEWT_VAL(BME280_CSPIN), 1);
+
+    return 0;
+err:
+    return rc;
+}
+
+/**
+ * Write multiple length data to BME280 sensor over SPI
+ *
+ * @param register address
+ * @param variable length payload
+ * @param length of the payload to write
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+bme280_writelen(uint8_t addr, uint8_t *payload, uint8_t len)
+{
+    int i;
+    int rc;
+
+    /* Select the device */
+    hal_gpio_write(MYNEWT_VAL(BME280_CSPIN), 0);
+
+    /* Send the address */
+    rc = hal_spi_tx_val(MYNEWT_VAL(BME280_SPINUM), addr | BME280_SPI_READ_CMD_BIT);
+    if (rc) {
+        goto err;
+    }
+
+    for (i = 0; i < len; i++) {
+        /* Read data */
+        rc = hal_spi_tx_val(MYNEWT_VAL(BME280_SPINUM), payload[i]);
+        if (rc) {
+            goto err;
+        }
+    }
+
+    /* De-select the device */
+    hal_gpio_write(MYNEWT_VAL(BME280_CSPIN), 1);
+
+    return 0;
+err:
+    return rc;
+}
+
+/**
+ * Gets temperature
+ *
+ * @param temperature
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int
+bme280_get_temperature(uint32_t *temp)
+{
+    int rc;
+    uint8_t tmp[3];
+
+    rc = bme280_readlen(BME280_REG_ADDR_TEMP, tmp, 3);
+    if (rc) {
+        goto err;
+    }
+
+    *temp = (tmp[1] << 8 | tmp[0]) << 4 | (tmp[2] >> 4);
+
+err:
+    return rc;
+}
+
+/**
+ * Gets humidity
+ *
+ * @param humidity
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int
+bme280_get_humidity(uint32_t *humid)
+{
+    int rc;
+    uint8_t tmp[2];
+
+    rc = bme280_readlen(BME280_REG_ADDR_HUM, tmp, 2);
+    if (rc) {
+        goto err;
+    }
+
+    *humid = (tmp[1] << 8 | tmp[0]);
+
+err:
+    return rc;
+}
+
+/**
+ * Gets pressure
+ *
+ * @param pressure
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int
+bme280_get_pressure(uint32_t *press)
+{
+    int rc;
+    uint8_t tmp[3];
+
+    rc = bme280_readlen(BME280_REG_ADDR_PRESS, tmp, 2);
+    if (rc) {
+        goto err;
+    }
+
+    *press = (tmp[1] << 8 | tmp[0]) << 4 | (tmp[2] >> 4);
+
+err:
+    return rc;
+}
+
+/**
+ * Resets the BME280 chip
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+bme280_reset(void)
+{
+    uint8_t txdata;
+
+    txdata = 1;
+
+    return bme280_writelen(BME280_REG_ADDR_RESET, &txdata, 1);
+}
+
+/**
+ * Get IIR filter setting
+ *
+ * @param ptr to fill up iir setting into
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+bme280_get_iir(uint8_t *iir)
+{
+    int rc;
+    uint8_t tmp;
+
+    rc = bme280_readlen(BME280_REG_ADDR_CONFIG, &tmp, 1);
+    if (rc) {
+        goto err;
+    }
+
+    *iir = ((tmp & BME280_REG_CONFIG_FILTER) >> 5);
+
+err:
+    return rc;
+}
+
+/**
+ * Sets IIR filter
+ *
+ * @param filter setting
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+bme280_set_iir(uint8_t iir)
+{
+    int rc;
+    uint8_t cfg;
+
+    rc = bme280_readlen(BME280_REG_ADDR_CONFIG, &cfg, 1);
+    if (rc) {
+        goto err;
+    }
+
+    iir = cfg | ((iir << 5) & BME280_REG_CONFIG_FILTER);
+
+    rc = bme280_writelen(BME280_REG_ADDR_CONFIG, &iir, 1);
+    if (rc) {
+        goto err;
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+/**
+ * Gets the operating mode
+ *
+ * @param ptr to the mode variable to be filled up
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int
+bme280_get_mode(uint8_t *mode)
+{
+    int rc;
+    uint8_t tmp;
+
+    rc = bme280_readlen(BME280_REG_ADDR_CTRL_MEAS, &tmp, 1);
+    if (rc) {
+        goto err;
+    }
+
+    *mode = (tmp & BME280_REG_CTRL_MEAS_MODE);
+
+err:
+    return rc;
+}
+
+/**
+ * Sets the operating mode
+ *
+ * @param mode
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int
+bme280_set_mode(uint8_t mode)
+{
+    int rc;
+    uint8_t cfg;
+
+    rc = bme280_readlen(BME280_REG_ADDR_CTRL_MEAS, &cfg, 1);
+    if (rc) {
+        goto err;
+    }
+
+    mode = cfg | (mode & BME280_REG_CTRL_MEAS_MODE);
+
+    rc = bme280_writelen(BME280_REG_ADDR_CTRL_MEAS, &mode, 1);
+    if (rc) {
+        goto err;
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+/**
+ * Gets the current sampling rate for the type of sensor
+ *
+ * @param Type of sensor to return sampling rate
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+bme280_get_oversample(sensor_type_t type, uint8_t *oversample)
+{
+    int rc;
+    uint8_t tmp;
+
+    if (type & SENSOR_TYPE_TEMPERATURE || type & SENSOR_TYPE_PRESSURE) {
+        rc = bme280_readlen(BME280_REG_ADDR_CTRL_MEAS, &tmp, 1);
+        if (rc) {
+            goto err;
+        }
+
+        if (type & SENSOR_TYPE_TEMPERATURE) {
+            *oversample = ((tmp & BME280_REG_CTRL_MEAS_TOVER) >> 5);
+        }
+
+        if (type & SENSOR_TYPE_PRESSURE) {
+            *oversample = ((tmp & BME280_REG_CTRL_MEAS_POVER) >> 3);
+        }
+    }
+
+    if (type & SENSOR_TYPE_RELATIVE_HUMIDITY) {
+        rc = bme280_readlen(BME280_REG_ADDR_CTRL_HUM, &tmp, 1);
+        if (rc) {
+            goto err;
+        }
+        *oversample = (tmp & BME280_REG_CTRL_HUM_HOVER);
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+/**
+ * Sets the sampling rate
+ *
+ * @param sensor type
+ * @param sampling rate
+ *
+ * @return 0 on success, and non-zero error code on failure
+ */
+int
+bme280_set_oversample(sensor_type_t type, uint8_t oversample)
+{
+    int rc;
+    uint8_t cfg;
+
+    if (type & SENSOR_TYPE_TEMPERATURE || type & SENSOR_TYPE_PRESSURE) {
+        rc = bme280_readlen(BME280_REG_ADDR_CTRL_MEAS, &cfg, 1);
+        if (rc) {
+            goto err;
+        }
+
+        if (type & SENSOR_TYPE_TEMPERATURE) {
+            oversample = cfg | ((oversample << 5) & BME280_REG_CTRL_MEAS_TOVER);
+        }
+
+        if (type & SENSOR_TYPE_PRESSURE) {
+            oversample = cfg | ((oversample << 3) & BME280_REG_CTRL_MEAS_POVER);
+        }
+
+        rc = bme280_writelen(BME280_REG_ADDR_CTRL_MEAS, &oversample, 1);
+        if (rc) {
+            goto err;
+        }
+    }
+
+    if (type & SENSOR_TYPE_RELATIVE_HUMIDITY) {
+        rc = bme280_readlen(BME280_REG_ADDR_CTRL_HUM, &cfg, 1);
+        if (rc) {
+            goto err;
+        }
+
+        oversample = cfg | (oversample & BME280_REG_CTRL_HUM_HOVER);
+
+        rc = bme280_writelen(BME280_REG_ADDR_CTRL_HUM, &oversample, 1);
+        if (rc) {
+            goto err;
+        }
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+/**
+ * Get the chip id
+ *
+ * @param ptr to fill up the chip id
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+bme280_get_chipid(uint8_t *chipid)
+{
+    int rc;
+    uint8_t tmp;
+
+    rc = bme280_readlen(BME280_REG_ADDR_PRESS, &tmp, 1);
+    if (rc) {
+        goto err;
+    }
+
+    *chipid = tmp;
+
+err:
+    return rc;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad7cdf09/hw/drivers/sensors/bme280/src/bme280_priv.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/src/bme280_priv.h b/hw/drivers/sensors/bme280/src/bme280_priv.h
new file mode 100644
index 0000000..1c93aeb
--- /dev/null
+++ b/hw/drivers/sensors/bme280/src/bme280_priv.h
@@ -0,0 +1,110 @@
+/*
+ * 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 __BME280_PRIV_H__
+#define __BME280_PRIV_H__
+
+#define BME280_REG_ADDR_DIG_T1            0x88
+#define BME280_REG_ADDR_DIG_T2            0x8A
+#define BME280_REG_ADDR_DIG_T3            0x8C
+
+#define BME280_REG_ADDR_DIG_P1            0x8E
+#define BME280_REG_ADDR_DIG_P2            0x90
+#define BME280_REG_ADDR_DIG_P3            0x92
+#define BME280_REG_ADDR_DIG_P4            0x94
+#define BME280_REG_ADDR_DIG_P5            0x96
+#define BME280_REG_ADDR_DIG_P6            0x98
+#define BME280_REG_ADDR_DIG_P7            0x9A
+#define BME280_REG_ADDR_DIG_P8            0x9C
+#define BME280_REG_ADDR_DIG_P9            0x9E
+
+#define BME280_REG_ADDR_DIG_H1            0xA1
+#define BME280_REG_ADDR_DIG_H2            0xE1
+#define BME280_REG_ADDR_DIG_H3            0xE3
+#define BME280_REG_ADDR_DIG_H4            0xE4
+#define BME280_REG_ADDR_DIG_H5            0xE5
+#define BME280_REG_ADDR_DIG_H6            0xE7
+
+#define BME280_REG_ADDR_CHIPID            0xD0
+#define BME280_REG_ADDR_VERSION           0xD1
+#define BME280_REG_ADDR_SOFTRESET         0xE0
+
+#define BME280_REG_ADDR_CAL26             0xE1  // R calibration stored in 0xE1-0xF0
+
+#define BME280_REG_ADDR_CTRL_HUM          0xF2
+#define BME280_REG_CTRL_HUM_NONE        (0x1F)
+#define BME280_REG_CTRL_HUM_HOVER       (0x11)
+
+#define BME280_REG_ADDR_STATUS            0XF3
+#define BME280_REG_STATUS_MEAS            0x04
+#define BME280_REG_STATUS_IM_UP           0x01
+
+#define BME280_REG_ADDR_CTRL_MEAS         0xF4
+#define BME280_REG_CTRL_MEAS_TOVER (0x11 << 5)
+#define BME280_REG_CTRL_MEAS_POVER (0x11 << 3)
+#define BME280_REG_CTRL_MEAS_MODE       (0x11)
+
+#define BME280_REG_ADDR_CONFIG            0xF5
+#define BME280_REG_CONFIG_STANDBY  (0x11 << 5)
+#define BME280_REG_CONFIG_FILTER   (0x11 << 3)
+#define BME280_REG_CONFIG_SPI3_EN        (0x1)
+
+#define BME280_REG_ADDR_PRESS             0xF7
+#define BME280_REG_ADDR_PRESS_MSB         0xF7
+#define BME280_REG_ADDR_PRESS_LSB         0xF8
+#define BME280_REG_ADDR_PRESS_XLSB        0xF9
+
+#define BME280_REG_ADDR_TEMP              0xFA
+#define BME280_REG_ADDR_TEMP_MSB          0xFA
+#define BME280_REG_ADDR_TEMP_LSB          0xFB
+#define BME280_REG_ADDR_TEMP_XLSB         0xFC
+
+#define BME280_REG_ADDR_HUM               0xFD
+
+#define BME280_REG_ADDR_RESET             0xE0
+
+#define BME280_REG_CHIPID                 0x60
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Write multiple length data to BME280 sensor over SPI
+ *
+ * @param register address
+ * @param variable length payload
+ * @param length of the payload to write
+ */
+int bme280_writelen(uint8_t addr, uint8_t *payload, uint8_t len);
+
+/**
+ * Read multiple length data from BME280 sensor over SPI
+ *
+ * @param register address
+ * @param variable length payload
+ * @param length of the payload to read
+ */
+int bme280_readlen(uint8_t addr, uint8_t *payload, uint8_t len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BME280_PRIV_H_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad7cdf09/hw/drivers/sensors/bme280/src/bme280_shell.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/src/bme280_shell.c b/hw/drivers/sensors/bme280/src/bme280_shell.c
new file mode 100644
index 0000000..f9d3f46
--- /dev/null
+++ b/hw/drivers/sensors/bme280/src/bme280_shell.c
@@ -0,0 +1,364 @@
+/*
+ * 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 <string.h>
+#include <errno.h>
+#include "sysinit/sysinit.h"
+#include "console/console.h"
+#include "shell/shell.h"
+#include "hal/hal_gpio.h"
+#include "bme280/bme280.h"
+#include "bme280_priv.h"
+
+#if MYNEWT_VAL(BME280_CLI)
+
+static int bme280_shell_cmd(int argc, char **argv);
+
+static struct shell_cmd bme280_shell_cmd_struct = {
+    .sc_cmd = "bme280",
+    .sc_cmd_func = bme280_shell_cmd
+};
+
+static int
+bme280_shell_stol(char *param_val, long min, long max, long *output)
+{
+    char *endptr;
+    long lval;
+
+    lval = strtol(param_val, &endptr, 10); /* Base 10 */
+    if (param_val != '\0' && *endptr == '\0' &&
+        lval >= min && lval <= max) {
+            *output = lval;
+    } else {
+        return EINVAL;
+    }
+
+    return 0;
+}
+
+static int
+bme280_shell_err_too_many_args(char *cmd_name)
+{
+    console_printf("Error: too many arguments for command \"%s\"\n",
+                   cmd_name);
+    return EINVAL;
+}
+
+static int
+bme280_shell_err_unknown_arg(char *cmd_name)
+{
+    console_printf("Error: unknown argument \"%s\"\n",
+                   cmd_name);
+    return EINVAL;
+}
+
+static int
+bme280_shell_err_invalid_arg(char *cmd_name)
+{
+    console_printf("Error: invalid argument \"%s\"\n",
+                   cmd_name);
+    return EINVAL;
+}
+
+static int
+bme280_shell_help(void)
+{
+    console_printf("%s cmd [flags...]\n", bme280_shell_cmd_struct.sc_cmd);
+    console_printf("cmd:\n");
+    console_printf("\tr    [n_samples]\n");
+    console_printf("\tmode [0-sleep | 1-forced | 3-normal]\n");
+    console_printf("\tiir [1-enabled | 0-disabled]");
+    console_printf("\toversample [type 5-temperature | 6-pressure | 8-humidity]\n"
+                   "             [0-none | 1-x1 | 2-x2 | 3-x4 | 4-x8 | 5-x16]\n");
+    console_printf("\treset\n");
+    console_printf("\tchip_id");
+    console_printf("\tdump\n");
+
+    return 0;
+}
+
+static int
+bme280_shell_cmd_read_chipid(int argc, char **argv)
+{
+    int rc;
+    uint8_t chipid;
+
+    rc = bme280_get_chipid(&chipid);
+    if (rc) {
+        goto err;
+    }
+
+    console_printf("CHIP_ID:%02X", chipid);
+
+    return 0;
+err:
+    return rc;
+}
+
+static int
+bme280_shell_cmd_reset(int argc, char **argv)
+{
+    return bme280_reset();
+}
+
+static int
+bme280_shell_cmd_read(int argc, char **argv)
+{
+    uint32_t temp;
+    uint32_t press;
+    uint32_t humid;
+    uint16_t samples = 1;
+    long val;
+    int rc;
+    struct bme280 bme280;
+
+    if (argc > 3) {
+        return bme280_shell_err_too_many_args(argv[1]);
+    }
+
+    /* Check if more than one sample requested */
+    if (argc == 3) {
+        if (bme280_shell_stol(argv[2], 1, UINT16_MAX, &val)) {
+            return bme280_shell_err_invalid_arg(argv[2]);
+        }
+        samples = (uint16_t)val;
+    }
+
+    while(samples--) {
+
+        rc = bme280_get_data(&temp, &press, &humid, &bme280);
+        if (rc != 0) {
+            console_printf("Read failed: %d\n", rc);
+            return rc;
+        }
+        console_printf("temperature: %u\tpressure: %u\thumidity: %u\n",
+                       temp, press, humid);
+    }
+
+    return 0;
+}
+
+static int
+bme280_shell_cmd_oversample(int argc, char **argv)
+{
+    long val;
+    int rc;
+    uint8_t oversample;
+    uint32_t type;
+
+    if (argc > 3) {
+        return bme280_shell_err_too_many_args(argv[1]);
+    }
+
+    /* Display the oversample */
+    if (argc == 3) {
+        if (bme280_shell_stol(argv[2], 4, 8, &val)) {
+            return bme280_shell_err_invalid_arg(argv[2]);
+        }
+        rc = bme280_get_oversampling(val, &oversample);
+        if (rc) {
+            goto err;
+        }
+        console_printf("%u\n", oversample);
+    }
+
+    /* Update the oversampling  */
+    if (argc == 4) {
+        if (bme280_shell_stol(argv[2], 4, 8, &val)) {
+            return bme280_shell_err_invalid_arg(argv[2]);
+        }
+
+        type = val;
+
+        if (bme280_shell_stol(argv[3], 0, 5, &val)) {
+            return bme280_shell_err_invalid_arg(argv[2]);
+        }
+
+        oversample = val;
+
+        rc = bme280_set_oversample(type, oversample);
+        if (rc) {
+            goto err;
+        }
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+static int
+bme280_shell_cmd_iir(int argc, char **argv)
+{
+    uint8_t iir;
+    long val;
+
+    if (argc > 3) {
+        return bme280_shell_err_too_many_args(argv[1]);
+    }
+
+    /* Display if iir enabled */
+    if (argc == 2) {
+        rc = bme280_get_iir(&iir);
+        if (rc) {
+            goto err;
+        }
+        console_printf("IIR: %02X", iir);
+    }
+
+    /* Enable/disable iir*/
+    if (argc == 3) {
+        if (bme280_shell_stol(argv[2], 0, 1, &val)) {
+            return bme280_shell_err_invalid_arg(argv[2]);
+        }
+        rc = bme280_set_iir(val);
+        if (rc) {
+            goto err;
+        }
+    }
+
+    return 0;
+}
+
+static int
+bme280_shell_cmd_dump(int argc, char **argv)
+{
+  uint8_t val;
+
+  if (argc > 3) {
+      return bme280_shell_err_too_many_args(argv[1]);
+  }
+
+  /* Dump all the register values for debug purposes */
+  val = 0;
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_T1, &val, 1));
+  console_printf("0x%02X (DIG_T1): 0x%02X\n", BME280_REG_ADDR_DIG_T1, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_T2, &val, 1));
+  console_printf("0x%02X (DIG_T2):  0x%02X\n", BME280_REG_ADDR_DIG_T2, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_T3, &val, 1));
+  console_printf("0x%02X (DIG_T3):   0x%02X\n", BME280_REG_ADDR_DIG_T3, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_P1, &val, 1));
+  console_printf("0x%02X (DIG_P1): 0x%02X\n", BME280_REG_ADDR_DIG_P1, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_P2, &val, 1));
+  console_printf("0x%02X (DIG_P2):  0x%02X\n", BME280_REG_ADDR_DIG_P2, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_P3, &val, 1));
+  console_printf("0x%02X (DIG_P3):   0x%02X\n", BME280_REG_ADDR_DIG_P3, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_P4, &val, 1));
+  console_printf("0x%02X (DIG_P4): 0x%02X\n", BME280_REG_ADDR_DIG_P4, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_P5, &val, 1));
+  console_printf("0x%02X (DIG_P5):  0x%02X\n", BME280_REG_ADDR_DIG_P5, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_P6, &val, 1));
+  console_printf("0x%02X (DIG_P6):   0x%02X\n", BME280_REG_ADDR_DIG_P6, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_P7, &val, 1));
+  console_printf("0x%02X (DIG_P7): 0x%02X\n", BME280_REG_ADDR_DIG_P7, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_P8, &val, 1));
+  console_printf("0x%02X (DIG_P8):  0x%02X\n", BME280_REG_ADDR_DIG_P8, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_P9, &val, 1));
+  console_printf("0x%02X (DIG_P9):   0x%02X\n", BME280_REG_ADDR_DIG_P9, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_H1, &val, 1));
+  console_printf("0x%02X (DIG_H1): 0x%02X\n", BME280_REG_ADDR_DIG_H1, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_H2, &val, 1));
+  console_printf("0x%02X (DIG_H2):  0x%02X\n", BME280_REG_ADDR_DIG_H2, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_H3, &val, 1));
+  console_printf("0x%02X (DIG_H3):   0x%02X\n", BME280_REG_ADDR_DIG_H3, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_H4, &val, 1));
+  console_printf("0x%02X (DIG_H4): 0x%02X\n", BME280_REG_ADDR_DIG_H4, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_H5, &val, 1));
+  console_printf("0x%02X (DIG_H5):  0x%02X\n", BME280_REG_ADDR_DIG_H5, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_DIG_H6, &val, 1));
+  console_printf("0x%02X (DIG_H6):   0x%02X\n", BME280_REG_ADDR_DIG_H6, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_CHIPID, &val, 1));
+  console_printf("0x%02X (CHIPID):   0x%02X\n", BME280_REG_ADDR_CHIPID, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_VERSION, &val, 1));
+  console_printf("0x%02X (VER):   0x%02X\n", BME280_REG_ADDR_VERSION, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_CTRL_HUM, &val, 1));
+  console_printf("0x%02X (CTRL_HUM):   0x%02X\n", BME280_REG_ADDR_CTRL_HUM, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_STATUS, &val, 1));
+  console_printf("0x%02X (STATUS):   0x%02X\n", BME280_REG_ADDR_STATUS, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_CTRL_MEAS, &val, 1));
+  console_printf("0x%02X (CTRL_MEAS):   0x%02X\n", BME280_REG_ADDR_CTRL_MEAS, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_CONFIG, &val, 1));
+  console_printf("0x%02X (CONFIG):   0x%02X\n", BME280_REG_ADDR_CONFIG, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_PRESS, &val, 1));
+  console_printf("0x%02X (PRESS):   0x%02X\n", BME280_REG_ADDR_PRESS, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_TEMP, &val, 1));
+  console_printf("0x%02X (TEMP):   0x%02X\n", BME280_REG_ADDR_TEMP, val);
+  assert(0 == bme280_readlen(BME280_REG_ADDR_HUM, &val, 1));
+  console_printf("0x%02X (HUM):   0x%02X\n", BME280_REG_ADDR_HUM, val);
+
+  return 0;
+}
+
+static int
+bme280_shell_cmd(int argc, char **argv)
+{
+    if (argc == 1) {
+        return bme280_shell_help();
+    }
+
+    /* Read command (get a new data sample) */
+    if (argc > 1 && strcmp(argv[1], "r") == 0) {
+        return bme280_shell_cmd_read(argc, argv);
+    }
+
+    /* Mode command */
+    if (argc > 1 && strcmp(argv[1], "mode") == 0) {
+        return bme280_shell_cmd_mode(argc, argv);
+    }
+
+    /* IIR */
+    if (argc > 1 && strcmp(argv[1], "iir") == 0) {
+        return bme280_shell_cmd_iir(argc, argv);
+    }
+
+    /* Oversample */
+    if (argc > 1 && strcmp(argv[1], "oversample") == 0) {
+        return bme280_shell_cmd_oversample(argc, argv);
+    }
+
+    /* Reset */
+    if (argc > 1 && strcmp(argv[1], "reset") == 0) {
+        return bme280_shell_cmd_reset(argc, argv);
+    }
+
+    /* Chip ID */
+    if (argc > 1 && strcmp(argv[1], "chipid") == 0) {
+        return bme280_shell_cmd_read_chipid(argc, argv);
+    }
+
+    /* Dump */
+    if (argc > 1 && strcmp(argv[1], "dump") == 0) {
+        return bme280_shell_cmd_dump(argc, argv);
+    }
+
+    return bme280_shell_err_unknown_arg(argv[1]);
+}
+
+int
+bme280_shell_init(void)
+{
+    int rc;
+
+    rc = shell_cmd_register(&bme280_shell_cmd_struct);
+    SYSINIT_PANIC_ASSERT(rc == 0);
+
+    return rc;
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad7cdf09/hw/drivers/sensors/bme280/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/syscfg.yml b/hw/drivers/sensors/bme280/syscfg.yml
new file mode 100644
index 0000000..126ecda
--- /dev/null
+++ b/hw/drivers/sensors/bme280/syscfg.yml
@@ -0,0 +1,38 @@
+# The BSD License (BSD)
+#
+# Copyright (c) 2016 Adafruit Industries
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+syscfg.defs:
+    BME280_SPINUM:
+        description: 'SPI number for the BME280'
+        value: -1
+    BME280_CLI:
+        description: 'Enable shell support for the BME280'
+        value: 0
+    BME280_LOG:
+        description: 'Enable BME280 logging'
+        value: 0
+    BME280_STATS:
+        description: 'Enable BME280 statistics'
+        value: 0
+    BME280_CSPIN:
+        description: 'CS pin for BME280'
+        value : 0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad7cdf09/hw/sensor/src/sensor_shell.c
----------------------------------------------------------------------
diff --git a/hw/sensor/src/sensor_shell.c b/hw/sensor/src/sensor_shell.c
index 481e241..ebe3b1b 100644
--- a/hw/sensor/src/sensor_shell.c
+++ b/hw/sensor/src/sensor_shell.c
@@ -230,7 +230,6 @@ sensor_shell_read_listener(struct sensor *sensor, void *arg, void *data)
     struct sensor_euler_data *sed;
     struct sensor_quat_data *sqd;
     struct sensor_color_data *scd;
-    int8_t *temperature;
     char tmpstr[13];
 
     ctx = (struct sensor_shell_read_ctx *) arg;
@@ -288,8 +287,7 @@ sensor_shell_read_listener(struct sensor *sensor, void *arg, void *data)
     }
 
     if (ctx->type == SENSOR_TYPE_TEMPERATURE) {
-        temperature = (int8_t *) data;
-        console_printf("temprature = %d", *temperature);
+        console_printf("temprature = %d", *(int *)data);
         console_printf("\n");
     }
 
@@ -366,6 +364,16 @@ sensor_shell_read_listener(struct sensor *sensor, void *arg, void *data)
         console_printf("\n\n");
     }
 
+    if (ctx->type == SENSOR_TYPE_PRESSURE) {
+        console_printf("pressure = %d", *(int *)data);
+        console_printf("\n");
+    }
+
+    if (ctx->type == SENSOR_TYPE_RELATIVE_HUMIDITY) {
+        console_printf("relative humidity = %d", *(int *)data);
+        console_printf("\n");
+    }
+
     return (0);
 }
 



[03/43] incubator-mynewt-core git commit: jlink.sh; pass extra jtag command line arguments to JLinkExe.

Posted by an...@apache.org.
jlink.sh; pass extra jtag command line arguments to JLinkExe.


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

Branch: refs/heads/bluetooth5
Commit: 9cec09579fa1c4aa8a799d9f818e10b187242076
Parents: debf64f
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon May 8 13:14:05 2017 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon May 8 13:14:05 2017 -0700

----------------------------------------------------------------------
 hw/scripts/jlink.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9cec0957/hw/scripts/jlink.sh
----------------------------------------------------------------------
diff --git a/hw/scripts/jlink.sh b/hw/scripts/jlink.sh
index 5087ceb..422c4f7 100644
--- a/hw/scripts/jlink.sh
+++ b/hw/scripts/jlink.sh
@@ -53,7 +53,7 @@ jlink_load () {
     # downloading somewhere in the flash. So need to figure out how to tell it
     # not to do that, or report failure if gdb fails to write this file
     #
-    echo "shell sh -c \"trap '' 2; $JLINK_GDB_SERVER -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun &\" " > $GDB_CMD_FILE
+    echo "shell sh -c \"trap '' 2; $JLINK_GDB_SERVER $EXTRA_JTAG_CMD -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun &\" " > $GDB_CMD_FILE
     echo "target remote localhost:3333" >> $GDB_CMD_FILE
     echo "mon reset" >> $GDB_CMD_FILE
     echo "restore $FILE_NAME binary $FLASH_OFFSET" >> $GDB_CMD_FILE
@@ -125,13 +125,13 @@ jlink_debug() {
             # Launch jlink server in a separate command interpreter, to make
             # sure it doesn't get killed by Ctrl-C signal from bash.
             #
-            $COMSPEC "/C start $COMSPEC /C $JLINK_GDB_SERVER -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun"
+            $COMSPEC "/C start $COMSPEC /C $JLINK_GDB_SERVER $EXTRA_JTAG_CMD -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun"
         else
             #
             # Block Ctrl-C from getting passed to jlink server.
             #
             set -m
-            $JLINK_GDB_SERVER -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun > /dev/null &
+            $JLINK_GDB_SERVER $EXTRA_JTAG_CMD -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun > /dev/null &
             set +m
         fi
 
@@ -151,7 +151,7 @@ jlink_debug() {
             rm $GDB_CMD_FILE
 	fi
     else
-        $JLINK_GDB_SERVER -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun
+        $JLINK_GDB_SERVER $EXTRA_JTAG_CMD -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun
     fi
     return 0
 }


[20/43] incubator-mynewt-core git commit: various fixes

Posted by an...@apache.org.
various fixes


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

Branch: refs/heads/bluetooth5
Commit: 56e5f25d8cab939fe97e2246674dcac1c03be5fc
Parents: 5c343f5
Author: Jacob Rosenthal <ja...@gmail.com>
Authored: Wed May 10 21:54:07 2017 -0700
Committer: Jacob Rosenthal <ja...@gmail.com>
Committed: Wed May 10 22:06:15 2017 -0700

----------------------------------------------------------------------
 hw/drivers/sensors/bno055/src/bno055.c     | 10 +++++-----
 hw/drivers/sensors/tcs34725/src/tcs34725.c | 14 +++++++-------
 2 files changed, 12 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/56e5f25d/hw/drivers/sensors/bno055/src/bno055.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055.c b/hw/drivers/sensors/bno055/src/bno055.c
index eac3600..7502c5b 100644
--- a/hw/drivers/sensors/bno055/src/bno055.c
+++ b/hw/drivers/sensors/bno055/src/bno055.c
@@ -141,7 +141,7 @@ bno055_writelen(uint8_t reg, uint8_t *buffer, uint8_t len)
     rc = hal_i2c_master_write(MYNEWT_VAL(BNO055_I2CBUS), &data_struct,
                               OS_TICKS_PER_SEC / 10, 1);
     if (rc) {
-        BNO055_ERR("I2C access failed at address 0x%02X\n", addr);
+        BNO055_ERR("I2C access failed at address 0x%02X\n", data_struct.address);
 #if MYNEWT_VAL(BNO055_STATS)
         STATS_INC(g_bno055stats, errors);
 #endif
@@ -154,7 +154,7 @@ bno055_writelen(uint8_t reg, uint8_t *buffer, uint8_t len)
                               OS_TICKS_PER_SEC / 10, len);
 
     if (rc) {
-        BNO055_ERR("Failed to read from 0x%02X:0x%02X\n", addr, reg);
+        BNO055_ERR("Failed to read from 0x%02X:0x%02X\n", data_struct.address, reg);
 #if MYNEWT_VAL(BNO055_STATS)
         STATS_INC(g_bno055stats, errors);
 #endif
@@ -205,7 +205,7 @@ bno055_read8(uint8_t reg, uint8_t *value)
                              OS_TICKS_PER_SEC / 10, 1);
     *value = payload;
     if (rc) {
-        BNO055_ERR("Failed to read from 0x%02X:0x%02X\n", addr, reg);
+        BNO055_ERR("Failed to read from 0x%02X:0x%02X\n", data_struct.address, reg);
 #if MYNEWT_VAL(BNO055_STATS)
         STATS_INC(g_bno055stats, errors);
 #endif
@@ -246,7 +246,7 @@ bno055_readlen(uint8_t reg, uint8_t *buffer, uint8_t len)
     rc = hal_i2c_master_write(MYNEWT_VAL(BNO055_I2CBUS), &data_struct,
                               OS_TICKS_PER_SEC / 10, 1);
     if (rc) {
-        BNO055_ERR("I2C access failed at address 0x%02X\n", addr);
+        BNO055_ERR("I2C access failed at address 0x%02X\n", data_struct.address);
 #if MYNEWT_VAL(BNO055_STATS)
         STATS_INC(g_bno055stats, errors);
 #endif
@@ -260,7 +260,7 @@ bno055_readlen(uint8_t reg, uint8_t *buffer, uint8_t len)
                              OS_TICKS_PER_SEC / 10, 1);
 
     if (rc) {
-        BNO055_ERR("Failed to read from 0x%02X:0x%02X\n", addr, reg);
+        BNO055_ERR("Failed to read from 0x%02X:0x%02X\n", data_struct.address, reg);
 #if MYNEWT_VAL(BNO055_STATS)
         STATS_INC(g_bno055stats, errors);
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/56e5f25d/hw/drivers/sensors/tcs34725/src/tcs34725.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/tcs34725/src/tcs34725.c b/hw/drivers/sensors/tcs34725/src/tcs34725.c
index e535512..d023d21 100644
--- a/hw/drivers/sensors/tcs34725/src/tcs34725.c
+++ b/hw/drivers/sensors/tcs34725/src/tcs34725.c
@@ -115,7 +115,7 @@ tcs34725_write8(uint8_t reg, uint32_t value)
                               OS_TICKS_PER_SEC / 10, 1);
     if (rc) {
         TCS34725_ERR("Failed to write to 0x%02X:0x%02X with value 0x%02X\n",
-                       addr, reg, value);
+                       data_struct.address, reg, value);
 #if MYNEWT_VAL(TCS34725_STATS)
         STATS_INC(g_tcs34725stats, errors);
 #endif
@@ -149,7 +149,7 @@ tcs34725_read8(uint8_t reg, uint8_t *value)
     rc = hal_i2c_master_write(MYNEWT_VAL(TCS34725_I2CBUS), &data_struct,
                               OS_TICKS_PER_SEC / 10, 1);
     if (rc) {
-        TCS34725_ERR("I2C access failed at address 0x%02X\n", addr);
+        TCS34725_ERR("I2C access failed at address 0x%02X\n", data_struct.address);
 #if MYNEWT_VAL(TCS34725_STATS)
         STATS_INC(g_tcs34725stats, errors);
 #endif
@@ -162,7 +162,7 @@ tcs34725_read8(uint8_t reg, uint8_t *value)
                              OS_TICKS_PER_SEC / 10, 1);
     *value = payload;
     if (rc) {
-        TCS34725_ERR("Failed to read from 0x%02X:0x%02X\n", addr, reg);
+        TCS34725_ERR("Failed to read from 0x%02X:0x%02X\n", data_struct.address, reg);
 #if MYNEWT_VAL(TCS34725_STATS)
         STATS_INC(g_tcs34725stats, errors);
 #endif
@@ -200,7 +200,7 @@ tcs34725_readlen(uint8_t reg, uint8_t *buffer, uint8_t len)
     rc = hal_i2c_master_write(MYNEWT_VAL(TCS34725_I2CBUS), &data_struct,
                               OS_TICKS_PER_SEC / 10, 1);
     if (rc) {
-        TCS34725_ERR("I2C access failed at address 0x%02X\n", addr);
+        TCS34725_ERR("I2C access failed at address 0x%02X\n", data_struct.address);
 #if MYNEWT_VAL(TCS34725_STATS)
         STATS_INC(g_tcs34725stats, errors);
 #endif
@@ -214,7 +214,7 @@ tcs34725_readlen(uint8_t reg, uint8_t *buffer, uint8_t len)
                              OS_TICKS_PER_SEC / 10, 1);
 
     if (rc) {
-        TCS34725_ERR("Failed to read from 0x%02X:0x%02X\n", addr, reg);
+        TCS34725_ERR("Failed to read from 0x%02X:0x%02X\n", data_struct.address, reg);
 #if MYNEWT_VAL(TCS34725_STATS)
         STATS_INC(g_tcs34725stats, errors);
 #endif
@@ -255,7 +255,7 @@ tcs34725_writelen(uint8_t reg, uint8_t *buffer, uint8_t len)
     rc = hal_i2c_master_write(MYNEWT_VAL(TCS34725_I2CBUS), &data_struct,
                               OS_TICKS_PER_SEC / 10, 1);
     if (rc) {
-        TCS34725_ERR("I2C access failed at address 0x%02X\n", addr);
+        TCS34725_ERR("I2C access failed at address 0x%02X\n", data_struct.address);
 #if MYNEWT_VAL(TCS34725_STATS)
         STATS_INC(g_tcs34725stats, errors);
 #endif
@@ -268,7 +268,7 @@ tcs34725_writelen(uint8_t reg, uint8_t *buffer, uint8_t len)
                               OS_TICKS_PER_SEC / 10, len);
 
     if (rc) {
-        TCS34725_ERR("Failed to read from 0x%02X:0x%02X\n", addr, reg);
+        TCS34725_ERR("Failed to read from 0x%02X:0x%02X\n", data_struct.address, reg);
 #if MYNEWT_VAL(TCS34725_STATS)
         STATS_INC(g_tcs34725stats, errors);
 #endif


[14/43] incubator-mynewt-core git commit: This closes pull request #266.

Posted by an...@apache.org.
This closes pull request #266.


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

Branch: refs/heads/bluetooth5
Commit: 4c4ae1c97f88ca7645cc588102eef8213e8caf20
Parents: 21d4cf0 1191e7d
Author: julian <ju...@imgtec.com>
Authored: Wed May 10 11:59:07 2017 +0100
Committer: julian <ju...@imgtec.com>
Committed: Wed May 10 11:59:07 2017 +0100

----------------------------------------------------------------------
 hw/bsp/pic32mz2048_wi-fire/include/bsp/bsp.h | 8 ++++++++
 1 file changed, 8 insertions(+)
----------------------------------------------------------------------



[41/43] incubator-mynewt-core git commit: This closes #269.

Posted by an...@apache.org.
This closes #269.

Merge remote-tracking branch 'ccollins476ad/sim-no-signals'

* ccollins476ad/sim-no-signals:
  MYNEWT-745 Make native sockets nonblocking.
  MYNEWT-745 Sim - deadlock involving system calls


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

Branch: refs/heads/bluetooth5
Commit: dd4baa28ea899c0bfd444551ccba78309f3847df
Parents: b26a78d 71811d4
Author: Christopher Collins <cc...@apache.org>
Authored: Fri May 12 18:39:11 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri May 12 18:39:11 2017 -0700

----------------------------------------------------------------------
 hw/mcu/native/syscfg.yml                   |  21 ++
 kernel/os/src/arch/sim/os_arch_sim.c       | 461 ------------------------
 kernel/os/src/arch/sim/os_arch_sim_gen.c   | 248 +++++++++++++
 kernel/os/src/arch/sim/os_arch_sim_nosig.c | 241 +++++++++++++
 kernel/os/src/arch/sim/os_arch_sim_priv.h  |  29 ++
 kernel/os/src/arch/sim/os_arch_sim_sig.c   | 266 ++++++++++++++
 net/ip/native_sockets/src/native_sock.c    |   6 +
 7 files changed, 811 insertions(+), 461 deletions(-)
----------------------------------------------------------------------



[02/43] incubator-mynewt-core git commit: hw: pic32mz2048efg100: Remove unused variables in hal_gpio

Posted by an...@apache.org.
hw: pic32mz2048efg100: Remove unused variables in hal_gpio

Signed-off-by: Francois Berder <fb...@outlook.fr>


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

Branch: refs/heads/bluetooth5
Commit: 8c999d5d3bb66e922dca9a03222b748577098627
Parents: debf64f
Author: Francois Berder <fb...@outlook.fr>
Authored: Mon May 8 12:23:51 2017 +0200
Committer: Francois Berder <fb...@outlook.fr>
Committed: Mon May 8 12:23:51 2017 +0200

----------------------------------------------------------------------
 hw/mcu/microchip/pic32mz2048efg100/src/hal_gpio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8c999d5d/hw/mcu/microchip/pic32mz2048efg100/src/hal_gpio.c
----------------------------------------------------------------------
diff --git a/hw/mcu/microchip/pic32mz2048efg100/src/hal_gpio.c b/hw/mcu/microchip/pic32mz2048efg100/src/hal_gpio.c
index 1c98a7a..6e82f6e 100644
--- a/hw/mcu/microchip/pic32mz2048efg100/src/hal_gpio.c
+++ b/hw/mcu/microchip/pic32mz2048efg100/src/hal_gpio.c
@@ -136,7 +136,7 @@ static void
 hal_gpio_handle_isr(uint32_t port)
 {
     uint8_t index = 0;
-    static unsigned int i = 0;
+
     for (index = 0; index < HAL_GPIO_MAX_IRQ; ++index) {
         uint32_t mask, val;
 
@@ -377,7 +377,6 @@ hal_gpio_irq_release(int pin)
 void
 hal_gpio_irq_enable(int pin)
 {
-    volatile uint32_t dummy;
     uint32_t port, mask, ctx;
 
     uint8_t index = hal_gpio_find_pin(pin);


[05/43] incubator-mynewt-core git commit: Merge branch 'jlink_extra_cmds' of https://github.com/mkiiskila/incubator-mynewt-core

Posted by an...@apache.org.
Merge branch 'jlink_extra_cmds' of https://github.com/mkiiskila/incubator-mynewt-core


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

Branch: refs/heads/bluetooth5
Commit: cb23f34e9b55de68078c0c2200b268cf536d003b
Parents: 1080d5c 9cec095
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon May 8 18:30:54 2017 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon May 8 18:30:54 2017 -0700

----------------------------------------------------------------------
 hw/scripts/jlink.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cb23f34e/hw/scripts/jlink.sh
----------------------------------------------------------------------
diff --cc hw/scripts/jlink.sh
index 88391b3,422c4f7..e07049b
--- a/hw/scripts/jlink.sh
+++ b/hw/scripts/jlink.sh
@@@ -125,7 -125,7 +125,7 @@@ jlink_debug() 
              # Launch jlink server in a separate command interpreter, to make
              # sure it doesn't get killed by Ctrl-C signal from bash.
              #
-             $COMSPEC /C "start $JLINK_GDB_SERVER -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun"
 -            $COMSPEC "/C start $COMSPEC /C $JLINK_GDB_SERVER $EXTRA_JTAG_CMD -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun"
++            $COMSPEC /C "start $JLINK_GDB_SERVER $EXTRA_JTAG_CMD -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun"
          else
              #
              # Block Ctrl-C from getting passed to jlink server.


[19/43] incubator-mynewt-core git commit: This closes pull request #271.

Posted by an...@apache.org.
This closes pull request #271.


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

Branch: refs/heads/bluetooth5
Commit: 5c343f58cc101d63d1cde78b01a79eb687f22cd7
Parents: 4c4ae1c 1465652
Author: julian <ju...@imgtec.com>
Authored: Wed May 10 13:41:19 2017 +0100
Committer: julian <ju...@imgtec.com>
Committed: Wed May 10 13:41:19 2017 +0100

----------------------------------------------------------------------
 hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c         |  11 +-
 .../pic32mz2048efg100/include/mcu/mips_hal.h    |   6 +
 .../pic32mz2048efg100/include/mcu/pps.h         | 161 +++++++++++++++
 .../microchip/pic32mz2048efg100/src/hal_uart.c  |  44 ++++
 hw/mcu/microchip/pic32mz2048efg100/src/ppc.c    | 207 +++++++++++++++++++
 5 files changed, 427 insertions(+), 2 deletions(-)
----------------------------------------------------------------------



[15/43] incubator-mynewt-core git commit: hw: bsp: pic32mz2048 wi-fire: Fix ifdef to include uart.h

Posted by an...@apache.org.
hw: bsp: pic32mz2048 wi-fire: Fix ifdef to include uart.h

Signed-off-by: Francois Berder <fb...@outlook.fr>


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

Branch: refs/heads/bluetooth5
Commit: 9d7b29d1ffbded0050128c42c812ef914198cced
Parents: 4c4ae1c
Author: Francois Berder <fb...@outlook.fr>
Authored: Tue May 9 11:27:38 2017 +0200
Committer: Francois Berder <fb...@outlook.fr>
Committed: Wed May 10 13:22:56 2017 +0200

----------------------------------------------------------------------
 hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9d7b29d1/hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c b/hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c
index af46cea..17ac864 100644
--- a/hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c
+++ b/hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c
@@ -20,7 +20,8 @@
 #include "hal/hal_bsp.h"
 #include "syscfg/syscfg.h"
 #include "uart/uart.h"
-#if MYNEWT_VAL(UART_0) || MYNEWT_VAL(UART_1)
+#if MYNEWT_VAL(UART_0) || MYNEWT_VAL(UART_1) || MYNEWT_VAL(UART_2) || \
+    MYNEWT_VAL(UART_3) || MYNEWT_VAL(UART_4) || MYNEWT_VAL(UART_5)
 #include "uart_hal/uart_hal.h"
 #endif
 


[38/43] incubator-mynewt-core git commit: MYNEWT-748 SensorAPI: Add BME280 support

Posted by an...@apache.org.
MYNEWT-748 SensorAPI: Add BME280 support

- SensorAPI pressure, temperature and humidity support
- OIC support
- ruuvi_tag_revb2 bsp, create sensor device
- nrf52840pdk bsp, create sensor device
- Add BMP280 sensor device support since BME280 and BMP280 are pin to
  pin compatible


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

Branch: refs/heads/bluetooth5
Commit: 8d98e078c7281265f7f20af1b97042289d2c5a27
Parents: ad7cdf0
Author: Vipul Rahane <vi...@apache.org>
Authored: Thu Apr 27 14:56:20 2017 -0700
Committer: Vipul Rahane <vi...@apache.org>
Committed: Fri May 12 17:08:16 2017 -0700

----------------------------------------------------------------------
 apps/sensors_test/src/main.c                    |   6 ++
 apps/sensors_test/syscfg.yml                    |   2 +-
 hw/bsp/nrf52840pdk/src/hal_bsp.c                |  20 ++++
 hw/bsp/ruuvi_tag_revb2/src/hal_bsp.c            |  31 +++++-
 .../sensors/bme280/include/bme280/bme280.h      |   2 +-
 hw/drivers/sensors/bme280/src/bme280.c          | 105 ++++++++++++++-----
 hw/drivers/sensors/bme280/src/bme280_priv.h     |   4 +-
 hw/drivers/sensors/bme280/src/bme280_shell.c    |  61 ++++++++++-
 hw/sensor/src/sensor_oic.c                      |  29 +++--
 9 files changed, 209 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8d98e078/apps/sensors_test/src/main.c
----------------------------------------------------------------------
diff --git a/apps/sensors_test/src/main.c b/apps/sensors_test/src/main.c
index 152d48e..ce5f4bd 100755
--- a/apps/sensors_test/src/main.c
+++ b/apps/sensors_test/src/main.c
@@ -398,6 +398,8 @@ config_sensor(void)
         goto err;
     }
 
+    memset(&bmecfg, 0, sizeof(bmecfg));
+
     rc = bme280_config((struct bme280 *)dev, &bmecfg);
     if (rc) {
         os_dev_close(dev);
@@ -566,6 +568,10 @@ sensors_dev_shell_init(void)
     bno055_shell_init();
 #endif
 
+#if MYNEWT_VAL(BME280_CLI)
+    bme280_shell_init();
+#endif
+
 }
 
 static void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8d98e078/apps/sensors_test/syscfg.yml
----------------------------------------------------------------------
diff --git a/apps/sensors_test/syscfg.yml b/apps/sensors_test/syscfg.yml
index 8172a62..fe8b2d7 100644
--- a/apps/sensors_test/syscfg.yml
+++ b/apps/sensors_test/syscfg.yml
@@ -44,7 +44,7 @@ syscfg.vals:
     TSL2561_CLI: 0
     BNO055_CLI: 0
     TCS34725_CLI: 0
-    BME280_CLI: 0
+    BME280_CLI: 1
 
     # Setup Sensor BLE OIC GATT Server
     SENSOR_OIC: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8d98e078/hw/bsp/nrf52840pdk/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52840pdk/src/hal_bsp.c b/hw/bsp/nrf52840pdk/src/hal_bsp.c
index bf2dd36..88b42b0 100644
--- a/hw/bsp/nrf52840pdk/src/hal_bsp.c
+++ b/hw/bsp/nrf52840pdk/src/hal_bsp.c
@@ -48,6 +48,9 @@ static struct lsm303dlhc lsm303dlhc;
 #if MYNEWT_VAL(TCS34725_PRESENT)
 #include <tcs34725/tcs34725.h>
 #endif
+#if MYNEWT_VAL(BME280_PRESENT)
+#include <bme280/bme280.h>
+#endif
 
 #if MYNEWT_VAL(LSM303DLHC_PRESENT)
 static struct lsm303dlhc lsm303dlhc;
@@ -65,6 +68,9 @@ static struct tsl2561 tsl2561;
 static struct tcs34725 tcs34725;
 #endif
 
+#if MYNEWT_VAL(BME280_PRESENT)
+static struct bme280 bme280;
+#endif
 
 #if MYNEWT_VAL(UART_0)
 static struct uart_dev os_bsp_uart0;
@@ -198,6 +204,14 @@ color_init(struct os_dev *dev, void *arg)
 }
 #endif
 
+#if MYNEWT_VAL(BME280_PRESENT)
+static int
+press_init(struct os_dev *dev, void *arg)
+{
+    return (0);
+}
+#endif
+
 static void
 sensor_dev_create(void)
 {
@@ -227,6 +241,12 @@ sensor_dev_create(void)
       OS_DEV_INIT_PRIMARY, 0, color_init, NULL);
     assert(rc == 0);
 #endif
+
+#if MYNEWT_VAL(BME280_PRESENT)
+    rc = os_dev_create((struct os_dev *) &bme280, "bme280",
+      OS_DEV_INIT_PRIMARY, 0, press_init, NULL);
+    assert(rc == 0);
+#endif
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8d98e078/hw/bsp/ruuvi_tag_revb2/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/ruuvi_tag_revb2/src/hal_bsp.c b/hw/bsp/ruuvi_tag_revb2/src/hal_bsp.c
index ab960ce..30da796 100644
--- a/hw/bsp/ruuvi_tag_revb2/src/hal_bsp.c
+++ b/hw/bsp/ruuvi_tag_revb2/src/hal_bsp.c
@@ -55,6 +55,9 @@ static struct lsm303dlhc lsm303dlhc;
 #if MYNEWT_VAL(TCS34725_PRESENT)
 #include <tcs34725/tcs34725.h>
 #endif
+#if MYNEWT_VAL(BME280_PRESENT)
+#include <bme280/bme280.h>
+#endif
 
 #if MYNEWT_VAL(LSM303DLHC_PRESENT)
 static struct lsm303dlhc lsm303dlhc;
@@ -72,6 +75,10 @@ static struct tsl2561 tsl2561;
 static struct tcs34725 tcs34725;
 #endif
 
+#if MYNEWT_VAL(BME280_PRESENT)
+static struct bme280 bme280;
+#endif
+
 #if MYNEWT_VAL(UART_0)
 static struct uart_dev os_bsp_uart0;
 static const struct nrf52_uart_cfg os_bsp_uart0_cfg = {
@@ -198,7 +205,15 @@ slinky_light_init(struct os_dev *dev, void *arg)
 
 #if MYNEWT_VAL(TCS34725_PRESENT)
 static int
-slinky_color_init(struct os_dev *dev, void *arg)
+color_init(struct os_dev *dev, void *arg)
+{
+    return (0);
+}
+#endif
+
+#if MYNEWT_VAL(BME280_PRESENT)
+static int
+press_init(struct os_dev *dev, void *arg)
 {
     return (0);
 }
@@ -212,25 +227,31 @@ sensor_dev_create(void)
     (void)rc;
 #if MYNEWT_VAL(LSM303DLHC_PRESENT)
     rc = os_dev_create((struct os_dev *) &lsm303dlhc, "accel0",
-      OS_DEV_INIT_PRIMARY, 0, slinky_accel_init, NULL);
+      OS_DEV_INIT_PRIMARY, 0, accel_init, NULL);
     assert(rc == 0);
 #endif
 
 #if MYNEWT_VAL(BNO055_PRESENT)
     rc = os_dev_create((struct os_dev *) &bno055, "accel1",
-      OS_DEV_INIT_PRIMARY, 0, slinky_accel_init, NULL);
+      OS_DEV_INIT_PRIMARY, 0, accel_init, NULL);
     assert(rc == 0);
 #endif
 
 #if MYNEWT_VAL(TSL2561_PRESENT)
     rc = os_dev_create((struct os_dev *) &tsl2561, "light0",
-      OS_DEV_INIT_PRIMARY, 0, slinky_light_init, NULL);
+      OS_DEV_INIT_PRIMARY, 0, light_init, NULL);
     assert(rc == 0);
 #endif
 
 #if MYNEWT_VAL(TCS34725_PRESENT)
     rc = os_dev_create((struct os_dev *) &tcs34725, "color0",
-      OS_DEV_INIT_PRIMARY, 0, slinky_color_init, NULL);
+      OS_DEV_INIT_PRIMARY, 0, color_init, NULL);
+    assert(rc == 0);
+#endif
+
+#if MYNEWT_VAL(BME280_PRESENT)
+    rc = os_dev_create((struct os_dev *) &bme280, "bme280",
+      OS_DEV_INIT_PRIMARY, 0, press_init, NULL);
     assert(rc == 0);
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8d98e078/hw/drivers/sensors/bme280/include/bme280/bme280.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/include/bme280/bme280.h b/hw/drivers/sensors/bme280/include/bme280/bme280.h
index f5ea131..4ef5d78 100644
--- a/hw/drivers/sensors/bme280/include/bme280/bme280.h
+++ b/hw/drivers/sensors/bme280/include/bme280/bme280.h
@@ -167,7 +167,7 @@ int bme280_get_pressure(uint32_t *press);
  *
  * @return 0 on success, and non-zero error code on failure
  */
-int bme280_get_humidity(uint32_t *humidity);
+int bme280_get_humidity(uint32_t *humid);
 
 /**
  * Sets the sampling rate

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8d98e078/hw/drivers/sensors/bme280/src/bme280.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/src/bme280.c b/hw/drivers/sensors/bme280/src/bme280.c
index ca5ee0a..e31cffc 100644
--- a/hw/drivers/sensors/bme280/src/bme280.c
+++ b/hw/drivers/sensors/bme280/src/bme280.c
@@ -195,8 +195,8 @@ bme280_sensor_read(struct sensor *sensor, sensor_type_t type,
     uint32_t humid;
     int rc;
 
-    if (!(type & SENSOR_TYPE_PRESSURE)    ||
-        !(type & SENSOR_TYPE_TEMPERATURE) ||
+    if (!(type & SENSOR_TYPE_PRESSURE)    &&
+        !(type & SENSOR_TYPE_TEMPERATURE) &&
         !(type & SENSOR_TYPE_RELATIVE_HUMIDITY)) {
         rc = SYS_EINVAL;
         goto err;
@@ -289,26 +289,74 @@ int
 bme280_config(struct bme280 *bme280, struct bme280_cfg *cfg)
 {
     int rc;
+    uint8_t id;
 
-    rc = bme280_set_iir(cfg->bc_iir);
+    /* Check if we can read the chip address */
+    rc = bme280_get_chipid(&id);
+    if (rc) {
+        goto err;
+    }
 
-    rc |= bme280_set_mode(cfg->bc_mode);
+    if (id != BME280_CHIPID && id != BMP280_CHIPID) {
+        os_time_delay((OS_TICKS_PER_SEC * 100)/1000 + 1);
 
-    rc |= bme280_set_oversample(cfg->bc_boc[0].boc_type,
-                                cfg->bc_boc[0].boc_oversample);
+        rc = bme280_get_chipid(&id);
+        if (rc) {
+            goto err;
+        }
 
-    rc |= bme280_set_oversample(cfg->bc_boc[1].boc_type,
-                                cfg->bc_boc[1].boc_oversample);
+        if(id != BME280_CHIPID && id != BMP280_CHIPID) {
+            rc = SYS_EINVAL;
+            goto err;
+        }
+    }
 
-    rc |= bme280_set_oversample(cfg->bc_boc[2].boc_type,
-                                cfg->bc_boc[2].boc_oversample);
+    rc = bme280_set_iir(cfg->bc_iir);
+    if (rc) {
+        goto err;
+    }
 
+    bme280->cfg.bc_iir = cfg->bc_iir;
+
+    rc = bme280_set_mode(cfg->bc_mode);
     if (rc) {
         goto err;
     }
 
-    /* Overwrite the configuration data. */
-    memcpy(&bme280->cfg, cfg, sizeof(*cfg));
+    bme280->cfg.bc_mode = cfg->bc_mode;
+
+    if (!cfg->bc_boc[0].boc_type) {
+        rc = bme280_set_oversample(cfg->bc_boc[0].boc_type,
+                                   cfg->bc_boc[0].boc_oversample);
+        if (rc) {
+            goto err;
+        }
+    }
+
+    bme280->cfg.bc_boc[0].boc_type = cfg->bc_boc[0].boc_type;
+    bme280->cfg.bc_boc[0].boc_oversample = cfg->bc_boc[0].boc_oversample;
+
+    if (!cfg->bc_boc[1].boc_type) {
+        rc = bme280_set_oversample(cfg->bc_boc[1].boc_type,
+                                   cfg->bc_boc[1].boc_oversample);
+        if (rc) {
+            goto err;
+        }
+    }
+
+    bme280->cfg.bc_boc[1].boc_type = cfg->bc_boc[1].boc_type;
+    bme280->cfg.bc_boc[1].boc_oversample = cfg->bc_boc[1].boc_oversample;
+
+    if (!cfg->bc_boc[2].boc_type) {
+        rc = bme280_set_oversample(cfg->bc_boc[2].boc_type,
+                                   cfg->bc_boc[2].boc_oversample);
+        if (rc) {
+            goto err;
+        }
+    }
+
+    bme280->cfg.bc_boc[2].boc_type = cfg->bc_boc[2].boc_type;
+    bme280->cfg.bc_boc[2].boc_oversample = cfg->bc_boc[2].boc_oversample;
 
 err:
     return (rc);
@@ -327,36 +375,35 @@ int
 bme280_readlen(uint8_t addr, uint8_t *payload, uint8_t len)
 {
     int i;
+    uint16_t retval;
     int rc;
-    uint8_t txdata;
-    uint8_t rxdata;
+
+    rc = 0;
 
     /* Select the device */
     hal_gpio_write(MYNEWT_VAL(BME280_CSPIN), 0);
 
     /* Send the address */
-    rc = hal_spi_tx_val(MYNEWT_VAL(BME280_SPINUM), addr | BME280_SPI_READ_CMD_BIT);
-    if (rc) {
+    retval = hal_spi_tx_val(MYNEWT_VAL(BME280_SPINUM),
+                            addr | BME280_SPI_READ_CMD_BIT);
+    if (retval == 0xFFFF) {
+        rc = SYS_EINVAL;
         goto err;
     }
 
-    txdata = 0;
-
     for (i = 0; i < len; i++) {
         /* Read data */
-        rc = hal_spi_txrx(MYNEWT_VAL(BME280_SPINUM), &txdata, &rxdata, 1);
-        if (rc) {
+        retval = hal_spi_tx_val(MYNEWT_VAL(BME280_SPINUM), 0);
+        if (retval == 0xFFFF) {
+            rc = SYS_EINVAL;
             goto err;
         }
-
-        payload[i] = rxdata;
+        payload[i] = retval;
     }
 
+err:
     /* De-select the device */
     hal_gpio_write(MYNEWT_VAL(BME280_CSPIN), 1);
-
-    return 0;
-err:
     return rc;
 }
 
@@ -380,14 +427,16 @@ bme280_writelen(uint8_t addr, uint8_t *payload, uint8_t len)
 
     /* Send the address */
     rc = hal_spi_tx_val(MYNEWT_VAL(BME280_SPINUM), addr | BME280_SPI_READ_CMD_BIT);
-    if (rc) {
+    if (rc == 0xFFFF) {
+        rc = SYS_EINVAL;
         goto err;
     }
 
     for (i = 0; i < len; i++) {
         /* Read data */
         rc = hal_spi_tx_val(MYNEWT_VAL(BME280_SPINUM), payload[i]);
-        if (rc) {
+        if (rc == 0xFFFF) {
+            rc = SYS_EINVAL;
             goto err;
         }
     }
@@ -702,7 +751,7 @@ bme280_get_chipid(uint8_t *chipid)
     int rc;
     uint8_t tmp;
 
-    rc = bme280_readlen(BME280_REG_ADDR_PRESS, &tmp, 1);
+    rc = bme280_readlen(BME280_REG_ADDR_CHIPID, &tmp, 1);
     if (rc) {
         goto err;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8d98e078/hw/drivers/sensors/bme280/src/bme280_priv.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/src/bme280_priv.h b/hw/drivers/sensors/bme280/src/bme280_priv.h
index 1c93aeb..23d0aaf 100644
--- a/hw/drivers/sensors/bme280/src/bme280_priv.h
+++ b/hw/drivers/sensors/bme280/src/bme280_priv.h
@@ -79,7 +79,9 @@
 
 #define BME280_REG_ADDR_RESET             0xE0
 
-#define BME280_REG_CHIPID                 0x60
+#define BME280_CHIPID                     0x60
+
+#define BMP280_CHIPID                     0x58
 
 #ifdef __cplusplus
 extern "C" {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8d98e078/hw/drivers/sensors/bme280/src/bme280_shell.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/src/bme280_shell.c b/hw/drivers/sensors/bme280/src/bme280_shell.c
index f9d3f46..78f5d2e 100644
--- a/hw/drivers/sensors/bme280/src/bme280_shell.c
+++ b/hw/drivers/sensors/bme280/src/bme280_shell.c
@@ -126,7 +126,6 @@ bme280_shell_cmd_read(int argc, char **argv)
     uint16_t samples = 1;
     long val;
     int rc;
-    struct bme280 bme280;
 
     if (argc > 3) {
         return bme280_shell_err_too_many_args(argv[1]);
@@ -142,13 +141,27 @@ bme280_shell_cmd_read(int argc, char **argv)
 
     while(samples--) {
 
-        rc = bme280_get_data(&temp, &press, &humid, &bme280);
-        if (rc != 0) {
+        rc = bme280_get_pressure(&press);
+        if (rc) {
+            console_printf("Read failed: %d\n", rc);
+            return rc;
+        }
+
+        rc = bme280_get_temperature(&temp);
+        if (rc) {
+            console_printf("Read failed: %d\n", rc);
+            return rc;
+        }
+
+        rc = bme280_get_humidity(&humid);
+        if (rc) {
             console_printf("Read failed: %d\n", rc);
             return rc;
         }
+
         console_printf("temperature: %u\tpressure: %u\thumidity: %u\n",
-                       temp, press, humid);
+                       (unsigned int)temp, (unsigned int)press,
+                       (unsigned int)humid);
     }
 
     return 0;
@@ -171,7 +184,7 @@ bme280_shell_cmd_oversample(int argc, char **argv)
         if (bme280_shell_stol(argv[2], 4, 8, &val)) {
             return bme280_shell_err_invalid_arg(argv[2]);
         }
-        rc = bme280_get_oversampling(val, &oversample);
+        rc = bme280_get_oversample(val, &oversample);
         if (rc) {
             goto err;
         }
@@ -204,10 +217,46 @@ err:
 }
 
 static int
+bme280_shell_cmd_mode(int argc, char **argv)
+{
+    uint8_t mode;
+    long val;
+    int rc;
+
+    if (argc > 3) {
+        return bme280_shell_err_too_many_args(argv[1]);
+    }
+
+    if (argc == 2) {
+        rc = bme280_get_mode(&mode);
+        if (rc) {
+            goto err;
+        }
+        console_printf("mode: %u", mode);
+    }
+
+    /* Chaneg mode */
+    if (argc == 3) {
+        if (bme280_shell_stol(argv[2], 0, 1, &val)) {
+            return bme280_shell_err_invalid_arg(argv[2]);
+        }
+        rc = bme280_set_mode(val);
+        if (rc) {
+            goto err;
+        }
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+static int
 bme280_shell_cmd_iir(int argc, char **argv)
 {
     uint8_t iir;
     long val;
+    int rc;
 
     if (argc > 3) {
         return bme280_shell_err_too_many_args(argv[1]);
@@ -234,6 +283,8 @@ bme280_shell_cmd_iir(int argc, char **argv)
     }
 
     return 0;
+err:
+    return rc;
 }
 
 static int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8d98e078/hw/sensor/src/sensor_oic.c
----------------------------------------------------------------------
diff --git a/hw/sensor/src/sensor_oic.c b/hw/sensor/src/sensor_oic.c
index de9e65a..879da5d 100644
--- a/hw/sensor/src/sensor_oic.c
+++ b/hw/sensor/src/sensor_oic.c
@@ -134,17 +134,19 @@ sensor_oic_encode(struct sensor* sensor, void *arg, void *databuf)
             oc_rep_set_double(root, ambient_temp, *(double *)databuf);
             break;
 
-#if 0
         /* Pressure sensor supported */
-        SENSOR_TYPE_PRESSURE:
-            oc_rep_set_double(root, pressure, (double *)databuf);
-
+        case SENSOR_TYPE_PRESSURE:
+            oc_rep_set_uint(root, pressure, *(uint32_t *)databuf);
+            break;
+#if 0
         /* Proximity sensor supported */
         SENSOR_TYPE_PROXIMITY:
-
-        /* Relative humidity supported */
-        SENSOR_TYPE_RELATIVE_HUMIDITY:
 #endif
+        /* Relative humidity supported */
+        case SENSOR_TYPE_RELATIVE_HUMIDITY:
+            oc_rep_set_uint(root, humidity, *(uint32_t *)databuf);
+            break;
+
         /* Rotation vector (quaternion) supported */
         case SENSOR_TYPE_ROTATION_VECTOR:
             if (((struct sensor_quat_data *)(databuf))->sqd_x_is_valid) {
@@ -457,13 +459,20 @@ sensor_oic_get_data(oc_request_t *request, oc_interface_mask_t interface)
     int rc;
     struct sensor *sensor;
     struct sensor_listener listener;
-    char devname[COAP_MAX_URI] = {0};
+    char *devname;
     char *typename;
     sensor_type_t type;
+    char tmpstr[COAP_MAX_URI] = {0};
+    const char s[2] = "/";
 
-    memcpy(devname, (char *)&(request->resource->uri.os_str[1]),
+    memcpy(tmpstr, (char *)&(request->resource->uri.os_str[1]),
            request->resource->uri.os_sz - 1);
 
+    /* Parse the sensor device name from the uri  */
+    devname = strtok(tmpstr, s);
+
+    typename = strtok(NULL, s);
+
     /* Look up sensor by name */
     sensor = sensor_mgr_find_next_bydevname(devname, NULL);
     if (!sensor) {
@@ -563,7 +572,7 @@ sensor_oic_init(void)
                 }
 
                 memset(tmpstr, 0, sizeof(tmpstr));
-                snprintf(tmpstr, sizeof(tmpstr), "/%s", sensor->s_dev->od_name);
+                snprintf(tmpstr, sizeof(tmpstr), "/%s/%s", sensor->s_dev->od_name, typename);
 
                 res = oc_new_resource(tmpstr, 1, 0);
 


[30/43] incubator-mynewt-core git commit: This closes #276

Posted by an...@apache.org.
This closes #276


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

Branch: refs/heads/bluetooth5
Commit: d96b601572271c90a6031529b47a667c7c5fc8d0
Parents: fe9bf2c ef1b67f
Author: Łukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu May 11 19:19:27 2017 +0200
Committer: Łukasz Rymanowski <lu...@codecoup.pl>
Committed: Thu May 11 19:19:27 2017 +0200

----------------------------------------------------------------------
 apps/bletiny/src/main.c                 | 4 ----
 apps/bletiny/src/misc.c                 | 2 +-
 net/nimble/controller/src/ble_ll_scan.c | 2 +-
 net/nimble/host/src/ble_gap.c           | 4 ++--
 4 files changed, 4 insertions(+), 8 deletions(-)
----------------------------------------------------------------------



[32/43] incubator-mynewt-core git commit: This closes #275

Posted by an...@apache.org.
This closes #275

Merge remote-tracking branch 'jacobrosenthal/semis'

* jacobrosenthal/semis:
  fix double semicolons


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

Branch: refs/heads/bluetooth5
Commit: 5ccaebb116e09a3f4e3acc0ebd3c972ae59a46de
Parents: d96b601 4e06eb5
Author: Vipul Rahane <vi...@apache.org>
Authored: Thu May 11 11:35:38 2017 -0700
Committer: Vipul Rahane <vi...@apache.org>
Committed: Thu May 11 11:39:01 2017 -0700

----------------------------------------------------------------------
 apps/sensors_test/src/main.c      | 2 +-
 hw/mcu/nxp/MK64F12/src/hal_uart.c | 2 +-
 net/nimble/host/src/ble_sm.c      | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------



[43/43] incubator-mynewt-core git commit: This closes #282.

Posted by an...@apache.org.
This closes #282.

Merge branch 'bluetooth5_master' of https://github.com/sjanc/incubator-mynewt-core into bluetooth5


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

Branch: refs/heads/bluetooth5
Commit: 2446dcb642ac8276848058e5c1a7ca01a6766785
Parents: 958bce0 c6003a4
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Wed May 17 11:54:41 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Wed May 17 11:54:41 2017 +0200

----------------------------------------------------------------------
 apps/bletiny/src/main.c                         |    4 -
 apps/bletiny/src/misc.c                         |    2 +-
 apps/sensors_test/pkg.yml                       |    1 +
 apps/sensors_test/src/main.c                    |   40 +-
 apps/sensors_test/syscfg.yml                    |    4 +
 hw/bsp/nrf52840pdk/src/hal_bsp.c                |   20 +
 hw/bsp/nrf52dk/src/hal_bsp.c                    |   12 +
 hw/bsp/pic32mz2048_wi-fire/include/bsp/bsp.h    |    8 +
 hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c        |   12 +
 hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c         |   11 +-
 hw/bsp/ruuvi_tag_revb2/src/hal_bsp.c            |   33 +-
 .../sensors/bme280/include/bme280/bme280.h      |  259 ++++
 hw/drivers/sensors/bme280/pkg.yml               |   32 +
 hw/drivers/sensors/bme280/src/bme280.c          | 1360 ++++++++++++++++++
 hw/drivers/sensors/bme280/src/bme280_priv.h     |  111 ++
 hw/drivers/sensors/bme280/src/bme280_shell.c    |  414 ++++++
 hw/drivers/sensors/bme280/syscfg.yml            |   41 +
 .../sensors/bno055/include/bno055/bno055.h      |    2 +-
 hw/drivers/sensors/bno055/src/bno055.c          |   42 +-
 hw/drivers/sensors/tcs34725/src/tcs34725.c      |   14 +-
 .../pic32mz2048efg100/include/mcu/mips_hal.h    |    6 +
 .../pic32mz2048efg100/include/mcu/pps.h         |  161 +++
 .../microchip/pic32mz2048efg100/src/hal_gpio.c  |    3 +-
 .../microchip/pic32mz2048efg100/src/hal_uart.c  |   44 +
 hw/mcu/microchip/pic32mz2048efg100/src/ppc.c    |  207 +++
 hw/mcu/native/syscfg.yml                        |   21 +
 hw/mcu/nordic/nrf51xxx/src/hal_spi.c            |    2 +-
 hw/mcu/nxp/MK64F12/src/hal_uart.c               |    2 +-
 hw/scripts/jlink.sh                             |   10 +-
 hw/scripts/openocd.sh                           |    6 +-
 hw/sensor/include/sensor/humidity.h             |   45 +
 hw/sensor/include/sensor/pressure.h             |   45 +
 hw/sensor/include/sensor/temperature.h          |   45 +
 hw/sensor/src/sensor_oic.c                      |   54 +-
 hw/sensor/src/sensor_shell.c                    |   35 +-
 hw/sensor/syscfg.yml                            |    8 +
 kernel/os/src/arch/sim/os_arch_sim.c            |  461 ------
 kernel/os/src/arch/sim/os_arch_sim_gen.c        |  248 ++++
 kernel/os/src/arch/sim/os_arch_sim_nosig.c      |  241 ++++
 kernel/os/src/arch/sim/os_arch_sim_priv.h       |   29 +
 kernel/os/src/arch/sim/os_arch_sim_sig.c        |  266 ++++
 net/ip/native_sockets/src/native_sock.c         |    6 +
 .../controller/include/controller/ble_ll_ctrl.h |    2 +-
 net/nimble/controller/src/ble_ll_conn_hci.c     |    4 +-
 net/nimble/controller/src/ble_ll_ctrl.c         |   10 +-
 net/nimble/controller/src/ble_ll_scan.c         |    2 +-
 net/nimble/controller/src/ble_ll_sched.c        |    9 +-
 net/nimble/controller/syscfg.yml                |   10 +
 net/nimble/host/src/ble_gap.c                   |    4 +-
 net/nimble/host/src/ble_sm.c                    |    2 +-
 50 files changed, 3872 insertions(+), 538 deletions(-)
----------------------------------------------------------------------



[18/43] incubator-mynewt-core git commit: hw: mcu: pic32mz2048efg100: Add Peripheral Pin Select wrapper

Posted by an...@apache.org.
hw: mcu: pic32mz2048efg100: Add Peripheral Pin Select wrapper

This wrapper make it easier to configure pins as peripheral
input or output.

Signed-off-by: Francois Berder <fb...@outlook.fr>


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

Branch: refs/heads/bluetooth5
Commit: 2bdc9c138b3398517bfee169ed563630583a3beb
Parents: 9d7b29d
Author: Francois Berder <fb...@outlook.fr>
Authored: Tue May 9 11:31:28 2017 +0200
Committer: Francois Berder <fb...@outlook.fr>
Committed: Wed May 10 13:54:43 2017 +0200

----------------------------------------------------------------------
 .../pic32mz2048efg100/include/mcu/pps.h         | 161 +++++++++++++++
 hw/mcu/microchip/pic32mz2048efg100/src/ppc.c    | 207 +++++++++++++++++++
 2 files changed, 368 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2bdc9c13/hw/mcu/microchip/pic32mz2048efg100/include/mcu/pps.h
----------------------------------------------------------------------
diff --git a/hw/mcu/microchip/pic32mz2048efg100/include/mcu/pps.h b/hw/mcu/microchip/pic32mz2048efg100/include/mcu/pps.h
new file mode 100644
index 0000000..84d4fda
--- /dev/null
+++ b/hw/mcu/microchip/pic32mz2048efg100/include/mcu/pps.h
@@ -0,0 +1,161 @@
+/**
+ * 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.
+ */
+
+/* This file defines the Periphal Pin Select module within this MCU */
+
+#ifndef __MCU_PPS_H__
+#define __MCU_PPS_H__
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NO_CONNECT      (0)
+
+/* Input */
+#define INT3_IN_FUNC           (0)
+#define T2CK_IN_FUNC           (1)
+#define T6CK_IN_FUNC           (2)
+#define IC3_IN_FUNC            (3)
+#define IC7_IN_FUNC            (4)
+#define U1RX_IN_FUNC           (5)
+#define U2CTS_IN_FUNC          (6)
+#define U5RX_IN_FUNC           (7)
+#define U6CTS_IN_FUNC          (8)
+#define SDI1_IN_FUNC           (9)
+#define SDI3_IN_FUNC           (10)
+#define SDI5_IN_FUNC           (11)
+#define SS6_IN_FUNC            (12)
+#define REFCLKI1_IN_FUNC       (13)
+
+#define INT4_IN_FUNC            (16 + 0)
+#define T5CK_IN_FUNC            (16 + 1)
+#define T7CK_IN_FUNC            (16 + 2)
+#define IC4_IN_FUNC             (16 + 3)
+#define IC8_IN_FUNC             (16 + 4)
+#define U3RX_IN_FUNC            (16 + 5)
+#define U4CTS_IN_FUNC           (16 + 6)
+#define SDI2_IN_FUNC            (16 + 7)
+#define SDI4_IN_FUNC            (16 + 8)
+#define REFCLKI4_IN_FUNC        (16 + 10)
+
+#define INT2_IN_FUNC            (32 + 0)
+#define T3CK_IN_FUNC            (32 + 1)
+#define T8CK_IN_FUNC            (32 + 2)
+#define IC2_IN_FUNC             (32 + 3)
+#define IC5_IN_FUNC             (32 + 4)
+#define IC9_IN_FUNC             (32 + 5)
+#define U1CTS_IN_FUNC           (32 + 6)
+#define U2RX_IN_FUNC            (32 + 7)
+#define U5CTS_IN_FUNC           (32 + 8)
+#define SS1_IN_FUNC             (32 + 9)
+#define SS3_IN_FUNC             (32 + 10)
+#define SS4_IN_FUNC             (32 + 11)
+#define SS5_IN_FUNC             (32 + 12)
+
+#define INT1_IN_FUNC            (48 + 0)
+#define T4CK_IN_FUNC            (48 + 1)
+#define T9CK_IN_FUNC            (48 + 2)
+#define IC1_IN_FUNC             (48 + 3)
+#define IC6_IN_FUNC             (48 + 4)
+#define U3CTS_IN_FUNC           (48 + 5)
+#define U4RX_IN_FUNC            (48 + 6)
+#define U6RX_IN_FUNC            (48 + 7)
+#define SS2_IN_FUNC             (48 + 8)
+#define SDI6_IN_FUNC            (48 + 9)
+#define OCFA_IN_FUNC            (48 + 10)
+#define REFCLKI3_IN_FUNC        (48 + 11)
+
+
+/* Output */
+#define U3TX_OUT_FUNC           (0b0001)
+#define U4RTS_OUT_FUNC          (0b0010)
+#define SDO1_OUT_FUNC           (0b0101)
+#define SDO2_OUT_FUNC           (0b0110)
+#define SDO3_OUT_FUNC           (0b0111)
+#define SDO5_OUT_FUNC           (0b1001)
+#define SS6_OUT_FUNC            (0b1010)
+#define OC3_OUT_FUNC            (0b1011)
+#define OC6_OUT_FUNC            (0b1100)
+#define REFCLKO4_OUT_FUNC       (0b1101)
+#define C2OUT_OUT_FUNC          (0b1110)
+
+#define U1TX_OUT_FUNC           (0b0001)
+#define U2RTS_OUT_FUNC          (0b0010)
+#define U5TX_OUT_FUNC           (0b0011)
+#define U6RTS_OUT_FUNC          (0b0100)
+#define SDO1_OUT_FUNC           (0b0101)
+#define SDO2_OUT_FUNC           (0b0110)
+#define SDO3_OUT_FUNC           (0b0111)
+#define SDO4_OUT_FUNC           (0b1000)
+#define SDO5_OUT_FUNC           (0b1001)
+#define OC4_OUT_FUNC            (0b1011)
+#define OC7_OUT_FUNC            (0b1100)
+#define REFCLKO1_OUT_FUNC       (0b1111)
+
+#define U3RTS_OUT_FUNC          (0b0001)
+#define U4TX_OUT_FUNC           (0b0010)
+#define U6TX_OUT_FUNC           (0b0100)
+#define SS1_OUT_FUNC            (0b0101)
+#define SS3_OUT_FUNC            (0b0111)
+#define SS4_OUT_FUNC            (0b1000)
+#define SS5_OUT_FUNC            (0b1001)
+#define SDO6_OUT_FUNC           (0b1010)
+#define OC5_OUT_FUNC            (0b1011)
+#define OC8_OUT_FUNC            (0b1100)
+#define C1OUT_OUT_FUNC          (0b1110)
+#define REFCLKO3_OUT_FUNC       (0b1111)
+
+#define U1RTS_OUT_FUNC          (0b0001)
+#define U2TX_OUT_FUNC           (0b0010)
+#define U5RTS_OUT_FUNC          (0b0011)
+#define U6TX_OUT_FUNC           (0b0100)
+#define SS2_OUT_FUNC            (0b0110)
+#define SDO4_OUT_FUNC           (0b1000)
+#define SDO6_OUT_FUNC           (0b1010)
+#define OC2_OUT_FUNC            (0b1011)
+#define OC1_OUT_FUNC            (0b1100)
+#define OC9_OUT_FUNC            (0b1101)
+
+
+/**
+ * @brief Configure pin as a peripheral output
+ *
+ * @param pin
+ * @param func
+ * @return 0 if successful, -1 otherwise
+ */
+int pps_configure_output(uint8_t pin, uint8_t func);
+
+/**
+ * @brief Configure pin as a peripheral input
+ *
+ * @param pin
+ * @param func
+ * @return 0 if successful, -1 otherwise
+ */
+int pps_configure_input(uint8_t pin, uint8_t func);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __MCU_PPS_H__ */
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2bdc9c13/hw/mcu/microchip/pic32mz2048efg100/src/ppc.c
----------------------------------------------------------------------
diff --git a/hw/mcu/microchip/pic32mz2048efg100/src/ppc.c b/hw/mcu/microchip/pic32mz2048efg100/src/ppc.c
new file mode 100644
index 0000000..7fd0e24
--- /dev/null
+++ b/hw/mcu/microchip/pic32mz2048efg100/src/ppc.c
@@ -0,0 +1,207 @@
+/**
+ * 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 <xc.h>
+#include "mcu/mcu.h"
+#include "mcu/pps.h"
+
+#define MCU_GPIO_UNDEF                  (0xFF)
+#define PPS_BASE_ADDRESS                (0xBF801500)
+#define PPS_PORT_SPACING                (0x40)
+
+static volatile uint32_t *input_regs[4][16] = {
+    {
+        &INT3R,
+        &T2CKR,
+        &T6CKR,
+        &IC3R,
+        &IC7R,
+        &U1RXR,
+        &U2CTSR,
+        &U5RXR,
+        &U6CTSR,
+        &SDI1R,
+        &SDI3R,
+        &SDI5R,
+        &SS6R,
+        &REFCLKI1R
+    },
+    {
+        &INT4R,
+        &T5CKR,
+        &T7CKR,
+        &IC4R,
+        &IC8R,
+        &U3RXR,
+        &U4CTSR,
+        &SDI2R,
+        &SDI4R,
+        NULL,
+        &REFCLKI4R
+    },
+    {
+        &INT2R,
+        &T3CKR,
+        &T8CKR,
+        &IC2R,
+        &IC5R,
+        &IC9R,
+        &U1CTSR,
+        &SS1R,
+        &SS3R,
+        &SS4R,
+        &SS5R,
+        NULL
+    },
+    {
+        &INT1R,
+        &T4CKR,
+        &T9CKR,
+        &IC1R,
+        &IC6R,
+        &U3CTSR,
+        &U4RXR,
+        &U6RXR,
+        &SS2R,
+        &SDI6R,
+        &OCFAR,
+        &REFCLKI3R
+    }
+};
+
+static const uint8_t output_pins[4][16] = {
+    {
+        MCU_GPIO_PORTD(2),
+        MCU_GPIO_PORTG(8),
+        MCU_GPIO_PORTF(4),
+        MCU_GPIO_PORTD(10),
+        MCU_GPIO_PORTF(1),
+        MCU_GPIO_PORTB(9),
+        MCU_GPIO_PORTB(10),
+        MCU_GPIO_PORTC(14),
+        MCU_GPIO_PORTB(5),
+        MCU_GPIO_UNDEF,
+        MCU_GPIO_PORTC(1),
+        MCU_GPIO_PORTD(14),
+        MCU_GPIO_PORTG(1),
+        MCU_GPIO_PORTA(14),
+        MCU_GPIO_UNDEF,
+        MCU_GPIO_UNDEF
+    },
+    {
+        MCU_GPIO_PORTD(3),
+        MCU_GPIO_PORTG(7),
+        MCU_GPIO_PORTF(5),
+        MCU_GPIO_PORTD(11),
+        MCU_GPIO_PORTF(0),
+        MCU_GPIO_PORTB(1),
+        MCU_GPIO_PORTE(5),
+        MCU_GPIO_PORTC(13),
+        MCU_GPIO_PORTB(3),
+        MCU_GPIO_UNDEF,
+        MCU_GPIO_PORTC(4),
+        MCU_GPIO_PORTD(15),
+        MCU_GPIO_PORTG(0),
+        MCU_GPIO_PORTA(15),
+        MCU_GPIO_UNDEF,
+        MCU_GPIO_UNDEF
+    },
+    {
+        MCU_GPIO_PORTD(9),
+        MCU_GPIO_PORTG(6),
+        MCU_GPIO_PORTB(8),
+        MCU_GPIO_PORTB(15),
+        MCU_GPIO_PORTD(4),
+        MCU_GPIO_PORTB(0),
+        MCU_GPIO_PORTE(3),
+        MCU_GPIO_PORTB(7),
+        MCU_GPIO_UNDEF,
+        MCU_GPIO_PORTF(12),
+        MCU_GPIO_PORTD(12),
+        MCU_GPIO_PORTF(8),
+        MCU_GPIO_PORTC(3),
+        MCU_GPIO_PORTE(9),
+        MCU_GPIO_UNDEF,
+        MCU_GPIO_UNDEF
+    },
+    {
+        MCU_GPIO_PORTD(1),
+        MCU_GPIO_PORTG(9),
+        MCU_GPIO_PORTB(14),
+        MCU_GPIO_PORTD(0),
+        MCU_GPIO_UNDEF,
+        MCU_GPIO_PORTB(6),
+        MCU_GPIO_PORTD(5),
+        MCU_GPIO_PORTB(2),
+        MCU_GPIO_PORTF(3),
+        MCU_GPIO_PORTF(13),
+        MCU_GPIO_UNDEF,
+        MCU_GPIO_PORTF(2),
+        MCU_GPIO_PORTC(2),
+        MCU_GPIO_PORTE(8),
+        MCU_GPIO_UNDEF,
+        MCU_GPIO_UNDEF
+    }
+};
+
+int
+pps_configure_output(uint8_t pin, uint8_t func)
+{
+    uint32_t port = pin >> 4;
+    uint32_t index = pin & 0xF;
+    volatile uint32_t *ptr;
+
+    if (func >= 16) {
+        return -1;
+    }
+
+    ptr = (volatile uint32_t *) (PPS_BASE_ADDRESS +
+                                 (port * PPS_PORT_SPACING) + index * 4);
+
+    *ptr = func;
+    return 0;
+}
+
+int
+pps_configure_input(uint8_t pin, uint8_t func)
+{
+    uint8_t index = func >> 4;
+    uint8_t val;
+
+    if (index > 3) {
+        return -1;
+    }
+
+    func &= 0xF;
+    if (input_regs[index][func]  == NULL) {
+        return -1;
+    }
+
+    for (val = 0; val < 16; ++val) {
+        if (output_pins[index][val] == pin) {
+            break;
+        }
+    }
+    if (val == 16) {
+        return -1;
+    }
+
+    *input_regs[index][func] = val;
+    return 0;
+}
\ No newline at end of file


[28/43] incubator-mynewt-core git commit: bletiny: Fix printing uuid

Posted by an...@apache.org.
bletiny: Fix printing uuid


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

Branch: refs/heads/bluetooth5
Commit: 652b4590e589b595484958bed023704a8b6bdf62
Parents: f051851
Author: Łukasz Rymanowski <lu...@codecoup.pl>
Authored: Tue May 9 10:44:48 2017 +0200
Committer: Łukasz Rymanowski <lu...@codecoup.pl>
Committed: Thu May 11 14:16:39 2017 +0200

----------------------------------------------------------------------
 apps/bletiny/src/misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/652b4590/apps/bletiny/src/misc.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/misc.c b/apps/bletiny/src/misc.c
index d39016b..9914bfe 100644
--- a/apps/bletiny/src/misc.c
+++ b/apps/bletiny/src/misc.c
@@ -70,7 +70,7 @@ print_uuid(const ble_uuid_t *uuid)
 
     ble_uuid_to_str(uuid, buf);
 
-    console_printf(buf);
+    console_printf("%s", buf);
 }
 
 int


[13/43] incubator-mynewt-core git commit: This closes pull request #261.

Posted by an...@apache.org.
This closes pull request #261.


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

Branch: refs/heads/bluetooth5
Commit: 21d4cf079dceab478c6d8792b18ee13a80a8f0b2
Parents: 850b9cb e278c35
Author: julian <ju...@imgtec.com>
Authored: Wed May 10 11:57:11 2017 +0100
Committer: julian <ju...@imgtec.com>
Committed: Wed May 10 11:57:11 2017 +0100

----------------------------------------------------------------------
 hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
----------------------------------------------------------------------



[37/43] incubator-mynewt-core git commit: MYNEWT-748 SensorAPI: Add BME280 support

Posted by an...@apache.org.
MYNEWT-748 SensorAPI: Add BME280 support

- SensorAPI support for pressure, temperature and humidity
- Check for validity of values
- Fix calculations
- Add BME280 shell support
- Fix sensors_test app
- cleanup


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

Branch: refs/heads/bluetooth5
Commit: c9ca827561a1c1fbc35ca15864be6dd20cc0bd14
Parents: 1dc1635
Author: Vipul Rahane <vi...@apache.org>
Authored: Wed May 3 18:11:45 2017 -0700
Committer: Vipul Rahane <vi...@apache.org>
Committed: Fri May 12 17:08:16 2017 -0700

----------------------------------------------------------------------
 apps/sensors_test/src/main.c                    |  10 +-
 apps/sensors_test/syscfg.yml                    |   8 +-
 hw/bsp/ruuvi_tag_revb2/src/hal_bsp.c            |   2 +-
 .../sensors/bme280/include/bme280/bme280.h      |  27 +-
 hw/drivers/sensors/bme280/src/bme280.c          | 409 ++++++++++++++-----
 hw/drivers/sensors/bme280/src/bme280_shell.c    |  11 +-
 hw/drivers/sensors/bme280/syscfg.yml            |   3 +
 hw/sensor/src/sensor_oic.c                      |  27 +-
 hw/sensor/src/sensor_shell.c                    |   8 +-
 hw/sensor/syscfg.yml                            |   4 +
 10 files changed, 365 insertions(+), 144 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c9ca8275/apps/sensors_test/src/main.c
----------------------------------------------------------------------
diff --git a/apps/sensors_test/src/main.c b/apps/sensors_test/src/main.c
index ace40af..3c07e21 100755
--- a/apps/sensors_test/src/main.c
+++ b/apps/sensors_test/src/main.c
@@ -401,14 +401,14 @@ config_sensor(void)
     memset(&bmecfg, 0, sizeof(bmecfg));
 
     bmecfg.bc_mode = BME280_MODE_NORMAL;
-    bmecfg.bc_iir = BME280_FILTER_OFF;
-    bmecfg.bc_sby_dur = BME280_STANDBY_MS_1000;
+    bmecfg.bc_iir = BME280_FILTER_X16;
+    bmecfg.bc_sby_dur = BME280_STANDBY_MS_0_5;
     bmecfg.bc_boc[0].boc_type = SENSOR_TYPE_RELATIVE_HUMIDITY;
     bmecfg.bc_boc[1].boc_type = SENSOR_TYPE_PRESSURE;
-    bmecfg.bc_boc[2].boc_type = SENSOR_TYPE_TEMPERATURE;
+    bmecfg.bc_boc[2].boc_type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
     bmecfg.bc_boc[0].boc_oversample = BME280_SAMPLING_X1;
-    bmecfg.bc_boc[1].boc_oversample = BME280_SAMPLING_X1;
-    bmecfg.bc_boc[2].boc_oversample = BME280_SAMPLING_X1;
+    bmecfg.bc_boc[1].boc_oversample = BME280_SAMPLING_X16;
+    bmecfg.bc_boc[2].boc_oversample = BME280_SAMPLING_X2;
 
     rc = bme280_config((struct bme280 *)dev, &bmecfg);
     if (rc) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c9ca8275/apps/sensors_test/syscfg.yml
----------------------------------------------------------------------
diff --git a/apps/sensors_test/syscfg.yml b/apps/sensors_test/syscfg.yml
index fe8b2d7..8d5e407 100644
--- a/apps/sensors_test/syscfg.yml
+++ b/apps/sensors_test/syscfg.yml
@@ -42,8 +42,8 @@ syscfg.vals:
     CONFIG_NEWTMGR: 0
 
     TSL2561_CLI: 0
-    BNO055_CLI: 0
-    TCS34725_CLI: 0
+    BNO055_CLI: 1
+    TCS34725_CLI: 1
     BME280_CLI: 1
 
     # Setup Sensor BLE OIC GATT Server
@@ -66,13 +66,13 @@ syscfg.defs:
         value : 0
     BNO055_PRESENT:
         description: 'BNO055 is present'
-        value : 0
+        value : 1
     BME280_PRESENT:
         description: 'BME280 is present'
         value : 1
     TCS34725_PRESENT:
         description: 'TCS34725 is present'
-        value : 0
+        value : 1
     SIM_ACCEL_PRESENT:
         description: 'SIM ACCEL is present'
         value : 0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c9ca8275/hw/bsp/ruuvi_tag_revb2/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/ruuvi_tag_revb2/src/hal_bsp.c b/hw/bsp/ruuvi_tag_revb2/src/hal_bsp.c
index 30da796..7916f1f 100644
--- a/hw/bsp/ruuvi_tag_revb2/src/hal_bsp.c
+++ b/hw/bsp/ruuvi_tag_revb2/src/hal_bsp.c
@@ -189,7 +189,7 @@ hal_bsp_get_nvic_priority(int irq_num, uint32_t pri)
 
 #if MYNEWT_VAL(LSM303DLHC_PRESENT) || MYNEWT_VAL(BNO055_PRESENT)
 static int
-slinky_accel_init(struct os_dev *dev, void *arg)
+accel_init(struct os_dev *dev, void *arg)
 {
    return (0);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c9ca8275/hw/drivers/sensors/bme280/include/bme280/bme280.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/include/bme280/bme280.h b/hw/drivers/sensors/bme280/include/bme280/bme280.h
index ff3daa3..d881812 100644
--- a/hw/drivers/sensors/bme280/include/bme280/bme280.h
+++ b/hw/drivers/sensors/bme280/include/bme280/bme280.h
@@ -131,26 +131,13 @@ int bme280_set_iir(uint8_t iir);
 int bme280_get_iir(uint8_t *iir);
 
 /**
- * Gets a new data sample from the sensor.
- *
- * @param temperature sensor output
- * @param pressure sensor output
- * @param humidity sensor output
- * @param bme280 config and OS device structure
- *
- * @return 0 on success, and non-zero error code on failure
- */
-int bme280_get_data(uint32_t *temp, uint32_t *press, uint32_t *humidity,
-                    struct bme280 *bme280);
-
-/**
  * Gets temperature
  *
  * @param temperature
  *
  * @return 0 on success, and non-zero error code on failure
  */
-int bme280_get_temperature(uint32_t *temp);
+int bme280_get_temperature(int32_t *temp);
 
 /**
  * Gets pressure
@@ -159,7 +146,7 @@ int bme280_get_temperature(uint32_t *temp);
  *
  * @return 0 on success, and non-zero error code on failure
  */
-int bme280_get_pressure(uint32_t *press);
+int bme280_get_pressure(int32_t *press);
 
 /**
  * Gets humidity
@@ -168,7 +155,7 @@ int bme280_get_pressure(uint32_t *press);
  *
  * @return 0 on success, and non-zero error code on failure
  */
-int bme280_get_humidity(uint32_t *humid);
+int bme280_get_humidity(int32_t *humid);
 
 /**
  * Sets the sampling rate
@@ -253,6 +240,14 @@ bme280_set_sby_duration(uint8_t dur);
 int
 bme280_get_sby_duration(uint8_t *dur);
 
+/**
+ * Take forced measurement
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+bme280_forced_mode_measurement(void);
+
 #if MYNEWT_VAL(BME280_CLI)
 int bme280_shell_init(void);
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c9ca8275/hw/drivers/sensors/bme280/src/bme280.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/src/bme280.c b/hw/drivers/sensors/bme280/src/bme280.c
index 7c66307..c88a79c 100644
--- a/hw/drivers/sensors/bme280/src/bme280.c
+++ b/hw/drivers/sensors/bme280/src/bme280.c
@@ -42,6 +42,14 @@
 #include "stats/stats.h"
 #endif
 
+#ifndef MATHLIB_SUPPORT
+
+double NAN = 0.0/0.0;
+double POS_INF = 1.0 /0.0;
+double NEG_INF = -1.0/0.0;
+
+#endif
+
 static struct hal_spi_settings spi_bme280_settings = {
     .data_order = HAL_SPI_MSB_FIRST,
     .data_mode  = HAL_SPI_MODE0,
@@ -54,12 +62,16 @@ struct bme280_calib_data bcd;
 #if MYNEWT_VAL(BME280_STATS)
 /* Define the stats section and records */
 STATS_SECT_START(bme280_stat_section)
-    STATS_SECT_ENTRY(errors)
+    STATS_SECT_ENTRY(read_errors)
+    STATS_SECT_ENTRY(write_errors)
+    STATS_SECT_ENTRY(invalid_data_errors)
 STATS_SECT_END
 
 /* Define stat names for querying */
 STATS_NAME_START(bme280_stat_section)
-    STATS_NAME(bme280_stat_section, errors)
+    STATS_NAME(bme280_stat_section, read_errors)
+    STATS_NAME(bme280_stat_section, write_errors)
+    STATS_NAME(bme280_stat_section, invalid_data_errors)
 STATS_NAME_END(bme280_stat_section)
 
 /* Global variable used to hold stats data */
@@ -67,7 +79,7 @@ STATS_SECT_DECL(bme280_stat_section) g_bme280stats;
 #endif
 
 #if MYNEWT_VAL(BME280_LOG)
-#define LOG_MODULE_BME280    (2561)
+#define LOG_MODULE_BME280    (280)
 #define BME280_INFO(...)     LOG_INFO(&_log, LOG_MODULE_BME280, __VA_ARGS__)
 #define BME280_ERR(...)      LOG_ERROR(&_log, LOG_MODULE_BME280, __VA_ARGS__)
 static struct log _log;
@@ -90,7 +102,7 @@ static const struct sensor_driver g_bme280_sensor_driver = {
     bme280_sensor_get_config
 };
 
-float g_t_fine;
+int32_t g_t_fine;
 
 static int
 bme280_default_cfg(struct bme280_cfg *cfg)
@@ -98,7 +110,7 @@ bme280_default_cfg(struct bme280_cfg *cfg)
     cfg->bc_iir = BME280_FILTER_OFF;
     cfg->bc_mode = BME280_MODE_NORMAL;
 
-    cfg->bc_boc[0].boc_type = SENSOR_TYPE_TEMPERATURE;
+    cfg->bc_boc[0].boc_type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
     cfg->bc_boc[0].boc_oversample = BME280_SAMPLING_NONE;
     cfg->bc_boc[1].boc_type = SENSOR_TYPE_PRESSURE;
     cfg->bc_boc[1].boc_oversample = BME280_SAMPLING_NONE;
@@ -153,7 +165,7 @@ bme280_init(struct os_dev *dev, void *arg)
     }
 
     /* Add the driver */
-    rc = sensor_set_driver(sensor, SENSOR_TYPE_TEMPERATURE |
+    rc = sensor_set_driver(sensor, SENSOR_TYPE_AMBIENT_TEMPERATURE |
                            SENSOR_TYPE_PRESSURE            |
                            SENSOR_TYPE_RELATIVE_HUMIDITY,
                            (struct sensor_driver *) &g_bme280_sensor_driver);
@@ -195,22 +207,30 @@ bme280_sensor_get_interface(struct sensor *sensor, sensor_type_t type)
 
 #if MYNEWT_VAL(BME280_SPEC_CALC)
 /**
- * Returns temperature in DegC, as float
- * Output value of “51.23” equals 51.23 DegC.
+ * Returns temperature in DegC, as double
+ * Output value of "51.23" equals 51.23 DegC.
  *
  * @param uncompensated raw temperature value
  * @return 0 on success, non-zero on failure
  */
-static float
-bme280_compensate_temperature(uint32_t rawtemp, struct bme280_calib_data *bcd)
+static double
+bme280_compensate_temperature(int32_t rawtemp, struct bme280_calib_data *bcd)
 {
-    float var1, var2, comptemp;
+    double var1, var2, comptemp;
 
-    var1 = (((float)rawtemp)/16384.0 – ((float)bcd->bcd_dig_T1)/1024.0) *
-            ((float)bcd->bcd_dig_T2);
-    var2 = ((((float)rawtemp)/131072.0 – ((float)bcd->bcd_dig_T1)/8192.0) *
-            (((float)rawtemp)/131072.0 – ((float)bcd->bcd_dig_T1)/8192.0)) *
-             ((float)bcd->bcd_dig_T3);
+    if (rawtemp == 0x800000) {
+        BME280_ERR("Invalid temp data\n");
+#if MYNEWT_VAL(BME280_STATS)
+        STATS_INC(g_bme280stats, invalid_data_errors);
+#endif
+        return NAN;
+    }
+
+    var1 = (((double)rawtemp)/16384.0 - ((double)bcd->bcd_dig_T1)/1024.0) *
+            ((double)bcd->bcd_dig_T2);
+    var2 = ((((double)rawtemp)/131072.0 - ((double)bcd->bcd_dig_T1)/8192.0) *
+            (((double)rawtemp)/131072.0 - ((double)bcd->bcd_dig_T1)/8192.0)) *
+             ((double)bcd->bcd_dig_T3);
 
     g_t_fine = var1 + var2;
 
@@ -220,60 +240,76 @@ bme280_compensate_temperature(uint32_t rawtemp, struct bme280_calib_data *bcd)
 }
 
 /**
- * Returns pressure in Pa as float.
- * Output value of “96386.2” equals 96386.2 Pa = 963.862 hPa
+ * Returns pressure in Pa as double.
+ * Output value of "96386.2" equals 96386.2 Pa = 963.862 hPa
  *
  * @param uncompensated raw pressure value
  * @return 0 on success, non-zero on failure
  */
-static float
-bme280_compensate_pressure(uint32_t rawpress, struct bme280_calib_data *bcd)
+static double
+bme280_compensate_pressure(int32_t rawpress, struct bme280_calib_data *bcd)
 {
-    float var1, var2, p;
-    uint32_t temp;
+    double var1, var2, p;
+    int32_t temp;
+
+    if (rawpress == 0x800000) {
+        BME280_ERR("Invalid press data\n");
+#if MYNEWT_VAL(BME280_STATS)
+        STATS_INC(g_bme280stats, invalid_data_errors);
+#endif
+        return NAN;
+    }
 
     if (!g_t_fine) {
         if(!bme280_get_temperature(&temp)) {
-            (void)bme280_compensate_temperature(temp);
+            (void)bme280_compensate_temperature(temp, bcd);
         }
     }
 
-    var1 = ((float)g_t_fine/2.0) – 64000.0;
-    var2 = var1 * var1 * ((float)bcd->bcd_dig_P6) / 32768.0;
-    var2 = var2 + var1 * ((float)bcd->bcd_dig_P5) * 2.0;
-    var2 = (var2/4.0)+(((float)bcd->bcd_dig_P4) * 65536.0);
-    var1 = (((float)bcd->bcd_dig_P3) * var1 * var1 / 524288.0 +
-            ((float)bcd->bcd_dig_P2) * var1) / 524288.0;
-    var1 = (1.0 + var1 / 32768.0)*((float)bcd->bcd_dig_P1);
+    var1 = ((double)g_t_fine/2.0) - 64000.0;
+    var2 = var1 * var1 * ((double)bcd->bcd_dig_P6) / 32768.0;
+    var2 = var2 + var1 * ((double)bcd->bcd_dig_P5) * 2.0;
+    var2 = (var2/4.0)+(((double)bcd->bcd_dig_P4) * 65536.0);
+    var1 = (((double)bcd->bcd_dig_P3) * var1 * var1 / 524288.0 +
+            ((double)bcd->bcd_dig_P2) * var1) / 524288.0;
+    var1 = (1.0 + var1 / 32768.0)*((double)bcd->bcd_dig_P1);
 
     if (var1 == 0.0)
     {
         return 0;
     }
 
-    p = 1048576.0 – (float)rawpress;
-    p = (p – (var2 / 4096.0)) * 6250.0 / var1;
+    p = 1048576.0 - (double)rawpress;
+    p = (p - (var2 / 4096.0)) * 6250.0 / var1;
 
-    var1 = ((float)bcd->bcd_dig_P9) * p * p / 2147483648.0;
-    var2 = p * ((float)bcd->bcd_dig_P8) / 32768.0;
+    var1 = ((double)bcd->bcd_dig_P9) * p * p / 2147483648.0;
+    var2 = p * ((double)bcd->bcd_dig_P8) / 32768.0;
 
-    p = p + (var1 + var2 + ((float)bcd->bcd_dig_P7)) / 16.0;
+    p = p + (var1 + var2 + ((double)bcd->bcd_dig_P7)) / 16.0;
 
     return p;
 }
 
 /**
- * Returns humidity in %rH as float.
- * Output value of “46.332” represents 46.332 %rH
+ * Returns humidity in %rH as double.
+ * Output value of "46.332" represents 46.332 %rH
  *
  * @param uncompensated raw humidity value
  * @return 0 on success, non-zero on failure
  */
-static float
-bme280_compensate_humidity(uint32_t rawhumid, struct bme280_calib_data *bcd)
+static double
+bme280_compensate_humidity(int32_t rawhumid, struct bme280_calib_data *bcd)
 {
-    float h;
-    uint32_t temp;
+    double h;
+    int32_t temp;
+
+    if (rawhumid == 0x8000) {
+        BME280_ERR("Invalid humidity data\n");
+#if MYNEWT_VAL(BME280_STATS)
+        STATS_INC(g_bme280stats, invalid_data_errors);
+#endif
+        return NAN;
+    }
 
     if (!g_t_fine) {
         if(!bme280_get_temperature(&temp)) {
@@ -281,14 +317,14 @@ bme280_compensate_humidity(uint32_t rawhumid, struct bme280_calib_data *bcd)
         }
     }
 
-    h = (((float)g_t_fine) – 76800.0);
-    h = (rawhumid – (((float)bcd->bcd_dig_H4) * 64.0 +
-         ((float)bcd->bcd_dig_H5) / 16384.0 * h)) *
-         (((float)bcd->bcd_dig_H2) / 65536.0 * (1.0 +
-           ((float)bcd->bcd_dig_H6) / 67108864.0 * h *
-          (1.0 + ((float)bcd->bcd_dig_H3) / 67108864.0 * h)));
+    h = (((double)g_t_fine) - 76800.0);
+    h = (rawhumid - (((double)bcd->bcd_dig_H4) * 64.0 +
+         ((double)bcd->bcd_dig_H5) / 16384.0 * h)) *
+         (((double)bcd->bcd_dig_H2) / 65536.0 * (1.0 +
+           ((double)bcd->bcd_dig_H6) / 67108864.0 * h *
+          (1.0 + ((double)bcd->bcd_dig_H3) / 67108864.0 * h)));
 
-    h = h * (1.0 – ((float)bcd->bcd_dig_H1) * h / 524288.0);
+    h = h * (1.0 - ((double)bcd->bcd_dig_H1) * h / 524288.0);
     if (h > 100.0) {
         h = 100.0;
     } else if (h < 0.0) {
@@ -302,15 +338,23 @@ bme280_compensate_humidity(uint32_t rawhumid, struct bme280_calib_data *bcd)
 
 /**
  * Returns temperature in DegC, as float
- * Output value of “51.23” equals 51.23 DegC.
+ * Output value of "51.23" equals 51.23 DegC.
  *
  * @param uncompensated raw temperature value
  * @return 0 on success, non-zero on failure
  */
 static float
-bme280_compensate_temperature(uint32_t rawtemp, struct bme280_calib_data *bcd)
+bme280_compensate_temperature(int32_t rawtemp, struct bme280_calib_data *bcd)
 {
-    float var1, var2, comptemp;
+    int32_t var1, var2, comptemp;
+
+    if (rawtemp == 0x800000) {
+        BME280_ERR("Invalid temp data\n");
+#if MYNEWT_VAL(BME280_STATS)
+        STATS_INC(g_bme280stats, invalid_data_errors);
+#endif
+        return NAN;
+    }
 
     rawtemp >>= 4;
 
@@ -325,21 +369,29 @@ bme280_compensate_temperature(uint32_t rawtemp, struct bme280_calib_data *bcd)
 
     comptemp = ((int32_t)(g_t_fine * 5 + 128)) >> 8;
 
-    return comptemp/100;
+    return (float)comptemp/100;
 }
 
 /**
  * Returns pressure in Pa as float.
- * Output value of “96386.2” equals 96386.2 Pa = 963.862 hPa
+ * Output value of "96386.2" equals 96386.2 Pa = 963.862 hPa
  *
  * @param uncompensated raw pressure value
  * @return 0 on success, non-zero on failure
  */
 static float
-bme280_compensate_pressure(uint32_t rawpress, struct bme280_calib_data *bcd)
+bme280_compensate_pressure(int32_t rawpress, struct bme280_calib_data *bcd)
 {
-    float var1, var2, p;
-    uint32_t temp;
+    int64_t var1, var2, p;
+    int32_t temp;
+
+    if (rawpress == 0x800000) {
+        BME280_ERR("Invalid pressure data\n");
+#if MYNEWT_VAL(BME280_STATS)
+        STATS_INC(g_bme280stats, invalid_data_errors);
+#endif
+        return NAN;
+    }
 
     if (!g_t_fine) {
         if(!bme280_get_temperature(&temp)) {
@@ -375,7 +427,7 @@ bme280_compensate_pressure(uint32_t rawpress, struct bme280_calib_data *bcd)
 
 /**
  * Returns humidity in %rH as float.
- * Output value of “46.332” represents 46.332 %rH
+ * Output value of "46.332" represents 46.332 %rH
  *
  * @param uncompensated raw humidity value
  * @return 0 on success, non-zero on failure
@@ -383,10 +435,18 @@ bme280_compensate_pressure(uint32_t rawpress, struct bme280_calib_data *bcd)
 static float
 bme280_compensate_humidity(uint32_t rawhumid, struct bme280_calib_data *bcd)
 {
-    float h;
-    uint32_t temp;
+    int32_t h;
+    int32_t temp;
     int32_t tmp32;
 
+    if (rawhumid == 0x8000) {
+        BME280_ERR("Invalid humidity data\n");
+#if MYNEWT_VAL(BME280_STATS)
+        STATS_INC(g_bme280stats, invalid_data_errors);
+#endif
+        return NAN;
+    }
+
     if (!g_t_fine) {
         if(!bme280_get_temperature(&temp)) {
             (void)bme280_compensate_temperature(temp, bcd);
@@ -419,21 +479,35 @@ static int
 bme280_sensor_read(struct sensor *sensor, sensor_type_t type,
         sensor_data_func_t data_func, void *data_arg, uint32_t timeout)
 {
-    uint32_t rawtemp;
-    uint32_t rawpress;
-    uint32_t rawhumid;
+    int32_t rawtemp;
+    int32_t rawpress;
+    int32_t rawhumid;
     struct sensor_temp_data std;
     struct sensor_press_data spd;
     struct sensor_humid_data shd;
+    struct bme280 *bme280;
     int rc;
 
     if (!(type & SENSOR_TYPE_PRESSURE)    &&
-        !(type & SENSOR_TYPE_TEMPERATURE) &&
+        !(type & SENSOR_TYPE_AMBIENT_TEMPERATURE) &&
         !(type & SENSOR_TYPE_RELATIVE_HUMIDITY)) {
         rc = SYS_EINVAL;
         goto err;
     }
 
+    bme280 = (struct bme280 *)SENSOR_GET_DEVICE(sensor);
+
+    /*
+     * For forced mode the sensor goes to sleep after setting the sensor to
+     * forced mode and grabbing sensor data
+     */
+    if (bme280->cfg.bc_mode == BME280_MODE_FORCED) {
+        rc = bme280_forced_mode_measurement();
+        if (rc) {
+            goto err;
+        }
+    }
+
     rawtemp = rawpress = rawhumid = 0;
 
     /* Get a new pressure sample */
@@ -444,7 +518,10 @@ bme280_sensor_read(struct sensor *sensor, sensor_type_t type,
         }
 
         spd.spd_press = bme280_compensate_pressure(rawpress, &bcd);
-        spd.spd_press_is_valid = 1;
+
+        if (spd.spd_press != NAN) {
+            spd.spd_press_is_valid = 1;
+        }
 
         /* Call data function */
         rc = data_func(sensor, data_arg, &spd);
@@ -454,14 +531,17 @@ bme280_sensor_read(struct sensor *sensor, sensor_type_t type,
     }
 
     /* Get a new temperature sample */
-    if (type & SENSOR_TYPE_TEMPERATURE) {
+    if (type & SENSOR_TYPE_AMBIENT_TEMPERATURE) {
         rc = bme280_get_temperature(&rawtemp);
         if (rc) {
             goto err;
         }
 
         std.std_temp = bme280_compensate_temperature(rawtemp, &bcd);
-        std.std_temp_is_valid = 1;
+
+        if (std.std_temp != NAN) {
+            std.std_temp_is_valid = 1;
+        }
 
         /* Call data function */
         rc = data_func(sensor, data_arg, &std);
@@ -478,7 +558,10 @@ bme280_sensor_read(struct sensor *sensor, sensor_type_t type,
         }
 
         shd.shd_humid = bme280_compensate_humidity(rawhumid, &bcd);
-        shd.shd_humid_is_valid = 1;
+
+        if (shd.shd_humid != NAN) {
+            shd.shd_humid_is_valid = 1;
+        }
 
         /* Call data function */
         rc = data_func(sensor, data_arg, &shd);
@@ -499,7 +582,7 @@ bme280_sensor_get_config(struct sensor *sensor, sensor_type_t type,
     int rc;
 
     if (!(type & SENSOR_TYPE_PRESSURE)    ||
-        !(type & SENSOR_TYPE_TEMPERATURE) ||
+        !(type & SENSOR_TYPE_AMBIENT_TEMPERATURE) ||
         !(type & SENSOR_TYPE_RELATIVE_HUMIDITY)) {
         rc = SYS_EINVAL;
         goto err;
@@ -547,31 +630,68 @@ bme280_get_calibinfo(struct bme280_calib_data *bcd)
     int rc;
     uint8_t payload[33];
 
+    /**
+     *------------|------------------|--------------------|
+     *  trimming  |    reg addrs     |    bits            |
+     *____________|__________________|____________________|
+     *	dig_T1    |  0x88  |  0x89   | from 0 : 7 to 8: 15
+     *	dig_T2    |  0x8A  |  0x8B   | from 0 : 7 to 8: 15
+     *	dig_T3    |  0x8C  |  0x8D   | from 0 : 7 to 8: 15
+     *	dig_P1    |  0x8E  |  0x8F   | from 0 : 7 to 8: 15
+     *	dig_P2    |  0x90  |  0x91   | from 0 : 7 to 8: 15
+     *	dig_P3    |  0x92  |  0x93   | from 0 : 7 to 8: 15
+     *	dig_P4    |  0x94  |  0x95   | from 0 : 7 to 8: 15
+     *	dig_P5    |  0x96  |  0x97   | from 0 : 7 to 8: 15
+     *	dig_P6    |  0x98  |  0x99   | from 0 : 7 to 8: 15
+     *	dig_P7    |  0x9A  |  0x9B   | from 0 : 7 to 8: 15
+     *	dig_P8    |  0x9C  |  0x9D   | from 0 : 7 to 8: 15
+     *	dig_P9    |  0x9E  |  0x9F   | from 0 : 7 to 8: 15
+     *	dig_H1    |       0xA1       | from 0 to 7
+     *	dig_H2    |  0xE1  |  0xE2   | from 0 : 7 to 8: 15
+     *	dig_H3    |       0xE3       | from 0 to 7
+     *	dig_H4    |  0xE4  | 0xE5    | from 4 : 11 to 0: 3
+     *	dig_H5    |  0xE5  | 0xE6    | from 0 : 3 to 4: 11
+     *	dig_H6    |       0xE7       | from 0 to 7
+     *------------|------------------|--------------------|
+     * Hence, we read it in two transactions, one starting at
+     * BME280_REG_ADDR_DIG_T1, second one starting at
+     * BME280_REG_ADDR_DIG_H2.
+     */
+
     rc = bme280_readlen(BME280_REG_ADDR_DIG_T1, payload, sizeof(payload));
     if (rc) {
         goto err;
     }
 
-    bcd->bcd_dig_T1 = payload[0] | payload[1] << 8;
-    bcd->bcd_dig_T2 = payload[3] | payload[2] << 8;
-    bcd->bcd_dig_T3 = payload[5] | payload[4] << 8;
-
-    bcd->bcd_dig_P1 = payload[7] | payload[6] << 8;
-    bcd->bcd_dig_P2 = payload[9] | payload[8] << 8;
-    bcd->bcd_dig_P3 = payload[11] | payload[10] << 8;
-    bcd->bcd_dig_P4 = payload[13] | payload[12] << 8;
-    bcd->bcd_dig_P5 = payload[15] | payload[14] << 8;
-    bcd->bcd_dig_P6 = payload[17] | payload[16] << 8;
-    bcd->bcd_dig_P7 = payload[19] | payload[18] << 8;
-    bcd->bcd_dig_P8 = payload[21] | payload[20] << 8;
-    bcd->bcd_dig_P9 = payload[23] | payload[22] << 8;
-
-    bcd->bcd_dig_H1 = payload[24];
-    bcd->bcd_dig_H2 = payload[26] | payload[25] << 8;
-    bcd->bcd_dig_H3 = payload[27];
-    bcd->bcd_dig_H4 = (payload[28] << 4) | (payload[29] & 0xF);
-    bcd->bcd_dig_H5 = (payload[31] << 4) | (payload[30] >> 4);
-    bcd->bcd_dig_H6 = (int8_t)payload[32];
+    bcd->bcd_dig_T1 = (uint16_t)(payload[0] | (uint16_t)(((uint8_t)payload[1]) << 8));
+    bcd->bcd_dig_T2 = (int16_t) (payload[2] | (int16_t)((int8_t)payload[3]) << 8);
+    bcd->bcd_dig_T3 = (int16_t) (payload[4] | (int16_t)((int8_t)payload[5]) << 8);
+
+    bcd->bcd_dig_P1 = (uint16_t) (payload[6] |  (uint16_t)(((uint8_t)payload[7]) << 8));
+    bcd->bcd_dig_P2 = (int16_t) (payload[8]  | (int16_t)(((int8_t)payload[9])  << 8));
+    bcd->bcd_dig_P3 = (int16_t) (payload[10] | (int16_t)(((int8_t)payload[11]) << 8));
+    bcd->bcd_dig_P4 = (int16_t) (payload[12] | (int16_t)(((int8_t)payload[13]) << 8));
+    bcd->bcd_dig_P5 = (int16_t) (payload[14] | (int16_t)(((int8_t)payload[15]) << 8));
+    bcd->bcd_dig_P6 = (int16_t) (payload[16] | (int16_t)(((int8_t)payload[17]) << 8));
+    bcd->bcd_dig_P7 = (int16_t) (payload[18] | (int16_t)(((int8_t)payload[19]) << 8));
+    bcd->bcd_dig_P8 = (int16_t) (payload[20] | (int16_t)(((int8_t)payload[21]) << 8));
+    bcd->bcd_dig_P9 = (int16_t) (payload[22] | (int16_t)(((int8_t)payload[23]) << 8));
+
+    bcd->bcd_dig_H1 = payload[25];
+
+    memset(payload, 0, 7);
+    rc = bme280_readlen(BME280_REG_ADDR_DIG_H2, payload, 7);
+    if (rc) {
+        goto err;
+    }
+
+    bcd->bcd_dig_H2 = (int16_t) (payload[0] | (int16_t)(((int8_t)payload[1]) << 8));
+    bcd->bcd_dig_H3 = payload[2];
+    bcd->bcd_dig_H4 = (int16_t)(((int16_t)((int8_t)payload[3]) << 4) |
+                                (payload[4] & 0x0F));
+    bcd->bcd_dig_H5 = (int16_t)(((int16_t)((int8_t)payload[5]) << 4) |
+                                (((int8_t)payload[6]) >> 4));
+    bcd->bcd_dig_H6 = (int8_t)payload[7];
 
     return 0;
 err:
@@ -727,6 +847,11 @@ bme280_readlen(uint8_t addr, uint8_t *payload, uint8_t len)
                             addr | BME280_SPI_READ_CMD_BIT);
     if (retval == 0xFFFF) {
         rc = SYS_EINVAL;
+        BME280_ERR("SPI_%u register write failed addr:0x%02X\n",
+                   MYNEWT_VAL(BME280_SPINUM), addr);
+#if MYNEWT_VAL(BME280_STATS)
+        STATS_INC(g_bme280stats, read_errors);
+#endif
         goto err;
     }
 
@@ -735,14 +860,22 @@ bme280_readlen(uint8_t addr, uint8_t *payload, uint8_t len)
         retval = hal_spi_tx_val(MYNEWT_VAL(BME280_SPINUM), 0);
         if (retval == 0xFFFF) {
             rc = SYS_EINVAL;
+            BME280_ERR("SPI_%u read failed addr:0x%02X\n",
+                       MYNEWT_VAL(BME280_SPINUM), addr);
+#if MYNEWT_VAL(BME280_STATS)
+            STATS_INC(g_bme280stats, read_errors);
+#endif
             goto err;
         }
         payload[i] = retval;
     }
 
+    rc = 0;
+
 err:
     /* De-select the device */
     hal_gpio_write(MYNEWT_VAL(BME280_CSPIN), 1);
+
     return rc;
 }
 
@@ -769,6 +902,11 @@ bme280_writelen(uint8_t addr, uint8_t *payload, uint8_t len)
                         addr & ~BME280_SPI_READ_CMD_BIT);
     if (rc == 0xFFFF) {
         rc = SYS_EINVAL;
+        BME280_ERR("SPI_%u register write failed addr:0x%02X\n",
+                   MYNEWT_VAL(BME280_SPINUM), addr);
+#if MYNEWT_VAL(BME280_STATS)
+        STATS_INC(g_bme280stats, write_errors);
+#endif
         goto err;
     }
 
@@ -777,15 +915,24 @@ bme280_writelen(uint8_t addr, uint8_t *payload, uint8_t len)
         rc = hal_spi_tx_val(MYNEWT_VAL(BME280_SPINUM), payload[i]);
         if (rc == 0xFFFF) {
             rc = SYS_EINVAL;
+            BME280_ERR("SPI_%u write failed addr:0x%02X:0x%02X\n",
+                       MYNEWT_VAL(BME280_SPINUM), addr);
+#if MYNEWT_VAL(BME280_STATS)
+            STATS_INC(g_bme280stats, write_errors);
+#endif
             goto err;
         }
     }
 
+
+    rc = 0;
+
+err:
     /* De-select the device */
     hal_gpio_write(MYNEWT_VAL(BME280_CSPIN), 1);
 
-    return 0;
-err:
+    os_time_delay((OS_TICKS_PER_SEC * 30)/1000 + 1);
+
     return rc;
 }
 
@@ -797,7 +944,7 @@ err:
  * @return 0 on success, and non-zero error code on failure
  */
 int
-bme280_get_temperature(uint32_t *temp)
+bme280_get_temperature(int32_t *temp)
 {
     int rc;
     uint8_t tmp[3];
@@ -807,8 +954,15 @@ bme280_get_temperature(uint32_t *temp)
         goto err;
     }
 
-    *temp = (tmp[1] << 8 | tmp[0]) << 4 | (tmp[2] >> 4);
+#if MYNEWT_VAL(BME280_SPEC_CALC)
+    *temp = (int32_t)((((uint32_t)(tmp[0])) << 12) |
+                      (((uint32_t)(tmp[1])) <<  4) |
+                       ((uint32_t)tmp[2] >> 4));
+#else
+    *temp = ((tmp[0] << 16) | (tmp[1] << 8) | tmp[2]);
+#endif
 
+    return 0;
 err:
     return rc;
 }
@@ -821,7 +975,7 @@ err:
  * @return 0 on success, and non-zero error code on failure
  */
 int
-bme280_get_humidity(uint32_t *humid)
+bme280_get_humidity(int32_t *humid)
 {
     int rc;
     uint8_t tmp[2];
@@ -830,9 +984,13 @@ bme280_get_humidity(uint32_t *humid)
     if (rc) {
         goto err;
     }
+#if MYNEWT_VAL(BME280_SPEC_CALC)
+    *humid = (tmp[0] << 8 | tmp[1]);
+#else
+    *humid = (tmp[0] << 8 | tmp[1]);
+#endif
 
-    *humid = (tmp[1] << 8 | tmp[0]);
-
+    return 0;
 err:
     return rc;
 }
@@ -845,18 +1003,25 @@ err:
  * @return 0 on success, and non-zero error code on failure
  */
 int
-bme280_get_pressure(uint32_t *press)
+bme280_get_pressure(int32_t *press)
 {
     int rc;
     uint8_t tmp[3];
 
-    rc = bme280_readlen(BME280_REG_ADDR_PRESS, tmp, 2);
+    rc = bme280_readlen(BME280_REG_ADDR_PRESS, tmp, 3);
     if (rc) {
         goto err;
     }
 
-    *press = (tmp[1] << 8 | tmp[0]) << 4 | (tmp[2] >> 4);
+#if MYNEWT_VAL(BME280_SPEC_CALC)
+    *press = (int32_t)((((uint32_t)(tmp[0])) << 12) |
+                      (((uint32_t)(tmp[1])) <<  4)  |
+                       ((uint32_t)tmp[2] >> 4));
+#else
+    *press = ((tmp[0] << 16) | (tmp[1] << 8) | tmp[2]);
+#endif
 
+    return 0;
 err:
     return rc;
 }
@@ -896,6 +1061,7 @@ bme280_get_iir(uint8_t *iir)
 
     *iir = ((tmp & BME280_REG_CONFIG_FILTER) >> 5);
 
+    return 0;
 err:
     return rc;
 }
@@ -950,6 +1116,7 @@ bme280_get_mode(uint8_t *mode)
 
     *mode = (tmp & BME280_REG_CTRL_MEAS_MODE);
 
+    return 0;
 err:
     return rc;
 }
@@ -997,18 +1164,18 @@ bme280_get_oversample(sensor_type_t type, uint8_t *oversample)
     int rc;
     uint8_t tmp;
 
-    if (type & SENSOR_TYPE_TEMPERATURE || type & SENSOR_TYPE_PRESSURE) {
+    if (type & SENSOR_TYPE_AMBIENT_TEMPERATURE || type & SENSOR_TYPE_PRESSURE) {
         rc = bme280_readlen(BME280_REG_ADDR_CTRL_MEAS, &tmp, 1);
         if (rc) {
             goto err;
         }
 
-        if (type & SENSOR_TYPE_TEMPERATURE) {
+        if (type & SENSOR_TYPE_AMBIENT_TEMPERATURE) {
             *oversample = ((tmp & BME280_REG_CTRL_MEAS_TOVER) >> 5);
         }
 
         if (type & SENSOR_TYPE_PRESSURE) {
-            *oversample = ((tmp & BME280_REG_CTRL_MEAS_POVER) >> 3);
+            *oversample = ((tmp & BME280_REG_CTRL_MEAS_POVER) >> 2);
         }
     }
 
@@ -1039,13 +1206,13 @@ bme280_set_oversample(sensor_type_t type, uint8_t oversample)
     int rc;
     uint8_t cfg;
 
-    if (type & SENSOR_TYPE_TEMPERATURE || type & SENSOR_TYPE_PRESSURE) {
+    if (type & SENSOR_TYPE_AMBIENT_TEMPERATURE || type & SENSOR_TYPE_PRESSURE) {
         rc = bme280_readlen(BME280_REG_ADDR_CTRL_MEAS, &cfg, 1);
         if (rc) {
             goto err;
         }
 
-        if (type & SENSOR_TYPE_TEMPERATURE) {
+        if (type & SENSOR_TYPE_AMBIENT_TEMPERATURE) {
             cfg = cfg | ((oversample << 5) & BME280_REG_CTRL_MEAS_TOVER);
         }
 
@@ -1098,6 +1265,7 @@ bme280_get_chipid(uint8_t *chipid)
 
     *chipid = tmp;
 
+    return 0;
 err:
     return rc;
 }
@@ -1155,3 +1323,38 @@ err:
     return rc;
 }
 
+/**
+ * Take forced measurement
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+bme280_forced_mode_measurement(void)
+{
+    uint8_t status;
+    int rc;
+
+    /*
+     * If we are in forced mode, the BME sensor goes back to sleep after each
+     * measurement and we need to set it to forced mode once at this point, so
+     * it will take the next measurement and then return to sleep again.
+     * In normal mode simply does new measurements periodically.
+     */
+    rc = bme280_set_mode(BME280_MODE_FORCED);
+    if (rc) {
+        goto err;
+    }
+
+    status = 1;
+    while(status) {
+        rc = bme280_readlen(BME280_REG_ADDR_STATUS, &status, 1);
+        if (rc) {
+            goto err;
+        }
+        os_time_delay(OS_TICKS_PER_SEC/1000);
+    }
+
+    return 0;
+err:
+    return rc;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c9ca8275/hw/drivers/sensors/bme280/src/bme280_shell.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/src/bme280_shell.c b/hw/drivers/sensors/bme280/src/bme280_shell.c
index aeea071..7366b2d 100644
--- a/hw/drivers/sensors/bme280/src/bme280_shell.c
+++ b/hw/drivers/sensors/bme280/src/bme280_shell.c
@@ -120,9 +120,9 @@ bme280_shell_cmd_reset(int argc, char **argv)
 static int
 bme280_shell_cmd_read(int argc, char **argv)
 {
-    uint32_t temp;
-    uint32_t press;
-    uint32_t humid;
+    int32_t temp;
+    int32_t press;
+    int32_t humid;
     uint16_t samples = 1;
     long val;
     int rc;
@@ -159,9 +159,8 @@ bme280_shell_cmd_read(int argc, char **argv)
             return rc;
         }
 
-        console_printf("temperature: %u pressure: %u\thumidity: %u\n",
-                       (unsigned int)temp, (unsigned int)press,
-                       (unsigned int)humid);
+        console_printf("temperature: %d pressure: %d\thumidity: %d\n",
+                       (int)temp, (int)press, (int)humid);
     }
 
     return 0;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c9ca8275/hw/drivers/sensors/bme280/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/syscfg.yml b/hw/drivers/sensors/bme280/syscfg.yml
index 126ecda..c5318df 100644
--- a/hw/drivers/sensors/bme280/syscfg.yml
+++ b/hw/drivers/sensors/bme280/syscfg.yml
@@ -36,3 +36,6 @@ syscfg.defs:
     BME280_CSPIN:
         description: 'CS pin for BME280'
         value : 0
+    BME280_SPEC_CALC:
+        description: 'BME280 Spec calculation insetad of built in one'
+        value : 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c9ca8275/hw/sensor/src/sensor_oic.c
----------------------------------------------------------------------
diff --git a/hw/sensor/src/sensor_oic.c b/hw/sensor/src/sensor_oic.c
index 879da5d..53c5406 100644
--- a/hw/sensor/src/sensor_oic.c
+++ b/hw/sensor/src/sensor_oic.c
@@ -37,13 +37,16 @@
 #include "sensor/quat.h"
 #include "sensor/euler.h"
 #include "sensor/color.h"
+#include "sensor/temperature.h"
+#include "sensor/pressure.h"
+#include "sensor/humidity.h"
 
 /* OIC */
 #include <oic/oc_rep.h>
 #include <oic/oc_ri.h>
 #include <oic/oc_api.h>
 
-static const char g_s_oic_dn[] = "x.mynewt.sensors.r.";
+static const char g_s_oic_dn[] = "x.mynewt.snsr.";
 
 static int
 sensor_oic_encode(struct sensor* sensor, void *arg, void *databuf)
@@ -126,17 +129,26 @@ sensor_oic_encode(struct sensor* sensor, void *arg, void *databuf)
 
         /* Temperature supported */
         case SENSOR_TYPE_TEMPERATURE:
-            oc_rep_set_double(root, temp, *(double *)databuf);
+            if (((struct sensor_temp_data *)(databuf))->std_temp_is_valid) {
+                oc_rep_set_double(root, temp,
+                    ((struct sensor_temp_data *)(databuf))->std_temp);
+            }
             break;
 
         /* Ambient temperature supported */
         case SENSOR_TYPE_AMBIENT_TEMPERATURE:
-            oc_rep_set_double(root, ambient_temp, *(double *)databuf);
+            if (((struct sensor_temp_data *)(databuf))->std_temp_is_valid) {
+                oc_rep_set_double(root, temp,
+                    ((struct sensor_temp_data *)(databuf))->std_temp);
+            }
             break;
 
         /* Pressure sensor supported */
         case SENSOR_TYPE_PRESSURE:
-            oc_rep_set_uint(root, pressure, *(uint32_t *)databuf);
+            if (((struct sensor_press_data *)(databuf))->spd_press_is_valid) {
+                oc_rep_set_double(root, press,
+                    ((struct sensor_press_data *)(databuf))->spd_press);
+            }
             break;
 #if 0
         /* Proximity sensor supported */
@@ -144,7 +156,10 @@ sensor_oic_encode(struct sensor* sensor, void *arg, void *databuf)
 #endif
         /* Relative humidity supported */
         case SENSOR_TYPE_RELATIVE_HUMIDITY:
-            oc_rep_set_uint(root, humidity, *(uint32_t *)databuf);
+            if (((struct sensor_humid_data *)(databuf))->shd_humid_is_valid) {
+                oc_rep_set_double(root, humid,
+                    ((struct sensor_humid_data *)(databuf))->shd_humid);
+            }
             break;
 
         /* Rotation vector (quaternion) supported */
@@ -577,7 +592,7 @@ sensor_oic_init(void)
                 res = oc_new_resource(tmpstr, 1, 0);
 
                 memset(tmpstr, 0, sizeof(tmpstr));
-                snprintf(tmpstr, sizeof(tmpstr), "x.mynewt.sensors.r.%s", typename);
+                snprintf(tmpstr, sizeof(tmpstr), "%s%s", g_s_oic_dn, typename);
                 oc_resource_bind_resource_type(res, tmpstr);
                 oc_resource_bind_resource_interface(res, OC_IF_R);
                 oc_resource_set_default_interface(res, OC_IF_R);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c9ca8275/hw/sensor/src/sensor_shell.c
----------------------------------------------------------------------
diff --git a/hw/sensor/src/sensor_shell.c b/hw/sensor/src/sensor_shell.c
index 69c1b94..318cbe6 100644
--- a/hw/sensor/src/sensor_shell.c
+++ b/hw/sensor/src/sensor_shell.c
@@ -292,10 +292,12 @@ sensor_shell_read_listener(struct sensor *sensor, void *arg, void *data)
         console_printf("\n");
     }
 
-    if (ctx->type == SENSOR_TYPE_TEMPERATURE) {
+    if (ctx->type == SENSOR_TYPE_TEMPERATURE      ||
+        ctx->type == SENSOR_TYPE_AMBIENT_TEMPERATURE) {
+
         std = (struct sensor_temp_data *) data;
         if (std->std_temp_is_valid) {
-            console_printf("temprature = %s", sensor_ftostr(std->std_temp, tmpstr, 13));
+            console_printf("temperature = %s Deg C", sensor_ftostr(std->std_temp, tmpstr, 13));
         }
         console_printf("\n");
     }
@@ -385,7 +387,7 @@ sensor_shell_read_listener(struct sensor *sensor, void *arg, void *data)
     if (ctx->type == SENSOR_TYPE_RELATIVE_HUMIDITY) {
         shd = (struct sensor_humid_data *) data;
         if (shd->shd_humid_is_valid) {
-            console_printf("relative humidity = %s",
+            console_printf("relative humidity = %s%%rh",
                            sensor_ftostr(shd->shd_humid, tmpstr, 13));
         }
         console_printf("\n");

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c9ca8275/hw/sensor/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/sensor/syscfg.yml b/hw/sensor/syscfg.yml
index 3495534..761d62b 100644
--- a/hw/sensor/syscfg.yml
+++ b/hw/sensor/syscfg.yml
@@ -32,3 +32,7 @@ syscfg.defs:
         value: 1
         restrictions:
             - OC_SERVER
+
+    MATHLIB_SUPPORT:
+        description: 'Is MATHLIB support present'
+        value: 0



[11/43] incubator-mynewt-core git commit: This closes #270

Posted by an...@apache.org.
This closes #270

NRF_SPIM1 didnt appear to exist. I believe its supposed to be NRF_SPI1


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

Branch: refs/heads/bluetooth5
Commit: d5cfc5cdb7684c1c902d62baea79e7a40139d2d9
Parents: eb4f289 f42bc72
Author: William San Filippo <wi...@runtime.io>
Authored: Tue May 9 21:08:05 2017 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Tue May 9 21:08:05 2017 -0700

----------------------------------------------------------------------
 apps/iptest/src/main.c                          |    4 +-
 apps/loraping/pkg.yml                           |   47 +
 apps/loraping/src/loraping.h                    |   27 +
 apps/loraping/src/main.c                        |  277 ++
 apps/loraping/src/rxinfo.c                      |  139 +
 apps/lorashell/pkg.yml                          |   34 +
 apps/lorashell/src/main.c                       |  514 ++
 apps/lorashell/syscfg.yml                       |   29 +
 compiler/xc32/compiler.yml                      |    4 +-
 compiler/xc32/pkg.yml                           |    3 +
 encoding/cborattr/src/cborattr.c                |    3 +-
 encoding/cborattr/test/src/test_cborattr.c      |    1 +
 encoding/cborattr/test/src/test_cborattr.h      |    1 +
 .../testcases/cborattr_decode_substring_key.c   |  111 +
 hw/bsp/nrf51-blenano/src/hal_bsp.c              |   31 +
 hw/bsp/nrf51-blenano/syscfg.yml                 |   26 +
 hw/bsp/pic32mx470_6lp_clicker/pkg.yml           |    4 +-
 hw/bsp/pic32mx470_6lp_clicker/src/hal_bsp.c     |    2 +-
 hw/bsp/pic32mz2048_wi-fire/pkg.yml              |    2 +
 hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c        |    2 +-
 hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c         |    2 +-
 .../src/arch/cortex_m4/startup_STM32F429x.s     |    3 -
 hw/bsp/telee02/pkg.yml                          |    3 +
 hw/bsp/telee02/syscfg.yml                       |    1 +
 hw/drivers/lora/sx1276/LICENSE.txt              |   25 +
 hw/drivers/lora/sx1276/include/radio/radio.h    |   33 +
 hw/drivers/lora/sx1276/pkg.yml                  |   32 +
 hw/drivers/lora/sx1276/src/sx1276-board.c       |  179 +
 hw/drivers/lora/sx1276/src/sx1276-board.h       |  127 +
 hw/drivers/lora/sx1276/src/sx1276.c             | 1824 +++++++
 hw/drivers/lora/sx1276/src/sx1276.h             |  364 ++
 hw/drivers/lora/sx1276/src/sx1276Regs-Fsk.h     | 1134 +++++
 hw/drivers/lora/sx1276/src/sx1276Regs-LoRa.h    |  565 +++
 hw/drivers/lora/sx1276/syscfg.yml               |   27 +
 hw/drivers/lwip/stm32_eth/src/stm32_eth.c       |    2 +-
 hw/mcu/microchip/pic32mx470f512h/pkg.yml        |    2 -
 .../pic32mz2048efg100/include/mcu/mcu.h         |   16 +
 hw/mcu/microchip/pic32mz2048efg100/pkg.yml      |    2 -
 .../microchip/pic32mz2048efg100/src/hal_gpio.c  |  485 ++
 .../microchip/pic32mz2048efg100/src/hal_uart.c  |    2 +-
 hw/mcu/nordic/nrf51xxx/src/hal_spi.c            |    2 +-
 hw/scripts/jlink.sh                             |   10 +-
 hw/scripts/openocd.sh                           |    6 +-
 .../arch/pic32/startup/cache-err-exception.S    |  129 +
 kernel/os/src/arch/pic32/startup/crt0.S         |  623 +++
 .../src/arch/pic32/startup/general-exception.S  |  141 +
 .../pic32/startup/simple-tlb-refill-exception.S |  135 +
 .../stubs/default-bootstrap-exception-handler.c |   58 +
 .../stubs/default-cache-err-exception-handler.c |   56 +
 .../stubs/default-general-exception-handler.c   |   54 +
 .../src/arch/pic32/stubs/default-nmi-handler.S  |   63 +
 .../src/arch/pic32/stubs/default-on-bootstrap.c |   43 +
 .../os/src/arch/pic32/stubs/default-on-reset.c  |   43 +
 ...efault-simple-tlb-refill-exception-handler.c |   56 +
 .../os/src/arch/pic32/stubs/pic32_init_cache.S  |  299 ++
 .../arch/pic32/stubs/pic32_init_tlb_ebi_sqi.S   |  145 +
 kernel/os/src/os_callout.c                      |    6 +-
 net/lora/node/LICENSE.txt                       |   25 +
 net/lora/node/README.md                         |   28 +
 net/lora/node/include/node/lora.h               |   34 +
 .../node/include/node/mac/LoRaMac-definitions.h |  610 +++
 net/lora/node/include/node/mac/LoRaMac.h        | 1830 ++++++++
 net/lora/node/include/node/mac/LoRaMacCrypto.h  |  111 +
 net/lora/node/include/node/mac/LoRaMacTest.h    |   81 +
 net/lora/node/include/node/radio.h              |  337 ++
 net/lora/node/include/node/utilities.h          |   79 +
 net/lora/node/pkg.yml                           |   41 +
 net/lora/node/src/lora_cli.c                    |  569 +++
 net/lora/node/src/lora_node.c                   |   48 +
 net/lora/node/src/lora_priv.h                   |   44 +
 net/lora/node/src/mac/LoRaMac.c                 | 4442 ++++++++++++++++++
 net/lora/node/src/mac/LoRaMacCrypto.c           |  203 +
 net/lora/node/src/mac/aes.h                     |  160 +
 net/lora/node/src/mac/cmac.h                    |   63 +
 net/lora/node/src/utilities.c                   |   67 +
 net/lora/node/syscfg.yml                        |   39 +
 sys/console/full/src/console.c                  |    6 +-
 sys/console/minimal/src/console.c               |    6 +-
 util/parse/include/parse/parse.h                |   47 +
 util/parse/pkg.yml                              |   32 +
 util/parse/src/parse.c                          |  263 ++
 81 files changed, 17094 insertions(+), 29 deletions(-)
----------------------------------------------------------------------



[06/43] incubator-mynewt-core git commit: hw: hsp: pic32mz2048_wi-fire: Define LED pins

Posted by an...@apache.org.
hw: hsp: pic32mz2048_wi-fire: Define LED pins

Signed-off-by: Francois Berder <fb...@outlook.fr>


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

Branch: refs/heads/bluetooth5
Commit: 1191e7da69143830def3c4166948aefe86f8659d
Parents: cb23f34
Author: Francois Berder <fb...@outlook.fr>
Authored: Tue May 9 14:15:45 2017 +0200
Committer: Francois Berder <fb...@outlook.fr>
Committed: Tue May 9 14:15:45 2017 +0200

----------------------------------------------------------------------
 hw/bsp/pic32mz2048_wi-fire/include/bsp/bsp.h | 8 ++++++++
 1 file changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1191e7da/hw/bsp/pic32mz2048_wi-fire/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/pic32mz2048_wi-fire/include/bsp/bsp.h b/hw/bsp/pic32mz2048_wi-fire/include/bsp/bsp.h
index 1a8a40c..06cd45f 100644
--- a/hw/bsp/pic32mz2048_wi-fire/include/bsp/bsp.h
+++ b/hw/bsp/pic32mz2048_wi-fire/include/bsp/bsp.h
@@ -20,6 +20,7 @@
 #define H_BSP_H
 
 #include <inttypes.h>
+#include "mcu/mcu.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -39,6 +40,13 @@ extern uint8_t _ccram_start;
 #define RAM_SIZE        (128 * 1024)
 #define CCRAM_SIZE      (64 * 1024)
 
+/* LED pins */
+#define LED_1           MCU_GPIO_PORTG(6)
+#define LED_2           MCU_GPIO_PORTD(4)
+#define LED_3           MCU_GPIO_PORTB(11)
+#define LED_4           MCU_GPIO_PORTG(15)
+#define LED_BLINK_PIN   LED_1
+
 /* UART */
 #define UART_CNT 6
 #define CONSOLE_UART "uart3"


[29/43] incubator-mynewt-core git commit: This closes #257

Posted by an...@apache.org.
This closes #257


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

Branch: refs/heads/bluetooth5
Commit: fe9bf2cd51aeef53a3d8fc8443c1521ed5a2f3ba
Parents: 5c343f5 80793bf
Author: Łukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu May 11 15:40:27 2017 +0200
Committer: Łukasz Rymanowski <lu...@codecoup.pl>
Committed: Thu May 11 15:40:27 2017 +0200

----------------------------------------------------------------------
 net/nimble/controller/include/controller/ble_ll_ctrl.h |  2 +-
 net/nimble/controller/src/ble_ll_conn_hci.c            |  4 ++--
 net/nimble/controller/src/ble_ll_ctrl.c                |  9 +++++----
 net/nimble/controller/src/ble_ll_sched.c               |  7 ++++---
 net/nimble/controller/syscfg.yml                       | 10 ++++++++++
 5 files changed, 22 insertions(+), 10 deletions(-)
----------------------------------------------------------------------



[26/43] incubator-mynewt-core git commit: bletiny: Remove not needed includes

Posted by an...@apache.org.
bletiny: Remove not needed includes


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

Branch: refs/heads/bluetooth5
Commit: 5ea502caf1a61de720dea676e6e3af3f065a0cb1
Parents: 652b459
Author: Łukasz Rymanowski <lu...@codecoup.pl>
Authored: Sat Apr 29 00:57:48 2017 +0200
Committer: Łukasz Rymanowski <lu...@codecoup.pl>
Committed: Thu May 11 14:16:39 2017 +0200

----------------------------------------------------------------------
 apps/bletiny/src/main.c | 4 ----
 1 file changed, 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5ea502ca/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 25ba5b0..676ad69 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -37,7 +37,6 @@
 #include "nimble/ble.h"
 #include "nimble/nimble_opt.h"
 #include "nimble/ble_hci_trans.h"
-#include "controller/ble_ll.h"
 #include "host/ble_hs.h"
 #include "host/ble_hs_adv.h"
 #include "host/ble_uuid.h"
@@ -47,9 +46,6 @@
 #include "host/ble_store.h"
 #include "host/ble_sm.h"
 
-/* RAM HCI transport. */
-#include "transport/ram/ble_hci_ram.h"
-
 /* Mandatory services. */
 #include "services/gap/ble_svc_gap.h"
 #include "services/gatt/ble_svc_gatt.h"


[21/43] incubator-mynewt-core git commit: nimble/ll: Fix sending features xchange PDUs

Posted by an...@apache.org.
nimble/ll: Fix sending features xchange PDUs

We only set single octet of CtrData field so need to clear other octets
as otherwise we can send some random value there.


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

Branch: refs/heads/bluetooth5
Commit: baa74ed2d3f6a5936b59c599265d2cd0296a6d69
Parents: 5c343f5
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Tue Apr 25 08:11:31 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Thu May 11 10:47:08 2017 +0200

----------------------------------------------------------------------
 net/nimble/controller/src/ble_ll_ctrl.c | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/baa74ed2/net/nimble/controller/src/ble_ll_ctrl.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_ctrl.c b/net/nimble/controller/src/ble_ll_ctrl.c
index 5522564..1535792 100644
--- a/net/nimble/controller/src/ble_ll_ctrl.c
+++ b/net/nimble/controller/src/ble_ll_ctrl.c
@@ -1283,6 +1283,7 @@ ble_ll_ctrl_proc_init(struct ble_ll_conn_sm *connsm, int ctrl_proc)
             } else {
                 opcode = BLE_LL_CTRL_SLAVE_FEATURE_REQ;
             }
+            memset(ctrdata, 0, BLE_LL_CTRL_FEATURE_LEN);
             ctrdata[0] = ble_ll_read_supp_features();
             break;
         case BLE_LL_CTRL_PROC_VERSION_XCHG:


[25/43] incubator-mynewt-core git commit: nimble/controller: Use scansm from function parameter

Posted by an...@apache.org.
nimble/controller: Use scansm from function parameter


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

Branch: refs/heads/bluetooth5
Commit: ef1b67ff8700db9e191ec5a67c74c6e29311ff26
Parents: 5ea502c
Author: Łukasz Rymanowski <lu...@codecoup.pl>
Authored: Fri May 5 14:12:47 2017 +0200
Committer: Łukasz Rymanowski <lu...@codecoup.pl>
Committed: Thu May 11 14:16:39 2017 +0200

----------------------------------------------------------------------
 net/nimble/controller/src/ble_ll_scan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ef1b67ff/net/nimble/controller/src/ble_ll_scan.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_scan.c b/net/nimble/controller/src/ble_ll_scan.c
index 7f0c40b..1b540bc 100644
--- a/net/nimble/controller/src/ble_ll_scan.c
+++ b/net/nimble/controller/src/ble_ll_scan.c
@@ -486,7 +486,7 @@ ble_ll_hci_send_adv_report(uint8_t pdu_type, uint8_t txadd, uint8_t *rxbuf,
             rc = ble_ll_hci_event_send(orig_evbuf);
             if (!rc) {
                 /* If filtering, add it to list of duplicate addresses */
-                if (g_ble_ll_scan_sm.scan_filt_dups) {
+                if (scansm->scan_filt_dups) {
                     ble_ll_scan_add_dup_adv(adv_addr, txadd, subev);
                 }
             }


[23/43] incubator-mynewt-core git commit: nimble/ll: Change LL PDU name to match spec

Posted by an...@apache.org.
nimble/ll: Change LL PDU name to match spec

The LL_CONNECTION_UPDATE_REQ is renamed to LL_CONNECTION_UPDATE_IND in
the latest versions of spec, so let's follow this.


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

Branch: refs/heads/bluetooth5
Commit: fb476e7192c4f84b1eb9618c65f94eabd4ee3c23
Parents: 9f3452c
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Tue Apr 25 08:19:00 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Thu May 11 10:47:11 2017 +0200

----------------------------------------------------------------------
 net/nimble/controller/include/controller/ble_ll_ctrl.h | 2 +-
 net/nimble/controller/src/ble_ll_ctrl.c                | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fb476e71/net/nimble/controller/include/controller/ble_ll_ctrl.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_ctrl.h b/net/nimble/controller/include/controller/ble_ll_ctrl.h
index ab302e4..a0b24a9 100644
--- a/net/nimble/controller/include/controller/ble_ll_ctrl.h
+++ b/net/nimble/controller/include/controller/ble_ll_ctrl.h
@@ -53,7 +53,7 @@ extern "C" {
  *  -> Opcode   (1 byte)
  *  -> Data     (0 - 26 bytes)
  */
-#define BLE_LL_CTRL_CONN_UPDATE_REQ     (0)
+#define BLE_LL_CTRL_CONN_UPDATE_IND     (0)
 #define BLE_LL_CTRL_CHANNEL_MAP_REQ     (1)
 #define BLE_LL_CTRL_TERMINATE_IND       (2)
 #define BLE_LL_CTRL_ENC_REQ             (3)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fb476e71/net/nimble/controller/src/ble_ll_ctrl.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_ctrl.c b/net/nimble/controller/src/ble_ll_ctrl.c
index 1535792..8db0727 100644
--- a/net/nimble/controller/src/ble_ll_ctrl.c
+++ b/net/nimble/controller/src/ble_ll_ctrl.c
@@ -295,7 +295,7 @@ ble_ll_ctrl_proc_unk_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr)
     case BLE_LL_CTRL_LENGTH_REQ:
         ctrl_proc = BLE_LL_CTRL_PROC_DATA_LEN_UPD;
         break;
-    case BLE_LL_CTRL_CONN_UPDATE_REQ:
+    case BLE_LL_CTRL_CONN_UPDATE_IND:
         ctrl_proc = BLE_LL_CTRL_PROC_CONN_UPDATE;
         break;
     case BLE_LL_CTRL_SLAVE_FEATURE_REQ:
@@ -911,7 +911,7 @@ ble_ll_ctrl_conn_param_reply(struct ble_ll_conn_sm *connsm, uint8_t *rsp,
     } else {
         /* Create a connection update pdu */
         ble_ll_ctrl_conn_upd_make(connsm, rsp + 1, req);
-        rsp_opcode = BLE_LL_CTRL_CONN_UPDATE_REQ;
+        rsp_opcode = BLE_LL_CTRL_CONN_UPDATE_IND;
     }
 
     return rsp_opcode;
@@ -1270,7 +1270,7 @@ ble_ll_ctrl_proc_init(struct ble_ll_conn_sm *connsm, int ctrl_proc)
 
         switch (ctrl_proc) {
         case BLE_LL_CTRL_PROC_CONN_UPDATE:
-            opcode = BLE_LL_CTRL_CONN_UPDATE_REQ;
+            opcode = BLE_LL_CTRL_CONN_UPDATE_IND;
             ble_ll_ctrl_conn_upd_make(connsm, ctrdata, NULL);
             break;
         case BLE_LL_CTRL_PROC_CHAN_MAP_UPD:
@@ -1628,7 +1628,7 @@ ble_ll_ctrl_rx_pdu(struct ble_ll_conn_sm *connsm, struct os_mbuf *om)
     /* Process opcode */
     rsp_opcode = BLE_ERR_MAX;
     switch (opcode) {
-    case BLE_LL_CTRL_CONN_UPDATE_REQ:
+    case BLE_LL_CTRL_CONN_UPDATE_IND:
         rsp_opcode = ble_ll_ctrl_rx_conn_update(connsm, dptr, rspbuf);
         break;
     case BLE_LL_CTRL_CHANNEL_MAP_REQ:


[36/43] incubator-mynewt-core git commit: MYNEWT-748 SensorAPI: Add BME280 support

Posted by an...@apache.org.
MYNEWT-748 SensorAPI: Add BME280 support

SensorAPI support for pressure, temperature and humidity

- Add temperature, pressure, humidity support
- change temperature handling for bno055
- fix bugs with register values


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

Branch: refs/heads/bluetooth5
Commit: 1dc1635810bd5b0eea1c3faed1675d9139e2a32d
Parents: 8d98e07
Author: Vipul Rahane <vi...@apache.org>
Authored: Tue May 2 18:52:45 2017 -0700
Committer: Vipul Rahane <vi...@apache.org>
Committed: Fri May 12 17:08:16 2017 -0700

----------------------------------------------------------------------
 apps/sensors_test/src/main.c                    |  10 +
 .../sensors/bme280/include/bme280/bme280.h      |  19 +
 hw/drivers/sensors/bme280/src/bme280.c          | 446 +++++++++++++++++--
 hw/drivers/sensors/bme280/src/bme280_priv.h     |  15 +-
 hw/drivers/sensors/bme280/src/bme280_shell.c    |  16 +-
 .../sensors/bno055/include/bno055/bno055.h      |   2 +-
 hw/drivers/sensors/bno055/src/bno055.c          |  32 +-
 hw/sensor/include/sensor/humidity.h             |  45 ++
 hw/sensor/include/sensor/pressure.h             |  45 ++
 hw/sensor/include/sensor/temperature.h          |  45 ++
 hw/sensor/src/sensor_shell.c                    |  23 +-
 11 files changed, 649 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1dc16358/apps/sensors_test/src/main.c
----------------------------------------------------------------------
diff --git a/apps/sensors_test/src/main.c b/apps/sensors_test/src/main.c
index ce5f4bd..ace40af 100755
--- a/apps/sensors_test/src/main.c
+++ b/apps/sensors_test/src/main.c
@@ -400,6 +400,16 @@ config_sensor(void)
 
     memset(&bmecfg, 0, sizeof(bmecfg));
 
+    bmecfg.bc_mode = BME280_MODE_NORMAL;
+    bmecfg.bc_iir = BME280_FILTER_OFF;
+    bmecfg.bc_sby_dur = BME280_STANDBY_MS_1000;
+    bmecfg.bc_boc[0].boc_type = SENSOR_TYPE_RELATIVE_HUMIDITY;
+    bmecfg.bc_boc[1].boc_type = SENSOR_TYPE_PRESSURE;
+    bmecfg.bc_boc[2].boc_type = SENSOR_TYPE_TEMPERATURE;
+    bmecfg.bc_boc[0].boc_oversample = BME280_SAMPLING_X1;
+    bmecfg.bc_boc[1].boc_oversample = BME280_SAMPLING_X1;
+    bmecfg.bc_boc[2].boc_oversample = BME280_SAMPLING_X1;
+
     rc = bme280_config((struct bme280 *)dev, &bmecfg);
     if (rc) {
         os_dev_close(dev);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1dc16358/hw/drivers/sensors/bme280/include/bme280/bme280.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/include/bme280/bme280.h b/hw/drivers/sensors/bme280/include/bme280/bme280.h
index 4ef5d78..ff3daa3 100644
--- a/hw/drivers/sensors/bme280/include/bme280/bme280.h
+++ b/hw/drivers/sensors/bme280/include/bme280/bme280.h
@@ -93,6 +93,7 @@ struct bme280_cfg {
     uint8_t bc_iir;
     struct bme280_over_cfg bc_boc[3];
     uint8_t bc_mode;
+    uint8_t bc_sby_dur;
 };
 
 struct bme280 {
@@ -234,6 +235,24 @@ int bme280_config(struct bme280 *bme280, struct bme280_cfg *cfg);
 int
 bme280_get_chipid(uint8_t *chipid);
 
+/**
+ * Set the standy duration setting
+ *
+ * @param duration
+ * @return 0 on success, non-zero on failure
+ */
+int
+bme280_set_sby_duration(uint8_t dur);
+
+/**
+ * Get the standy duration setting
+ *
+ * @param ptr to duration
+ * @return 0 on success, non-zero on failure
+ */
+int
+bme280_get_sby_duration(uint8_t *dur);
+
 #if MYNEWT_VAL(BME280_CLI)
 int bme280_shell_init(void);
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1dc16358/hw/drivers/sensors/bme280/src/bme280.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/src/bme280.c b/hw/drivers/sensors/bme280/src/bme280.c
index e31cffc..7c66307 100644
--- a/hw/drivers/sensors/bme280/src/bme280.c
+++ b/hw/drivers/sensors/bme280/src/bme280.c
@@ -28,6 +28,9 @@
 #include "hal/hal_spi.h"
 #include "sensor/sensor.h"
 #include "bme280/bme280.h"
+#include "sensor/humidity.h"
+#include "sensor/temperature.h"
+#include "sensor/pressure.h"
 #include "bme280_priv.h"
 #include "hal/hal_gpio.h"
 
@@ -46,6 +49,8 @@ static struct hal_spi_settings spi_bme280_settings = {
     .word_size  = HAL_SPI_WORD_SIZE_8BIT,
 };
 
+struct bme280_calib_data bcd;
+
 #if MYNEWT_VAL(BME280_STATS)
 /* Define the stats section and records */
 STATS_SECT_START(bme280_stat_section)
@@ -85,6 +90,8 @@ static const struct sensor_driver g_bme280_sensor_driver = {
     bme280_sensor_get_config
 };
 
+float g_t_fine;
+
 static int
 bme280_default_cfg(struct bme280_cfg *cfg)
 {
@@ -186,13 +193,238 @@ bme280_sensor_get_interface(struct sensor *sensor, sensor_type_t type)
     return (NULL);
 }
 
+#if MYNEWT_VAL(BME280_SPEC_CALC)
+/**
+ * Returns temperature in DegC, as float
+ * Output value of “51.23” equals 51.23 DegC.
+ *
+ * @param uncompensated raw temperature value
+ * @return 0 on success, non-zero on failure
+ */
+static float
+bme280_compensate_temperature(uint32_t rawtemp, struct bme280_calib_data *bcd)
+{
+    float var1, var2, comptemp;
+
+    var1 = (((float)rawtemp)/16384.0 – ((float)bcd->bcd_dig_T1)/1024.0) *
+            ((float)bcd->bcd_dig_T2);
+    var2 = ((((float)rawtemp)/131072.0 – ((float)bcd->bcd_dig_T1)/8192.0) *
+            (((float)rawtemp)/131072.0 – ((float)bcd->bcd_dig_T1)/8192.0)) *
+             ((float)bcd->bcd_dig_T3);
+
+    g_t_fine = var1 + var2;
+
+    comptemp = (var1 + var2) / 5120.0;
+
+    return comptemp;
+}
+
+/**
+ * Returns pressure in Pa as float.
+ * Output value of “96386.2” equals 96386.2 Pa = 963.862 hPa
+ *
+ * @param uncompensated raw pressure value
+ * @return 0 on success, non-zero on failure
+ */
+static float
+bme280_compensate_pressure(uint32_t rawpress, struct bme280_calib_data *bcd)
+{
+    float var1, var2, p;
+    uint32_t temp;
+
+    if (!g_t_fine) {
+        if(!bme280_get_temperature(&temp)) {
+            (void)bme280_compensate_temperature(temp);
+        }
+    }
+
+    var1 = ((float)g_t_fine/2.0) – 64000.0;
+    var2 = var1 * var1 * ((float)bcd->bcd_dig_P6) / 32768.0;
+    var2 = var2 + var1 * ((float)bcd->bcd_dig_P5) * 2.0;
+    var2 = (var2/4.0)+(((float)bcd->bcd_dig_P4) * 65536.0);
+    var1 = (((float)bcd->bcd_dig_P3) * var1 * var1 / 524288.0 +
+            ((float)bcd->bcd_dig_P2) * var1) / 524288.0;
+    var1 = (1.0 + var1 / 32768.0)*((float)bcd->bcd_dig_P1);
+
+    if (var1 == 0.0)
+    {
+        return 0;
+    }
+
+    p = 1048576.0 – (float)rawpress;
+    p = (p – (var2 / 4096.0)) * 6250.0 / var1;
+
+    var1 = ((float)bcd->bcd_dig_P9) * p * p / 2147483648.0;
+    var2 = p * ((float)bcd->bcd_dig_P8) / 32768.0;
+
+    p = p + (var1 + var2 + ((float)bcd->bcd_dig_P7)) / 16.0;
+
+    return p;
+}
+
+/**
+ * Returns humidity in %rH as float.
+ * Output value of “46.332” represents 46.332 %rH
+ *
+ * @param uncompensated raw humidity value
+ * @return 0 on success, non-zero on failure
+ */
+static float
+bme280_compensate_humidity(uint32_t rawhumid, struct bme280_calib_data *bcd)
+{
+    float h;
+    uint32_t temp;
+
+    if (!g_t_fine) {
+        if(!bme280_get_temperature(&temp)) {
+            (void)bme280_compensate_temperature(temp, bcd);
+        }
+    }
+
+    h = (((float)g_t_fine) – 76800.0);
+    h = (rawhumid – (((float)bcd->bcd_dig_H4) * 64.0 +
+         ((float)bcd->bcd_dig_H5) / 16384.0 * h)) *
+         (((float)bcd->bcd_dig_H2) / 65536.0 * (1.0 +
+           ((float)bcd->bcd_dig_H6) / 67108864.0 * h *
+          (1.0 + ((float)bcd->bcd_dig_H3) / 67108864.0 * h)));
+
+    h = h * (1.0 – ((float)bcd->bcd_dig_H1) * h / 524288.0);
+    if (h > 100.0) {
+        h = 100.0;
+    } else if (h < 0.0) {
+        h = 0.0;
+    }
+
+    return h;
+}
+
+#else
+
+/**
+ * Returns temperature in DegC, as float
+ * Output value of “51.23” equals 51.23 DegC.
+ *
+ * @param uncompensated raw temperature value
+ * @return 0 on success, non-zero on failure
+ */
+static float
+bme280_compensate_temperature(uint32_t rawtemp, struct bme280_calib_data *bcd)
+{
+    float var1, var2, comptemp;
+
+    rawtemp >>= 4;
+
+    var1 = ((((rawtemp>>3) - ((int32_t)bcd->bcd_dig_T1 <<1))) *
+            ((int32_t)bcd->bcd_dig_T2)) >> 11;
+
+    var2 = (((((rawtemp>>4) - ((int32_t)bcd->bcd_dig_T1)) *
+              ((rawtemp>>4) - ((int32_t)bcd->bcd_dig_T1))) >> 12) *
+            ((int32_t)bcd->bcd_dig_T3)) >> 14;
+
+    g_t_fine = var1 + var2;
+
+    comptemp = ((int32_t)(g_t_fine * 5 + 128)) >> 8;
+
+    return comptemp/100;
+}
+
+/**
+ * Returns pressure in Pa as float.
+ * Output value of “96386.2” equals 96386.2 Pa = 963.862 hPa
+ *
+ * @param uncompensated raw pressure value
+ * @return 0 on success, non-zero on failure
+ */
+static float
+bme280_compensate_pressure(uint32_t rawpress, struct bme280_calib_data *bcd)
+{
+    float var1, var2, p;
+    uint32_t temp;
+
+    if (!g_t_fine) {
+        if(!bme280_get_temperature(&temp)) {
+            (void)bme280_compensate_temperature(temp, bcd);
+        }
+    }
+
+    rawpress >>= 4;
+
+    var1 = ((int64_t)g_t_fine) - 128000;
+    var2 = var1 * var1 * (int64_t)bcd->bcd_dig_P6;
+    var2 = var2 + ((int64_t)(var1*(int64_t)bcd->bcd_dig_P5) << 17);
+    var2 = var2 + (((int64_t)bcd->bcd_dig_P4) << 35);
+    var1 = ((int64_t)(var1 * var1 * (int64_t)bcd->bcd_dig_P3) >> 8) +
+    ((int64_t)(var1 * (int64_t)bcd->bcd_dig_P2) << 12);
+    var1 = (int64_t)((((((int64_t)1) << 47)+var1))*((int64_t)bcd->bcd_dig_P1)) >> 33;
+
+    if (var1 == 0) {
+        /* Avoid exception caused by division by zero */
+        return 0;
+    }
+
+    p = 1048576 - rawpress;
+    p = ((((int64_t)p << 31) - var2) * 3125) / var1;
+
+    var1 = (int64_t)(((int64_t)bcd->bcd_dig_P9) * ((int64_t)p >> 13) * ((int64_t)p >> 13)) >> 25;
+    var2 = (int64_t)(((int64_t)bcd->bcd_dig_P8) * (int64_t)p) >> 19;
+
+    p = ((int64_t)(p + var1 + var2) >> 8) + (((int64_t)bcd->bcd_dig_P7) << 4);
+
+    return (float)p/256;
+}
+
+/**
+ * Returns humidity in %rH as float.
+ * Output value of “46.332” represents 46.332 %rH
+ *
+ * @param uncompensated raw humidity value
+ * @return 0 on success, non-zero on failure
+ */
+static float
+bme280_compensate_humidity(uint32_t rawhumid, struct bme280_calib_data *bcd)
+{
+    float h;
+    uint32_t temp;
+    int32_t tmp32;
+
+    if (!g_t_fine) {
+        if(!bme280_get_temperature(&temp)) {
+            (void)bme280_compensate_temperature(temp, bcd);
+        }
+    }
+
+    tmp32 = (g_t_fine - ((int32_t)76800));
+
+    tmp32 = (((((rawhumid << 14) - (((int32_t)bcd->bcd_dig_H4) << 20) -
+             (((int32_t)bcd->bcd_dig_H5) * tmp32)) + ((int32_t)16384)) >> 15) *
+             (((((((tmp32 * ((int32_t)bcd->bcd_dig_H6)) >> 10) *
+              (((tmp32 * ((int32_t)bcd->bcd_dig_H3)) >> 11) + ((int32_t)32768))) >> 10) +
+                    ((int32_t)2097152)) * ((int32_t)bcd->bcd_dig_H2) + 8192) >> 14));
+
+    tmp32 = (tmp32 - (((((tmp32 >> 15) * (tmp32 >> 15)) >> 7) *
+                      ((int32_t)bcd->bcd_dig_H1)) >> 4));
+
+    tmp32 = (tmp32 < 0) ? 0 : tmp32;
+
+    tmp32 = (tmp32 > 419430400) ? 419430400 : tmp32;
+
+    h = (tmp32 >> 12);
+
+    return  h / 1024.0;
+}
+
+#endif
+
 static int
 bme280_sensor_read(struct sensor *sensor, sensor_type_t type,
         sensor_data_func_t data_func, void *data_arg, uint32_t timeout)
 {
-    uint32_t temp;
-    uint32_t press;
-    uint32_t humid;
+    uint32_t rawtemp;
+    uint32_t rawpress;
+    uint32_t rawhumid;
+    struct sensor_temp_data std;
+    struct sensor_press_data spd;
+    struct sensor_humid_data shd;
     int rc;
 
     if (!(type & SENSOR_TYPE_PRESSURE)    &&
@@ -202,19 +434,20 @@ bme280_sensor_read(struct sensor *sensor, sensor_type_t type,
         goto err;
     }
 
-    temp = press = humid = 0;
+    rawtemp = rawpress = rawhumid = 0;
 
     /* Get a new pressure sample */
     if (type & SENSOR_TYPE_PRESSURE) {
-        rc = bme280_get_pressure(&press);
+        rc = bme280_get_pressure(&rawpress);
         if (rc) {
             goto err;
         }
 
-        //lux = bme280_calculate_lux(full, ir, &(bme280->cfg));
+        spd.spd_press = bme280_compensate_pressure(rawpress, &bcd);
+        spd.spd_press_is_valid = 1;
 
         /* Call data function */
-        rc = data_func(sensor, data_arg, &press);
+        rc = data_func(sensor, data_arg, &spd);
         if (rc) {
             goto err;
         }
@@ -222,15 +455,16 @@ bme280_sensor_read(struct sensor *sensor, sensor_type_t type,
 
     /* Get a new temperature sample */
     if (type & SENSOR_TYPE_TEMPERATURE) {
-        rc = bme280_get_temperature(&temp);
+        rc = bme280_get_temperature(&rawtemp);
         if (rc) {
             goto err;
         }
 
-        //lux = bme280_calculate_lux(full, ir, &(bme280->cfg));
+        std.std_temp = bme280_compensate_temperature(rawtemp, &bcd);
+        std.std_temp_is_valid = 1;
 
         /* Call data function */
-        rc = data_func(sensor, data_arg, &temp);
+        rc = data_func(sensor, data_arg, &std);
         if (rc) {
             goto err;
         }
@@ -238,15 +472,16 @@ bme280_sensor_read(struct sensor *sensor, sensor_type_t type,
 
     /* Get a new relative humidity sample */
     if (type & SENSOR_TYPE_RELATIVE_HUMIDITY) {
-        rc = bme280_get_humidity(&humid);
+        rc = bme280_get_humidity(&rawhumid);
         if (rc) {
             goto err;
         }
 
-        //lux = bme280_calculate_lux(full, ir, &(bme280->cfg));
+        shd.shd_humid = bme280_compensate_humidity(rawhumid, &bcd);
+        shd.shd_humid_is_valid = 1;
 
         /* Call data function */
-        rc = data_func(sensor, data_arg, &humid);
+        rc = data_func(sensor, data_arg, &shd);
         if (rc) {
             goto err;
         }
@@ -270,7 +505,7 @@ bme280_sensor_get_config(struct sensor *sensor, sensor_type_t type,
         goto err;
     }
 
-    cfg->sc_valtype = SENSOR_VALUE_TYPE_INT32;
+    cfg->sc_valtype = SENSOR_VALUE_TYPE_FLOAT;
 
     return (0);
 err:
@@ -278,6 +513,72 @@ err:
 }
 
 /**
+ * Check status to see if the sensor is  reading calibration
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+bme280_is_calibrating(uint8_t *calibrating)
+{
+    uint8_t status;
+    int rc;
+
+    rc = bme280_readlen(BME280_REG_ADDR_STATUS, &status, 1);
+    if (rc) {
+        goto err;
+    }
+
+    *calibrating = (status & BME280_REG_STATUS_IM_UP) != 0;
+
+    return 0;
+err:
+    return rc;
+}
+
+/**
+ * Get calibration info from the sensor
+ *
+ * @param ptr to the calib data info
+ * @return 0 in success, non-zero on failure
+ */
+static int
+bme280_get_calibinfo(struct bme280_calib_data *bcd)
+{
+    int rc;
+    uint8_t payload[33];
+
+    rc = bme280_readlen(BME280_REG_ADDR_DIG_T1, payload, sizeof(payload));
+    if (rc) {
+        goto err;
+    }
+
+    bcd->bcd_dig_T1 = payload[0] | payload[1] << 8;
+    bcd->bcd_dig_T2 = payload[3] | payload[2] << 8;
+    bcd->bcd_dig_T3 = payload[5] | payload[4] << 8;
+
+    bcd->bcd_dig_P1 = payload[7] | payload[6] << 8;
+    bcd->bcd_dig_P2 = payload[9] | payload[8] << 8;
+    bcd->bcd_dig_P3 = payload[11] | payload[10] << 8;
+    bcd->bcd_dig_P4 = payload[13] | payload[12] << 8;
+    bcd->bcd_dig_P5 = payload[15] | payload[14] << 8;
+    bcd->bcd_dig_P6 = payload[17] | payload[16] << 8;
+    bcd->bcd_dig_P7 = payload[19] | payload[18] << 8;
+    bcd->bcd_dig_P8 = payload[21] | payload[20] << 8;
+    bcd->bcd_dig_P9 = payload[23] | payload[22] << 8;
+
+    bcd->bcd_dig_H1 = payload[24];
+    bcd->bcd_dig_H2 = payload[26] | payload[25] << 8;
+    bcd->bcd_dig_H3 = payload[27];
+    bcd->bcd_dig_H4 = (payload[28] << 4) | (payload[29] & 0xF);
+    bcd->bcd_dig_H5 = (payload[31] << 4) | (payload[30] >> 4);
+    bcd->bcd_dig_H6 = (int8_t)payload[32];
+
+    return 0;
+err:
+    return rc;
+}
+
+/**
  * Configure BME280 sensor
  *
  * @param Sensor device BME280 structure
@@ -290,6 +591,7 @@ bme280_config(struct bme280 *bme280, struct bme280_cfg *cfg)
 {
     int rc;
     uint8_t id;
+    uint8_t calibrating;
 
     /* Check if we can read the chip address */
     rc = bme280_get_chipid(&id);
@@ -311,11 +613,34 @@ bme280_config(struct bme280 *bme280, struct bme280_cfg *cfg)
         }
     }
 
+    rc = bme280_reset();
+    if (rc) {
+        goto err;
+    }
+
+    os_time_delay((OS_TICKS_PER_SEC * 300)/1000 + 1);
+
+    calibrating = 1;
+
+    while(calibrating) {
+        rc = bme280_is_calibrating(&calibrating);
+        if (rc) {
+            goto err;
+        }
+    }
+
+    rc = bme280_get_calibinfo(&bcd);
+    if (rc) {
+        goto err;
+    }
+
     rc = bme280_set_iir(cfg->bc_iir);
     if (rc) {
         goto err;
     }
 
+    os_time_delay((OS_TICKS_PER_SEC * 200)/1000 + 1);
+
     bme280->cfg.bc_iir = cfg->bc_iir;
 
     rc = bme280_set_mode(cfg->bc_mode);
@@ -323,9 +648,20 @@ bme280_config(struct bme280 *bme280, struct bme280_cfg *cfg)
         goto err;
     }
 
+    os_time_delay((OS_TICKS_PER_SEC * 200)/1000 + 1);
+
     bme280->cfg.bc_mode = cfg->bc_mode;
 
-    if (!cfg->bc_boc[0].boc_type) {
+    rc = bme280_set_sby_duration(cfg->bc_sby_dur);
+    if (rc) {
+        goto err;
+    }
+
+    os_time_delay((OS_TICKS_PER_SEC * 200)/1000 + 1);
+
+    bme280->cfg.bc_sby_dur = cfg->bc_sby_dur;
+
+    if (cfg->bc_boc[0].boc_type) {
         rc = bme280_set_oversample(cfg->bc_boc[0].boc_type,
                                    cfg->bc_boc[0].boc_oversample);
         if (rc) {
@@ -336,7 +672,7 @@ bme280_config(struct bme280 *bme280, struct bme280_cfg *cfg)
     bme280->cfg.bc_boc[0].boc_type = cfg->bc_boc[0].boc_type;
     bme280->cfg.bc_boc[0].boc_oversample = cfg->bc_boc[0].boc_oversample;
 
-    if (!cfg->bc_boc[1].boc_type) {
+    if (cfg->bc_boc[1].boc_type) {
         rc = bme280_set_oversample(cfg->bc_boc[1].boc_type,
                                    cfg->bc_boc[1].boc_oversample);
         if (rc) {
@@ -347,7 +683,7 @@ bme280_config(struct bme280 *bme280, struct bme280_cfg *cfg)
     bme280->cfg.bc_boc[1].boc_type = cfg->bc_boc[1].boc_type;
     bme280->cfg.bc_boc[1].boc_oversample = cfg->bc_boc[1].boc_oversample;
 
-    if (!cfg->bc_boc[2].boc_type) {
+    if (cfg->bc_boc[2].boc_type) {
         rc = bme280_set_oversample(cfg->bc_boc[2].boc_type,
                                    cfg->bc_boc[2].boc_oversample);
         if (rc) {
@@ -358,6 +694,9 @@ bme280_config(struct bme280 *bme280, struct bme280_cfg *cfg)
     bme280->cfg.bc_boc[2].boc_type = cfg->bc_boc[2].boc_type;
     bme280->cfg.bc_boc[2].boc_oversample = cfg->bc_boc[2].boc_oversample;
 
+    os_time_delay((OS_TICKS_PER_SEC * 200)/1000 + 1);
+
+    return 0;
 err:
     return (rc);
 }
@@ -426,7 +765,8 @@ bme280_writelen(uint8_t addr, uint8_t *payload, uint8_t len)
     hal_gpio_write(MYNEWT_VAL(BME280_CSPIN), 0);
 
     /* Send the address */
-    rc = hal_spi_tx_val(MYNEWT_VAL(BME280_SPINUM), addr | BME280_SPI_READ_CMD_BIT);
+    rc = hal_spi_tx_val(MYNEWT_VAL(BME280_SPINUM),
+                        addr & ~BME280_SPI_READ_CMD_BIT);
     if (rc == 0xFFFF) {
         rc = SYS_EINVAL;
         goto err;
@@ -531,7 +871,7 @@ bme280_reset(void)
 {
     uint8_t txdata;
 
-    txdata = 1;
+    txdata = 0xB6;
 
     return bme280_writelen(BME280_REG_ADDR_RESET, &txdata, 1);
 }
@@ -632,9 +972,9 @@ bme280_set_mode(uint8_t mode)
         goto err;
     }
 
-    mode = cfg | (mode & BME280_REG_CTRL_MEAS_MODE);
+    cfg = cfg | (mode & BME280_REG_CTRL_MEAS_MODE);
 
-    rc = bme280_writelen(BME280_REG_ADDR_CTRL_MEAS, &mode, 1);
+    rc = bme280_writelen(BME280_REG_ADDR_CTRL_MEAS, &cfg, 1);
     if (rc) {
         goto err;
     }
@@ -706,14 +1046,14 @@ bme280_set_oversample(sensor_type_t type, uint8_t oversample)
         }
 
         if (type & SENSOR_TYPE_TEMPERATURE) {
-            oversample = cfg | ((oversample << 5) & BME280_REG_CTRL_MEAS_TOVER);
+            cfg = cfg | ((oversample << 5) & BME280_REG_CTRL_MEAS_TOVER);
         }
 
         if (type & SENSOR_TYPE_PRESSURE) {
-            oversample = cfg | ((oversample << 3) & BME280_REG_CTRL_MEAS_POVER);
+            cfg = cfg | ((oversample << 2) & BME280_REG_CTRL_MEAS_POVER);
         }
 
-        rc = bme280_writelen(BME280_REG_ADDR_CTRL_MEAS, &oversample, 1);
+        rc = bme280_writelen(BME280_REG_ADDR_CTRL_MEAS, &cfg, 1);
         if (rc) {
             goto err;
         }
@@ -725,9 +1065,9 @@ bme280_set_oversample(sensor_type_t type, uint8_t oversample)
             goto err;
         }
 
-        oversample = cfg | (oversample & BME280_REG_CTRL_HUM_HOVER);
+        cfg = cfg | (oversample & BME280_REG_CTRL_HUM_HOVER);
 
-        rc = bme280_writelen(BME280_REG_ADDR_CTRL_HUM, &oversample, 1);
+        rc = bme280_writelen(BME280_REG_ADDR_CTRL_HUM, &cfg, 1);
         if (rc) {
             goto err;
         }
@@ -761,3 +1101,57 @@ bme280_get_chipid(uint8_t *chipid)
 err:
     return rc;
 }
+
+/**
+ * Set the standy duration setting
+ *
+ * @param duration
+ * @return 0 on success, non-zero on failure
+ */
+int
+bme280_set_sby_duration(uint8_t dur)
+{
+    int rc;
+    uint8_t cfg;
+
+    rc = bme280_readlen(BME280_REG_ADDR_CONFIG, &cfg, 1);
+    if (rc) {
+        goto err;
+    }
+
+    cfg = cfg | ((dur << 5) & BME280_REG_CONFIG_STANDBY);
+
+    rc = bme280_writelen(BME280_REG_ADDR_CONFIG, &cfg, 1);
+    if (rc) {
+        goto err;
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+/**
+ * Get the standy duration setting
+ *
+ * @param ptr to duration
+ * @return 0 on success, non-zero on failure
+ */
+int
+bme280_get_sby_duration(uint8_t *dur)
+{
+    int rc;
+    uint8_t tmp;
+
+    rc = bme280_readlen(BME280_REG_ADDR_CONFIG, &tmp, 1);
+    if (rc) {
+        goto err;
+    }
+
+    *dur = tmp & BME280_REG_CONFIG_STANDBY;
+
+    return 0;
+err:
+    return rc;
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1dc16358/hw/drivers/sensors/bme280/src/bme280_priv.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/src/bme280_priv.h b/hw/drivers/sensors/bme280/src/bme280_priv.h
index 23d0aaf..4b01e98 100644
--- a/hw/drivers/sensors/bme280/src/bme280_priv.h
+++ b/hw/drivers/sensors/bme280/src/bme280_priv.h
@@ -45,24 +45,23 @@
 #define BME280_REG_ADDR_VERSION           0xD1
 #define BME280_REG_ADDR_SOFTRESET         0xE0
 
-#define BME280_REG_ADDR_CAL26             0xE1  // R calibration stored in 0xE1-0xF0
+#define BME280_REG_ADDR_CAL26             0xE1  /* R calibration stored in 0xE1-0xF0 */
 
 #define BME280_REG_ADDR_CTRL_HUM          0xF2
-#define BME280_REG_CTRL_HUM_NONE        (0x1F)
-#define BME280_REG_CTRL_HUM_HOVER       (0x11)
+#define BME280_REG_CTRL_HUM_HOVER        (0x7)
 
 #define BME280_REG_ADDR_STATUS            0XF3
 #define BME280_REG_STATUS_MEAS            0x04
 #define BME280_REG_STATUS_IM_UP           0x01
 
 #define BME280_REG_ADDR_CTRL_MEAS         0xF4
-#define BME280_REG_CTRL_MEAS_TOVER (0x11 << 5)
-#define BME280_REG_CTRL_MEAS_POVER (0x11 << 3)
-#define BME280_REG_CTRL_MEAS_MODE       (0x11)
+#define BME280_REG_CTRL_MEAS_TOVER  (0x7 << 5)
+#define BME280_REG_CTRL_MEAS_POVER  (0x7 << 2)
+#define BME280_REG_CTRL_MEAS_MODE        (0x3)
 
 #define BME280_REG_ADDR_CONFIG            0xF5
-#define BME280_REG_CONFIG_STANDBY  (0x11 << 5)
-#define BME280_REG_CONFIG_FILTER   (0x11 << 3)
+#define BME280_REG_CONFIG_STANDBY   (0x7 << 5)
+#define BME280_REG_CONFIG_FILTER    (0x7 << 3)
 #define BME280_REG_CONFIG_SPI3_EN        (0x1)
 
 #define BME280_REG_ADDR_PRESS             0xF7

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1dc16358/hw/drivers/sensors/bme280/src/bme280_shell.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bme280/src/bme280_shell.c b/hw/drivers/sensors/bme280/src/bme280_shell.c
index 78f5d2e..aeea071 100644
--- a/hw/drivers/sensors/bme280/src/bme280_shell.c
+++ b/hw/drivers/sensors/bme280/src/bme280_shell.c
@@ -82,12 +82,12 @@ bme280_shell_help(void)
     console_printf("%s cmd [flags...]\n", bme280_shell_cmd_struct.sc_cmd);
     console_printf("cmd:\n");
     console_printf("\tr    [n_samples]\n");
-    console_printf("\tmode [0-sleep | 1-forced | 3-normal]\n");
-    console_printf("\tiir [1-enabled | 0-disabled]");
+    console_printf("\tmode [0-sleep | 1/2-forced | 3-normal]\n");
+    console_printf("\tiir [1-enabled | 0-disabled]\n");
     console_printf("\toversample [type 5-temperature | 6-pressure | 8-humidity]\n"
                    "             [0-none | 1-x1 | 2-x2 | 3-x4 | 4-x8 | 5-x16]\n");
     console_printf("\treset\n");
-    console_printf("\tchip_id");
+    console_printf("\tchipid\n");
     console_printf("\tdump\n");
 
     return 0;
@@ -104,7 +104,7 @@ bme280_shell_cmd_read_chipid(int argc, char **argv)
         goto err;
     }
 
-    console_printf("CHIP_ID:%02X", chipid);
+    console_printf("CHIP_ID:0x%02X\n", chipid);
 
     return 0;
 err:
@@ -159,7 +159,7 @@ bme280_shell_cmd_read(int argc, char **argv)
             return rc;
         }
 
-        console_printf("temperature: %u\tpressure: %u\thumidity: %u\n",
+        console_printf("temperature: %u pressure: %u\thumidity: %u\n",
                        (unsigned int)temp, (unsigned int)press,
                        (unsigned int)humid);
     }
@@ -235,9 +235,9 @@ bme280_shell_cmd_mode(int argc, char **argv)
         console_printf("mode: %u", mode);
     }
 
-    /* Chaneg mode */
+    /* Change mode */
     if (argc == 3) {
-        if (bme280_shell_stol(argv[2], 0, 1, &val)) {
+        if (bme280_shell_stol(argv[2], 0, 3, &val)) {
             return bme280_shell_err_invalid_arg(argv[2]);
         }
         rc = bme280_set_mode(val);
@@ -268,7 +268,7 @@ bme280_shell_cmd_iir(int argc, char **argv)
         if (rc) {
             goto err;
         }
-        console_printf("IIR: %02X", iir);
+        console_printf("IIR: 0x%02X", iir);
     }
 
     /* Enable/disable iir*/

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1dc16358/hw/drivers/sensors/bno055/include/bno055/bno055.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/include/bno055/bno055.h b/hw/drivers/sensors/bno055/include/bno055/bno055.h
index af1c836..f453871 100644
--- a/hw/drivers/sensors/bno055/include/bno055/bno055.h
+++ b/hw/drivers/sensors/bno055/include/bno055/bno055.h
@@ -223,7 +223,7 @@ bno055_get_quat_data(void *sqd);
  * @return temperature in degree celcius
  */
 int
-bno055_get_temp(int8_t *temp);
+bno055_get_temp(uint8_t *temp);
 
 /**
  * Gets current calibration status

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1dc16358/hw/drivers/sensors/bno055/src/bno055.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055.c b/hw/drivers/sensors/bno055/src/bno055.c
index 7502c5b..49eeb6e 100644
--- a/hw/drivers/sensors/bno055/src/bno055.c
+++ b/hw/drivers/sensors/bno055/src/bno055.c
@@ -30,6 +30,7 @@
 #include "sensor/mag.h"
 #include "sensor/quat.h"
 #include "sensor/euler.h"
+#include "sensor/temperature.h"
 #include "bno055/bno055.h"
 #include "bno055_priv.h"
 
@@ -1018,13 +1019,13 @@ err:
  * @return 0 on success, non-zero on error
  */
 int
-bno055_get_temp(int8_t *temp)
+bno055_get_temp(uint8_t *temp)
 {
     int rc;
     uint8_t units;
     uint8_t div;
 
-    rc = bno055_read8(BNO055_TEMP_ADDR, (uint8_t *)temp);
+    rc = bno055_read8(BNO055_TEMP_ADDR, temp);
     if (rc) {
         goto err;
     }
@@ -1044,6 +1045,31 @@ err:
 }
 
 /**
+ * Get temperature data from bno055 sensor and mark it valid
+ *
+ * @param pointer to the temperature data structure
+ * @return 0 on success, non-zero on error
+ */
+static int
+bno055_get_temp_data(struct sensor_temp_data *std)
+{
+    int rc;
+    uint8_t temp;
+
+    rc = bno055_get_temp(&temp);
+    if (rc) {
+        goto err;
+    }
+
+    std->std_temp = temp;
+    std->std_temp_is_valid = 1;
+
+    return 0;
+err:
+    return rc;
+}
+
+/**
  * Get sensor data of specific type. This function also allocates a buffer
  * to fill up the data in.
  *
@@ -1071,7 +1097,7 @@ bno055_sensor_read(struct sensor *sensor, sensor_type_t type,
             goto err;
         }
     } else if (type == SENSOR_TYPE_TEMPERATURE) {
-        rc = bno055_get_temp(databuf);
+        rc = bno055_get_temp_data(databuf);
         if (rc) {
             goto err;
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1dc16358/hw/sensor/include/sensor/humidity.h
----------------------------------------------------------------------
diff --git a/hw/sensor/include/sensor/humidity.h b/hw/sensor/include/sensor/humidity.h
new file mode 100644
index 0000000..40f5350
--- /dev/null
+++ b/hw/sensor/include/sensor/humidity.h
@@ -0,0 +1,45 @@
+/*
+ * 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 __SENSOR_HUMIDITY_H__
+#define __SENSOR_HUMIDITY_H__
+
+#include "os/os.h"
+#include "os/os_dev.h"
+#include "sensor/sensor.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Data representing a singular read from a pressure sensor
+ * All values are in %rH
+ */
+struct sensor_humid_data {
+    float shd_humid;
+
+    /* Validity */
+    uint8_t shd_humid_is_valid:1;
+} __attribute__((packed));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SENSOR_HUMIDITY_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1dc16358/hw/sensor/include/sensor/pressure.h
----------------------------------------------------------------------
diff --git a/hw/sensor/include/sensor/pressure.h b/hw/sensor/include/sensor/pressure.h
new file mode 100644
index 0000000..425fd91
--- /dev/null
+++ b/hw/sensor/include/sensor/pressure.h
@@ -0,0 +1,45 @@
+/*
+ * 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 __SENSOR_PRESSURE_H__
+#define __SENSOR_PRESSURE_H__
+
+#include "os/os.h"
+#include "os/os_dev.h"
+#include "sensor/sensor.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Data representing a singular read from a pressure sensor
+ * All values are in Pa
+ */
+struct sensor_press_data {
+    float spd_press;
+
+    /* Validity */
+    uint8_t spd_press_is_valid:1;
+} __attribute__((packed));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SENSOR_PRESSURE_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1dc16358/hw/sensor/include/sensor/temperature.h
----------------------------------------------------------------------
diff --git a/hw/sensor/include/sensor/temperature.h b/hw/sensor/include/sensor/temperature.h
new file mode 100644
index 0000000..247631f
--- /dev/null
+++ b/hw/sensor/include/sensor/temperature.h
@@ -0,0 +1,45 @@
+/*
+ * 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 __SENSOR_TEMPERATURE_H__
+#define __SENSOR_TEMPERATURE_H__
+
+#include "os/os.h"
+#include "os/os_dev.h"
+#include "sensor/sensor.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Data representing a singular read from a temperature sensor
+ * All values are in Deg C
+ */
+struct sensor_temp_data {
+    float std_temp;
+
+    /* Validity */
+    uint8_t std_temp_is_valid:1;
+} __attribute__((packed));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SENSOR_TEMPERATURE_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1dc16358/hw/sensor/src/sensor_shell.c
----------------------------------------------------------------------
diff --git a/hw/sensor/src/sensor_shell.c b/hw/sensor/src/sensor_shell.c
index ebe3b1b..69c1b94 100644
--- a/hw/sensor/src/sensor_shell.c
+++ b/hw/sensor/src/sensor_shell.c
@@ -37,6 +37,9 @@
 #include "sensor/quat.h"
 #include "sensor/euler.h"
 #include "sensor/color.h"
+#include "sensor/temperature.h"
+#include "sensor/pressure.h"
+#include "sensor/humidity.h"
 #include "console/console.h"
 #include "shell/shell.h"
 #include "hal/hal_i2c.h"
@@ -230,6 +233,9 @@ sensor_shell_read_listener(struct sensor *sensor, void *arg, void *data)
     struct sensor_euler_data *sed;
     struct sensor_quat_data *sqd;
     struct sensor_color_data *scd;
+    struct sensor_temp_data *std;
+    struct sensor_press_data *spd;
+    struct sensor_humid_data *shd;
     char tmpstr[13];
 
     ctx = (struct sensor_shell_read_ctx *) arg;
@@ -287,7 +293,10 @@ sensor_shell_read_listener(struct sensor *sensor, void *arg, void *data)
     }
 
     if (ctx->type == SENSOR_TYPE_TEMPERATURE) {
-        console_printf("temprature = %d", *(int *)data);
+        std = (struct sensor_temp_data *) data;
+        if (std->std_temp_is_valid) {
+            console_printf("temprature = %s", sensor_ftostr(std->std_temp, tmpstr, 13));
+        }
         console_printf("\n");
     }
 
@@ -365,12 +374,20 @@ sensor_shell_read_listener(struct sensor *sensor, void *arg, void *data)
     }
 
     if (ctx->type == SENSOR_TYPE_PRESSURE) {
-        console_printf("pressure = %d", *(int *)data);
+        spd = (struct sensor_press_data *) data;
+        if (spd->spd_press_is_valid) {
+            console_printf("pressure = %s Pa",
+                           sensor_ftostr(spd->spd_press, tmpstr, 13));
+        }
         console_printf("\n");
     }
 
     if (ctx->type == SENSOR_TYPE_RELATIVE_HUMIDITY) {
-        console_printf("relative humidity = %d", *(int *)data);
+        shd = (struct sensor_humid_data *) data;
+        if (shd->shd_humid_is_valid) {
+            console_printf("relative humidity = %s",
+                           sensor_ftostr(shd->shd_humid, tmpstr, 13));
+        }
         console_printf("\n");
     }
 


[04/43] incubator-mynewt-core git commit: Fix problems with starting debuggers on MSYS2/MINGW 1) Fixed launch hanging problem for openocd and jlink gdbserver when newt debug is run from mingw/bash (installed with msys2). openocd now starts in a new cmd p

Posted by an...@apache.org.
Fix problems with starting debuggers on MSYS2/MINGW
1) Fixed launch hanging problem for openocd and jlink gdbserver when
newt debug is run from mingw/bash (installed with msys2).
openocd now starts in a new cmd prompt window.
2) Fixed  to start gdb in a new cmd prompt when newt debug is run
from mingw/bash (installed with msys2). Before the fix, gdb did not
start in a new window and Control-C would cause gdb to exit.

Theses fixes should preserve the same behavior when running newt command
from git-bash, git-cmd, or cmd prompt.


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

Branch: refs/heads/bluetooth5
Commit: 1080d5c57220de83cf2a60608c7bef42fecfe2ad
Parents: debf64f
Author: cwanda <wa...@happycity.com>
Authored: Mon May 8 16:19:21 2017 -0700
Committer: cwanda <wa...@happycity.com>
Committed: Mon May 8 16:54:35 2017 -0700

----------------------------------------------------------------------
 hw/scripts/jlink.sh   | 4 ++--
 hw/scripts/openocd.sh | 6 ++++--
 2 files changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1080d5c5/hw/scripts/jlink.sh
----------------------------------------------------------------------
diff --git a/hw/scripts/jlink.sh b/hw/scripts/jlink.sh
index 5087ceb..88391b3 100644
--- a/hw/scripts/jlink.sh
+++ b/hw/scripts/jlink.sh
@@ -125,7 +125,7 @@ jlink_debug() {
             # Launch jlink server in a separate command interpreter, to make
             # sure it doesn't get killed by Ctrl-C signal from bash.
             #
-            $COMSPEC "/C start $COMSPEC /C $JLINK_GDB_SERVER -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun"
+            $COMSPEC /C "start $JLINK_GDB_SERVER -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun"
         else
             #
             # Block Ctrl-C from getting passed to jlink server.
@@ -145,7 +145,7 @@ jlink_debug() {
 
 	if [ $WINDOWS -eq 1 ]; then
 	    FILE_NAME=`echo $FILE_NAME | sed 's/\//\\\\/g'`
-	    $COMSPEC "/C start $COMSPEC /C arm-none-eabi-gdb -x $GDB_CMD_FILE $FILE_NAME"
+	    $COMSPEC /C "start arm-none-eabi-gdb -x $GDB_CMD_FILE $FILE_NAME"
 	else
             arm-none-eabi-gdb -x $GDB_CMD_FILE $FILE_NAME
             rm $GDB_CMD_FILE

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1080d5c5/hw/scripts/openocd.sh
----------------------------------------------------------------------
diff --git a/hw/scripts/openocd.sh b/hw/scripts/openocd.sh
index 12e5e32..50ac6ab 100644
--- a/hw/scripts/openocd.sh
+++ b/hw/scripts/openocd.sh
@@ -83,8 +83,9 @@ openocd_debug () {
             # Launch openocd in a separate command interpreter, to make sure
             # it doesn't get killed by Ctrl-C signal from bash.
             #
+
             CFG=`echo $CFG | sed 's/\//\\\\/g'`
-            $COMSPEC "/C start $COMSPEC /C openocd -l openocd.log $CFG -f $OCD_CMD_FILE -c init -c halt"
+            $COMSPEC /C "start openocd -l openocd.log $CFG -f $OCD_CMD_FILE -c init -c halt"
         else
             #
             # Block Ctrl-C from getting passed to openocd.
@@ -100,9 +101,10 @@ openocd_debug () {
         if [ ! -z "$RESET" ]; then
             echo "mon reset halt" >> $GDB_CMD_FILE
         fi
+	echo "FILENAME" $FILE_NAME >>out
 	if [ $WINDOWS -eq 1 ]; then
 	    FILE_NAME=`echo $FILE_NAME | sed 's/\//\\\\/g'`
-            $COMSPEC "/C start $COMSPEC /C arm-none-eabi-gdb -x $GDB_CMD_FILE $FILE_NAME"
+            $COMSPEC /C "start arm-none-eabi-gdb -x $GDB_CMD_FILE $FILE_NAME"
 	else
             arm-none-eabi-gdb -x $GDB_CMD_FILE $FILE_NAME
             rm $GDB_CMD_FILE


[16/43] incubator-mynewt-core git commit: hw: bsp: pic32mz2048_wi-fire: Set UART4 pins

Posted by an...@apache.org.
hw: bsp: pic32mz2048_wi-fire: Set UART4 pins

Specify the pins of UART4 (default console output) at
initialization:
RF8 -> U4TX
RF2 -> U4RX

Signed-off-by: Francois Berder <fb...@outlook.fr>


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

Branch: refs/heads/bluetooth5
Commit: 146565214f00fd006970ec749754ad5333f6b41d
Parents: bdd92f7
Author: Francois Berder <fb...@outlook.fr>
Authored: Tue May 9 11:29:42 2017 +0200
Committer: Francois Berder <fb...@outlook.fr>
Committed: Wed May 10 13:54:43 2017 +0200

----------------------------------------------------------------------
 hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/14656521/hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c b/hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c
index 17ac864..ccf5645 100644
--- a/hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c
+++ b/hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c
@@ -18,6 +18,8 @@
  */
 
 #include "hal/hal_bsp.h"
+#include "mcu/mcu.h"
+#include "mcu/mips_hal.h"
 #include "syscfg/syscfg.h"
 #include "uart/uart.h"
 #if MYNEWT_VAL(UART_0) || MYNEWT_VAL(UART_1) || MYNEWT_VAL(UART_2) || \
@@ -57,6 +59,10 @@ static struct uart_dev os_bsp_uart3;
 
 #if MYNEWT_VAL(UART_4)
 static struct uart_dev os_bsp_uart4;
+static const struct mips_uart_cfg uart4_cfg = {
+    .tx = MCU_GPIO_PORTF(8),
+    .rx = MCU_GPIO_PORTF(2)
+};
 #endif
 
 #if MYNEWT_VAL(UART_5)
@@ -90,7 +96,7 @@ hal_bsp_init(void)
 
     #if MYNEWT_VAL(UART_3)
         rc = os_dev_create((struct os_dev *) &os_bsp_uart3, "uart3",
-            OS_DEV_INIT_PRIMARY, 0, uart_hal_init, 0);
+            OS_DEV_INIT_PRIMARY, 0, uart_hal_init, &uart4_cfg);
         assert(rc == 0);
     #endif
 


[27/43] incubator-mynewt-core git commit: nimble/gap: Fix lock issue

Posted by an...@apache.org.
nimble/gap: Fix lock issue

Make sure proper cleaning is done when return error on connect and
discovery


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

Branch: refs/heads/bluetooth5
Commit: f05185188a15af2b5ead490b9d47e40ce6e5731a
Parents: 5c343f5
Author: Łukasz Rymanowski <lu...@codecoup.pl>
Authored: Sat Apr 29 00:50:50 2017 +0200
Committer: Łukasz Rymanowski <lu...@codecoup.pl>
Committed: Thu May 11 14:16:39 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_gap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f0518518/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 80bfa7a..122ef75 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -2217,7 +2217,7 @@ ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms,
     if (!params.passive) {
         rc = ble_hs_id_use_addr(own_addr_type);
         if (rc != 0) {
-            return rc;
+            goto done;
         }
     }
 
@@ -2426,7 +2426,7 @@ ble_gap_connect(uint8_t own_addr_type, const ble_addr_t *peer_addr,
 
     rc = ble_hs_id_use_addr(own_addr_type);
     if (rc != 0) {
-        return rc;
+        goto done;
     }
 
     BLE_HS_LOG(INFO, "GAP procedure initiated: connect; ");


[31/43] incubator-mynewt-core git commit: fix double semicolons

Posted by an...@apache.org.
fix double semicolons


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

Branch: refs/heads/bluetooth5
Commit: 4e06eb5d8dc93edfbc14e1a00b3edf8ebc93b1dc
Parents: d96b601
Author: Jacob Rosenthal <ja...@gmail.com>
Authored: Wed May 10 22:03:33 2017 -0700
Committer: Vipul Rahane <vi...@apache.org>
Committed: Thu May 11 11:39:00 2017 -0700

----------------------------------------------------------------------
 apps/sensors_test/src/main.c      | 2 +-
 hw/mcu/nxp/MK64F12/src/hal_uart.c | 2 +-
 net/nimble/host/src/ble_sm.c      | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4e06eb5d/apps/sensors_test/src/main.c
----------------------------------------------------------------------
diff --git a/apps/sensors_test/src/main.c b/apps/sensors_test/src/main.c
index f6ef755..d05cb94 100755
--- a/apps/sensors_test/src/main.c
+++ b/apps/sensors_test/src/main.c
@@ -398,7 +398,7 @@ config_sensor(void)
     }
 
     /* Gain set to 16X and Inetgration time set to 24ms */
-    tcscfg.gain = TCS34725_GAIN_16X;;
+    tcscfg.gain = TCS34725_GAIN_16X;
     tcscfg.integration_time = TCS34725_INTEGRATIONTIME_24MS;
 
     rc = tcs34725_config((struct tcs34725 *)dev, &tcscfg);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4e06eb5d/hw/mcu/nxp/MK64F12/src/hal_uart.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nxp/MK64F12/src/hal_uart.c b/hw/mcu/nxp/MK64F12/src/hal_uart.c
index ba56d5e..a4dcd14 100644
--- a/hw/mcu/nxp/MK64F12/src/hal_uart.c
+++ b/hw/mcu/nxp/MK64F12/src/hal_uart.c
@@ -100,7 +100,7 @@ static void (*s_uartirqs[])(void) = {
 
 static uint8_t ur_is_empty(struct uart_ring *ur)
 {
-    return (ur->ur_head == ur->ur_tail);;
+    return (ur->ur_head == ur->ur_tail);
 }
 
 static uint8_t ur_is_full(struct uart_ring *ur)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4e06eb5d/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index 9c925fd..0a4d09e 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -1720,7 +1720,7 @@ ble_sm_sec_req_rx(uint16_t conn_handle, struct os_mbuf **om,
          */
         ble_hs_conn_addrs(conn, &addrs);
         memset(&key_sec, 0, sizeof key_sec);
-        key_sec.peer_addr = addrs.peer_id_addr;;
+        key_sec.peer_addr = addrs.peer_id_addr;
     }
 
     ble_hs_unlock();


[07/43] incubator-mynewt-core git commit: Add back the 2nd explict COMSPEC /C. Simon's msys2 environment doesn't work without it. My msys2 works with and without the 2nd explicit COMPSEC /C/ Looks like the only fix that was needed is to move the opening

Posted by an...@apache.org.
Add back the 2nd explict COMSPEC /C.
Simon's msys2 environment doesn't work without it.
My msys2 works with and without the 2nd explicit COMPSEC /C/
Looks like the only fix that was needed is to move the opening "


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

Branch: refs/heads/bluetooth5
Commit: 39212f4592d5377f2a163e886e5aa506e6df5512
Parents: cb23f34
Author: cwanda <wa...@happycity.com>
Authored: Tue May 9 15:49:12 2017 -0700
Committer: cwanda <wa...@happycity.com>
Committed: Tue May 9 16:05:25 2017 -0700

----------------------------------------------------------------------
 hw/scripts/jlink.sh   | 4 ++--
 hw/scripts/openocd.sh | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/39212f45/hw/scripts/jlink.sh
----------------------------------------------------------------------
diff --git a/hw/scripts/jlink.sh b/hw/scripts/jlink.sh
index e07049b..962aa54 100644
--- a/hw/scripts/jlink.sh
+++ b/hw/scripts/jlink.sh
@@ -125,7 +125,7 @@ jlink_debug() {
             # Launch jlink server in a separate command interpreter, to make
             # sure it doesn't get killed by Ctrl-C signal from bash.
             #
-            $COMSPEC /C "start $JLINK_GDB_SERVER $EXTRA_JTAG_CMD -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun"
+            $COMSPEC /C "start $COMSPEC /C $JLINK_GDB_SERVER $EXTRA_JTAG_CMD -device $JLINK_DEV -speed 4000 -if SWD -port 3333 -singlerun"
         else
             #
             # Block Ctrl-C from getting passed to jlink server.
@@ -145,7 +145,7 @@ jlink_debug() {
 
 	if [ $WINDOWS -eq 1 ]; then
 	    FILE_NAME=`echo $FILE_NAME | sed 's/\//\\\\/g'`
-	    $COMSPEC /C "start arm-none-eabi-gdb -x $GDB_CMD_FILE $FILE_NAME"
+	    $COMSPEC /C "start $COMSPEC /C arm-none-eabi-gdb -x $GDB_CMD_FILE $FILE_NAME"
 	else
             arm-none-eabi-gdb -x $GDB_CMD_FILE $FILE_NAME
             rm $GDB_CMD_FILE

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/39212f45/hw/scripts/openocd.sh
----------------------------------------------------------------------
diff --git a/hw/scripts/openocd.sh b/hw/scripts/openocd.sh
index 50ac6ab..2400cb4 100644
--- a/hw/scripts/openocd.sh
+++ b/hw/scripts/openocd.sh
@@ -85,7 +85,7 @@ openocd_debug () {
             #
 
             CFG=`echo $CFG | sed 's/\//\\\\/g'`
-            $COMSPEC /C "start openocd -l openocd.log $CFG -f $OCD_CMD_FILE -c init -c halt"
+            $COMSPEC /C "start $COMSPEC /C openocd -l openocd.log $CFG -f $OCD_CMD_FILE -c init -c halt"
         else
             #
             # Block Ctrl-C from getting passed to openocd.
@@ -104,7 +104,7 @@ openocd_debug () {
 	echo "FILENAME" $FILE_NAME >>out
 	if [ $WINDOWS -eq 1 ]; then
 	    FILE_NAME=`echo $FILE_NAME | sed 's/\//\\\\/g'`
-            $COMSPEC /C "start arm-none-eabi-gdb -x $GDB_CMD_FILE $FILE_NAME"
+            $COMSPEC /C "start $COMSPEC /C arm-none-eabi-gdb -x $GDB_CMD_FILE $FILE_NAME"
 	else
             arm-none-eabi-gdb -x $GDB_CMD_FILE $FILE_NAME
             rm $GDB_CMD_FILE


[42/43] incubator-mynewt-core git commit: Merge branch 'master' into bluetooth5_master

Posted by an...@apache.org.
Merge branch 'master' into bluetooth5_master

 Conflicts:
	net/nimble/controller/src/ble_ll_ctrl.c
	net/nimble/controller/src/ble_ll_sched.c


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

Branch: refs/heads/bluetooth5
Commit: c6003a43437ee2c275fdc8f1a247e38fc0fa8962
Parents: 958bce0 dd4baa2
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Tue May 16 10:02:24 2017 +0200
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Tue May 16 10:02:24 2017 +0200

----------------------------------------------------------------------
 apps/bletiny/src/main.c                         |    4 -
 apps/bletiny/src/misc.c                         |    2 +-
 apps/sensors_test/pkg.yml                       |    1 +
 apps/sensors_test/src/main.c                    |   40 +-
 apps/sensors_test/syscfg.yml                    |    4 +
 hw/bsp/nrf52840pdk/src/hal_bsp.c                |   20 +
 hw/bsp/nrf52dk/src/hal_bsp.c                    |   12 +
 hw/bsp/pic32mz2048_wi-fire/include/bsp/bsp.h    |    8 +
 hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c        |   12 +
 hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c         |   11 +-
 hw/bsp/ruuvi_tag_revb2/src/hal_bsp.c            |   33 +-
 .../sensors/bme280/include/bme280/bme280.h      |  259 ++++
 hw/drivers/sensors/bme280/pkg.yml               |   32 +
 hw/drivers/sensors/bme280/src/bme280.c          | 1360 ++++++++++++++++++
 hw/drivers/sensors/bme280/src/bme280_priv.h     |  111 ++
 hw/drivers/sensors/bme280/src/bme280_shell.c    |  414 ++++++
 hw/drivers/sensors/bme280/syscfg.yml            |   41 +
 .../sensors/bno055/include/bno055/bno055.h      |    2 +-
 hw/drivers/sensors/bno055/src/bno055.c          |   42 +-
 hw/drivers/sensors/tcs34725/src/tcs34725.c      |   14 +-
 .../pic32mz2048efg100/include/mcu/mips_hal.h    |    6 +
 .../pic32mz2048efg100/include/mcu/pps.h         |  161 +++
 .../microchip/pic32mz2048efg100/src/hal_gpio.c  |    3 +-
 .../microchip/pic32mz2048efg100/src/hal_uart.c  |   44 +
 hw/mcu/microchip/pic32mz2048efg100/src/ppc.c    |  207 +++
 hw/mcu/native/syscfg.yml                        |   21 +
 hw/mcu/nordic/nrf51xxx/src/hal_spi.c            |    2 +-
 hw/mcu/nxp/MK64F12/src/hal_uart.c               |    2 +-
 hw/scripts/jlink.sh                             |   10 +-
 hw/scripts/openocd.sh                           |    6 +-
 hw/sensor/include/sensor/humidity.h             |   45 +
 hw/sensor/include/sensor/pressure.h             |   45 +
 hw/sensor/include/sensor/temperature.h          |   45 +
 hw/sensor/src/sensor_oic.c                      |   54 +-
 hw/sensor/src/sensor_shell.c                    |   35 +-
 hw/sensor/syscfg.yml                            |    8 +
 kernel/os/src/arch/sim/os_arch_sim.c            |  461 ------
 kernel/os/src/arch/sim/os_arch_sim_gen.c        |  248 ++++
 kernel/os/src/arch/sim/os_arch_sim_nosig.c      |  241 ++++
 kernel/os/src/arch/sim/os_arch_sim_priv.h       |   29 +
 kernel/os/src/arch/sim/os_arch_sim_sig.c        |  266 ++++
 net/ip/native_sockets/src/native_sock.c         |    6 +
 .../controller/include/controller/ble_ll_ctrl.h |    2 +-
 net/nimble/controller/src/ble_ll_conn_hci.c     |    4 +-
 net/nimble/controller/src/ble_ll_ctrl.c         |   10 +-
 net/nimble/controller/src/ble_ll_scan.c         |    2 +-
 net/nimble/controller/src/ble_ll_sched.c        |    9 +-
 net/nimble/controller/syscfg.yml                |   10 +
 net/nimble/host/src/ble_gap.c                   |    4 +-
 net/nimble/host/src/ble_sm.c                    |    2 +-
 50 files changed, 3872 insertions(+), 538 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c6003a43/apps/bletiny/src/main.c
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c6003a43/net/nimble/controller/include/controller/ble_ll_ctrl.h
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c6003a43/net/nimble/controller/src/ble_ll_conn_hci.c
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c6003a43/net/nimble/controller/src/ble_ll_ctrl.c
----------------------------------------------------------------------
diff --cc net/nimble/controller/src/ble_ll_ctrl.c
index 7fa0768,8db0727..dcd72bd
--- a/net/nimble/controller/src/ble_ll_ctrl.c
+++ b/net/nimble/controller/src/ble_ll_ctrl.c
@@@ -1794,8 -1283,8 +1794,8 @@@ ble_ll_ctrl_proc_init(struct ble_ll_con
              } else {
                  opcode = BLE_LL_CTRL_SLAVE_FEATURE_REQ;
              }
- 
+             memset(ctrdata, 0, BLE_LL_CTRL_FEATURE_LEN);
 -            ctrdata[0] = ble_ll_read_supp_features();
 +            put_le32(ctrdata, ble_ll_read_supp_features());
              break;
          case BLE_LL_CTRL_PROC_VERSION_XCHG:
              opcode = BLE_LL_CTRL_VERSION_IND;
@@@ -2152,8 -1628,8 +2152,8 @@@ ble_ll_ctrl_rx_pdu(struct ble_ll_conn_s
      /* Process opcode */
      rsp_opcode = BLE_ERR_MAX;
      switch (opcode) {
-     case BLE_LL_CTRL_CONN_UPDATE_REQ:
+     case BLE_LL_CTRL_CONN_UPDATE_IND:
 -        rsp_opcode = ble_ll_ctrl_rx_conn_update(connsm, dptr, rspbuf);
 +        rsp_opcode = ble_ll_ctrl_rx_conn_update(connsm, dptr);
          break;
      case BLE_LL_CTRL_CHANNEL_MAP_REQ:
          ble_ll_ctrl_rx_chanmap_req(connsm, dptr);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c6003a43/net/nimble/controller/src/ble_ll_scan.c
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c6003a43/net/nimble/controller/src/ble_ll_sched.c
----------------------------------------------------------------------
diff --cc net/nimble/controller/src/ble_ll_sched.c
index 5c292ae,6939a96..c7a5a95
--- a/net/nimble/controller/src/ble_ll_sched.c
+++ b/net/nimble/controller/src/ble_ll_sched.c
@@@ -375,9 -369,9 +375,10 @@@ ble_ll_sched_master_new(struct ble_ll_c
       */
      dur = os_cputime_usecs_to_ticks(req_slots * BLE_LL_SCHED_USECS_PER_SLOT);
      earliest_start = adv_rxend +
 -        os_cputime_usecs_to_ticks(BLE_LL_IFS + BLE_LL_CONN_REQ_DURATION +
 +        os_cputime_usecs_to_ticks(BLE_LL_IFS +
-             ble_phy_pdu_dur(BLE_CONNECT_REQ_LEN, BLE_PHY_1M) +
-             BLE_LL_CONN_INITIAL_OFFSET);
++                                  ble_phy_pdu_dur(BLE_CONNECT_REQ_LEN, BLE_PHY_1M) +
+                                   BLE_LL_CONN_INITIAL_OFFSET +
+                                   MYNEWT_VAL(BLE_LL_CONN_INIT_MIN_WIN_OFFSET) * BLE_LL_CONN_TX_OFF_USECS);
      earliest_end = earliest_start + dur;
      itvl_t = os_cputime_usecs_to_ticks(connsm->conn_itvl * BLE_LL_CONN_ITVL_USECS);
  #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c6003a43/net/nimble/controller/syscfg.yml
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c6003a43/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------


[08/43] incubator-mynewt-core git commit: MYNEWT-745 Sim - deadlock involving system calls

Posted by an...@apache.org.
MYNEWT-745 Sim - deadlock involving system calls

This commit splits sim into two separate implementations:
    * "signals"
    * "no-signals"

The user chooses which implementation to use via the
MCU_NATIVE_USE_SIGNALS syscfg setting (defined in hw/mcu/native).  The
two implementations are described below:

signals:
    More correctness; less stability.  The OS tick timer will
    cause a high-priority task to preempt a low-priority task.
    This causes stability issues because a task can be preempted
    while it is in the middle of a system call, potentially
    causing deadlock or memory corruption.

no-signals:
    Less correctness; more stability.  The OS tick timer only
    runs while the idle task is active.  Therefore, a sleeping
    high-priority task will not preempt a low-priority task due
    to a timing event (e.g., delay or callout expired).
    However, this version of sim does not suffer from the
    stability issues that affect the "signals" implementation.


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

Branch: refs/heads/bluetooth5
Commit: cc1acfe8ddc8d88c1637b7bd7374c35fc0ace90f
Parents: cb23f34
Author: Christopher Collins <cc...@apache.org>
Authored: Tue May 9 17:40:29 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue May 9 17:54:13 2017 -0700

----------------------------------------------------------------------
 hw/mcu/native/syscfg.yml                   |  21 ++
 kernel/os/src/arch/sim/os_arch_sim.c       | 461 ------------------------
 kernel/os/src/arch/sim/os_arch_sim_gen.c   | 248 +++++++++++++
 kernel/os/src/arch/sim/os_arch_sim_nosig.c | 241 +++++++++++++
 kernel/os/src/arch/sim/os_arch_sim_priv.h  |  29 ++
 kernel/os/src/arch/sim/os_arch_sim_sig.c   | 266 ++++++++++++++
 6 files changed, 805 insertions(+), 461 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cc1acfe8/hw/mcu/native/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/native/syscfg.yml b/hw/mcu/native/syscfg.yml
index d0c40be..230450f 100644
--- a/hw/mcu/native/syscfg.yml
+++ b/hw/mcu/native/syscfg.yml
@@ -24,3 +24,24 @@ syscfg.defs:
             Specifies the required alignment for internal flash writes.
             Used internally by the newt tool.
         value: 1
+
+    MCU_NATIVE_USE_SIGNALS:
+        description: >
+            Whether to use POSIX signals to implement context switches.  Valid
+            values are as follows:
+                1: More correctness; less stability.  The OS tick timer will
+                   cause a high-priority task to preempt a low-priority task.
+                   This causes stability issues because a task can be preempted
+                   while it is in the middle of a system call, potentially
+                   causing deadlock or memory corruption.
+
+                0: Less correctness; more stability.  The OS tick timer only
+                   runs while the idle task is active.  Therefore, a sleeping
+                   high-priority task will not preempt a low-priority task due
+                   to a timing event (e.g., delay or callout expired).
+                   However, this version of sim does not suffer from the
+                   stability issues that affect the "signals" implementation.
+
+            Unit tests should use 1.  Long-running sim processes should use 0.
+
+        value: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cc1acfe8/kernel/os/src/arch/sim/os_arch_sim.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/sim/os_arch_sim.c b/kernel/os/src/arch/sim/os_arch_sim.c
deleted file mode 100644
index bc9608c..0000000
--- a/kernel/os/src/arch/sim/os_arch_sim.c
+++ /dev/null
@@ -1,461 +0,0 @@
-/*
- * 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 "os/os.h"
-#include "os_priv.h"
-
-#include <hal/hal_bsp.h>
-
-#ifdef __APPLE__
-#define _XOPEN_SOURCE
-#endif
-
-#include <string.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <setjmp.h>
-#include <signal.h>
-#include <sys/time.h>
-#include <assert.h>
-
-struct stack_frame {
-    int sf_mainsp;              /* stack on which main() is executing */
-    sigjmp_buf sf_jb;
-    struct os_task *sf_task;
-};
-
-/*
- * Assert that 'sf_mainsp' and 'sf_jb' are at the specific offsets where
- * os_arch_frame_init() expects them to be.
- */
-CTASSERT(offsetof(struct stack_frame, sf_mainsp) == 0);
-CTASSERT(offsetof(struct stack_frame, sf_jb) == 4);
-
-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_USEC_PER_TICK    (1000000 / OS_TICKS_PER_SEC)
-
-static pid_t mypid;
-static sigset_t allsigs, nosigs;
-static void timer_handler(int sig);
-
-static bool suspended;      /* process is blocked in sigsuspend() */
-static sigset_t suspsigs;   /* signals delivered in sigsuspend() */
-
-/*
- * Called from 'os_arch_frame_init()' when setjmp returns indirectly via
- * longjmp. The return value of setjmp is passed to this function as 'rc'.
- */
-void
-os_arch_task_start(struct stack_frame *sf, int rc)
-{
-    struct os_task *task;
-
-    /*
-     * Interrupts are disabled when a task starts executing. This happens in
-     * two different ways:
-     * - via os_arch_os_start() for the first task.
-     * - via os_sched() for all other tasks.
-     *
-     * Enable interrupts before starting the task.
-     */
-    OS_EXIT_CRITICAL(0);
-
-    task = sf->sf_task;
-    task->t_func(task->t_arg);
-
-    /* This should never return */
-    assert(0);
-}
-
-os_stack_t *
-os_arch_task_stack_init(struct os_task *t, os_stack_t *stack_top, int size)
-{
-    struct stack_frame *sf;
-
-    sf = (struct stack_frame *) ((uint8_t *) stack_top - sizeof(*sf));
-    sf->sf_task = t;
-
-    os_arch_frame_init(sf);
-
-    return ((os_stack_t *)sf);
-}
-
-void
-os_arch_ctx_sw(struct os_task *next_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();
-
-    /*
-     * Just record that this handler was called when the process was blocked.
-     * The handler will be called after sigsuspend() returns in the correct
-     * order.
-     */
-    if (suspended) {
-        sigaddset(&suspsigs, sig);
-        return;
-    }
-
-    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;
-
-        rc = sim_setjmp(sf->sf_jb);
-        if (rc != 0) {
-            OS_ASSERT_CRITICAL();
-            return;
-        }
-    }
-
-    os_sched_ctx_sw_hook(next_t);
-
-    os_sched_set_current_task(next_t);
-
-    sf = (struct stack_frame *) next_t->t_stackptr;
-    sim_longjmp(sf->sf_jb, 1);
-}
-
-/*
- * Disable signals and enter a critical section.
- *
- * Returns 1 if signals were already blocked and 0 otherwise.
- */
-os_sr_t
-os_arch_save_sr(void)
-{
-    int error;
-    sigset_t omask;
-
-    error = sigprocmask(SIG_BLOCK, &allsigs, &omask);
-    assert(error == 0);
-
-    /*
-     * If any one of the signals in 'allsigs' is present in 'omask' then
-     * we are already inside a critical section.
-     */
-    return (sigismember(&omask, SIGALRM));
-}
-
-void
-os_arch_restore_sr(os_sr_t osr)
-{
-    int error;
-
-    OS_ASSERT_CRITICAL();
-    assert(osr == 0 || osr == 1);
-
-    if (osr == 1) {
-        /* Exiting a nested critical section */
-        return;
-    }
-
-    error = sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
-    assert(error == 0);
-}
-
-int
-os_arch_in_critical(void)
-{
-    int error;
-    sigset_t omask;
-
-    error = sigprocmask(SIG_SETMASK, NULL, &omask);
-    assert(error == 0);
-
-    /*
-     * If any one of the signals in 'allsigs' is present in 'omask' then
-     * we are already inside a critical section.
-     */
-    return (sigismember(&omask, SIGALRM));
-}
-
-static struct {
-    int num;
-    void (*handler)(int sig);
-} signals[] = {
-    { SIGALRM, timer_handler },
-    { SIGURG, ctxsw_handler },
-};
-
-#define NUMSIGS     (sizeof(signals)/sizeof(signals[0]))
-
-void
-os_tick_idle(os_time_t ticks)
-{
-    int i, rc, sig;
-    struct itimerval it;
-    void (*handler)(int sig);
-
-    OS_ASSERT_CRITICAL();
-
-    if (ticks > 0) {
-        /*
-         * Enter tickless regime and 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);
-    }
-
-    suspended = true;
-    sigemptyset(&suspsigs);
-    sigsuspend(&nosigs);        /* Wait for a signal to wake us up */
-    suspended = false;
-
-    /*
-     * Call handlers for signals delivered to the process during sigsuspend().
-     * The SIGALRM handler is called before any other handlers to ensure that
-     * OS time is always correct.
-     */
-    if (sigismember(&suspsigs, SIGALRM)) {
-        timer_handler(SIGALRM);
-    }
-    for (i = 0; i < NUMSIGS; i++) {
-        sig = signals[i].num;
-        handler = signals[i].handler;
-        if (sig != SIGALRM && sigismember(&suspsigs, sig)) {
-            handler(sig);
-        }
-    }
-
-    if (ticks > 0) {
-        /*
-         * Enable the periodic timer interrupt.
-         */
-        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);
-    }
-}
-
-static void
-signals_init(void)
-{
-    int i, error;
-    struct sigaction sa;
-
-    sigemptyset(&nosigs);
-    sigemptyset(&allsigs);
-    for (i = 0; i < NUMSIGS; i++) {
-        sigaddset(&allsigs, signals[i].num);
-    }
-
-    for (i = 0; i < NUMSIGS; i++) {
-        memset(&sa, 0, sizeof sa);
-        sa.sa_handler = signals[i].handler;
-        sa.sa_mask = allsigs;
-        sa.sa_flags = SA_RESTART;
-        error = sigaction(signals[i].num, &sa, NULL);
-        assert(error == 0);
-    }
-
-    /*
-     * We use SIGALRM as a proxy for 'allsigs' to check if we are inside
-     * a critical section (for e.g. see os_arch_in_critical()). Make sure
-     * that SIGALRM is indeed present in 'allsigs'.
-     */
-    assert(sigismember(&allsigs, SIGALRM));
-}
-
-static void
-signals_cleanup(void)
-{
-    int i, error;
-    struct sigaction sa;
-
-    for (i = 0; i < NUMSIGS; i++) {
-        memset(&sa, 0, sizeof sa);
-        sa.sa_handler = SIG_DFL;
-        error = sigaction(signals[i].num, &sa, NULL);
-        assert(error == 0);
-    }
-}
-
-static void
-timer_handler(int sig)
-{
-    struct timeval time_now, time_diff;
-    int ticks;
-
-    static struct timeval time_last;
-    static int time_inited;
-
-    OS_ASSERT_CRITICAL();
-
-    /*
-     * Just record that this handler was called when the process was blocked.
-     * The handler will be called after sigsuspend() returns in the proper
-     * order.
-     */
-    if (suspended) {
-        sigaddset(&suspsigs, sig);
-        return;
-    }
-
-    if (!time_inited) {
-        gettimeofday(&time_last, NULL);
-        time_inited = 1;
-    }
-
-    gettimeofday(&time_now, NULL);
-    if (timercmp(&time_now, &time_last, <)) {
-        /*
-         * System time going backwards.
-         */
-        time_last = time_now;
-    } else {
-        timersub(&time_now, &time_last, &time_diff);
-
-        ticks = time_diff.tv_sec * OS_TICKS_PER_SEC;
-        ticks += time_diff.tv_usec / OS_USEC_PER_TICK;
-
-        /*
-         * Update 'time_last' but account for the remainder usecs that did not
-         * contribute towards whole 'ticks'.
-         */
-        time_diff.tv_sec = 0;
-        time_diff.tv_usec %= OS_USEC_PER_TICK;
-        timersub(&time_now, &time_diff, &time_last);
-
-        os_time_advance(ticks);
-    }
-}
-
-static void
-start_timer(void)
-{
-    struct itimerval it;
-    int rc;
-
-    memset(&it, 0, sizeof(it));
-    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);
-}
-
-static void
-stop_timer(void)
-{
-    struct itimerval it;
-    int rc;
-
-    memset(&it, 0, sizeof(it));
-
-    rc = setitimer(ITIMER_REAL, &it, NULL);
-    assert(rc == 0);
-}
-
-os_error_t
-os_arch_os_init(void)
-{
-    mypid = getpid();
-    g_current_task = NULL;
-
-    STAILQ_INIT(&g_os_task_list);
-    TAILQ_INIT(&g_os_run_list);
-    TAILQ_INIT(&g_os_sleep_list);
-
-    /*
-     * Setup all interrupt handlers.
-     *
-     * This must be done early because task initialization uses critical
-     * sections which function correctly only when 'allsigs' is initialized.
-     */
-    signals_init();
-
-    os_init_idle_task();
-
-    return OS_OK;
-}
-
-os_error_t
-os_arch_os_start(void)
-{
-    struct stack_frame *sf;
-    struct os_task *t;
-    os_sr_t sr;
-
-    /*
-     * Disable interrupts before enabling any interrupt sources. Pending
-     * interrupts will be recognized when the first task starts executing.
-     */
-    OS_ENTER_CRITICAL(sr);
-    assert(sr == 0);
-
-    /* Enable the interrupt sources */
-    start_timer();
-
-    t = os_sched_next_task();
-    os_sched_set_current_task(t);
-
-    g_os_started = 1;
-
-    sf = (struct stack_frame *) t->t_stackptr;
-    sim_longjmp(sf->sf_jb, 1);
-
-    return 0;
-}
-
-/**
- * Stops the tick timer and clears the "started" flag.  This function is only
- * implemented for sim.
- */
-void
-os_arch_os_stop(void)
-{
-    stop_timer();
-    signals_cleanup();
-    g_os_started = 0;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cc1acfe8/kernel/os/src/arch/sim/os_arch_sim_gen.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/sim/os_arch_sim_gen.c b/kernel/os/src/arch/sim/os_arch_sim_gen.c
new file mode 100644
index 0000000..66202e1
--- /dev/null
+++ b/kernel/os/src/arch/sim/os_arch_sim_gen.c
@@ -0,0 +1,248 @@
+/*
+ * 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.
+ */
+
+/**
+ * This file contains code that is shared by both sim implementations (signals
+ * and no-signals).
+ */
+
+#include "os/os.h"
+#include "os_priv.h"
+
+#include <hal/hal_bsp.h>
+
+#ifdef __APPLE__
+#define _XOPEN_SOURCE
+#endif
+
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <assert.h>
+#include "os_arch_sim_priv.h"
+
+#define sim_setjmp(__jb) sigsetjmp(__jb, 0)
+#define sim_longjmp(__jb, __ret) siglongjmp(__jb, __ret)
+
+pid_t os_arch_sim_pid;
+
+extern void os_arch_frame_init(struct stack_frame *sf);
+
+void
+os_arch_sim_ctx_sw(void)
+{
+    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;
+
+        rc = sim_setjmp(sf->sf_jb);
+        if (rc != 0) {
+            OS_ASSERT_CRITICAL();
+            return;
+        }
+    }
+
+    os_sched_ctx_sw_hook(next_t);
+
+    os_sched_set_current_task(next_t);
+
+    sf = (struct stack_frame *) next_t->t_stackptr;
+    sim_longjmp(sf->sf_jb, 1);
+}
+
+void
+os_arch_sim_tick(void)
+{
+    struct timeval time_now, time_diff;
+    int ticks;
+
+    static struct timeval time_last;
+    static int time_inited;
+
+    OS_ASSERT_CRITICAL();
+
+    if (!time_inited) {
+        gettimeofday(&time_last, NULL);
+        time_inited = 1;
+    }
+
+    gettimeofday(&time_now, NULL);
+    if (timercmp(&time_now, &time_last, <)) {
+        /*
+         * System time going backwards.
+         */
+        time_last = time_now;
+    } else {
+        timersub(&time_now, &time_last, &time_diff);
+
+        ticks = time_diff.tv_sec * OS_TICKS_PER_SEC;
+        ticks += time_diff.tv_usec / OS_USEC_PER_TICK;
+
+        /*
+         * Update 'time_last' but account for the remainder usecs that did not
+         * contribute towards whole 'ticks'.
+         */
+        time_diff.tv_sec = 0;
+        time_diff.tv_usec %= OS_USEC_PER_TICK;
+        timersub(&time_now, &time_diff, &time_last);
+
+        os_time_advance(ticks);
+    }
+}
+
+static void
+os_arch_sim_start_timer(void)
+{
+    struct itimerval it;
+    int rc;
+
+    memset(&it, 0, sizeof(it));
+    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);
+}
+
+static void
+os_arch_sim_stop_timer(void)
+{
+    struct itimerval it;
+    int rc;
+
+    memset(&it, 0, sizeof(it));
+
+    rc = setitimer(ITIMER_REAL, &it, NULL);
+    assert(rc == 0);
+}
+
+/*
+ * Called from 'os_arch_frame_init()' when setjmp returns indirectly via
+ * longjmp. The return value of setjmp is passed to this function as 'rc'.
+ */
+void
+os_arch_task_start(struct stack_frame *sf, int rc)
+{
+    struct os_task *task;
+
+    /*
+     * Interrupts are disabled when a task starts executing. This happens in
+     * two different ways:
+     * - via os_arch_os_start() for the first task.
+     * - via os_sched() for all other tasks.
+     *
+     * Enable interrupts before starting the task.
+     */
+    OS_EXIT_CRITICAL(0);
+
+    task = sf->sf_task;
+    task->t_func(task->t_arg);
+
+    /* This should never return */
+    assert(0);
+}
+
+os_stack_t *
+os_arch_task_stack_init(struct os_task *t, os_stack_t *stack_top, int size)
+{
+    struct stack_frame *sf;
+
+    sf = (struct stack_frame *) ((uint8_t *) stack_top - sizeof(*sf));
+    sf->sf_task = t;
+
+    os_arch_frame_init(sf);
+
+    return ((os_stack_t *)sf);
+}
+
+os_error_t
+os_arch_os_start(void)
+{
+    struct stack_frame *sf;
+    struct os_task *t;
+    os_sr_t sr;
+
+    /*
+     * Disable interrupts before enabling any interrupt sources. Pending
+     * interrupts will be recognized when the first task starts executing.
+     */
+    OS_ENTER_CRITICAL(sr);
+    assert(sr == 0);
+
+    /* Enable the interrupt sources */
+    os_arch_sim_start_timer();
+
+    t = os_sched_next_task();
+    os_sched_set_current_task(t);
+
+    g_os_started = 1;
+
+    sf = (struct stack_frame *) t->t_stackptr;
+    sim_longjmp(sf->sf_jb, 1);
+
+    return 0;
+}
+
+/**
+ * Stops the tick timer and clears the "started" flag.  This function is only
+ * implemented for sim.
+ */
+void
+os_arch_os_stop(void)
+{
+    os_arch_sim_stop_timer();
+    os_arch_sim_signals_cleanup();
+    g_os_started = 0;
+}
+
+os_error_t
+os_arch_os_init(void)
+{
+    os_arch_sim_pid = getpid();
+    g_current_task = NULL;
+
+    STAILQ_INIT(&g_os_task_list);
+    TAILQ_INIT(&g_os_run_list);
+    TAILQ_INIT(&g_os_sleep_list);
+
+    os_arch_sim_signals_init();
+
+    os_init_idle_task();
+
+    return OS_OK;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cc1acfe8/kernel/os/src/arch/sim/os_arch_sim_nosig.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/sim/os_arch_sim_nosig.c b/kernel/os/src/arch/sim/os_arch_sim_nosig.c
new file mode 100644
index 0000000..9f23e67
--- /dev/null
+++ b/kernel/os/src/arch/sim/os_arch_sim_nosig.c
@@ -0,0 +1,241 @@
+/*
+ * 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.
+ */
+
+/**
+ * This file implements the "no-signals" version of sim.  This implementation
+ * does not use signals to perform context switches.  This is the less correct
+ * version of sim: the OS tick timer only runs while the idle task is active.
+ * Therefore, a sleeping high-priority task will not preempt a low-priority
+ * task due to a timing event (e.g., delay or callout expired).  However, this
+ * version of sim does not suffer from the stability issues that affect the
+ * "signals" implementation.
+ *
+ * To use this version of sim, disable the MCU_NATIVE_USE_SIGNALS syscfg
+ * setting.  
+ */
+
+#include "syscfg/syscfg.h"
+
+#if !MYNEWT_VAL(MCU_NATIVE_USE_SIGNALS)
+
+#include "os/os.h"
+#include "os_priv.h"
+
+#include <hal/hal_bsp.h>
+
+#ifdef __APPLE__
+#define _XOPEN_SOURCE
+#endif
+
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <assert.h>
+#include "os_arch_sim_priv.h"
+
+static sigset_t nosigs;
+static sigset_t suspsigs;   /* signals delivered in sigsuspend() */
+
+static int ctx_sw_pending;
+static int interrupts_enabled = 1;
+
+void
+os_arch_ctx_sw(struct os_task *next_t)
+{
+    if (interrupts_enabled) {
+        /* Perform the context switch immediately. */
+        os_arch_sim_ctx_sw();
+    } else {
+        /* Remember that we want to perform a context switch.  Perform it when
+         * interrupts are re-enabled.
+         */
+        ctx_sw_pending = 1;
+    }
+}
+
+/*
+ * Enter a critical section.
+ *
+ * Returns 1 if interrupts were already disabled; 0 otherwise.
+ */
+os_sr_t
+os_arch_save_sr(void)
+{
+    if (!interrupts_enabled) {
+        return 1;
+    }
+
+    interrupts_enabled = 0;
+    return 0;
+}
+
+void
+os_arch_restore_sr(os_sr_t osr)
+{
+    OS_ASSERT_CRITICAL();
+    assert(osr == 0 || osr == 1);
+
+    if (osr == 1) {
+        /* Exiting a nested critical section */
+        return;
+    }
+
+    if (ctx_sw_pending) {
+        /* A context switch was requested while interrupts were disabled.
+         * Perform it now that interrupts are enabled again.
+         */
+        ctx_sw_pending = 0;
+        os_arch_sim_ctx_sw();
+    }
+    interrupts_enabled = 1;
+}
+
+int
+os_arch_in_critical(void)
+{
+    return !interrupts_enabled;
+}
+
+/**
+ * Unblocks the SIGALRM signal that is delivered by the OS tick timer.
+ */
+static void
+unblock_timer(void)
+{
+    sigset_t sigs;
+    int rc;
+
+    sigemptyset(&sigs);
+    sigaddset(&sigs, SIGALRM);
+
+    rc = sigprocmask(SIG_UNBLOCK, &sigs, NULL);
+    assert(rc == 0);
+}
+
+/**
+ * Blocks the SIGALRM signal that is delivered by the OS tick timer.
+ */
+static void
+block_timer(void)
+{
+    sigset_t sigs;
+    int rc;
+
+    sigemptyset(&sigs);
+    sigaddset(&sigs, SIGALRM);
+
+    rc = sigprocmask(SIG_BLOCK, &sigs, NULL);
+    assert(rc == 0);
+}
+
+static void
+sig_handler_alrm(int sig)
+{
+    /* Wake the idle task. */
+    sigaddset(&suspsigs, sig);
+}
+
+void
+os_tick_idle(os_time_t ticks)
+{
+    int rc;
+    struct itimerval it;
+
+    OS_ASSERT_CRITICAL();
+
+    if (ticks > 0) {
+        /*
+         * Enter tickless regime and 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);
+    }
+
+    unblock_timer();
+
+    sigemptyset(&suspsigs);
+    sigsuspend(&nosigs);        /* Wait for a signal to wake us up */
+
+    block_timer();
+
+    /*
+     * Call handlers for signals delivered to the process during sigsuspend().
+     * The SIGALRM handler is called before any other handlers to ensure that
+     * OS time is always correct.
+     */
+    if (sigismember(&suspsigs, SIGALRM)) {
+        os_arch_sim_tick();
+    }
+
+    if (ticks > 0) {
+        /*
+         * Enable the periodic timer interrupt.
+         */
+        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);
+    }
+}
+
+void
+os_arch_sim_signals_init(void)
+{
+    sigset_t sigset_alrm;
+    struct sigaction sa;
+    int error;
+
+    block_timer();
+
+    sigemptyset(&nosigs);
+
+    sigemptyset(&sigset_alrm);
+    sigaddset(&sigset_alrm, SIGALRM);
+
+    memset(&sa, 0, sizeof sa);
+    sa.sa_handler = sig_handler_alrm;
+    sa.sa_mask = sigset_alrm;
+    sa.sa_flags = SA_RESTART;
+    error = sigaction(SIGALRM, &sa, NULL);
+    assert(error == 0);
+}
+
+void
+os_arch_sim_signals_cleanup(void)
+{
+    int error;
+    struct sigaction sa;
+
+    memset(&sa, 0, sizeof sa);
+    sa.sa_handler = SIG_DFL;
+    error = sigaction(SIGALRM, &sa, NULL);
+    assert(error == 0);
+}
+
+#endif /* !MYNEWT_VAL(MCU_NATIVE_USE_SIGNALS) */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cc1acfe8/kernel/os/src/arch/sim/os_arch_sim_priv.h
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/sim/os_arch_sim_priv.h b/kernel/os/src/arch/sim/os_arch_sim_priv.h
new file mode 100644
index 0000000..6a19cc5
--- /dev/null
+++ b/kernel/os/src/arch/sim/os_arch_sim_priv.h
@@ -0,0 +1,29 @@
+#ifndef H_OS_ARCH_SIM_PRIV_
+#define H_OS_ARCH_SIM_PRIV_
+
+#include <setjmp.h>
+#include <os/os.h>
+
+struct stack_frame {
+    int sf_mainsp;              /* stack on which main() is executing */
+    sigjmp_buf sf_jb;
+    struct os_task *sf_task;
+};
+
+/*
+ * Assert that 'sf_mainsp' and 'sf_jb' are at the specific offsets where
+ * os_arch_frame_init() expects them to be.
+ */
+CTASSERT(offsetof(struct stack_frame, sf_mainsp) == 0);
+CTASSERT(offsetof(struct stack_frame, sf_jb) == 4);
+
+#define OS_USEC_PER_TICK    (1000000 / OS_TICKS_PER_SEC)
+
+void os_arch_sim_ctx_sw(void);
+void os_arch_sim_tick(void);
+void os_arch_sim_signals_init(void);
+void os_arch_sim_signals_cleanup(void);
+
+extern pid_t os_arch_sim_pid;
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cc1acfe8/kernel/os/src/arch/sim/os_arch_sim_sig.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/sim/os_arch_sim_sig.c b/kernel/os/src/arch/sim/os_arch_sim_sig.c
new file mode 100644
index 0000000..d1df204
--- /dev/null
+++ b/kernel/os/src/arch/sim/os_arch_sim_sig.c
@@ -0,0 +1,266 @@
+/*
+ * 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.
+ */
+
+/**
+ * This file implements the "signals" version of sim.  This implementation uses
+ * signals to perform context switches.  This is the more correct version of
+ * sim: the OS tick timer will cause a high-priority task to preempt a
+ * low-priority task.  Unfortunately, there are stability issues because a task
+ * can be preempted while it is in the middle of a system call, potentially
+ * causing deadlock or memory corruption.
+ *
+ * To use this version of sim, enable the MCU_NATIVE_USE_SIGNALS syscfg
+ * setting.  
+ */
+
+#include "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(MCU_NATIVE_USE_SIGNALS)
+
+#include "os/os.h"
+#include "os_priv.h"
+#include "os_arch_sim_priv.h"
+
+#include <hal/hal_bsp.h>
+
+#ifdef __APPLE__
+#define _XOPEN_SOURCE
+#endif
+
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <assert.h>
+
+static bool suspended;      /* process is blocked in sigsuspend() */
+static sigset_t suspsigs;   /* signals delivered in sigsuspend() */
+static sigset_t allsigs;
+static sigset_t nosigs;
+
+void
+os_arch_ctx_sw(struct os_task *next_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(os_arch_sim_pid, SIGURG);
+}
+
+static void
+ctxsw_handler(int sig)
+{
+    OS_ASSERT_CRITICAL();
+
+    /*
+     * Just record that this handler was called when the process was blocked.
+     * The handler will be called after sigsuspend() returns in the correct
+     * order.
+     */
+    if (suspended) {
+        sigaddset(&suspsigs, sig);
+    } else {
+        os_arch_sim_ctx_sw();
+    }
+}
+
+/*
+ * Disable signals and enter a critical section.
+ *
+ * Returns 1 if signals were already blocked and 0 otherwise.
+ */
+os_sr_t
+os_arch_save_sr(void)
+{
+    int error;
+    sigset_t omask;
+
+    error = sigprocmask(SIG_BLOCK, &allsigs, &omask);
+    assert(error == 0);
+
+    /*
+     * If any one of the signals in 'allsigs' is present in 'omask' then
+     * we are already inside a critical section.
+     */
+    return (sigismember(&omask, SIGALRM));
+}
+
+void
+os_arch_restore_sr(os_sr_t osr)
+{
+    int error;
+
+    OS_ASSERT_CRITICAL();
+    assert(osr == 0 || osr == 1);
+
+    if (osr == 1) {
+        /* Exiting a nested critical section */
+        return;
+    }
+
+    error = sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
+    assert(error == 0);
+}
+
+int
+os_arch_in_critical(void)
+{
+    int error;
+    sigset_t omask;
+
+    error = sigprocmask(SIG_SETMASK, NULL, &omask);
+    assert(error == 0);
+
+    /*
+     * If any one of the signals in 'allsigs' is present in 'omask' then
+     * we are already inside a critical section.
+     */
+    return (sigismember(&omask, SIGALRM));
+}
+
+static void
+timer_handler(int sig)
+{
+    OS_ASSERT_CRITICAL();
+
+    /*
+     * Just record that this handler was called when the process was blocked.
+     * The handler will be called after sigsuspend() returns in the proper
+     * order.
+     */
+    if (suspended) {
+        sigaddset(&suspsigs, sig);
+    } else {
+        os_arch_sim_tick();
+    }
+}
+
+static struct {
+    int num;
+    void (*handler)(int sig);
+} signals[] = {
+    { SIGALRM, timer_handler },
+    { SIGURG, ctxsw_handler },
+};
+
+#define NUMSIGS     (sizeof(signals)/sizeof(signals[0]))
+
+void
+os_tick_idle(os_time_t ticks)
+{
+    int i, rc, sig;
+    struct itimerval it;
+    void (*handler)(int sig);
+
+    OS_ASSERT_CRITICAL();
+
+    if (ticks > 0) {
+        /*
+         * Enter tickless regime and 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);
+    }
+
+    suspended = true;
+    sigemptyset(&suspsigs);
+    sigsuspend(&nosigs);        /* Wait for a signal to wake us up */
+    suspended = false;
+
+    /*
+     * Call handlers for signals delivered to the process during sigsuspend().
+     * The SIGALRM handler is called before any other handlers to ensure that
+     * OS time is always correct.
+     */
+    if (sigismember(&suspsigs, SIGALRM)) {
+        os_arch_sim_tick();
+    }
+    for (i = 0; i < NUMSIGS; i++) {
+        sig = signals[i].num;
+        handler = signals[i].handler;
+        if (sig != SIGALRM && sigismember(&suspsigs, sig)) {
+            handler(sig);
+        }
+    }
+
+    if (ticks > 0) {
+        /*
+         * Enable the periodic timer interrupt.
+         */
+        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);
+    }
+}
+
+void
+os_arch_sim_signals_init(void)
+{
+    int i, error;
+    struct sigaction sa;
+
+    sigemptyset(&nosigs);
+    sigemptyset(&allsigs);
+    for (i = 0; i < NUMSIGS; i++) {
+        sigaddset(&allsigs, signals[i].num);
+    }
+
+    for (i = 0; i < NUMSIGS; i++) {
+        memset(&sa, 0, sizeof sa);
+        sa.sa_handler = signals[i].handler;
+        sa.sa_mask = allsigs;
+        sa.sa_flags = SA_RESTART;
+        error = sigaction(signals[i].num, &sa, NULL);
+        assert(error == 0);
+    }
+
+    /*
+     * We use SIGALRM as a proxy for 'allsigs' to check if we are inside
+     * a critical section (for e.g. see os_arch_in_critical()). Make sure
+     * that SIGALRM is indeed present in 'allsigs'.
+     */
+    assert(sigismember(&allsigs, SIGALRM));
+}
+
+void
+os_arch_sim_signals_cleanup(void)
+{
+    int i, error;
+    struct sigaction sa;
+
+    for (i = 0; i < NUMSIGS; i++) {
+        memset(&sa, 0, sizeof sa);
+        sa.sa_handler = SIG_DFL;
+        error = sigaction(signals[i].num, &sa, NULL);
+        assert(error == 0);
+    }
+}
+
+#endif /* MYNEWT_VAL(MCU_NATIVE_USE_SIGNALS) */


[24/43] incubator-mynewt-core git commit: nimble/ll: Check peer features for LE Connection Update

Posted by an...@apache.org.
nimble/ll: Check peer features for LE Connection Update

We should use Connection Parameters Request procedure only if both
master and slave support this feature so we need to check features
masks of both sides.

In other case, we can do Connection Update procedure only if we're
master.


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

Branch: refs/heads/bluetooth5
Commit: 80793bf6e36e13953fce18950929af5e91867d12
Parents: fb476e7
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Tue Apr 25 20:00:20 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Thu May 11 10:48:20 2017 +0200

----------------------------------------------------------------------
 net/nimble/controller/src/ble_ll_conn_hci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/80793bf6/net/nimble/controller/src/ble_ll_conn_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn_hci.c b/net/nimble/controller/src/ble_ll_conn_hci.c
index bd235e7..cfa603e 100644
--- a/net/nimble/controller/src/ble_ll_conn_hci.c
+++ b/net/nimble/controller/src/ble_ll_conn_hci.c
@@ -610,8 +610,8 @@ ble_ll_conn_hci_update(uint8_t *cmdbuf)
         return BLE_ERR_CMD_DISALLOWED;
     }
 
-    /* See if we support this feature */
-    if ((ble_ll_read_supp_features() & BLE_LL_FEAT_CONN_PARM_REQ) == 0) {
+    /* See if this feature is supported on both sides */
+    if ((connsm->common_features & BLE_LL_FEAT_CONN_PARM_REQ) == 0) {
         if (connsm->conn_role == BLE_LL_CONN_ROLE_SLAVE) {
             return BLE_ERR_UNKNOWN_HCI_CMD;
         }