You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2015/11/30 21:56:25 UTC

[2/2] incubator-mynewt-tadpole git commit: Merge larva changes to tadpole.

Merge larva changes to tadpole.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/commit/29ce5cdc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/tree/29ce5cdc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/diff/29ce5cdc

Branch: refs/heads/master
Commit: 29ce5cdc6409e210c12fb2eef8d222dd21efac12
Parents: ad160f5
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 30 12:55:58 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 30 12:55:58 2015 -0800

----------------------------------------------------------------------
 compiler/sim/compiler.yml                      |   2 +-
 compiler/sim/linux-compiler.yml                |   7 +-
 compiler/sim/osx-compiler.yml                  |   2 +-
 hw/bsp/native/egg.yml                          |   3 +
 hw/bsp/native/src/hal_bsp.c                    |  34 ++
 hw/bsp/native/src/os_bsp.c                     |  53 ++
 hw/bsp/native/src/sbrk.c                       |  56 ++
 hw/hal/include/hal/hal_cputime.h               |   2 +-
 hw/hal/include/hal/hal_flash.h                 |  14 +-
 hw/hal/include/hal/hal_flash_int.h             |  47 ++
 hw/hal/include/hal/hal_spim.h                  |  44 ++
 hw/hal/include/hal/hal_system.h                |   2 +-
 hw/hal/include/hal/hal_uart.h                  |  11 +-
 hw/hal/src/hal_flash.c                         | 153 ++++++
 hw/mcu/native/include/mcu/mcu_sim.h            |  23 +
 hw/mcu/native/include/mcu/native_bsp.h         |  21 +
 hw/mcu/native/src/hal_cputime.c                | 490 +++++++++++++++++
 hw/mcu/native/src/hal_flash.c                  | 257 ++++-----
 hw/mcu/native/src/hal_gpio.c                   |   1 -
 hw/mcu/native/src/hal_system.c                 |  49 +-
 hw/mcu/native/src/hal_uart.c                   |  90 +++-
 libs/os/egg.yml                                |  10 +
 libs/os/include/os/arch/cortex_m4/os/os_arch.h |   4 +-
 libs/os/include/os/arch/sim/os/os_arch.h       |   2 +
 libs/os/include/os/os.h                        |   3 +
 libs/os/include/os/os_eventq.h                 |   3 +
 libs/os/include/os/os_mbuf.h                   | 115 ++--
 libs/os/include/os/os_sched.h                  |   4 +
 libs/os/include/os/os_task.h                   |   7 +-
 libs/os/include/os/os_time.h                   |   7 +-
 libs/os/src/arch/cortex_m4/m4/HAL_CM4.s        |  30 ++
 libs/os/src/arch/cortex_m4/os_arch_arm.c       |  41 +-
 libs/os/src/arch/cortex_m4/os_fault.c          |  85 +++
 libs/os/src/arch/sim/os_arch_sim.c             |  15 +-
 libs/os/src/arch/sim/os_fault.c                |  30 ++
 libs/os/src/os.c                               |   3 +
 libs/os/src/os_info.c                          | 169 ++++++
 libs/os/src/os_mbuf.c                          | 568 +++++++++++++++++++-
 libs/os/src/os_sched.c                         |  56 +-
 libs/os/src/os_task.c                          |   6 +
 libs/os/src/os_time.c                          |   2 +-
 libs/os/src/test/mbuf_test.c                   |  18 +-
 libs/testutil/src/suite.c                      |   4 +-
 libs/util/egg.yml                              |  13 +
 libs/util/include/util/cbmem.h                 |  63 +++
 libs/util/include/util/flash_map.h             |  88 +++
 libs/util/include/util/log.h                   |  61 +++
 libs/util/include/util/stats.h                 | 108 ++++
 libs/util/include/util/tpq.h                   |  64 +++
 libs/util/include/util/util.h                  |  19 +
 libs/util/src/cbmem.c                          | 269 +++++++++
 libs/util/src/flash_map.c                      | 146 +++++
 libs/util/src/log.c                            | 274 ++++++++++
 libs/util/src/stats.c                          | 218 ++++++++
 libs/util/src/test/cbmem_test.c                | 173 ++++++
 libs/util/src/test/flash_map_test.c            | 151 ++++++
 libs/util/src/test/util_test.c                 |  43 ++
 libs/util/src/test/util_test_priv.h            |  23 +
 libs/util/src/tpq.c                            |  85 +++
 59 files changed, 4042 insertions(+), 299 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/compiler/sim/compiler.yml
----------------------------------------------------------------------
diff --git a/compiler/sim/compiler.yml b/compiler/sim/compiler.yml
index 6803c63..fd61dc9 100644
--- a/compiler/sim/compiler.yml
+++ b/compiler/sim/compiler.yml
@@ -23,7 +23,7 @@ compiler.path.objsize: "objsize"
 compiler.path.objcopy: "gobjcopy"
 
 compiler.flags.base: >
-    -m32 -Wall -Werror -ggdb -O0
+    -m32 -Wall -Werror -ggdb -O0 -DMN_OSX
 
 compiler.flags.default: [compiler.flags.base]
 compiler.flags.debug: [compiler.flags.base, -ggdb -O0]

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/compiler/sim/linux-compiler.yml
----------------------------------------------------------------------
diff --git a/compiler/sim/linux-compiler.yml b/compiler/sim/linux-compiler.yml
index 3dac5f2..d9603ec 100644
--- a/compiler/sim/linux-compiler.yml
+++ b/compiler/sim/linux-compiler.yml
@@ -16,17 +16,18 @@
 
 ############################# Compiler Variables #############################
 
-compiler.path.cc: "gcc" 
+compiler.path.cc: "gcc"
 compiler.path.archive: "ar"
 compiler.path.objdump: "objdump"
-compiler.path.objsize: "objsize"
+compiler.path.objsize: "size"
 compiler.path.objcopy: "objcopy"
 
 compiler.flags.base: >
-    -m32 -Wall -Werror -ggdb -O0
+    -m32 -Wall -Werror -ggdb -O0 -DMN_LINUX
 
 compiler.flags.default: [compiler.flags.base]
 compiler.flags.debug: [compiler.flags.base, -ggdb -O0]
 
 compiler.ld.mapfile: false
 compiler.ld.resolve_circular_deps: true
+compiler.ld.flags: -lutil

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/compiler/sim/osx-compiler.yml
----------------------------------------------------------------------
diff --git a/compiler/sim/osx-compiler.yml b/compiler/sim/osx-compiler.yml
index 6803c63..fd61dc9 100644
--- a/compiler/sim/osx-compiler.yml
+++ b/compiler/sim/osx-compiler.yml
@@ -23,7 +23,7 @@ compiler.path.objsize: "objsize"
 compiler.path.objcopy: "gobjcopy"
 
 compiler.flags.base: >
-    -m32 -Wall -Werror -ggdb -O0
+    -m32 -Wall -Werror -ggdb -O0 -DMN_OSX
 
 compiler.flags.default: [compiler.flags.base]
 compiler.flags.debug: [compiler.flags.base, -ggdb -O0]

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/bsp/native/egg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/native/egg.yml b/hw/bsp/native/egg.yml
index 64a7a20..8e0741c 100644
--- a/hw/bsp/native/egg.yml
+++ b/hw/bsp/native/egg.yml
@@ -1,3 +1,6 @@
 egg.name: "hw/bsp/native"
 egg.deps: 
     - hw/mcu/native
+    - libs/util
+egg.deps.BLE_DEVICE:
+    - net/nimble/drivers/native

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/bsp/native/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/native/src/hal_bsp.c b/hw/bsp/native/src/hal_bsp.c
new file mode 100644
index 0000000..389c49a
--- /dev/null
+++ b/hw/bsp/native/src/hal_bsp.c
@@ -0,0 +1,34 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 <stdio.h>
+#include <assert.h>
+#include <string.h>
+#include <inttypes.h>
+#include "hal/hal_flash_int.h"
+#include "mcu/native_bsp.h"
+
+const struct hal_flash *
+bsp_flash_dev(uint8_t id)
+{
+    /*
+     * Just one to start with
+     */
+    if (id != 0) {
+        return NULL;
+    }
+    return &native_flash_dev;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/bsp/native/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/native/src/os_bsp.c b/hw/bsp/native/src/os_bsp.c
new file mode 100644
index 0000000..cc414da
--- /dev/null
+++ b/hw/bsp/native/src/os_bsp.c
@@ -0,0 +1,53 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 <util/flash_map.h>
+
+static struct flash_area bsp_flash_areas[] = {
+    [FLASH_AREA_BOOTLOADER] = {
+        .fa_flash_id = 0,       /* internal flash */
+        .fa_off = 0x00000000,   /* beginning */
+        .fa_size = (32 * 1024)
+    },
+    /* 2 * 16K and 1*64K sectors here */
+    [FLASH_AREA_IMAGE_0] = {
+        .fa_flash_id = 0,
+        .fa_off = 0x00020000,
+        .fa_size = (384 * 1024)
+    },
+    [FLASH_AREA_IMAGE_1] = {
+        .fa_flash_id = 0,
+        .fa_off = 0x00080000,
+        .fa_size = (384 * 1024)
+    },
+    [FLASH_AREA_IMAGE_SCRATCH] = {
+        .fa_flash_id = 0,
+        .fa_off = 0x000e0000,
+        .fa_size = (128 * 1024)
+    },
+    [FLASH_AREA_NFFS] = {
+        .fa_flash_id = 0,
+        .fa_off = 0x00008000,
+        .fa_size = (32 * 1024)
+    }
+
+};
+
+void os_bsp_init(void)
+{
+    flash_area_init(bsp_flash_areas,
+      sizeof(bsp_flash_areas) / sizeof(bsp_flash_areas[0]));
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/bsp/native/src/sbrk.c
----------------------------------------------------------------------
diff --git a/hw/bsp/native/src/sbrk.c b/hw/bsp/native/src/sbrk.c
new file mode 100644
index 0000000..154bd39
--- /dev/null
+++ b/hw/bsp/native/src/sbrk.c
@@ -0,0 +1,56 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 <sys/mman.h>
+#include <unistd.h>
+#include <errno.h>
+
+extern int getpagesize(void);
+
+static void *cont;
+static int sys_pagesize;
+static int cont_left;
+
+void *
+_sbrk(int incr)
+{
+    void *result;
+
+    if (!sys_pagesize) {
+        sys_pagesize = getpagesize();
+    }
+    if (cont && incr <= cont_left) {
+        result = cont;
+        cont_left -= incr;
+        if (cont_left) {
+            cont = (char *)cont + incr;
+        } else {
+            cont = NULL;
+        }
+        return result;
+    }
+    result = mmap(NULL, incr, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED,
+      -1, 0);
+    if (result) {
+        cont_left = sys_pagesize - (incr % sys_pagesize);
+        if (cont_left) {
+            cont = (char *)result + incr;
+        } else {
+            cont = NULL;
+        }
+    }
+    return result;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/hal/include/hal/hal_cputime.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_cputime.h b/hw/hal/include/hal/hal_cputime.h
index 286736c..97d8709 100644
--- a/hw/hal/include/hal/hal_cputime.h
+++ b/hw/hal/include/hal/hal_cputime.h
@@ -170,7 +170,7 @@ void cputime_timer_relative(struct cpu_timer *timer, uint32_t usecs);
  *  
  * Stops a cputimer from running. The timer is removed from the timer queue 
  * and interrupts are disabled if no timers are left on the queue. Can be 
- * called even if timer is running. 
+ * called even if timer is not running. 
  * 
  * @param timer Pointer to cputimer to stop. Cannot be NULL.
  */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/hal/include/hal/hal_flash.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_flash.h b/hw/hal/include/hal/hal_flash.h
index 98813d1..be3b358 100644
--- a/hw/hal/include/hal/hal_flash.h
+++ b/hw/hal/include/hal/hal_flash.h
@@ -4,7 +4,7 @@
  * Licensed 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
@@ -19,11 +19,13 @@
 
 #include <inttypes.h>
 
-int flash_read(uint32_t address, void *dst, uint32_t num_bytes);
-int flash_write(uint32_t address, const void *src, uint32_t num_bytes);
-int flash_erase_sector(uint32_t sector_address);
-int flash_erase(uint32_t address, uint32_t num_bytes);
-int flash_init(void);
+int hal_flash_read(uint8_t flash_id, uint32_t address, void *dst,
+  uint32_t num_bytes);
+int hal_flash_write(uint8_t flash_id, uint32_t address, const void *src,
+  uint32_t num_bytes);
+int hal_flash_erase_sector(uint8_t flash_id, uint32_t sector_address);
+int hal_flash_erase(uint8_t flash_id, uint32_t address, uint32_t num_bytes);
+int hal_flash_init(void);
 
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/hal/include/hal/hal_flash_int.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_flash_int.h b/hw/hal/include/hal/hal_flash_int.h
new file mode 100644
index 0000000..ab7e159
--- /dev/null
+++ b/hw/hal/include/hal/hal_flash_int.h
@@ -0,0 +1,47 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 H_HAL_FLASH_INT
+#define H_HAL_FLASH_INT
+
+#include <inttypes.h>
+/*
+ * API that flash driver has to implement.
+ */
+struct hal_flash_funcs {
+    int (*hff_read)(uint32_t address, void *dst, uint32_t num_bytes);
+    int (*hff_write)(uint32_t address, const void *src, uint32_t num_bytes);
+    int (*hff_erase_sector)(uint32_t sector_address);
+    int (*hff_sector_info)(int idx, uint32_t *address, uint32_t *size);
+    int (*hff_init)(void);
+};
+
+struct hal_flash {
+    const struct hal_flash_funcs *hf_itf;
+    uint32_t hf_base_addr;
+    uint32_t hf_size;
+    int hf_sector_cnt;
+};
+
+/*
+ * Return size of the flash sector. sec_idx is index to hf_sectors array.
+ */
+uint32_t hal_flash_sector_size(const struct hal_flash *hf, int sec_idx);
+
+/* External function prototype supplied by BSP */
+const struct hal_flash *bsp_flash_dev(uint8_t flash_id);
+
+#endif /* H_HAL_FLASH_INT */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/hal/include/hal/hal_spim.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_spim.h b/hw/hal/include/hal/hal_spim.h
new file mode 100644
index 0000000..fa1eeeb
--- /dev/null
+++ b/hw/hal/include/hal/hal_spim.h
@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 H_HAL_SPIM_H_
+#define H_HAL_SPIM_H_
+
+#include <inttypes.h>
+
+/**
+ *
+ * hal_spim_init()
+ *
+ * Sets up a SPI master port ready for data transfer.
+ * Mapping logical port number to pins is dictated by BSP.
+ */
+int hal_spim_init(int port, int mode, int speed);
+
+/*
+ * hal_spim_select()/hal_spim_deselect.
+ * Assert and deassert chip select for the target, respectively.
+ */
+int hal_spim_select(int port);
+int hal_spim_deselect(int port);
+
+/**
+ *
+ * hal_spim_txrx()
+ * Initiate data transfer. Specify TX data or RX data, or both.
+ */
+int hal_spim_txrx(int port, void *tx_buf, int tx_len, void *rx_buf, int rx_len);
+
+#endif /* H_HAL_SPIM_H_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/hal/include/hal/hal_system.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_system.h b/hw/hal/include/hal/hal_system.h
index 3d5569c..19f5ed1 100644
--- a/hw/hal/include/hal/hal_system.h
+++ b/hw/hal/include/hal/hal_system.h
@@ -17,6 +17,6 @@
 #ifndef H_HAL_SYSTEM_
 #define H_HAL_SYSTEM_
 
-void system_reset(void);
+void system_reset(void) __attribute((noreturn));
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/hal/include/hal/hal_uart.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_uart.h b/hw/hal/include/hal/hal_uart.h
index 6dc47bd..b308b84 100644
--- a/hw/hal/include/hal/hal_uart.h
+++ b/hw/hal/include/hal/hal_uart.h
@@ -41,7 +41,7 @@ typedef void (*hal_uart_tx_done)(void *arg);
 typedef int (*hal_uart_rx_char)(void *arg, uint8_t byte);
 
 /**
- * hal uart init
+ * hal uart init cbs
  *
  * Initializes given uart. Mapping of logical UART number to physical
  * UART/GPIO pins is in BSP.
@@ -85,4 +85,13 @@ void hal_uart_start_tx(int uart);
  */
 void hal_uart_start_rx(int uart);
 
+/**
+ * hal uart blocking tx
+ *
+ * This is type of write where UART has to block until character has been sent.
+ * Used when printing diag output from system crash.
+ * Must be called with interrupts disabled.
+ */
+void hal_uart_blocking_tx(int uart, uint8_t byte);
+
 #endif /* H_HAL_UART_H_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/hal/src/hal_flash.c
----------------------------------------------------------------------
diff --git a/hw/hal/src/hal_flash.c b/hw/hal/src/hal_flash.c
new file mode 100644
index 0000000..90fd985
--- /dev/null
+++ b/hw/hal/src/hal_flash.c
@@ -0,0 +1,153 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 <inttypes.h>
+#include <assert.h>
+#include <bsp/bsp.h>
+
+#include "hal/hal_flash.h"
+#include "hal/hal_flash_int.h"
+
+int
+hal_flash_init(void)
+{
+    const struct hal_flash *hf;
+    uint8_t i;
+    int rc = 0;
+
+    for (i = 0; ; i++) {
+        hf = bsp_flash_dev(i);
+        if (!hf) {
+            break;
+        }
+        if (hf->hf_itf->hff_init()) {
+            rc = -1;
+        }
+    }
+    return rc;
+}
+
+uint32_t
+hal_flash_sector_size(const struct hal_flash *hf, int sec_idx)
+{
+    uint32_t size;
+    uint32_t start;
+
+    if (hf->hf_itf->hff_sector_info(sec_idx, &start, &size)) {
+        return 0;
+    }
+    return size;
+}
+
+static int
+hal_flash_check_addr(const struct hal_flash *hf, uint32_t addr)
+{
+    if (addr < hf->hf_base_addr || addr > hf->hf_base_addr + hf->hf_size) {
+        return -1;
+    }
+    return 0;
+}
+
+int
+hal_flash_read(uint8_t id, uint32_t address, void *dst, uint32_t num_bytes)
+{
+    const struct hal_flash *hf;
+
+    hf = bsp_flash_dev(id);
+    if (!hf) {
+        return -1;
+    }
+    if (hal_flash_check_addr(hf, address) ||
+      hal_flash_check_addr(hf, address + num_bytes)) {
+        return -1;
+    }
+    return hf->hf_itf->hff_read(address, dst, num_bytes);
+}
+
+int
+hal_flash_write(uint8_t id, uint32_t address, const void *src,
+  uint32_t num_bytes)
+{
+    const struct hal_flash *hf;
+
+    hf = bsp_flash_dev(id);
+    if (!hf) {
+        return -1;
+    }
+    if (hal_flash_check_addr(hf, address) ||
+      hal_flash_check_addr(hf, address + num_bytes)) {
+        return -1;
+    }
+    return hf->hf_itf->hff_write(address, src, num_bytes);
+}
+
+int
+hal_flash_erase_sector(uint8_t id, uint32_t sector_address)
+{
+    const struct hal_flash *hf;
+
+    hf = bsp_flash_dev(id);
+    if (!hf) {
+        return -1;
+    }
+    if (hal_flash_check_addr(hf, sector_address)) {
+        return -1;
+    }
+    return hf->hf_itf->hff_erase_sector(sector_address);
+}
+
+int
+hal_flash_erase(uint8_t id, uint32_t address, uint32_t num_bytes)
+{
+    const struct hal_flash *hf;
+    uint32_t start, size;
+    uint32_t end;
+    uint32_t end_area;
+    int i;
+    int rc;
+
+    hf = bsp_flash_dev(id);
+    if (!hf) {
+        return -1;
+    }
+    if (hal_flash_check_addr(hf, address) ||
+      hal_flash_check_addr(hf, address + num_bytes)) {
+        return -1;
+    }
+
+    end = address + num_bytes;
+    if (end <= address) {
+        /*
+         * Check for wrap-around.
+         */
+        return -1;
+    }
+
+    for (i = 0; i < hf->hf_sector_cnt; i++) {
+        rc = hf->hf_itf->hff_sector_info(i, &start, &size);
+        assert(rc == 0);
+        end_area = start + size;
+        if (address < end_area && end > start) {
+            /*
+             * If some region of eraseable area falls inside sector,
+             * erase the sector.
+             */
+            if (hf->hf_itf->hff_erase_sector(start)) {
+                return -1;
+            }
+        }
+    }
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/mcu/native/include/mcu/mcu_sim.h
----------------------------------------------------------------------
diff --git a/hw/mcu/native/include/mcu/mcu_sim.h b/hw/mcu/native/include/mcu/mcu_sim.h
new file mode 100644
index 0000000..7ab0842
--- /dev/null
+++ b/hw/mcu/native/include/mcu/mcu_sim.h
@@ -0,0 +1,23 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 __MCU_SIM_H__
+#define __MCU_SIM_H__
+
+extern char *native_flash_file;
+
+void mcu_sim_parse_args(int argc, char **argv);
+
+#endif /* __MCU_SIM_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/mcu/native/include/mcu/native_bsp.h
----------------------------------------------------------------------
diff --git a/hw/mcu/native/include/mcu/native_bsp.h b/hw/mcu/native/include/mcu/native_bsp.h
new file mode 100644
index 0000000..91d41dc
--- /dev/null
+++ b/hw/mcu/native/include/mcu/native_bsp.h
@@ -0,0 +1,21 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 H_NATIVE_BSP_
+#define H_NATIVE_BSP_
+
+extern const struct hal_flash native_flash_dev;
+
+#endif /* H_NATIVE_BSP_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/mcu/native/src/hal_cputime.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_cputime.c b/hw/mcu/native/src/hal_cputime.c
new file mode 100644
index 0000000..6aef643
--- /dev/null
+++ b/hw/mcu/native/src/hal_cputime.c
@@ -0,0 +1,490 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 <stdint.h>
+#include <assert.h>
+#include "os/os.h"
+#include "hal/hal_cputime.h"
+
+/* CPUTIME data */
+struct cputime_data
+{
+    uint32_t ticks_per_usec;    /* number of ticks per usec */
+    uint32_t timer_isrs;        /* Number of timer interrupts */
+    uint32_t ocmp_ints;         /* Number of ocmp interrupts */
+    uint32_t uif_ints;          /* Number of overflow interrupts */
+    uint32_t last_ostime;
+    uint64_t cputime;           /* 64-bit cputime */
+};
+struct cputime_data g_cputime;
+
+/* Queue for timers */
+TAILQ_HEAD(cputime_qhead, cpu_timer) g_cputimer_q;
+
+/* For native cpu implementation */
+#define NATIVE_CPUTIME_STACK_SIZE   (1024)
+os_stack_t g_native_cputime_stack[NATIVE_CPUTIME_STACK_SIZE];
+struct os_task g_native_cputime_task;
+
+struct os_callout_func g_native_cputimer;
+struct os_eventq g_native_cputime_evq;
+static uint32_t g_native_cputime_cputicks_per_ostick;
+
+
+/**
+ * Convert cpu time ticks to os ticks.
+ * 
+ * 
+ * @param cputicks 
+ * 
+ * @return uint32_t 
+ */
+static uint32_t
+native_cputime_ticks_to_osticks(uint32_t cputicks)
+{
+    uint32_t osticks;
+
+    osticks = cputicks / g_native_cputime_cputicks_per_ostick;
+    return osticks;
+}
+
+/**
+ * cputime set ocmp 
+ *  
+ * Set the OCMP used by the cputime module to the desired cputime. 
+ * 
+ * @param timer Pointer to timer.
+ */
+static void
+cputime_set_ocmp(struct cpu_timer *timer)
+{
+    uint32_t curtime;
+    uint32_t osticks;
+
+    curtime = cputime_get32();
+    if ((int32_t)(timer->cputime - curtime) < 0) {
+        osticks = 0;
+    } else {
+        osticks = native_cputime_ticks_to_osticks(timer->cputime - curtime);
+    }
+
+    /* Re-start the timer */
+    os_callout_reset(&g_native_cputimer.cf_c, osticks);
+}
+
+/**
+ * cputime chk expiration 
+ *  
+ * Iterates through the cputimer queue to determine if any timers have expired. 
+ * If the timer has expired the timer is removed from the queue and the timer 
+ * callback function is executed. 
+ * 
+ */
+static void
+cputime_chk_expiration(void)
+{
+    os_sr_t sr;
+    struct cpu_timer *timer;
+
+    OS_ENTER_CRITICAL(sr);
+    while ((timer = TAILQ_FIRST(&g_cputimer_q)) != NULL) {
+        if ((int32_t)(cputime_get32() - timer->cputime) >= 0) {
+            TAILQ_REMOVE(&g_cputimer_q, timer, link);
+            timer->cb(timer->arg);
+        } else {
+            break;
+        }
+    }
+
+    /* Any timers left on queue? If so, we need to set OCMP */
+    timer = TAILQ_FIRST(&g_cputimer_q);
+    if (timer) {
+        cputime_set_ocmp(timer);
+    } else {
+        os_callout_stop(&g_native_cputimer.cf_c);
+    }
+    OS_EXIT_CRITICAL(sr);
+}
+
+/**
+ * This is the function called when the cputimer fires off. 
+ * 
+ * @param arg 
+ */
+void
+native_cputimer_cb(void *arg)
+{
+    /* Count # of interrupts */
+    ++g_cputime.ocmp_ints;
+
+    /* Execute the timer */
+    cputime_chk_expiration();
+}
+
+void
+native_cputime_task_handler(void *arg)
+{
+    struct os_event *ev;
+    struct os_callout_func *cf;
+
+    while (1) {
+        ev = os_eventq_get(&g_native_cputime_evq);
+        switch (ev->ev_type) {
+        case OS_EVENT_T_TIMER:
+            cf = (struct os_callout_func *)ev;
+            assert(cf->cf_func);
+            cf->cf_func(cf->cf_arg);
+            break;
+        default:
+            assert(0);
+            break;
+        }
+    }
+}
+
+/**
+ * cputime init 
+ *  
+ * Initialize the cputime module. This must be called after os_init is called 
+ * and before any other timer API are used. This should be called only once 
+ * and should be called before the hardware timer is used. 
+ * 
+ * @param clock_freq The desired cputime frequency, in hertz (Hz).
+ * 
+ * @return int 0 on success; -1 on error.
+ */
+int
+cputime_init(uint32_t clock_freq)
+{
+    /* Clock frequency must be at least 1 MHz */
+    if (clock_freq < 1000000U) {
+        return -1;
+    }
+
+    /* Initialize the timer queue */
+    TAILQ_INIT(&g_cputimer_q);
+
+    /* Set the clock frequency */
+    g_cputime.ticks_per_usec = clock_freq / 1000000U;
+    g_native_cputime_cputicks_per_ostick = clock_freq / OS_TICKS_PER_SEC;
+
+    os_task_init(&g_native_cputime_task, 
+                 "native_cputimer", 
+                 native_cputime_task_handler, 
+                 NULL, 
+                 OS_TASK_PRI_HIGHEST, 
+                 OS_WAIT_FOREVER, 
+                 g_native_cputime_stack, 
+                 NATIVE_CPUTIME_STACK_SIZE);
+
+    /* Initialize the eventq and task */
+    os_eventq_init(&g_native_cputime_evq);
+
+    /* Initialize the callout function */
+    os_callout_func_init(&g_native_cputimer,
+                         &g_native_cputime_evq,
+                         native_cputimer_cb,
+                         NULL);
+
+    return 0;
+}
+
+/**
+ * cputime get64
+ *  
+ * Returns cputime as a 64-bit number. 
+ * 
+ * @return uint64_t The 64-bit representation of cputime.
+ */
+uint64_t 
+cputime_get64(void)
+{
+    cputime_get32();
+    return g_cputime.cputime;
+}
+
+/**
+ * cputime get32 
+ *  
+ * Returns the low 32 bits of cputime. 
+ * 
+ * @return uint32_t The lower 32 bits of cputime
+ */
+uint32_t
+cputime_get32(void)
+{
+    os_sr_t sr;
+    uint32_t ostime;
+    uint32_t delta_osticks;
+
+    OS_ENTER_CRITICAL(sr);
+    ostime = os_time_get();
+    delta_osticks = (uint32_t)(ostime - g_cputime.last_ostime);
+    if (delta_osticks) {
+        g_cputime.last_ostime = ostime;
+        g_cputime.cputime +=
+            (uint64_t)g_native_cputime_cputicks_per_ostick * delta_osticks;
+
+    }
+    OS_EXIT_CRITICAL(sr);
+
+    return (uint32_t)g_cputime.cputime;
+}
+
+/**
+ * cputime nsecs to ticks 
+ *  
+ * Converts the given number of nanoseconds into cputime ticks. 
+ * 
+ * @param usecs The number of nanoseconds to convert to ticks
+ * 
+ * @return uint32_t The number of ticks corresponding to 'nsecs'
+ */
+uint32_t 
+cputime_nsecs_to_ticks(uint32_t nsecs)
+{
+    uint32_t ticks;
+
+    ticks = ((nsecs * g_cputime.ticks_per_usec) + 999) / 1000;
+    return ticks;
+}
+
+/**
+ * cputime ticks to nsecs
+ *  
+ * Convert the given number of ticks into nanoseconds. 
+ * 
+ * @param ticks The number of ticks to convert to nanoseconds.
+ * 
+ * @return uint32_t The number of nanoseconds corresponding to 'ticks'
+ */
+uint32_t 
+cputime_ticks_to_nsecs(uint32_t ticks)
+{
+    uint32_t nsecs;
+
+    nsecs = ((ticks * 1000) + (g_cputime.ticks_per_usec - 1)) / 
+            g_cputime.ticks_per_usec;
+
+    return nsecs;
+}
+
+/**
+ * cputime usecs to ticks 
+ *  
+ * Converts the given number of microseconds into cputime ticks. 
+ * 
+ * @param usecs The number of microseconds to convert to ticks
+ * 
+ * @return uint32_t The number of ticks corresponding to 'usecs'
+ */
+uint32_t 
+cputime_usecs_to_ticks(uint32_t usecs)
+{
+    uint32_t ticks;
+
+    ticks = (usecs * g_cputime.ticks_per_usec);
+    return ticks;
+}
+
+/**
+ * cputime ticks to usecs
+ *  
+ * Convert the given number of ticks into microseconds. 
+ * 
+ * @param ticks The number of ticks to convert to microseconds.
+ * 
+ * @return uint32_t The number of microseconds corresponding to 'ticks'
+ */
+uint32_t 
+cputime_ticks_to_usecs(uint32_t ticks)
+{
+    uint32_t us;
+
+    us =  (ticks + (g_cputime.ticks_per_usec - 1)) / g_cputime.ticks_per_usec;
+    return us;
+}
+
+/**
+ * cputime delay ticks
+ *  
+ * Wait until the number of ticks has elapsed. This is a blocking delay. 
+ * 
+ * @param ticks The number of ticks to wait.
+ */
+void 
+cputime_delay_ticks(uint32_t ticks)
+{
+    uint32_t until;
+
+    until = cputime_get32() + ticks;
+    while ((int32_t)(cputime_get32() - until) < 0) {
+        /* Loop here till finished */
+    }
+}
+
+/**
+ * cputime delay nsecs 
+ *  
+ * Wait until 'nsecs' nanoseconds has elapsed. This is a blocking delay. 
+ *  
+ * @param nsecs The number of nanoseconds to wait.
+ */
+void 
+cputime_delay_nsecs(uint32_t nsecs)
+{
+    uint32_t ticks;
+
+    ticks = cputime_nsecs_to_ticks(nsecs);
+    cputime_delay_ticks(ticks);
+}
+
+/**
+ * cputime delay usecs 
+ *  
+ * Wait until 'usecs' microseconds has elapsed. This is a blocking delay. 
+ *  
+ * @param usecs The number of usecs to wait.
+ */
+void 
+cputime_delay_usecs(uint32_t usecs)
+{
+    uint32_t ticks;
+
+    ticks = cputime_usecs_to_ticks(usecs);
+    cputime_delay_ticks(ticks);
+}
+
+/**
+ * cputime timer init
+ * 
+ * 
+ * @param timer The timer to initialize. Cannot be NULL.
+ * @param fp    The timer callback function. Cannot be NULL.
+ * @param arg   Pointer to data object to pass to timer. 
+ */
+void 
+cputime_timer_init(struct cpu_timer *timer, cputimer_func fp, void *arg)
+{
+    assert(timer != NULL);
+    assert(fp != NULL);
+
+    timer->cb = fp;
+    timer->arg = arg;
+    timer->link.tqe_prev = (void *) NULL;
+}
+
+/**
+ * cputime timer start 
+ *  
+ * Start a cputimer that will expire at 'cputime'. If cputime has already 
+ * passed, the timer callback will still be called (at interrupt context). 
+ * 
+ * @param timer     Pointer to timer to start. Cannot be NULL.
+ * @param cputime   The cputime at which the timer should expire.
+ */
+void 
+cputime_timer_start(struct cpu_timer *timer, uint32_t cputime)
+{
+    struct cpu_timer *entry;
+    os_sr_t sr;
+
+    assert(timer != NULL);
+
+    /* XXX: should this use a mutex? not sure... */
+    OS_ENTER_CRITICAL(sr);
+
+    timer->cputime = cputime;
+    if (TAILQ_EMPTY(&g_cputimer_q)) {
+        TAILQ_INSERT_HEAD(&g_cputimer_q, timer, link);
+    } else {
+        TAILQ_FOREACH(entry, &g_cputimer_q, link) {
+            if ((int32_t)(timer->cputime - entry->cputime) < 0) {
+                TAILQ_INSERT_BEFORE(entry, timer, link);   
+                break;
+            }
+        }
+        if (!entry) {
+            TAILQ_INSERT_TAIL(&g_cputimer_q, timer, link);
+        }
+    }
+
+    /* If this is the head, we need to set new OCMP */
+    if (timer == TAILQ_FIRST(&g_cputimer_q)) {
+        cputime_set_ocmp(timer);
+    }
+
+    OS_EXIT_CRITICAL(sr);
+}
+
+/**
+ * cputimer timer relative 
+ *  
+ * Sets a cpu timer that will expire 'usecs' microseconds from the current 
+ * cputime. 
+ * 
+ * @param timer Pointer to timer. Cannot be NULL.
+ * @param usecs The number of usecs from now at which the timer will expire.
+ */
+void 
+cputime_timer_relative(struct cpu_timer *timer, uint32_t usecs)
+{
+    uint32_t cputime;
+
+    assert(timer != NULL);
+
+    cputime = cputime_get32() + cputime_usecs_to_ticks(usecs);
+    cputime_timer_start(timer, cputime);
+}
+
+/**
+ * cputime timer stop 
+ *  
+ * Stops a cputimer from running. The timer is removed from the timer queue 
+ * and interrupts are disabled if no timers are left on the queue. Can be 
+ * called even if timer is running. 
+ * 
+ * @param timer Pointer to cputimer to stop. Cannot be NULL.
+ */
+void 
+cputime_timer_stop(struct cpu_timer *timer)
+{
+    os_sr_t sr;
+    int reset_ocmp;
+    struct cpu_timer *entry;
+
+    assert(timer != NULL);
+
+    OS_ENTER_CRITICAL(sr);
+
+    /* If first on queue, we will need to reset OCMP */
+    if (timer->link.tqe_prev != NULL) {
+        reset_ocmp = 0;
+        if (timer == TAILQ_FIRST(&g_cputimer_q)) {
+            entry = TAILQ_NEXT(timer, link);
+            reset_ocmp = 1;
+        }
+        TAILQ_REMOVE(&g_cputimer_q, timer, link);
+        if (reset_ocmp) {
+            if (entry) {
+                cputime_set_ocmp(entry);
+            } else {
+                os_callout_stop(&g_native_cputimer.cf_c);
+            }
+        }
+    }
+
+    OS_EXIT_CRITICAL(sr);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/mcu/native/src/hal_flash.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_flash.c b/hw/mcu/native/src/hal_flash.c
index 63f3645..98eb6df 100644
--- a/hw/mcu/native/src/hal_flash.c
+++ b/hw/mcu/native/src/hal_flash.c
@@ -4,7 +4,7 @@
  * Licensed 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
@@ -14,79 +14,97 @@
  * limitations under the License.
  */
 
-#include <stdio.h>
+#include <sys/mman.h>
+#include <fcntl.h>
 #include <assert.h>
 #include <string.h>
 #include <inttypes.h>
-#include "hal/hal_flash.h"
-
-static FILE *file;
-
-static const struct flash_area_desc {
-    uint32_t fad_offset;
-    uint32_t fad_length;
-    uint32_t fad_sector_id;
-} flash_area_descs[] = {
-    { 0x00000000, 16 * 1024,  0 },
-    { 0x00004000, 16 * 1024,  1 },
-    { 0x00008000, 16 * 1024,  2 },
-    { 0x0000c000, 16 * 1024,  3 },
-    { 0x00010000, 64 * 1024,  4 },
-    { 0x00020000, 128 * 1024, 5 },
-    { 0x00040000, 128 * 1024, 6 },
-    { 0x00060000, 128 * 1024, 7 },
-    { 0x00080000, 128 * 1024, 8 },
-    { 0x000a0000, 128 * 1024, 9 },
-    { 0x000c0000, 128 * 1024, 10 },
-    { 0x000e0000, 128 * 1024, 11 },
+#include <stdlib.h>
+#include "hal/hal_flash_int.h"
+#include "mcu/mcu_sim.h"
+
+char *native_flash_file;
+static int file;
+static void *file_loc;
+
+static int native_flash_init(void);
+static int native_flash_read(uint32_t address, void *dst, uint32_t length);
+static int native_flash_write(uint32_t address, const void *src,
+  uint32_t length);
+static int native_flash_erase_sector(uint32_t sector_address);
+static int native_flash_sector_info(int idx, uint32_t *address, uint32_t *size);
+
+static const struct hal_flash_funcs native_flash_funcs = {
+    .hff_read = native_flash_read,
+    .hff_write = native_flash_write,
+    .hff_erase_sector = native_flash_erase_sector,
+    .hff_sector_info = native_flash_sector_info,
+    .hff_init = native_flash_init
+};
+
+static const uint32_t native_flash_sectors[] = {
+    0x00000000, /* 16 * 1024 */
+    0x00004000, /* 16 * 1024 */
+    0x00008000, /* 16 * 1024 */
+    0x0000c000, /* 16 * 1024 */
+    0x00010000, /* 64 * 1024 */
+    0x00020000, /* 128 * 1024 */
+    0x00040000, /* 128 * 1024 */
+    0x00060000, /* 128 * 1024 */
+    0x00080000, /* 128 * 1024 */
+    0x000a0000, /* 128 * 1024 */
+    0x000c0000, /* 128 * 1024 */
+    0x000e0000, /* 128 * 1024 */
 };
 
-#define FLASH_NUM_AREAS   (int)(sizeof flash_area_descs /       \
-                                sizeof flash_area_descs[0])
+#define FLASH_NUM_AREAS   (int)(sizeof native_flash_sectors /           \
+                                sizeof native_flash_sectors[0])
+
+const struct hal_flash native_flash_dev = {
+    .hf_itf = &native_flash_funcs,
+    .hf_base_addr = 0,
+    .hf_size = 1024 * 1024,
+    .hf_sector_cnt = FLASH_NUM_AREAS,
+};
 
 static void
 flash_native_erase(uint32_t addr, uint32_t len)
 {
-    static uint8_t buf[256];
-    uint32_t end;
-    int chunk_sz;
-    int rc;
-
-    end = addr + len;
-    memset(buf, 0xff, sizeof buf);
+    memset(file_loc + addr, 0xff, len);
+}
 
-    rc = fseek(file, addr, SEEK_SET);
-    assert(rc == 0);
+static void
+flash_native_file_open(char *name)
+{
+    int created = 0;
+    extern char *tmpnam(char *s);
+    extern int ftruncate(int fd, off_t length);
 
-    while (addr < end) {
-        if (end - addr < sizeof buf) {
-            chunk_sz = end - addr;
-        } else {
-            chunk_sz = sizeof buf;
+    if (!name) {
+        name = tmpnam(NULL);
+    }
+    file = open(name, O_RDWR);
+    if (file < 0) {
+        file = open(name, O_RDWR | O_CREAT);
+        assert(file > 0);
+        created = 1;
+        if (ftruncate(file, native_flash_dev.hf_size) < 0) {
+            assert(0);
         }
-        rc = fwrite(buf, chunk_sz, 1, file);
-        assert(rc == 1);
-
-        addr += chunk_sz;
     }
-    fflush(file);
+    file_loc = mmap(0, native_flash_dev.hf_size,
+          PROT_READ | PROT_WRITE, MAP_SHARED, file, 0);
+    assert(file_loc != MAP_FAILED);
+    if (created) {
+        flash_native_erase(0, native_flash_dev.hf_size);
+    }
 }
 
 static void
 flash_native_ensure_file_open(void)
 {
-    int expected_sz;
-    int i;
-
-    if (file == NULL) {
-        expected_sz = 0;
-        for (i = 0; i < FLASH_NUM_AREAS; i++) {
-            expected_sz += flash_area_descs[i].fad_length;
-        }
-
-        file = tmpfile();
-        assert(file != NULL);
-        flash_native_erase(0, expected_sz);
+    if (file == 0) {
+        flash_native_file_open(NULL);
     }
 }
 
@@ -109,8 +127,6 @@ flash_native_write_internal(uint32_t address, const void *src, uint32_t length,
 
     flash_native_ensure_file_open();
 
-    fseek(file, address, SEEK_SET);
-
     cur = address;
     while (cur < end) {
         if (end - cur < sizeof buf) {
@@ -121,7 +137,7 @@ flash_native_write_internal(uint32_t address, const void *src, uint32_t length,
 
         /* Ensure data is not being overwritten. */
         if (!allow_overwrite) {
-            rc = flash_read(cur, buf, chunk_sz);
+            rc = native_flash_read(cur, buf, chunk_sz);
             assert(rc == 0);
             for (i = 0; i < chunk_sz; i++) {
                 assert(buf[i] == 0xff);
@@ -131,60 +147,29 @@ flash_native_write_internal(uint32_t address, const void *src, uint32_t length,
         cur += chunk_sz;
     }
 
-    fseek(file, address, SEEK_SET);
-    rc = fwrite(src, length, 1, file);
-    assert(rc == 1);
+    memcpy((char *)file_loc + address, src, length);
 
-    fflush(file);
     return 0;
 }
 
-int
-flash_write(uint32_t address, const void *src, uint32_t length)
+static int
+native_flash_write(uint32_t address, const void *src, uint32_t length)
 {
     return flash_native_write_internal(address, src, length, 0);
 }
 
 int
-flash_native_overwrite(uint32_t address, const void *src, uint32_t length)
-{
-    return flash_native_write_internal(address, src, length, 1);
-}
-
-int
 flash_native_memset(uint32_t offset, uint8_t c, uint32_t len)
 {
-    uint8_t buf[256];
-    int chunk_sz;
-    int rc;
-
-    memset(buf, c, sizeof buf);
-
-    while (len > 0) {
-        if (len > sizeof buf) {
-            chunk_sz = sizeof buf;
-        } else {
-            chunk_sz = len;
-        }
-
-        rc = flash_native_overwrite(offset, buf, chunk_sz);
-        if (rc != 0) {
-            return rc;
-        }
-
-        offset += chunk_sz;
-        len -= chunk_sz;
-    }
-
+    memset(file_loc + offset, c, len);
     return 0;
 }
 
-int
-flash_read(uint32_t address, void *dst, uint32_t length)
+static int
+native_flash_read(uint32_t address, void *dst, uint32_t length)
 {
     flash_native_ensure_file_open();
-    fseek(file, address, SEEK_SET);
-    fread(dst, length, 1, file);
+    memcpy(dst, (char *)file_loc + address, length);
 
     return 0;
 }
@@ -195,7 +180,7 @@ find_area(uint32_t address)
     int i;
 
     for (i = 0; i < FLASH_NUM_AREAS; i++) {
-        if (flash_area_descs[i].fad_offset == address) {
+        if (native_flash_sectors[i] == address) {
             return i;
         }
     }
@@ -203,12 +188,24 @@ find_area(uint32_t address)
     return -1;
 }
 
-int
-flash_erase_sector(uint32_t sector_address)
+static int
+flash_sector_len(int sector)
+{
+    uint32_t end;
+
+    if (sector == FLASH_NUM_AREAS - 1) {
+        end = native_flash_dev.hf_size + native_flash_sectors[0];
+    } else {
+        end = native_flash_sectors[sector + 1];
+    }
+    return end - native_flash_sectors[sector];
+}
+
+static int
+native_flash_erase_sector(uint32_t sector_address)
 {
-    int next_sector_id;
-    int sector_id;
     int area_id;
+    uint32_t len;
 
     flash_native_ensure_file_open();
 
@@ -216,59 +213,27 @@ flash_erase_sector(uint32_t sector_address)
     if (area_id == -1) {
         return -1;
     }
-
-    sector_id = flash_area_descs[area_id].fad_sector_id;
-    while (1) {
-        flash_native_erase(sector_address,
-                           flash_area_descs[area_id].fad_length);
-
-        area_id++;
-        if (area_id >= FLASH_NUM_AREAS) {
-            break;
-        }
-
-        next_sector_id = flash_area_descs[area_id].fad_sector_id;
-        if (next_sector_id != sector_id) {
-            break;
-        }
-
-        sector_id = next_sector_id;
-    }
-
+    len = flash_sector_len(area_id);
+    flash_native_erase(sector_address, len);
     return 0;
 }
 
-int
-flash_erase(uint32_t address, uint32_t num_bytes)
+static int
+native_flash_sector_info(int idx, uint32_t *address, uint32_t *size)
 {
-    const struct flash_area_desc *area;
-    uint32_t end;
-    int i;
-
-    flash_native_ensure_file_open();
-
-    end = address + num_bytes;
-
-    for (i = 0; i < FLASH_NUM_AREAS; i++) {
-        area = flash_area_descs + i;
-
-        if (area->fad_offset >= end) {
-            return 0;
-        }
-
-        if (address >= area->fad_offset &&
-            address < area->fad_offset + area->fad_length) {
-
-            flash_native_erase(area->fad_offset, area->fad_length);
-        }
-    }
+    assert(idx < FLASH_NUM_AREAS);
 
+    *address = native_flash_sectors[idx];
+    *size = flash_sector_len(idx);
     return 0;
 }
 
-int
-flash_init(void)
+static int
+native_flash_init(void)
 {
+    if (native_flash_file) {
+        flash_native_file_open(native_flash_file);
+    }
     return 0;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/mcu/native/src/hal_gpio.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_gpio.c b/hw/mcu/native/src/hal_gpio.c
index 5e864de..98f7c8c 100644
--- a/hw/mcu/native/src/hal_gpio.c
+++ b/hw/mcu/native/src/hal_gpio.c
@@ -78,7 +78,6 @@ void gpio_write(int pin, int val)
         return;
     }
     hal_gpio[pin].val = (val != 0);
-    printf("GPIO %d is now %d\n", pin, val);
 }
 
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/mcu/native/src/hal_system.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_system.c b/hw/mcu/native/src/hal_system.c
index 00a981e..eb64b60 100644
--- a/hw/mcu/native/src/hal_system.c
+++ b/hw/mcu/native/src/hal_system.c
@@ -4,7 +4,7 @@
  * Licensed 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
@@ -13,9 +13,54 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
 
 #include "hal/hal_system.h"
+#include "mcu/mcu_sim.h"
 
 void
 system_reset(void)
-{ }
+{
+    while(1);
+}
+
+/*
+ * When running projects within simulator, it's useful to be able to
+ * pass operating info as parameters to simulator program.
+ * This routine is meant to parse those.
+ */
+static void
+usage(char *progname, int rc)
+{
+    const char msg[] =
+      "Usage: %s [-f flash_file]\n"
+      "     -f flash_file tells where binary flash file is located. It gets\n"
+      "        created if it doesn't already exist.\n";
+
+    write(2, msg, strlen(msg));
+    exit(rc);
+}
+
+void
+mcu_sim_parse_args(int argc, char **argv)
+{
+    int ch;
+    char *progname = argv[0];
+
+    while ((ch = getopt(argc, argv, "hf:")) != -1) {
+        switch (ch) {
+        case 'f':
+            native_flash_file = optarg;
+            break;
+        case 'h':
+            usage(progname, 0);
+            break;
+        default:
+            usage(progname, -1);
+            break;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/hw/mcu/native/src/hal_uart.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_uart.c b/hw/mcu/native/src/hal_uart.c
index dd1d6a8..2f66016 100644
--- a/hw/mcu/native/src/hal_uart.c
+++ b/hw/mcu/native/src/hal_uart.c
@@ -18,14 +18,20 @@
 #include "hal/hal_uart.h"
 #include "bsp/bsp.h"
 
+#ifdef MN_LINUX
+#include <pty.h>
+#endif
+#ifdef MN_OSX
 #include <util.h>
+#endif
+#include <stdio.h>
 #include <fcntl.h>
 #include <assert.h>
 #include <unistd.h>
 #include <string.h>
 
 #define UART_MAX_BYTES_PER_POLL	64
-#define UART_POLLER_STACK_SZ	1024
+#define UART_POLLER_STACK_SZ	(1024)
 #define UART_POLLER_PRIO	0
 
 struct uart {
@@ -117,23 +123,33 @@ uart_poller(void *arg)
     }
 }
 
-static int
-uart_pty(void)
+static void
+set_nonblock(int fd)
 {
-    int fd;
-    int loop_slave;
     int flags;
-    struct termios tios;
-    char pty_name[32];
 
-    if (openpty(&fd, &loop_slave, pty_name, NULL, NULL) < 0) {
-        perror("openpty() failed");
-        return -1;
+    flags = fcntl(fd, F_GETFL);
+    if (flags == -1) {
+        const char msg[] = "fcntl(F_GETFL) fail";
+        write(1, msg, sizeof(msg));
+        return;
+    }
+    if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
+        const char msg[] = "fcntl(F_SETFL) fail";
+        write(1, msg, sizeof(msg));
+        return;
     }
+}
 
-    if (tcgetattr(loop_slave, &tios)) {
-        perror("tcgetattr() failed");
-        goto err;
+static int
+uart_set_attr(int fd)
+{
+    struct termios tios;
+
+    if (tcgetattr(fd, &tios)) {
+        const char msg[] = "tcgetattr() failed";
+        write(1, msg, sizeof(msg));
+        return -1;
     }
 
     tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB);
@@ -141,22 +157,34 @@ uart_pty(void)
     tios.c_iflag = IGNPAR | IXON;
     tios.c_oflag = 0;
     tios.c_lflag = 0;
-    if (tcsetattr(loop_slave, TCSAFLUSH, &tios) < 0) {
-        perror("tcsetattr() failed");
-        goto err;
+    if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
+        const char msg[] = "tcsetattr() failed";
+        write(1, msg, sizeof(msg));
+        return -1;
     }
+    return 0;
+}
 
-    flags = fcntl(fd, F_GETFL);
-    if (flags == -1) {
-        perror("fcntl(F_GETFL) fail");
-        goto err;
+static int
+uart_pty(int port)
+{
+    int fd;
+    int loop_slave;
+    char pty_name[32];
+    char msg[64];
+
+    if (openpty(&fd, &loop_slave, pty_name, NULL, NULL) < 0) {
+        const char msg[] = "openpty() failed";
+        write(1, msg, sizeof(msg));
+        return -1;
     }
-    if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
-        perror("fcntl(F_SETFL) fail");
+
+    if (uart_set_attr(loop_slave)) {
         goto err;
     }
 
-    printf("console at %s\n", pty_name);
+    snprintf(msg, sizeof(msg), "uart%d at %s\n", port, pty_name);
+    write(1, msg, strlen(msg));
     return fd;
 err:
     close(fd);
@@ -183,6 +211,17 @@ hal_uart_start_rx(int port)
     /* nothing to do here */
 }
 
+void
+hal_uart_blocking_tx(int port, uint8_t data)
+{
+    if (port >= UART_CNT || uarts[port].u_open == 0) {
+        return;
+    }
+
+    /* XXX: Count statistics and add error checking here. */
+    (void) write(uarts[port].u_fd, &data, sizeof(data));
+}
+
 int
 hal_uart_init_cbs(int port, hal_uart_tx_char tx_func, hal_uart_tx_done tx_done,
   hal_uart_rx_char rx_func, void *arg)
@@ -228,10 +267,13 @@ hal_uart_config(int port, int32_t baudrate, uint8_t databits, uint8_t stopbits,
     if (uart->u_open) {
         return -1;
     }
-    uart->u_fd = uart_pty();
+
+    uart->u_fd = uart_pty(port);
     if (uart->u_fd < 0) {
         return -1;
     }
+    set_nonblock(uart->u_fd);
+
     uart->u_open = 1;
     return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/libs/os/egg.yml
----------------------------------------------------------------------
diff --git a/libs/os/egg.yml b/libs/os/egg.yml
index c8bd535..08c4413 100644
--- a/libs/os/egg.yml
+++ b/libs/os/egg.yml
@@ -2,3 +2,13 @@ egg.name: libs/os
 egg.vers: 0.1 
 egg.deps:
     - libs/testutil
+egg.req_caps:
+    - console
+
+egg.deps.SHELL:
+    - libs/console/full 
+    - libs/shell 
+egg.cflags.SHELL: -DSHELL_PRESENT 
+
+# Satisfy capability dependencies for the self-contained test executable.
+egg.deps.selftest: libs/console/stub

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/libs/os/include/os/arch/cortex_m4/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/cortex_m4/os/os_arch.h b/libs/os/include/os/arch/cortex_m4/os/os_arch.h
index b6e0006..1d6bd13 100755
--- a/libs/os/include/os/arch/cortex_m4/os/os_arch.h
+++ b/libs/os/include/os/arch/cortex_m4/os/os_arch.h
@@ -57,9 +57,6 @@ typedef uint32_t os_stack_t;
 #define sec_bss_core    __attribute__((section(".bss.core")))
 #define sec_bss_nz_core __attribute__((section(".bss.core.nz")))
 
-/* Define "assert" funtion */
-void _Die(char *file, int line);
-
 os_stack_t *os_arch_task_stack_init(struct os_task *, os_stack_t *, int);
 void timer_handler(void);
 void os_arch_ctx_sw(struct os_task *);
@@ -72,6 +69,7 @@ os_error_t os_arch_os_init(void);
 os_error_t os_arch_os_start(void);
 void os_set_env(void);
 void os_arch_init_task_stack(os_stack_t *sf);
+void os_default_irq_asm(void);
 
 /* External function prototypes supplied by BSP */
 void os_bsp_systick_init(uint32_t os_tick_usecs);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/libs/os/include/os/arch/sim/os/os_arch.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/arch/sim/os/os_arch.h b/libs/os/include/os/arch/sim/os/os_arch.h
index 7144a44..3466727 100644
--- a/libs/os/include/os/arch/sim/os/os_arch.h
+++ b/libs/os/include/os/arch/sim/os/os_arch.h
@@ -60,4 +60,6 @@ void os_arch_restore_sr(int);
 os_error_t os_arch_os_init(void);
 os_error_t os_arch_os_start(void);
 
+void os_bsp_init(void);
+
 #endif /* _OS_ARCH_SIM_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/libs/os/include/os/os.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os.h b/libs/os/include/os/os.h
index 62b4c11..938f8b7 100644
--- a/libs/os/include/os/os.h
+++ b/libs/os/include/os/os.h
@@ -43,6 +43,8 @@
  */
 extern int g_os_started; 
 
+int os_info_init(void);
+
 /**
  * Returns 1 if the OS has been started, 0 if it has not yet been 
  * been started.
@@ -84,6 +86,7 @@ void os_init_idle_task(void);
 #include "os/os_sched.h"
 #include "os/os_eventq.h"
 #include "os/os_callout.h" 
+#include "os/os_heap.h"
 #include "os/os_mutex.h"
 #include "os/os_sem.h"
 #include "os/os_mempool.h"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/libs/os/include/os/os_eventq.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_eventq.h b/libs/os/include/os/os_eventq.h
index 56dc436..4abdea4 100644
--- a/libs/os/include/os/os_eventq.h
+++ b/libs/os/include/os/os_eventq.h
@@ -17,6 +17,8 @@
 #ifndef _OS_EVENTQ_H
 #define _OS_EVENTQ_H
 
+#include <inttypes.h>
+
 struct os_event {
     uint8_t ev_queued;
     uint8_t ev_type;
@@ -27,6 +29,7 @@ struct os_event {
 #define OS_EVENT_QUEUED(__ev) ((__ev)->ev_queued)
 
 #define OS_EVENT_T_TIMER (1)
+#define OS_EVENT_T_MQUEUE_DATA (2) 
 #define OS_EVENT_T_PERUSER (16)
 
 struct os_eventq {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/libs/os/include/os/os_mbuf.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_mbuf.h b/libs/os/include/os/os_mbuf.h
index 9cb26f6..881ddba 100644
--- a/libs/os/include/os/os_mbuf.h
+++ b/libs/os/include/os/os_mbuf.h
@@ -17,11 +17,14 @@
 #ifndef _OS_MBUF_H 
 #define _OS_MBUF_H 
 
+#include "os/os_eventq.h"
 
 /**
- * A mbuf pool to allocate a mbufs out of.  This contains a pointer to the 
- * mempool to allocate mbufs out of, along with convenient housekeeping 
- * information on mbufs in the pool (e.g. length of variable packet header)
+ * A mbuf pool from which to allocate mbufs. This contains a pointer to the os 
+ * mempool to allocate mbufs out of, the total number of elements in the pool, 
+ * and the amount of "user" data in a non-packet header mbuf. The total pool 
+ * size, in bytes, should be: 
+ *  os_mbuf_count * (omp_databuf_len + sizeof(struct os_mbuf))
  */
 struct os_mbuf_pool {
     /** 
@@ -34,10 +37,6 @@ struct os_mbuf_pool {
      */
     uint16_t omp_mbuf_count;
     /**
-     * The length of the variable portion of the mbuf header
-     */
-    uint16_t omp_hdr_len;
-    /**
      * The memory pool which to allocate mbufs out of 
      */
     struct os_mempool *omp_pool;
@@ -51,7 +50,11 @@ struct os_mbuf_pkthdr {
     /**
      * Overall length of the packet. 
      */
-    uint32_t omp_len;
+    uint16_t omp_len;
+    /**
+     * Flags
+     */
+    uint16_t omp_flags;
     /**
      * Next packet in the mbuf chain.
      */
@@ -69,13 +72,22 @@ struct os_mbuf {
     /**
      * Flags associated with this buffer, see OS_MBUF_F_* defintions
      */
-    uint16_t om_flags;
+    uint8_t om_flags;
+    /**
+     * Length of packet header
+     */
+    uint8_t om_pkthdr_len;
     /**
      * Length of data in this buffer 
      */
     uint16_t om_len;
 
     /**
+     * The mbuf pool this mbuf was allocated out of 
+     */
+    struct os_mbuf_pool *om_omp;
+
+    /**
      * Pointer to next entry in the chained memory buffer
      */
     SLIST_ENTRY(os_mbuf) om_next;
@@ -86,15 +98,10 @@ struct os_mbuf {
     uint8_t om_databuf[0];
 };
 
-/*
- * Mbuf flags: 
- *  - OS_MBUF_F_PKTHDR: Whether or not this mbuf is a packet header mbuf
- *  - OS_MBUF_F_USER: The base user defined mbuf flag, start defining your 
- *    own flags from this flag number.
- */
-
-#define OS_MBUF_F_PKTHDR (0)
-#define OS_MBUF_F_USER   (OS_MBUF_F_PKTHDR + 1) 
+struct os_mqueue {
+    STAILQ_HEAD(, os_mbuf_pkthdr) mq_head;
+    struct os_event mq_ev;
+};
 
 /*
  * Given a flag number, provide the mask for it
@@ -109,12 +116,16 @@ struct os_mbuf {
  * @param __om The mbuf to check 
  */
 #define OS_MBUF_IS_PKTHDR(__om) \
-    ((__om)->om_flags & OS_MBUF_F_MASK(OS_MBUF_F_PKTHDR))
-
+    ((__om)->om_pkthdr_len >= sizeof (struct os_mbuf_pkthdr))
 
+/* Get a packet header pointer given an mbuf pointer */
 #define OS_MBUF_PKTHDR(__om) ((struct os_mbuf_pkthdr *)     \
     ((uint8_t *)&(__om)->om_data + sizeof(struct os_mbuf)))
 
+/* Given a mbuf packet header pointer, return a pointer to the mbuf */
+#define OS_MBUF_PKTHDR_TO_MBUF(__hdr)   \
+     (struct os_mbuf *)((uint8_t *)(__hdr) - sizeof(struct os_mbuf))
+
 /*
  * Access the data of a mbuf, and cast it to type
  *
@@ -124,31 +135,19 @@ struct os_mbuf {
 #define OS_MBUF_DATA(__om, __type) \
      (__type) ((__om)->om_data)
 
-/**
- * Returns the end offset of a mbuf buffer 
- * 
- * @param __omp 
- */
-#define OS_MBUF_END_OFF(__omp) ((__omp)->omp_databuf_len)
-
-/**
- * Returns the start offset of a mbuf buffer
- */
-#define OS_MBUF_START_OFF(__omp) (0)
-
 
 /*
  * Called by OS_MBUF_LEADINGSPACE() macro
  */
 static inline uint16_t 
-_os_mbuf_leadingspace(struct os_mbuf_pool *omp, struct os_mbuf *om)
+_os_mbuf_leadingspace(struct os_mbuf *om)
 {
     uint16_t startoff;
     uint16_t leadingspace;
 
     startoff = 0;
     if (OS_MBUF_IS_PKTHDR(om)) {
-        startoff = sizeof(struct os_mbuf_pkthdr) + omp->omp_hdr_len;
+        startoff = om->om_pkthdr_len;
     }
 
     leadingspace = (uint16_t) (OS_MBUF_DATA(om, uint8_t *) - 
@@ -167,12 +166,16 @@ _os_mbuf_leadingspace(struct os_mbuf_pool *omp, struct os_mbuf *om)
  *
  * @return Amount of leading space available in the mbuf 
  */
-#define OS_MBUF_LEADINGSPACE(__omp, __om) _os_mbuf_leadingspace(__omp, __om)
+#define OS_MBUF_LEADINGSPACE(__om) _os_mbuf_leadingspace(__om)
 
 /* Called by OS_MBUF_TRAILINGSPACE() macro. */
 static inline uint16_t 
-_os_mbuf_trailingspace(struct os_mbuf_pool *omp, struct os_mbuf *om)
+_os_mbuf_trailingspace(struct os_mbuf *om)
 {
+    struct os_mbuf_pool *omp;
+
+    omp = om->om_omp;
+
     return (&om->om_databuf[0] + omp->omp_databuf_len) - om->om_data;
 }
 
@@ -185,30 +188,54 @@ _os_mbuf_trailingspace(struct os_mbuf_pool *omp, struct os_mbuf *om)
  *
  * @return The amount of trailing space available in the mbuf 
  */
-#define OS_MBUF_TRAILINGSPACE(__omp, __om) _os_mbuf_trailingspace(__omp, __om)
+#define OS_MBUF_TRAILINGSPACE(__om) _os_mbuf_trailingspace(__om)
 
+/* Mbuf queue functions */
+
+/* Initialize a mbuf queue */
+int os_mqueue_init(struct os_mqueue *, void *arg);
+
+/* Get an element from a mbuf queue */
+struct os_mbuf *os_mqueue_get(struct os_mqueue *);
+
+/* Put an element in a mbuf queue */
+int os_mqueue_put(struct os_mqueue *, struct os_eventq *, struct os_mbuf *);
 
 /* Initialize a mbuf pool */
-int os_mbuf_pool_init(struct os_mbuf_pool *, struct os_mempool *mp, uint16_t, 
+int os_mbuf_pool_init(struct os_mbuf_pool *, struct os_mempool *mp, 
         uint16_t, uint16_t);
 
 /* Allocate a new mbuf out of the os_mbuf_pool */ 
 struct os_mbuf *os_mbuf_get(struct os_mbuf_pool *omp, uint16_t);
 
 /* Allocate a new packet header mbuf out of the os_mbuf_pool */ 
-struct os_mbuf *os_mbuf_get_pkthdr(struct os_mbuf_pool *omp);
+struct os_mbuf *os_mbuf_get_pkthdr(struct os_mbuf_pool *omp, 
+        uint8_t pkthdr_len);
 
 /* Duplicate a mbuf from the pool */
-struct os_mbuf *os_mbuf_dup(struct os_mbuf_pool *omp, struct os_mbuf *m);
+struct os_mbuf *os_mbuf_dup(struct os_mbuf *m);
+
+struct os_mbuf * os_mbuf_off(struct os_mbuf *om, int off, int *out_off);
+
+/* Copy data from an mbuf to a flat buffer. */
+int os_mbuf_copydata(const struct os_mbuf *m, int off, int len, void *dst);
 
 /* Append data onto a mbuf */
-int os_mbuf_append(struct os_mbuf_pool *omp, struct os_mbuf *m, void *, 
-        uint16_t);
+int os_mbuf_append(struct os_mbuf *m, const void *, uint16_t);
 
 /* Free a mbuf */
-int os_mbuf_free(struct os_mbuf_pool *omp, struct os_mbuf *mb);
+int os_mbuf_free(struct os_mbuf *mb);
 
 /* Free a mbuf chain */
-int os_mbuf_free_chain(struct os_mbuf_pool *omp, struct os_mbuf *om);
+int os_mbuf_free_chain(struct os_mbuf *om);
+
+void os_mbuf_adj(struct os_mbuf *mp, int req_len);
+int os_mbuf_memcmp(const struct os_mbuf *om, int off, const void *data,
+                   int len);
+
+struct os_mbuf *os_mbuf_prepend(struct os_mbuf *om, int len);
+int os_mbuf_copyinto(struct os_mbuf *om, int off, const void *src, int len);
+void os_mbuf_concat(struct os_mbuf *first, struct os_mbuf *second);
+void *os_mbuf_extend(struct os_mbuf *om, uint16_t len);
 
 #endif /* _OS_MBUF_H */ 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/libs/os/include/os/os_sched.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_sched.h b/libs/os/include/os/os_sched.h
index ee84f76..a34c5e3 100644
--- a/libs/os/include/os/os_sched.h
+++ b/libs/os/include/os/os_sched.h
@@ -19,6 +19,10 @@
 
 #include "os/os_task.h"
 
+typedef int (*os_sched_walk_func_t)(struct os_task *, void *arg);
+
+int os_sched_walk(os_sched_walk_func_t walk_func, void *arg);
+void os_sched_ctx_sw_hook(struct os_task *);
 struct os_task *os_sched_get_current_task(void);
 void os_sched_set_current_task(struct os_task *);
 struct os_task *os_sched_next_task(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/libs/os/include/os/os_task.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_task.h b/libs/os/include/os/os_task.h
index 8f7c746..3f75432 100644
--- a/libs/os/include/os/os_task.h
+++ b/libs/os/include/os/os_task.h
@@ -47,7 +47,8 @@ struct os_task {
 
     uint8_t t_taskid;
     uint8_t t_prio;
-    uint8_t t_pad[2];
+    uint8_t t_state;
+    uint8_t t_pad;
 
     char *t_name;
     os_task_func_t t_func;
@@ -57,8 +58,9 @@ struct os_task {
 
     struct os_sanity_check t_sanity_check; 
 
-    os_task_state_t t_state;
     os_time_t t_next_wakeup;
+    os_time_t t_run_time;
+    uint32_t t_ctx_sw_cnt;
     
     /* Used to chain task to either the run or sleep list */ 
     TAILQ_ENTRY(os_task) t_os_list;
@@ -71,6 +73,7 @@ int os_task_init(struct os_task *, char *, os_task_func_t, void *, uint8_t,
         os_time_t, os_stack_t *, uint16_t);
 
 int os_task_sanity_checkin(struct os_task *);
+uint8_t os_task_count(void);
 
 
 #endif /* _OS_TASK_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/libs/os/include/os/os_time.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_time.h b/libs/os/include/os/os_time.h
index d934a68..9c2bc23 100644
--- a/libs/os/include/os/os_time.h
+++ b/libs/os/include/os/os_time.h
@@ -14,8 +14,10 @@
  * limitations under the License.
  */
 
-#ifndef _OS_TIME_H 
-#define _OS_TIME_H 
+#ifndef _OS_TIME_H
+#define _OS_TIME_H
+
+#include <stdint.h>
 
 typedef uint32_t os_time_t;
 
@@ -34,5 +36,4 @@ void os_time_delay(int32_t osticks);
 #define OS_TIME_TICK_GT(__t1, __t2) ((int32_t) ((__t1) - (__t2)) > 0)
 #define OS_TIME_TICK_GEQ(__t1, __t2) ((int32_t) ((__t1) - (__t2)) >= 0)
 
-
 #endif /* _OS_TIME_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/libs/os/src/arch/cortex_m4/m4/HAL_CM4.s
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/m4/HAL_CM4.s b/libs/os/src/arch/cortex_m4/m4/HAL_CM4.s
index 1c5651d..dcde207 100755
--- a/libs/os/src/arch/cortex_m4/m4/HAL_CM4.s
+++ b/libs/os/src/arch/cortex_m4/m4/HAL_CM4.s
@@ -201,6 +201,36 @@ SysTick_Handler:
         .fnend
         .size   SysTick_Handler, .-SysTick_Handler
 
+        .thumb_func
+        .type   os_default_irq_asm, %function
+        .global os_default_irq_asm
+os_default_irq_asm:
+        .fnstart
+        .cantunwind
+
+        /*
+         * LR = 0xfffffff9 if we were using MSP as SP
+         * LR = 0xfffffffd if we were using PSP as SP
+         */
+        TST     LR,#4
+        ITE     EQ
+        MRSEQ   R3,MSP
+        MRSNE   R3,PSP
+        PUSH    {R3-R11,LR}
+        MOV     R0, SP
+        BL      os_default_irq
+        POP     {R3-R11,LR}                 /* Restore EXC_RETURN */
+        BX      LR
+
+        .fnend
+        .size   os_default_irq_asm, .-os_default_irq_asm
+
+	/*
+	 * Prevent libgcc unwind stuff from getting pulled in.
+	 */
+        .section ".data"
+	.global __aeabi_unwind_cpp_pr0
+__aeabi_unwind_cpp_pr0:
         .end
 
 /*----------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/libs/os/src/arch/cortex_m4/os_arch_arm.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/os_arch_arm.c b/libs/os/src/arch/cortex_m4/os_arch_arm.c
index fc69a91..d941809 100755
--- a/libs/os/src/arch/cortex_m4/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m4/os_arch_arm.c
@@ -17,6 +17,8 @@
 #include "os/os.h"
 #include "os/os_arch.h"
 
+#include <bsp/cmsis_nvic.h>
+
 /* Initial program status register */
 #define INITIAL_xPSR    0x01000000
 
@@ -50,9 +52,6 @@ struct stack_frame {
     uint32_t    xpsr;
 };
 
-int     die_line;
-char    *die_module;
-
 #define SVC_ArgN(n) \
   register int __r##n __asm("r"#n);
 
@@ -100,6 +99,8 @@ timer_handler(void)
 void
 os_arch_ctx_sw(struct os_task *t)
 {
+    os_sched_ctx_sw_hook(t);
+
     /* Set PendSV interrupt pending bit to force context switch */
     SCB->ICSR = SCB_ICSR_PENDSVSET_Msk;
 }
@@ -107,6 +108,8 @@ os_arch_ctx_sw(struct os_task *t)
 void
 os_arch_ctx_sw_isr(struct os_task *t)
 {
+    os_sched_ctx_sw_hook(t);
+
     /* Set PendSV interrupt pending bit to force context switch */
     SCB->ICSR = SCB_ICSR_PENDSVSET_Msk;
 }
@@ -129,15 +132,6 @@ os_arch_restore_sr(os_sr_t isr_ctx)
     }
 }
 
-void
-_Die(char *file, int line)
-{
-    die_line = line;
-    die_module = file;
-    while (1) {
-    }
-}
-
 os_stack_t *
 os_arch_task_stack_init(struct os_task *t, os_stack_t *stack_top, int size)
 {
@@ -168,6 +162,10 @@ os_arch_task_stack_init(struct os_task *t, os_stack_t *stack_top, int size)
 void
 os_arch_init(void)
 {
+    /*
+     * Trap on divide-by-zero.
+     */
+    SCB->CCR |= SCB_CCR_DIV_0_TRP_Msk;
     os_init_idle_task();
 }
 
@@ -195,6 +193,19 @@ os_arch_os_init(void)
             NVIC->IP[i] = 0xff;
         }
 
+        /*
+         * Install default interrupt handler, which'll print out system
+         * state at the time of the interrupt, and few other regs which
+         * should help in trying to figure out what went wrong.
+         */
+        NVIC_SetVector(-13, (uint32_t)os_default_irq_asm); /* Hardfault */
+        NVIC_SetVector(MemoryManagement_IRQn, (uint32_t)os_default_irq_asm);
+        NVIC_SetVector(BusFault_IRQn, (uint32_t)os_default_irq_asm);
+        NVIC_SetVector(UsageFault_IRQn, (uint32_t)os_default_irq_asm);
+        for (i = 0; i < NVIC_NUM_VECTORS - NVIC_USER_IRQ_OFFSET; i++) {
+            NVIC_SetVector(i, (uint32_t)os_default_irq_asm);
+        }
+
         /* Call bsp related OS initializations */
         os_bsp_init();
 
@@ -224,9 +235,9 @@ os_arch_os_init(void)
 
 /**
  * os systick init
- *  
+ *
  * Initializes systick for the MCU
- * 
+ *
  * @param os_tick_usecs The number of microseconds in an os time tick
  */
 static void
@@ -283,7 +294,7 @@ os_arch_os_start(void)
 
     err = OS_ERR_IN_ISR;
     if (__get_IPSR() == 0) {
-        /* 
+        /*
          * The following switch statement is really just a sanity check to
          * insure that the os initialization routine was called prior to the
          * os start routine.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/libs/os/src/arch/cortex_m4/os_fault.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/os_fault.c b/libs/os/src/arch/cortex_m4/os_fault.c
new file mode 100644
index 0000000..2c7c6fb
--- /dev/null
+++ b/libs/os/src/arch/cortex_m4/os_fault.c
@@ -0,0 +1,85 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 <console/console.h>
+#include <hal/hal_system.h>
+#include "os/os.h"
+
+#include <stdint.h>
+#include <unistd.h>
+
+int             os_die_line;
+const char     *os_die_module;
+
+void __assert_func(const char *file, int line, const char *func, const char *e);
+
+void
+__assert_func(const char *file, int line, const char *func, const char *e)
+{
+    int sr;
+
+    OS_ENTER_CRITICAL(sr);
+    (void)sr;
+    os_die_line = line;
+    os_die_module = file;
+    console_blocking_mode();
+    console_printf("Assert %s; failed in %s:%d\n", e ? e : "", file, line);
+    system_reset();
+}
+
+struct exception_frame {
+    uint32_t r0;
+    uint32_t r1;
+    uint32_t r2;
+    uint32_t r3;
+    uint32_t r12;
+    uint32_t lr;
+    uint32_t pc;
+    uint32_t psr;
+};
+
+struct trap_frame {
+    struct exception_frame *ef;
+    uint32_t sp;
+    uint32_t r4;
+    uint32_t r5;
+    uint32_t r6;
+    uint32_t r7;
+    uint32_t r8;
+    uint32_t r9;
+    uint32_t r10;
+    uint32_t r11;
+};
+
+void
+os_default_irq(struct trap_frame *tf)
+{
+    console_blocking_mode();
+    console_printf("Unhandled interrupt (%d), exception sp 0x%08x\n",
+      SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk, (uint32_t)tf->ef);
+    console_printf(" r0:0x%08x  r1:0x%08x  r2:0x%08x  r3:0x%08x\n",
+      tf->ef->r0, tf->ef->r1, tf->ef->r2, tf->ef->r3);
+    console_printf(" r4:0x%08x  r5:0x%08x  r6:0x%08x  r7:0x%08x\n",
+      tf->r4, tf->r5, tf->r6, tf->r7);
+    console_printf(" r8:0x%08x  r9:0x%08x r10:0x%08x r11:0x%08x\n",
+      tf->r8, tf->r9, tf->r10, tf->r11);
+    console_printf("r12:0x%08x  lr:0x%08x  pc:0x%08x psr:0x%08x\n",
+      tf->ef->r12, tf->ef->lr, tf->ef->pc, tf->ef->psr);
+    console_printf("ICSR:0x%08x HFSR:0x%08x CFSR:0x%08x\n",
+      SCB->ICSR, SCB->HFSR, SCB->CFSR);
+    console_printf("BFAR:0x%08x MMFAR:0x%08x\n", SCB->BFAR, SCB->MMFAR);
+    system_reset();
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/libs/os/src/arch/sim/os_arch_sim.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/sim/os_arch_sim.c b/libs/os/src/arch/sim/os_arch_sim.c
index 5d2bfe6..0c83487 100644
--- a/libs/os/src/arch/sim/os_arch_sim.c
+++ b/libs/os/src/arch/sim/os_arch_sim.c
@@ -23,6 +23,7 @@
 
 #include <string.h>
 #include <stdio.h>
+#include <unistd.h>
 #include <setjmp.h>
 #include <signal.h>
 #include <sys/time.h>
@@ -152,6 +153,8 @@ os_arch_ctx_sw(struct os_task *next_t)
         }
     }
 
+    os_sched_ctx_sw_hook(next_t);
+
     os_sched_set_current_task(next_t);
 
     sf = (struct stack_frame *) next_t->t_stackptr;
@@ -196,6 +199,8 @@ os_arch_ctx_sw_isr(struct os_task *next_t)
 
     isr_state(&block_isr_off, NULL);
 
+    os_sched_ctx_sw_hook(next_t);
+
     os_sched_set_current_task(next_t);
     
     sf = (struct stack_frame *) next_t->t_stackptr;
@@ -294,8 +299,9 @@ start_timer(void)
 
     rc = setitimer(ITIMER_VIRTUAL, &it, NULL);
     if (rc != 0) {
-        perror("Cannot set itimer");
-        abort();
+        const char msg[] = "Cannot set itimer";
+        write(2, msg, sizeof(msg));
+        _exit(1);
     }
 }
 
@@ -308,7 +314,10 @@ os_arch_os_init(void)
     TAILQ_INIT(&g_os_sleep_list);
 
     os_init_idle_task();
-    os_sanity_task_init(); 
+    os_sanity_task_init();
+
+    os_bsp_init();
+
     return OS_OK;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/libs/os/src/arch/sim/os_fault.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/sim/os_fault.c b/libs/os/src/arch/sim/os_fault.c
new file mode 100644
index 0000000..8bd8fbe
--- /dev/null
+++ b/libs/os/src/arch/sim/os_fault.c
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "os/os.h"
+#include "os_priv.h"
+
+void
+__assert_func(const char *file, int line, const char *func, const char *e)
+{
+    char msg[256];
+
+    snprintf(msg, sizeof(msg), "assert at %s:%d\n", file, line);
+    write(1, msg, strlen(msg));
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/libs/os/src/os.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os.c b/libs/os/src/os.c
index 3ca3177..581db1d 100644
--- a/libs/os/src/os.c
+++ b/libs/os/src/os.c
@@ -59,6 +59,9 @@ os_init(void)
 
     err = os_arch_os_init();
     assert(err == OS_OK);
+
+    err = os_info_init();
+    assert(err == OS_OK);
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/29ce5cdc/libs/os/src/os_info.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_info.c b/libs/os/src/os_info.c
new file mode 100644
index 0000000..ebb6f12
--- /dev/null
+++ b/libs/os/src/os_info.c
@@ -0,0 +1,169 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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/queue.h"
+
+#include "console/console.h"
+#ifdef SHELL_PRESENT
+#include "shell/shell.h" 
+#endif
+
+#include <string.h>
+
+struct os_task_info_walk {
+    struct os_task_info *info;
+    int info_cnt;
+};
+
+#define OS_TASK_INFO_NAME_SIZE (32)
+struct os_task_info {
+    uint8_t oti_tid;
+    uint8_t oti_prio;
+    uint8_t oti_state;
+    uint8_t oti_pad1;
+    uint16_t oti_flags;
+    uint16_t oti_stack_size;
+    uint32_t oti_csw_cnt;
+    os_time_t oti_next_wakeup;
+    os_time_t oti_run_time;
+    char oti_name[OS_TASK_INFO_NAME_SIZE];
+};
+
+int os_task_info_get(struct os_task_info *info, int info_cnt);
+
+#ifdef SHELL_PRESENT
+struct shell_cmd shell_os_tasks_display_cmd;
+#endif
+
+
+#ifdef SHELL_PRESENT
+/* Code to register with shell, and display the results of os_getinfo() 
+ */
+
+
+int 
+shell_os_tasks_display(int argc, char **argv)
+{
+    struct os_task_info *info; 
+    char *name;
+    int i;
+    int found;
+    int rc;
+    uint8_t tcount;
+
+    name = NULL;
+    found = 0;
+
+    if (argv[1] != NULL && strcmp(argv[1], "")) {
+        name = argv[1];
+    }   
+
+    tcount = os_task_count();
+
+    info = (struct os_task_info *) os_malloc(
+            sizeof(struct os_task_info) * tcount);
+    if (!info) {
+        rc = -1;
+        goto err;
+    }
+
+    rc = os_task_info_get(info, tcount);
+
+    console_printf("%d tasks: \n", rc);
+    for (i = 0; i < rc; i++) {
+        if (name) {
+            if (strcmp(name, info[i].oti_name)) {
+                continue;
+            } else {
+                found = 1;
+            }
+        }
+
+        console_printf("  %s (prio: %u, nw: %u, flags: 0x%x, "
+                "ssize: %u, cswcnt: %lu, tot_run_time: %ums)", 
+                info[i].oti_name, 
+                info[i].oti_prio, info[i].oti_next_wakeup, info[i].oti_flags, 
+                info[i].oti_stack_size,
+                info[i].oti_csw_cnt, info[i].oti_run_time);
+
+    }
+
+    if (name && !found) {
+        console_printf("Couldn't find task with name %s\n", name);
+    }
+
+    os_free(info);
+
+    return (0);
+err:
+    return (rc);
+}
+    
+
+#endif 
+
+static int
+_os_task_copy_info(struct os_task *t, void *arg)
+{
+    struct os_task_info_walk *walk;
+
+    walk = (struct os_task_info_walk *) arg;
+
+    if (walk->info_cnt == 0) {
+        /* Stored all the elements we can fit, exit out */
+        return (1);
+    }
+
+    walk->info->oti_tid = t->t_taskid;
+    walk->info->oti_prio = t->t_prio;
+    strncpy(walk->info->oti_name, t->t_name, OS_TASK_INFO_NAME_SIZE);
+    walk->info->oti_state = (uint8_t) t->t_state;
+    walk->info->oti_next_wakeup = t->t_next_wakeup;
+    walk->info->oti_flags = t->t_flags;
+    walk->info->oti_stack_size = t->t_stacksize;
+    walk->info->oti_csw_cnt = t->t_ctx_sw_cnt;
+    walk->info->oti_run_time = t->t_run_time;
+
+    walk->info += 1;
+    walk->info_cnt--;
+
+    return (0);
+}
+
+int
+os_task_info_get(struct os_task_info *info, int info_cnt)
+{
+    struct os_task_info_walk walk;
+
+    walk.info = info;
+    walk.info_cnt = info_cnt;
+
+    os_sched_walk(_os_task_copy_info, (void *) &walk);
+    return (info_cnt - walk.info_cnt);
+}
+
+
+int 
+os_info_init(void)
+{
+#ifdef SHELL_PRESENT 
+    shell_cmd_register(&shell_os_tasks_display_cmd, "tasks", 
+            shell_os_tasks_display);
+#endif
+    return (0);
+}