You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/09/28 00:43:37 UTC

[11/51] [abbrv] [partial] incubator-mynewt-core git commit: directory re-org, part 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/drivers/nimble/nrf52/src/ble_hw.c
----------------------------------------------------------------------
diff --git a/drivers/nimble/nrf52/src/ble_hw.c b/drivers/nimble/nrf52/src/ble_hw.c
deleted file mode 100644
index 569596c..0000000
--- a/drivers/nimble/nrf52/src/ble_hw.c
+++ /dev/null
@@ -1,434 +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 <stdint.h>
-#include <assert.h>
-#include <string.h>
-#include "syscfg/syscfg.h"
-#include "os/os.h"
-#include "ble/xcvr.h"
-#include "nimble/ble.h"
-#include "nimble/nimble_opt.h"
-#include "nrf52_bitfields.h"
-#include "controller/ble_hw.h"
-#include "bsp/cmsis_nvic.h"
-
-#include "nrf52_bitfields.h"
-
-/* Total number of resolving list elements */
-#define BLE_HW_RESOLV_LIST_SIZE     (16)
-
-/* We use this to keep track of which entries are set to valid addresses */
-static uint8_t g_ble_hw_whitelist_mask;
-
-/* Random number generator isr callback */
-ble_rng_isr_cb_t g_ble_rng_isr_cb;
-
-/* If LL privacy is enabled, allocate memory for AAR */
-#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
-
-/* The NRF51 supports up to 16 IRK entries */
-#if (MYNEWT_VAL(BLE_LL_RESOLV_LIST_SIZE) < 16)
-#define NRF_IRK_LIST_ENTRIES    (MYNEWT_VAL(BLE_LL_RESOLV_LIST_SIZE))
-#else
-#define NRF_IRK_LIST_ENTRIES    (16)
-#endif
-
-/* NOTE: each entry is 16 bytes long. */
-uint32_t g_nrf_irk_list[NRF_IRK_LIST_ENTRIES * 4];
-
-/* Current number of IRK entries */
-uint8_t g_nrf_num_irks;
-
-#endif
-
-/**
- * Clear the whitelist
- *
- * @return int
- */
-void
-ble_hw_whitelist_clear(void)
-{
-    NRF_RADIO->DACNF = 0;
-    g_ble_hw_whitelist_mask = 0;
-}
-
-/**
- * Add a device to the hw whitelist
- *
- * @param addr
- * @param addr_type
- *
- * @return int 0: success, BLE error code otherwise
- */
-int
-ble_hw_whitelist_add(uint8_t *addr, uint8_t addr_type)
-{
-    int i;
-    uint32_t mask;
-
-    /* Find first ununsed device address match element */
-    mask = 0x01;
-    for (i = 0; i < BLE_HW_WHITE_LIST_SIZE; ++i) {
-        if ((mask & g_ble_hw_whitelist_mask) == 0) {
-            NRF_RADIO->DAB[i] = le32toh(addr);
-            NRF_RADIO->DAP[i] = le16toh(addr + 4);
-            if (addr_type == BLE_ADDR_TYPE_RANDOM) {
-                NRF_RADIO->DACNF |= (mask << 8);
-            }
-            g_ble_hw_whitelist_mask |= mask;
-            return BLE_ERR_SUCCESS;
-        }
-        mask <<= 1;
-    }
-
-    return BLE_ERR_MEM_CAPACITY;
-}
-
-/**
- * Remove a device from the hw whitelist
- *
- * @param addr
- * @param addr_type
- *
- */
-void
-ble_hw_whitelist_rmv(uint8_t *addr, uint8_t addr_type)
-{
-    int i;
-    uint8_t cfg_addr;
-    uint16_t dap;
-    uint16_t txadd;
-    uint32_t dab;
-    uint32_t mask;
-
-    /* Find first ununsed device address match element */
-    dab = le32toh(addr);
-    dap = le16toh(addr + 4);
-    txadd = NRF_RADIO->DACNF >> 8;
-    mask = 0x01;
-    for (i = 0; i < BLE_HW_WHITE_LIST_SIZE; ++i) {
-        if (mask & g_ble_hw_whitelist_mask) {
-            if ((dab == NRF_RADIO->DAB[i]) && (dap == NRF_RADIO->DAP[i])) {
-                cfg_addr = txadd & mask;
-                if (addr_type == BLE_ADDR_TYPE_RANDOM) {
-                    if (cfg_addr != 0) {
-                        break;
-                    }
-                } else {
-                    if (cfg_addr == 0) {
-                        break;
-                    }
-                }
-            }
-        }
-        mask <<= 1;
-    }
-
-    if (i < BLE_HW_WHITE_LIST_SIZE) {
-        g_ble_hw_whitelist_mask &= ~mask;
-        NRF_RADIO->DACNF &= ~mask;
-    }
-}
-
-/**
- * Returns the size of the whitelist in HW
- *
- * @return int Number of devices allowed in whitelist
- */
-uint8_t
-ble_hw_whitelist_size(void)
-{
-    return BLE_HW_WHITE_LIST_SIZE;
-}
-
-/**
- * Enable the whitelisted devices
- */
-void
-ble_hw_whitelist_enable(void)
-{
-    /* Enable the configured device addresses */
-    NRF_RADIO->DACNF |= g_ble_hw_whitelist_mask;
-}
-
-/**
- * Disables the whitelisted devices
- */
-void
-ble_hw_whitelist_disable(void)
-{
-    /* Disable all whitelist devices */
-    NRF_RADIO->DACNF &= 0x0000ff00;
-}
-
-/**
- * Boolean function which returns true ('1') if there is a match on the
- * whitelist.
- *
- * @return int
- */
-int
-ble_hw_whitelist_match(void)
-{
-    return (int)NRF_RADIO->EVENTS_DEVMATCH;
-}
-
-/* Encrypt data */
-int
-ble_hw_encrypt_block(struct ble_encryption_block *ecb)
-{
-    int rc;
-    uint32_t end;
-    uint32_t err;
-
-    /* Stop ECB */
-    NRF_ECB->TASKS_STOPECB = 1;
-    /* XXX: does task stop clear these counters? Anyway to do this quicker? */
-    NRF_ECB->EVENTS_ENDECB = 0;
-    NRF_ECB->EVENTS_ERRORECB = 0;
-    NRF_ECB->ECBDATAPTR = (uint32_t)ecb;
-
-    /* Start ECB */
-    NRF_ECB->TASKS_STARTECB = 1;
-
-    /* Wait till error or done */
-    rc = 0;
-    while (1) {
-        end = NRF_ECB->EVENTS_ENDECB;
-        err = NRF_ECB->EVENTS_ERRORECB;
-        if (end || err) {
-            if (err) {
-                rc = -1;
-            }
-            break;
-        }
-    }
-
-    return rc;
-}
-
-/**
- * Random number generator ISR.
- */
-static void
-ble_rng_isr(void)
-{
-    uint8_t rnum;
-
-    /* No callback? Clear and disable interrupts */
-    if (g_ble_rng_isr_cb == NULL) {
-        NRF_RNG->INTENCLR = 1;
-        NRF_RNG->EVENTS_VALRDY = 0;
-        (void)NRF_RNG->SHORTS;
-        return;
-    }
-
-    /* If there is a value ready grab it */
-    if (NRF_RNG->EVENTS_VALRDY) {
-        NRF_RNG->EVENTS_VALRDY = 0;
-        rnum = (uint8_t)NRF_RNG->VALUE;
-        (*g_ble_rng_isr_cb)(rnum);
-    }
-}
-
-/**
- * Initialize the random number generator
- *
- * @param cb
- * @param bias
- *
- * @return int
- */
-int
-ble_hw_rng_init(ble_rng_isr_cb_t cb, int bias)
-{
-    /* Set bias */
-    if (bias) {
-        NRF_RNG->CONFIG = 1;
-    } else {
-        NRF_RNG->CONFIG = 0;
-    }
-
-    /* If we were passed a function pointer we need to enable the interrupt */
-    if (cb != NULL) {
-        NVIC_SetPriority(RNG_IRQn, (1 << __NVIC_PRIO_BITS) - 1);
-        NVIC_SetVector(RNG_IRQn, (uint32_t)ble_rng_isr);
-        NVIC_EnableIRQ(RNG_IRQn);
-        g_ble_rng_isr_cb = cb;
-    }
-
-    return 0;
-}
-
-/**
- * Start the random number generator
- *
- * @return int
- */
-int
-ble_hw_rng_start(void)
-{
-    os_sr_t sr;
-
-    /* No need for interrupt if there is no callback */
-    OS_ENTER_CRITICAL(sr);
-    if (NRF_RNG->TASKS_START == 0) {
-        NRF_RNG->EVENTS_VALRDY = 0;
-        if (g_ble_rng_isr_cb) {
-            NRF_RNG->INTENSET = 1;
-        }
-        NRF_RNG->TASKS_START = 1;
-    }
-    OS_EXIT_CRITICAL(sr);
-
-    return 0;
-}
-
-/**
- * Stop the random generator
- *
- * @return int
- */
-int
-ble_hw_rng_stop(void)
-{
-    os_sr_t sr;
-
-    /* No need for interrupt if there is no callback */
-    OS_ENTER_CRITICAL(sr);
-    NRF_RNG->INTENCLR = 1;
-    NRF_RNG->TASKS_STOP = 1;
-    NRF_RNG->EVENTS_VALRDY = 0;
-    OS_EXIT_CRITICAL(sr);
-
-    return 0;
-}
-
-/**
- * Read the random number generator.
- *
- * @return uint8_t
- */
-uint8_t
-ble_hw_rng_read(void)
-{
-    uint8_t rnum;
-
-    /* Wait for a sample */
-    while (NRF_RNG->EVENTS_VALRDY == 0) {
-    }
-
-    NRF_RNG->EVENTS_VALRDY = 0;
-    rnum = (uint8_t)NRF_RNG->VALUE;
-
-    return rnum;
-}
-
-#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY))
-/**
- * Clear the resolving list
- *
- * @return int
- */
-void
-ble_hw_resolv_list_clear(void)
-{
-    g_nrf_num_irks = 0;
-}
-
-/**
- * Add a device to the hw resolving list
- *
- * @param irk   Pointer to IRK to add
- *
- * @return int 0: success, BLE error code otherwise
- */
-int
-ble_hw_resolv_list_add(uint8_t *irk)
-{
-    uint32_t *nrf_entry;
-
-    /* Find first ununsed device address match element */
-    if (g_nrf_num_irks == NRF_IRK_LIST_ENTRIES) {
-        return BLE_ERR_MEM_CAPACITY;
-    }
-
-    /* Copy into irk list */
-    nrf_entry = &g_nrf_irk_list[4 * g_nrf_num_irks];
-    memcpy(nrf_entry, irk, 16);
-
-    /* Add to total */
-    ++g_nrf_num_irks;
-    return BLE_ERR_SUCCESS;
-}
-
-/**
- * Remove a device from the hw resolving list
- *
- * @param index Index of IRK to remove
- */
-void
-ble_hw_resolv_list_rmv(int index)
-{
-    uint32_t *irk_entry;
-
-    if (index < g_nrf_num_irks) {
-        --g_nrf_num_irks;
-        irk_entry = &g_nrf_irk_list[index];
-        if (g_nrf_num_irks > index) {
-            memmove(irk_entry, irk_entry + 4, g_nrf_num_irks - index);
-        }
-    }
-}
-
-/**
- * Returns the size of the resolving list. NOTE: this returns the maximum
- * allowable entries in the HW. Configuration options may limit this.
- *
- * @return int Number of devices allowed in resolving list
- */
-uint8_t
-ble_hw_resolv_list_size(void)
-{
-    return BLE_HW_RESOLV_LIST_SIZE;
-}
-
-/**
- * Called to determine if the address received was resolved.
- *
- * @return int  Negative values indicate unresolved address; positive values
- *              indicate index in resolving list of resolved address.
- */
-int
-ble_hw_resolv_list_match(void)
-{
-    uint32_t index;
-
-    if (NRF_AAR->EVENTS_END) {
-        if (NRF_AAR->EVENTS_RESOLVED) {
-            index = NRF_AAR->STATUS;
-            return (int)index;
-        }
-    }
-
-    return -1;
-}
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/drivers/nimble/nrf52/src/ble_phy.c
----------------------------------------------------------------------
diff --git a/drivers/nimble/nrf52/src/ble_phy.c b/drivers/nimble/nrf52/src/ble_phy.c
deleted file mode 100644
index 6498a06..0000000
--- a/drivers/nimble/nrf52/src/ble_phy.c
+++ /dev/null
@@ -1,1170 +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 <stdint.h>
-#include <string.h>
-#include <assert.h>
-#include "syscfg/syscfg.h"
-#include "os/os.h"
-#include "ble/xcvr.h"
-#include "bsp/cmsis_nvic.h"
-#include "nimble/ble.h"
-#include "nimble/nimble_opt.h"
-#include "controller/ble_phy.h"
-#include "controller/ble_ll.h"
-#include "nrf52_bitfields.h"
-
-/* XXX: 4) Make sure RF is higher priority interrupt than schedule */
-
-/*
- * XXX: Maximum possible transmit time is 1 msec for a 60ppm crystal
- * and 16ms for a 30ppm crystal! We need to limit PDU size based on
- * crystal accuracy. Look at this in the spec.
- */
-
-/* XXX: private header file? */
-extern uint8_t g_nrf_num_irks;
-extern uint32_t g_nrf_irk_list[];
-
-/* To disable all radio interrupts */
-#define NRF_RADIO_IRQ_MASK_ALL  (0x34FF)
-
-/*
- * We configure the nrf with a 1 byte S0 field, 8 bit length field, and
- * zero bit S1 field. The preamble is 8 bits long.
- */
-#define NRF_LFLEN_BITS          (8)
-#define NRF_S0_LEN              (1)
-
-/* Maximum length of frames */
-#define NRF_MAXLEN              (255)
-#define NRF_BALEN               (3)     /* For base address of 3 bytes */
-#define NRF_RX_START_OFFSET     (5)
-
-/* Maximum tx power */
-#define NRF_TX_PWR_MAX_DBM      (4)
-#define NRF_TX_PWR_MIN_DBM      (-40)
-
-/* BLE PHY data structure */
-struct ble_phy_obj
-{
-    uint8_t phy_stats_initialized;
-    int8_t  phy_txpwr_dbm;
-    uint8_t phy_chan;
-    uint8_t phy_state;
-    uint8_t phy_transition;
-    uint8_t phy_rx_started;
-    uint8_t phy_encrypted;
-    uint8_t phy_privacy;
-    uint8_t phy_tx_pyld_len;
-    uint32_t phy_aar_scratch;
-    uint32_t phy_access_address;
-    struct ble_mbuf_hdr rxhdr;
-    void *txend_arg;
-    ble_phy_tx_end_func txend_cb;
-};
-struct ble_phy_obj g_ble_phy_data;
-
-/* XXX: if 27 byte packets desired we can make this smaller */
-/* Global transmit/receive buffer */
-static uint32_t g_ble_phy_tx_buf[(BLE_PHY_MAX_PDU_LEN + 3) / 4];
-static uint32_t g_ble_phy_rx_buf[(BLE_PHY_MAX_PDU_LEN + 3) / 4];
-
-#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
-/* Make sure word-aligned for faster copies */
-static uint32_t g_ble_phy_enc_buf[(BLE_PHY_MAX_PDU_LEN + 3) / 4];
-#endif
-
-/* Statistics */
-STATS_SECT_START(ble_phy_stats)
-    STATS_SECT_ENTRY(phy_isrs)
-    STATS_SECT_ENTRY(tx_good)
-    STATS_SECT_ENTRY(tx_fail)
-    STATS_SECT_ENTRY(tx_late)
-    STATS_SECT_ENTRY(tx_bytes)
-    STATS_SECT_ENTRY(rx_starts)
-    STATS_SECT_ENTRY(rx_aborts)
-    STATS_SECT_ENTRY(rx_valid)
-    STATS_SECT_ENTRY(rx_crc_err)
-    STATS_SECT_ENTRY(rx_late)
-    STATS_SECT_ENTRY(radio_state_errs)
-    STATS_SECT_ENTRY(rx_hw_err)
-    STATS_SECT_ENTRY(tx_hw_err)
-STATS_SECT_END
-STATS_SECT_DECL(ble_phy_stats) ble_phy_stats;
-
-STATS_NAME_START(ble_phy_stats)
-    STATS_NAME(ble_phy_stats, phy_isrs)
-    STATS_NAME(ble_phy_stats, tx_good)
-    STATS_NAME(ble_phy_stats, tx_fail)
-    STATS_NAME(ble_phy_stats, tx_late)
-    STATS_NAME(ble_phy_stats, tx_bytes)
-    STATS_NAME(ble_phy_stats, rx_starts)
-    STATS_NAME(ble_phy_stats, rx_aborts)
-    STATS_NAME(ble_phy_stats, rx_valid)
-    STATS_NAME(ble_phy_stats, rx_crc_err)
-    STATS_NAME(ble_phy_stats, rx_late)
-    STATS_NAME(ble_phy_stats, radio_state_errs)
-    STATS_NAME(ble_phy_stats, rx_hw_err)
-    STATS_NAME(ble_phy_stats, tx_hw_err)
-STATS_NAME_END(ble_phy_stats)
-
-/*
- * NOTE:
- * Tested the following to see what would happen:
- *  -> NVIC has radio irq enabled (interrupt # 1, mask 0x2).
- *  -> Set up nrf to receive. Clear ADDRESS event register.
- *  -> Enable ADDRESS interrupt on nrf5 by writing to INTENSET.
- *  -> Enable RX.
- *  -> Disable interrupts globally using OS_ENTER_CRITICAL().
- *  -> Wait until a packet is received and the ADDRESS event occurs.
- *  -> Call ble_phy_disable().
- *
- *  At this point I wanted to see the state of the cortex NVIC. The IRQ
- *  pending bit was TRUE for the radio interrupt (as expected) as we never
- *  serviced the radio interrupt (interrupts were disabled).
- *
- *  What was unexpected was this: without clearing the pending IRQ in the NVIC,
- *  when radio interrupts were re-enabled (address event bit in INTENSET set to
- *  1) and the radio ADDRESS event register read 1 (it was never cleared after
- *  the first address event), the radio did not enter the ISR! I would have
- *  expected that if the following were true, an interrupt would occur:
- *      -> NVIC ISER bit set to TRUE
- *      -> NVIC ISPR bit reads TRUE, meaning interrupt is pending.
- *      -> Radio peripheral interrupts are enabled for some event (or events).
- *      -> Corresponding event register(s) in radio peripheral read 1.
- *
- *  Not sure what the end result of all this is. We will clear the pending
- *  bit in the NVIC just to be sure when we disable the PHY.
- */
-
-#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
-
-/*
- * Per nordic, the number of bytes needed for scratch is 16 + MAX_PKT_SIZE.
- * However, when I used a smaller size it still overwrote the scratchpad. Until
- * I figure this out I am just going to allocate 67 words so we have enough
- * space for 267 bytes of scratch. I used 268 bytes since not sure if this
- * needs to be aligned and burning a byte is no big deal.
- */
-//#define NRF_ENC_SCRATCH_WORDS (((MYNEWT_VAL(BLE_LL_MAX_PKT_SIZE) + 16) + 3) / 4)
-#define NRF_ENC_SCRATCH_WORDS   (67)
-
-uint32_t g_nrf_encrypt_scratchpad[NRF_ENC_SCRATCH_WORDS];
-
-struct nrf_ccm_data
-{
-    uint8_t key[16];
-    uint64_t pkt_counter;
-    uint8_t dir_bit;
-    uint8_t iv[8];
-} __attribute__((packed));
-
-struct nrf_ccm_data g_nrf_ccm_data;
-#endif
-
-/**
- * Copies the data from the phy receive buffer into a mbuf chain.
- *
- * @param dptr Pointer to receive buffer
- * @param rxpdu Pointer to already allocated mbuf chain
- *
- * NOTE: the packet header already has the total mbuf length in it. The
- * lengths of the individual mbufs are not set prior to calling.
- *
- */
-void
-ble_phy_rxpdu_copy(uint8_t *dptr, struct os_mbuf *rxpdu)
-{
-    uint16_t rem_bytes;
-    uint16_t mb_bytes;
-    uint16_t copylen;
-    uint32_t *dst;
-    uint32_t *src;
-    struct os_mbuf *m;
-    struct ble_mbuf_hdr *ble_hdr;
-    struct os_mbuf_pkthdr *pkthdr;
-
-    /* Better be aligned */
-    assert(((uint32_t)dptr & 3) == 0);
-
-    pkthdr = OS_MBUF_PKTHDR(rxpdu);
-    rem_bytes = pkthdr->omp_len;
-
-    /* Fill in the mbuf pkthdr first. */
-    dst = (uint32_t *)(rxpdu->om_data);
-    src = (uint32_t *)dptr;
-
-    mb_bytes = (rxpdu->om_omp->omp_databuf_len - rxpdu->om_pkthdr_len - 4);
-    copylen = min(mb_bytes, rem_bytes);
-    copylen &= 0xFFFC;
-    rem_bytes -= copylen;
-    mb_bytes -= copylen;
-    rxpdu->om_len = copylen;
-    while (copylen > 0) {
-        *dst = *src;
-        ++dst;
-        ++src;
-        copylen -= 4;
-    }
-
-    /* Copy remaining bytes */
-    m = rxpdu;
-    while (rem_bytes > 0) {
-        /* If there are enough bytes in the mbuf, copy them and leave */
-        if (rem_bytes <= mb_bytes) {
-            memcpy(m->om_data + m->om_len, src, rem_bytes);
-            m->om_len += rem_bytes;
-            break;
-        }
-
-        m = SLIST_NEXT(m, om_next);
-        assert(m != NULL);
-
-        mb_bytes = m->om_omp->omp_databuf_len;
-        copylen = min(mb_bytes, rem_bytes);
-        copylen &= 0xFFFC;
-        rem_bytes -= copylen;
-        mb_bytes -= copylen;
-        m->om_len = copylen;
-        dst = (uint32_t *)m->om_data;
-        while (copylen > 0) {
-            *dst = *src;
-            ++dst;
-            ++src;
-            copylen -= 4;
-        }
-    }
-
-    /* Copy ble header */
-    ble_hdr = BLE_MBUF_HDR_PTR(rxpdu);
-    memcpy(ble_hdr, &g_ble_phy_data.rxhdr, sizeof(struct ble_mbuf_hdr));
-}
-
-/**
- * Called when we want to wait if the radio is in either the rx or tx
- * disable states. We want to wait until that state is over before doing
- * anything to the radio
- */
-static void
-nrf_wait_disabled(void)
-{
-    uint32_t state;
-
-    state = NRF_RADIO->STATE;
-    if (state != RADIO_STATE_STATE_Disabled) {
-        if ((state == RADIO_STATE_STATE_RxDisable) ||
-            (state == RADIO_STATE_STATE_TxDisable)) {
-            /* This will end within a short time (6 usecs). Just poll */
-            while (NRF_RADIO->STATE == state) {
-                /* If this fails, something is really wrong. Should last
-                 * no more than 6 usecs */
-            }
-        }
-    }
-}
-
-/**
- * Setup transceiver for receive.
- */
-static void
-ble_phy_rx_xcvr_setup(void)
-{
-    uint8_t *dptr;
-
-    dptr = (uint8_t *)&g_ble_phy_rx_buf[0];
-    dptr += 3;
-
-#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
-    if (g_ble_phy_data.phy_encrypted) {
-        NRF_RADIO->PACKETPTR = (uint32_t)&g_ble_phy_enc_buf[0];
-        NRF_CCM->INPTR = (uint32_t)&g_ble_phy_enc_buf[0];
-        NRF_CCM->OUTPTR = (uint32_t)dptr;
-        NRF_CCM->SCRATCHPTR = (uint32_t)&g_nrf_encrypt_scratchpad[0];
-        NRF_CCM->MODE = CCM_MODE_LENGTH_Msk | CCM_MODE_MODE_Decryption;
-        NRF_CCM->CNFPTR = (uint32_t)&g_nrf_ccm_data;
-        NRF_CCM->SHORTS = 0;
-        NRF_CCM->EVENTS_ERROR = 0;
-        NRF_CCM->EVENTS_ENDCRYPT = 0;
-        NRF_PPI->CHENSET = PPI_CHEN_CH24_Msk | PPI_CHEN_CH25_Msk;
-    } else {
-        NRF_RADIO->PACKETPTR = (uint32_t)dptr;
-    }
-#else
-    NRF_RADIO->PACKETPTR = (uint32_t)dptr;
-#endif
-
-#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
-    if (g_ble_phy_data.phy_privacy) {
-        NRF_AAR->ENABLE = AAR_ENABLE_ENABLE_Enabled;
-        NRF_AAR->IRKPTR = (uint32_t)&g_nrf_irk_list[0];
-        NRF_AAR->ADDRPTR = (uint32_t)dptr;
-        NRF_AAR->SCRATCHPTR = (uint32_t)&g_ble_phy_data.phy_aar_scratch;
-        NRF_AAR->EVENTS_END = 0;
-        NRF_AAR->EVENTS_RESOLVED = 0;
-        NRF_AAR->EVENTS_NOTRESOLVED = 0;
-    } else {
-        if (g_ble_phy_data.phy_encrypted == 0) {
-            NRF_AAR->ENABLE = AAR_ENABLE_ENABLE_Disabled;
-        }
-    }
-#endif
-
-    /* Turn off trigger TXEN on output compare match and AAR on bcmatch */
-    NRF_PPI->CHENCLR = PPI_CHEN_CH20_Msk | PPI_CHEN_CH23_Msk;
-
-    /* Reset the rx started flag. Used for the wait for response */
-    g_ble_phy_data.phy_rx_started = 0;
-    g_ble_phy_data.phy_state = BLE_PHY_STATE_RX;
-
-    /* I want to know when 1st byte received (after address) */
-    NRF_RADIO->BCC = 8; /* in bits */
-    NRF_RADIO->EVENTS_ADDRESS = 0;
-    NRF_RADIO->EVENTS_DEVMATCH = 0;
-    NRF_RADIO->EVENTS_BCMATCH = 0;
-    NRF_RADIO->EVENTS_RSSIEND = 0;
-    NRF_RADIO->SHORTS = RADIO_SHORTS_END_DISABLE_Msk |
-                        RADIO_SHORTS_READY_START_Msk |
-                        RADIO_SHORTS_DISABLED_TXEN_Msk |
-                        RADIO_SHORTS_ADDRESS_BCSTART_Msk |
-                        RADIO_SHORTS_ADDRESS_RSSISTART_Msk |
-                        RADIO_SHORTS_DISABLED_RSSISTOP_Msk;
-
-    NRF_RADIO->INTENSET = RADIO_INTENSET_ADDRESS_Msk;
-}
-
-/**
- * Called from interrupt context when the transmit ends
- *
- */
-static void
-ble_phy_tx_end_isr(void)
-{
-    uint8_t was_encrypted;
-    uint8_t transition;
-    uint8_t txlen;
-    uint32_t wfr_time;
-    uint32_t txstart;
-
-    /*
-     * Read captured tx start time. This is not the actual transmit start
-     * time but it is the time at which the address event occurred
-     * (after transmission of access address)
-     */
-    txstart = NRF_TIMER0->CC[1];
-
-    /* If this transmission was encrypted we need to remember it */
-    was_encrypted = g_ble_phy_data.phy_encrypted;
-
-    /* Better be in TX state! */
-    assert(g_ble_phy_data.phy_state == BLE_PHY_STATE_TX);
-
-    /* Log the event */
-    ble_ll_log(BLE_LL_LOG_ID_PHY_TXEND, (g_ble_phy_tx_buf[0] >> 8) & 0xFF,
-               was_encrypted, txstart);
-
-    /* Clear events and clear interrupt on disabled event */
-    NRF_RADIO->EVENTS_DISABLED = 0;
-    NRF_RADIO->INTENCLR = RADIO_INTENCLR_DISABLED_Msk;
-    NRF_RADIO->EVENTS_END = 0;
-    wfr_time = NRF_RADIO->SHORTS;
-
-#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
-    /*
-     * XXX: not sure what to do. We had a HW error during transmission.
-     * For now I just count a stat but continue on like all is good.
-     */
-    if (was_encrypted) {
-        if (NRF_CCM->EVENTS_ERROR) {
-            STATS_INC(ble_phy_stats, tx_hw_err);
-            NRF_CCM->EVENTS_ERROR = 0;
-        }
-    }
-#endif
-
-    /* Call transmit end callback */
-    if (g_ble_phy_data.txend_cb) {
-        g_ble_phy_data.txend_cb(g_ble_phy_data.txend_arg);
-    }
-
-    transition = g_ble_phy_data.phy_transition;
-    if (transition == BLE_PHY_TRANSITION_TX_RX) {
-        /* Packet pointer needs to be reset. */
-        ble_phy_rx_xcvr_setup();
-
-        /*
-         * Enable the wait for response timer. Note that cc #1 on
-         * timer 0 contains the transmit start time
-         */
-        txlen = g_ble_phy_data.phy_tx_pyld_len;
-        if (txlen && was_encrypted) {
-            txlen += BLE_LL_DATA_MIC_LEN;
-        }
-        wfr_time = txstart - BLE_TX_LEN_USECS_M(NRF_RX_START_OFFSET);
-        wfr_time += BLE_TX_DUR_USECS_M(txlen);
-        wfr_time += cputime_usecs_to_ticks(BLE_LL_WFR_USECS);
-        ble_ll_wfr_enable(wfr_time);
-    } else {
-        /* Disable automatic TXEN */
-        NRF_PPI->CHENCLR = PPI_CHEN_CH20_Msk;
-        assert(transition == BLE_PHY_TRANSITION_NONE);
-    }
-}
-
-static void
-ble_phy_rx_end_isr(void)
-{
-    int rc;
-    uint8_t *dptr;
-    uint8_t crcok;
-    struct ble_mbuf_hdr *ble_hdr;
-
-    /* Clear events and clear interrupt */
-    NRF_RADIO->EVENTS_END = 0;
-    NRF_RADIO->INTENCLR = RADIO_INTENCLR_END_Msk;
-
-    /* Disable automatic RXEN */
-    NRF_PPI->CHENCLR = PPI_CHEN_CH21_Msk;
-
-    /* Set RSSI and CRC status flag in header */
-    ble_hdr = &g_ble_phy_data.rxhdr;
-    assert(NRF_RADIO->EVENTS_RSSIEND != 0);
-    ble_hdr->rxinfo.rssi = -1 * NRF_RADIO->RSSISAMPLE;
-
-    dptr = (uint8_t *)&g_ble_phy_rx_buf[0];
-    dptr += 3;
-
-    /* Count PHY crc errors and valid packets */
-    crcok = (uint8_t)NRF_RADIO->CRCSTATUS;
-    if (!crcok) {
-        STATS_INC(ble_phy_stats, rx_crc_err);
-    } else {
-        STATS_INC(ble_phy_stats, rx_valid);
-        ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_CRC_OK;
-#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
-        if (g_ble_phy_data.phy_encrypted) {
-            /* Only set MIC failure flag if frame is not zero length */
-            if ((dptr[1] != 0) && (NRF_CCM->MICSTATUS == 0)) {
-                ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_MIC_FAILURE;
-            }
-
-            /*
-             * XXX: not sure how to deal with this. This should not
-             * be a MIC failure but we should not hand it up. I guess
-             * this is just some form of rx error and that is how we
-             * handle it? For now, just set CRC error flags
-             */
-            if (NRF_CCM->EVENTS_ERROR) {
-                STATS_INC(ble_phy_stats, rx_hw_err);
-                ble_hdr->rxinfo.flags &= ~BLE_MBUF_HDR_F_CRC_OK;
-            }
-
-            /*
-             * XXX: This is a total hack work-around for now but I dont
-             * know what else to do. If ENDCRYPT is not set and we are
-             * encrypted we need to not trust this frame and drop it.
-             */
-            if (NRF_CCM->EVENTS_ENDCRYPT == 0) {
-                STATS_INC(ble_phy_stats, rx_hw_err);
-                ble_hdr->rxinfo.flags &= ~BLE_MBUF_HDR_F_CRC_OK;
-            }
-        }
-#endif
-    }
-
-    /*
-     * XXX: This is a horrible ugly hack to deal with the RAM S1 byte
-     * that is not sent over the air but is present here. Simply move the
-     * data pointer to deal with it. Fix this later.
-     */
-    dptr[2] = dptr[1];
-    dptr[1] = dptr[0];
-    rc = ble_ll_rx_end(dptr + 1, ble_hdr);
-    if (rc < 0) {
-        ble_phy_disable();
-    }
-}
-
-static void
-ble_phy_rx_start_isr(void)
-{
-    int rc;
-    uint32_t state;
-    struct ble_mbuf_hdr *ble_hdr;
-
-    /* Clear events and clear interrupt */
-    NRF_RADIO->EVENTS_ADDRESS = 0;
-    NRF_RADIO->INTENCLR = RADIO_INTENCLR_ADDRESS_Msk;
-
-    /* Wait to get 1st byte of frame */
-    while (1) {
-        state = NRF_RADIO->STATE;
-        if (NRF_RADIO->EVENTS_BCMATCH != 0) {
-            break;
-        }
-
-        /*
-         * If state is disabled, we should have the BCMATCH. If not,
-         * something is wrong!
-         */
-        if (state == RADIO_STATE_STATE_Disabled) {
-            NRF_RADIO->INTENCLR = NRF_RADIO_IRQ_MASK_ALL;
-            NRF_RADIO->SHORTS = 0;
-            return;
-        }
-    }
-
-    /* Initialize flags, channel and state in ble header at rx start */
-    ble_hdr = &g_ble_phy_data.rxhdr;
-    ble_hdr->rxinfo.flags = ble_ll_state_get();
-    ble_hdr->rxinfo.channel = g_ble_phy_data.phy_chan;
-    ble_hdr->rxinfo.handle = 0;
-    ble_hdr->beg_cputime = NRF_TIMER0->CC[1] -
-        BLE_TX_LEN_USECS_M(NRF_RX_START_OFFSET);
-
-    /* Call Link Layer receive start function */
-    rc = ble_ll_rx_start((uint8_t *)&g_ble_phy_rx_buf[0] + 3,
-                         g_ble_phy_data.phy_chan,
-                         &g_ble_phy_data.rxhdr);
-    if (rc >= 0) {
-        /* Set rx started flag and enable rx end ISR */
-        g_ble_phy_data.phy_rx_started = 1;
-        NRF_RADIO->INTENSET = RADIO_INTENSET_END_Msk;
-
-#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
-        /* Must start aar if we need to  */
-        if (g_ble_phy_data.phy_privacy) {
-            NRF_RADIO->EVENTS_BCMATCH = 0;
-            NRF_PPI->CHENSET = PPI_CHEN_CH23_Msk;
-            NRF_RADIO->BCC = (BLE_DEV_ADDR_LEN + BLE_LL_PDU_HDR_LEN) * 8;
-        }
-#endif
-    } else {
-        /* Disable PHY */
-        ble_phy_disable();
-        STATS_INC(ble_phy_stats, rx_aborts);
-    }
-
-    /* Count rx starts */
-    STATS_INC(ble_phy_stats, rx_starts);
-}
-
-static void
-ble_phy_isr(void)
-{
-    uint32_t irq_en;
-
-    /* Read irq register to determine which interrupts are enabled */
-    irq_en = NRF_RADIO->INTENCLR;
-
-    /* Check for disabled event. This only happens for transmits now */
-    if ((irq_en & RADIO_INTENCLR_DISABLED_Msk) && NRF_RADIO->EVENTS_DISABLED) {
-        ble_phy_tx_end_isr();
-    }
-
-    /* We get this if we have started to receive a frame */
-    if ((irq_en & RADIO_INTENCLR_ADDRESS_Msk) && NRF_RADIO->EVENTS_ADDRESS) {
-        ble_phy_rx_start_isr();
-    }
-
-    /* Receive packet end (we dont enable this for transmit) */
-    if ((irq_en & RADIO_INTENCLR_END_Msk) && NRF_RADIO->EVENTS_END) {
-        ble_phy_rx_end_isr();
-    }
-
-    /* Ensures IRQ is cleared */
-    irq_en = NRF_RADIO->SHORTS;
-
-    /* Count # of interrupts */
-    STATS_INC(ble_phy_stats, phy_isrs);
-}
-
-/**
- * ble phy init
- *
- * Initialize the PHY.
- *
- * @return int 0: success; PHY error code otherwise
- */
-int
-ble_phy_init(void)
-{
-    int rc;
-    uint32_t os_tmo;
-
-    /* Make sure HFXO is started */
-    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
-    NRF_CLOCK->TASKS_HFCLKSTART = 1;
-    os_tmo = os_time_get() + (5 * (1000 / OS_TICKS_PER_SEC));
-    while (1) {
-        if (NRF_CLOCK->EVENTS_HFCLKSTARTED) {
-            break;
-        }
-        if ((int32_t)(os_time_get() - os_tmo) > 0) {
-            return BLE_PHY_ERR_INIT;
-        }
-    }
-
-    /* Set phy channel to an invalid channel so first set channel works */
-    g_ble_phy_data.phy_chan = BLE_PHY_NUM_CHANS;
-
-    /* Toggle peripheral power to reset (just in case) */
-    NRF_RADIO->POWER = 0;
-    NRF_RADIO->POWER = 1;
-
-    /* Disable all interrupts */
-    NRF_RADIO->INTENCLR = NRF_RADIO_IRQ_MASK_ALL;
-
-    /* Set configuration registers */
-    NRF_RADIO->MODE = RADIO_MODE_MODE_Ble_1Mbit;
-    NRF_RADIO->PCNF0 = (NRF_LFLEN_BITS << RADIO_PCNF0_LFLEN_Pos)    |
-                       RADIO_PCNF0_S1INCL_Msk                       |
-                       (NRF_S0_LEN << RADIO_PCNF0_S0LEN_Pos)        |
-                       (RADIO_PCNF0_PLEN_8bit << RADIO_PCNF0_PLEN_Pos);
-
-    /* XXX: should maxlen be 251 for encryption? */
-    NRF_RADIO->PCNF1 = NRF_MAXLEN |
-                       (RADIO_PCNF1_ENDIAN_Little <<  RADIO_PCNF1_ENDIAN_Pos) |
-                       (NRF_BALEN << RADIO_PCNF1_BALEN_Pos) |
-                       RADIO_PCNF1_WHITEEN_Msk;
-
-    /* Set base0 with the advertising access address */
-    NRF_RADIO->BASE0 = (BLE_ACCESS_ADDR_ADV << 8) & 0xFFFFFF00;
-    NRF_RADIO->PREFIX0 = (BLE_ACCESS_ADDR_ADV >> 24) & 0xFF;
-
-    /* Configure the CRC registers */
-    NRF_RADIO->CRCCNF = RADIO_CRCCNF_SKIPADDR_Msk | RADIO_CRCCNF_LEN_Three;
-
-    /* Configure BLE poly */
-    NRF_RADIO->CRCPOLY = 0x0100065B;
-
-    /* Configure IFS */
-    NRF_RADIO->TIFS = BLE_LL_IFS;
-
-    /* Captures tx/rx start in timer0 capture 1 */
-    NRF_PPI->CHENSET = PPI_CHEN_CH26_Msk;
-
-#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
-    NRF_CCM->INTENCLR = 0xffffffff;
-    NRF_CCM->SHORTS = CCM_SHORTS_ENDKSGEN_CRYPT_Msk;
-    NRF_CCM->EVENTS_ERROR = 0;
-    memset(g_nrf_encrypt_scratchpad, 0, sizeof(g_nrf_encrypt_scratchpad));
-#endif
-
-#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
-    g_ble_phy_data.phy_aar_scratch = 0;
-    NRF_AAR->IRKPTR = (uint32_t)&g_nrf_irk_list[0];
-    NRF_AAR->INTENCLR = 0xffffffff;
-    NRF_AAR->EVENTS_END = 0;
-    NRF_AAR->EVENTS_RESOLVED = 0;
-    NRF_AAR->EVENTS_NOTRESOLVED = 0;
-    NRF_AAR->NIRK = 0;
-#endif
-
-    /* Set isr in vector table and enable interrupt */
-    NVIC_SetPriority(RADIO_IRQn, 0);
-    NVIC_SetVector(RADIO_IRQn, (uint32_t)ble_phy_isr);
-    NVIC_EnableIRQ(RADIO_IRQn);
-
-    /* Register phy statistics */
-    if (!g_ble_phy_data.phy_stats_initialized) {
-        rc = stats_init_and_reg(STATS_HDR(ble_phy_stats),
-                                STATS_SIZE_INIT_PARMS(ble_phy_stats,
-                                                      STATS_SIZE_32),
-                                STATS_NAME_INIT_PARMS(ble_phy_stats),
-                                "ble_phy");
-        assert(rc == 0);
-
-        g_ble_phy_data.phy_stats_initialized  = 1;
-    }
-
-    return 0;
-}
-
-/**
- * Puts the phy into receive mode.
- *
- * @return int 0: success; BLE Phy error code otherwise
- */
-int
-ble_phy_rx(void)
-{
-    /* Check radio state */
-    nrf_wait_disabled();
-    if (NRF_RADIO->STATE != RADIO_STATE_STATE_Disabled) {
-        ble_phy_disable();
-        STATS_INC(ble_phy_stats, radio_state_errs);
-        return BLE_PHY_ERR_RADIO_STATE;
-    }
-
-    /* Make sure all interrupts are disabled */
-    NRF_RADIO->INTENCLR = NRF_RADIO_IRQ_MASK_ALL;
-
-    /* Clear events prior to enabling receive */
-    NRF_RADIO->EVENTS_END = 0;
-    NRF_RADIO->EVENTS_DISABLED = 0;
-
-    /* Setup for rx */
-    ble_phy_rx_xcvr_setup();
-
-    /* Start the receive task in the radio if not automatically going to rx */
-    if ((NRF_PPI->CHEN & PPI_CHEN_CH21_Msk) == 0) {
-        NRF_RADIO->TASKS_RXEN = 1;
-    }
-
-    ble_ll_log(BLE_LL_LOG_ID_PHY_RX, g_ble_phy_data.phy_encrypted, 0, 0);
-
-    return 0;
-}
-
-#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
-/**
- * Called to enable encryption at the PHY. Note that this state will persist
- * in the PHY; in other words, if you call this function you have to call
- * disable so that future PHY transmits/receives will not be encrypted.
- *
- * @param pkt_counter
- * @param iv
- * @param key
- * @param is_master
- */
-void
-ble_phy_encrypt_enable(uint64_t pkt_counter, uint8_t *iv, uint8_t *key,
-                       uint8_t is_master)
-{
-    memcpy(g_nrf_ccm_data.key, key, 16);
-    g_nrf_ccm_data.pkt_counter = pkt_counter;
-    memcpy(g_nrf_ccm_data.iv, iv, 8);
-    g_nrf_ccm_data.dir_bit = is_master;
-    g_ble_phy_data.phy_encrypted = 1;
-    /* Enable the module (AAR cannot be on while CCM on) */
-    NRF_AAR->ENABLE = AAR_ENABLE_ENABLE_Disabled;
-    NRF_CCM->ENABLE = CCM_ENABLE_ENABLE_Enabled;
-}
-
-void
-ble_phy_encrypt_set_pkt_cntr(uint64_t pkt_counter, int dir)
-{
-    g_nrf_ccm_data.pkt_counter = pkt_counter;
-    g_nrf_ccm_data.dir_bit = dir;
-}
-
-void
-ble_phy_encrypt_disable(void)
-{
-    NRF_PPI->CHENCLR = (PPI_CHEN_CH24_Msk | PPI_CHEN_CH25_Msk);
-    NRF_CCM->TASKS_STOP = 1;
-    NRF_CCM->EVENTS_ERROR = 0;
-    NRF_CCM->ENABLE = CCM_ENABLE_ENABLE_Disabled;
-
-    g_ble_phy_data.phy_encrypted = 0;
-}
-#endif
-
-void
-ble_phy_set_txend_cb(ble_phy_tx_end_func txend_cb, void *arg)
-{
-    /* Set transmit end callback and arg */
-    g_ble_phy_data.txend_cb = txend_cb;
-    g_ble_phy_data.txend_arg = arg;
-}
-
-/**
- * Called to set the start time of a transmission.
- *
- * This function is called to set the start time when we are not going from
- * rx to tx automatically.
- *
- * NOTE: care must be taken when calling this function. The channel should
- * already be set.
- *
- * @param cputime
- *
- * @return int
- */
-int
-ble_phy_tx_set_start_time(uint32_t cputime)
-{
-    int rc;
-
-    NRF_TIMER0->CC[0] = cputime;
-    NRF_PPI->CHENSET = PPI_CHEN_CH20_Msk;
-    NRF_PPI->CHENCLR = PPI_CHEN_CH21_Msk;
-    if ((int32_t)(cputime_get32() - cputime) >= 0) {
-        STATS_INC(ble_phy_stats, tx_late);
-        ble_phy_disable();
-        rc =  BLE_PHY_ERR_TX_LATE;
-    } else {
-        rc = 0;
-    }
-    return rc;
-}
-
-/**
- * Called to set the start time of a reception
- *
- * This function acts a bit differently than transmit. If we are late getting
- * here we will still attempt to receive.
- *
- * NOTE: care must be taken when calling this function. The channel should
- * already be set.
- *
- * @param cputime
- *
- * @return int
- */
-int
-ble_phy_rx_set_start_time(uint32_t cputime)
-{
-    int rc;
-
-    NRF_TIMER0->CC[0] = cputime;
-    NRF_PPI->CHENCLR = PPI_CHEN_CH20_Msk;
-    NRF_PPI->CHENSET = PPI_CHEN_CH21_Msk;
-    if ((int32_t)(cputime_get32() - cputime) >= 0) {
-        STATS_INC(ble_phy_stats, rx_late);
-        NRF_PPI->CHENCLR = PPI_CHEN_CH21_Msk;
-        NRF_RADIO->TASKS_RXEN = 1;
-        rc =  BLE_PHY_ERR_TX_LATE;
-    } else {
-        rc = 0;
-    }
-    return rc;
-}
-
-int
-ble_phy_tx(struct os_mbuf *txpdu, uint8_t end_trans)
-{
-    int rc;
-    uint8_t *dptr;
-    uint8_t *pktptr;
-    uint8_t payload_len;
-    uint32_t state;
-    uint32_t shortcuts;
-    struct ble_mbuf_hdr *ble_hdr;
-
-    /* Better have a pdu! */
-    assert(txpdu != NULL);
-
-    /*
-     * This check is to make sure that the radio is not in a state where
-     * it is moving to disabled state. If so, let it get there.
-     */
-    nrf_wait_disabled();
-
-    ble_hdr = BLE_MBUF_HDR_PTR(txpdu);
-    payload_len = ble_hdr->txinfo.pyld_len;
-
-#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
-    if (g_ble_phy_data.phy_encrypted) {
-        dptr = (uint8_t *)&g_ble_phy_enc_buf[0];
-        ++dptr;
-        pktptr = (uint8_t *)&g_ble_phy_tx_buf[0];
-        NRF_CCM->SHORTS = 1;
-        NRF_CCM->INPTR = (uint32_t)dptr;
-        NRF_CCM->OUTPTR = (uint32_t)pktptr;
-        NRF_CCM->SCRATCHPTR = (uint32_t)&g_nrf_encrypt_scratchpad[0];
-        NRF_CCM->EVENTS_ERROR = 0;
-        NRF_CCM->MODE = CCM_MODE_LENGTH_Msk;
-        NRF_CCM->CNFPTR = (uint32_t)&g_nrf_ccm_data;
-        NRF_PPI->CHENCLR = PPI_CHEN_CH25_Msk | PPI_CHEN_CH23_Msk;
-        NRF_PPI->CHENSET = PPI_CHEN_CH24_Msk;
-    } else {
-#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
-        NRF_PPI->CHENCLR = PPI_CHEN_CH23_Msk;
-        NRF_AAR->IRKPTR = (uint32_t)&g_nrf_irk_list[0];
-#endif
-        dptr = (uint8_t *)&g_ble_phy_tx_buf[0];
-        ++dptr;
-        pktptr = dptr;
-    }
-#else
-#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
-    NRF_PPI->CHENCLR = PPI_CHEN_CH23_Msk;
-#endif
-    dptr = (uint8_t *)&g_ble_phy_tx_buf[0];
-    ++dptr;
-    pktptr = dptr;
-#endif
-
-    /* RAM representation has S0, LENGTH and S1 fields. (3 bytes) */
-    dptr[0] = ble_hdr->txinfo.hdr_byte;
-    dptr[1] = payload_len;
-    dptr[2] = 0;
-    dptr += 3;
-    NRF_RADIO->PACKETPTR = (uint32_t)pktptr;
-
-    /* Clear the ready, end and disabled events */
-    NRF_RADIO->EVENTS_READY = 0;
-    NRF_RADIO->EVENTS_END = 0;
-    NRF_RADIO->EVENTS_DISABLED = 0;
-
-    /* Enable shortcuts for transmit start/end. */
-    shortcuts = RADIO_SHORTS_END_DISABLE_Msk | RADIO_SHORTS_READY_START_Msk;
-    if (end_trans == BLE_PHY_TRANSITION_TX_RX) {
-        shortcuts |= RADIO_SHORTS_DISABLED_RXEN_Msk;
-    }
-    NRF_RADIO->SHORTS = shortcuts;
-    NRF_RADIO->INTENSET = RADIO_INTENSET_DISABLED_Msk;
-
-    /* Set transmitted payload length */
-    g_ble_phy_data.phy_tx_pyld_len = payload_len;
-
-    /* Set the PHY transition */
-    g_ble_phy_data.phy_transition = end_trans;
-
-    /* If we already started transmitting, abort it! */
-    state = NRF_RADIO->STATE;
-    if (state != RADIO_STATE_STATE_Tx) {
-        /* Copy data from mbuf into transmit buffer */
-        os_mbuf_copydata(txpdu, ble_hdr->txinfo.offset, payload_len, dptr);
-
-        /* Set phy state to transmitting and count packet statistics */
-        g_ble_phy_data.phy_state = BLE_PHY_STATE_TX;
-        STATS_INC(ble_phy_stats, tx_good);
-        STATS_INCN(ble_phy_stats, tx_bytes, payload_len + BLE_LL_PDU_HDR_LEN);
-        rc = BLE_ERR_SUCCESS;
-    } else {
-        ble_phy_disable();
-        STATS_INC(ble_phy_stats, tx_late);
-        rc = BLE_PHY_ERR_RADIO_STATE;
-    }
-
-    return rc;
-}
-
-/**
- * ble phy txpwr set
- *
- * Set the transmit output power (in dBm).
- *
- * NOTE: If the output power specified is within the BLE limits but outside
- * the chip limits, we "rail" the power level so we dont exceed the min/max
- * chip values.
- *
- * @param dbm Power output in dBm.
- *
- * @return int 0: success; anything else is an error
- */
-int
-ble_phy_txpwr_set(int dbm)
-{
-    /* Check valid range */
-    assert(dbm <= BLE_PHY_MAX_PWR_DBM);
-
-    /* "Rail" power level if outside supported range */
-    if (dbm > NRF_TX_PWR_MAX_DBM) {
-        dbm = NRF_TX_PWR_MAX_DBM;
-    } else {
-        if (dbm < NRF_TX_PWR_MIN_DBM) {
-            dbm = NRF_TX_PWR_MIN_DBM;
-        }
-    }
-
-    NRF_RADIO->TXPOWER = dbm;
-    g_ble_phy_data.phy_txpwr_dbm = dbm;
-
-    return 0;
-}
-
-/**
- * ble phy txpwr get
- *
- * Get the transmit power.
- *
- * @return int  The current PHY transmit power, in dBm
- */
-int
-ble_phy_txpwr_get(void)
-{
-    return g_ble_phy_data.phy_txpwr_dbm;
-}
-
-/**
- * ble phy setchan
- *
- * Sets the logical frequency of the transceiver. The input parameter is the
- * BLE channel index (0 to 39, inclusive). The NRF frequency register works like
- * this: logical frequency = 2400 + FREQ (MHz).
- *
- * Thus, to get a logical frequency of 2402 MHz, you would program the
- * FREQUENCY register to 2.
- *
- * @param chan This is the Data Channel Index or Advertising Channel index
- *
- * @return int 0: success; PHY error code otherwise
- */
-int
-ble_phy_setchan(uint8_t chan, uint32_t access_addr, uint32_t crcinit)
-{
-    uint8_t freq;
-    uint32_t prefix;
-
-    assert(chan < BLE_PHY_NUM_CHANS);
-
-    /* Check for valid channel range */
-    if (chan >= BLE_PHY_NUM_CHANS) {
-        return BLE_PHY_ERR_INV_PARAM;
-    }
-
-    /* Get correct frequency */
-    if (chan < BLE_PHY_NUM_DATA_CHANS) {
-        if (chan < 11) {
-            /* Data channel 0 starts at 2404. 0 - 10 are contiguous */
-            freq = (BLE_PHY_DATA_CHAN0_FREQ_MHZ - 2400) +
-                   (BLE_PHY_CHAN_SPACING_MHZ * chan);
-        } else {
-            /* Data channel 11 starts at 2428. 0 - 10 are contiguous */
-            freq = (BLE_PHY_DATA_CHAN0_FREQ_MHZ - 2400) +
-                   (BLE_PHY_CHAN_SPACING_MHZ * (chan + 1));
-        }
-
-        /* Set current access address */
-        g_ble_phy_data.phy_access_address = access_addr;
-
-        /* Configure logical address 1 and crcinit */
-        prefix = NRF_RADIO->PREFIX0;
-        prefix &= 0xffff00ff;
-        prefix |= ((access_addr >> 24) & 0xFF) << 8;
-        NRF_RADIO->BASE1 = (access_addr << 8) & 0xFFFFFF00;
-        NRF_RADIO->PREFIX0 = prefix;
-        NRF_RADIO->TXADDRESS = 1;
-        NRF_RADIO->RXADDRESSES = (1 << 1);
-        NRF_RADIO->CRCINIT = crcinit;
-    } else {
-        if (chan == 37) {
-            freq = BLE_PHY_CHAN_SPACING_MHZ;
-        } else if (chan == 38) {
-            /* This advertising channel is at 2426 MHz */
-            freq = BLE_PHY_CHAN_SPACING_MHZ * 13;
-        } else {
-            /* This advertising channel is at 2480 MHz */
-            freq = BLE_PHY_CHAN_SPACING_MHZ * 40;
-        }
-
-        /* Logical adddress 0 preconfigured */
-        NRF_RADIO->TXADDRESS = 0;
-        NRF_RADIO->RXADDRESSES = (1 << 0);
-        NRF_RADIO->CRCINIT = BLE_LL_CRCINIT_ADV;
-
-        /* Set current access address */
-        g_ble_phy_data.phy_access_address = BLE_ACCESS_ADDR_ADV;
-    }
-
-    /* Set the frequency and the data whitening initial value */
-    g_ble_phy_data.phy_chan = chan;
-    NRF_RADIO->FREQUENCY = freq;
-    NRF_RADIO->DATAWHITEIV = chan;
-
-    ble_ll_log(BLE_LL_LOG_ID_PHY_SETCHAN, chan, freq, access_addr);
-
-    return 0;
-}
-
-/**
- * Disable the PHY. This will do the following:
- *  -> Turn off all phy interrupts.
- *  -> Disable internal shortcuts.
- *  -> Disable the radio.
- *  -> Make sure we wont automatically go to rx/tx on output compare
- *  -> Sets phy state to idle.
- *  -> Clears any pending irqs in the NVIC. Might not be necessary but we do
- *  it as a precaution.
- */
-void
-ble_phy_disable(void)
-{
-    ble_ll_log(BLE_LL_LOG_ID_PHY_DISABLE, g_ble_phy_data.phy_state, 0, 0);
-
-    NRF_RADIO->INTENCLR = NRF_RADIO_IRQ_MASK_ALL;
-    NRF_RADIO->SHORTS = 0;
-    NRF_RADIO->TASKS_DISABLE = 1;
-    NRF_PPI->CHENCLR = PPI_CHEN_CH23_Msk | PPI_CHEN_CH21_Msk | PPI_CHEN_CH20_Msk;
-    NVIC_ClearPendingIRQ(RADIO_IRQn);
-    g_ble_phy_data.phy_state = BLE_PHY_STATE_IDLE;
-}
-
-/* Gets the current access address */
-uint32_t ble_phy_access_addr_get(void)
-{
-    return g_ble_phy_data.phy_access_address;
-}
-
-/**
- * Return the phy state
- *
- * @return int The current PHY state.
- */
-int
-ble_phy_state_get(void)
-{
-    return g_ble_phy_data.phy_state;
-}
-
-/**
- * Called to see if a reception has started
- *
- * @return int
- */
-int
-ble_phy_rx_started(void)
-{
-    return g_ble_phy_data.phy_rx_started;
-}
-
-/**
- * Return the transceiver state
- *
- * @return int transceiver state.
- */
-uint8_t
-ble_phy_xcvr_state_get(void)
-{
-    uint32_t state;
-    state = NRF_RADIO->STATE;
-    return (uint8_t)state;
-}
-
-/**
- * Called to return the maximum data pdu payload length supported by the
- * phy. For this chip, if encryption is enabled, the maximum payload is 27
- * bytes.
- *
- * @return uint8_t Maximum data channel PDU payload size supported
- */
-uint8_t
-ble_phy_max_data_pdu_pyld(void)
-{
-    return BLE_LL_DATA_PDU_MAX_PYLD;
-}
-
-#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
-void
-ble_phy_resolv_list_enable(void)
-{
-    NRF_AAR->NIRK = (uint32_t)g_nrf_num_irks;
-    g_ble_phy_data.phy_privacy = 1;
-}
-
-void
-ble_phy_resolv_list_disable(void)
-{
-    g_ble_phy_data.phy_privacy = 0;
-}
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/drivers/uart/include/uart/uart.h
----------------------------------------------------------------------
diff --git a/drivers/uart/include/uart/uart.h b/drivers/uart/include/uart/uart.h
deleted file mode 100644
index e889722..0000000
--- a/drivers/uart/include/uart/uart.h
+++ /dev/null
@@ -1,139 +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.
- */
-
-#ifndef __DRIVERS_UART_H_
-#define __DRIVERS_UART_H_
-
-#include <inttypes.h>
-#include <os/os_dev.h>
-
-struct uart_dev;
-
-/*
- * Function prototype for UART driver to ask for more data to send.
- * Driver must call this with interrupts disabled.
- *
- * @param arg		This is uc_cb_arg passed in uart_conf in
- *			os_dev_open().
- *
- * @return		Byte value to send next, -1 if no more data to send.
- */
-typedef int (*uart_tx_char)(void *arg);
-
-/*
- * Function prototype for UART driver to report that transmission is
- * complete. This should be called when transmission of last byte is
- * finished.
- * Driver must call this with interrupts disabled.
- *
- * @param arg		This is uc_cb_arg passed in uart_conf in
- *			os_dev_open().
- */
-typedef void (*uart_tx_done)(void *arg);
-
-/*
- * Function prototype for UART driver to report incoming byte of data.
- * Driver must call this with interrupts disabled.
- *
- * @param arg		This is uc_cb_arg passed in uart_conf in
- *			os_dev_open().
- * @param byte		Received byte
- *
- * @return		0 on success; -1 if data could not be received.
- *			Note that returning -1 triggers flow control (if
- *			configured), and user must call uart_start_rx() to
- *			start receiving more data again.
- */
-typedef int (*uart_rx_char)(void *arg, uint8_t byte);
-
-struct uart_driver_funcs {
-    void (*uf_start_tx)(struct uart_dev *);
-    void (*uf_start_rx)(struct uart_dev *);
-    void (*uf_blocking_tx)(struct uart_dev *, uint8_t);
-};
-
-struct uart_dev {
-    struct os_dev ud_dev;
-    struct uart_driver_funcs ud_funcs;
-    void *ud_priv;
-};
-
-/*
- * ***Note that these enum values must match what hw/hal/hal_uart.h***
- */
-enum uart_parity {
-    UART_PARITY_NONE = 0,       /* no parity */
-    UART_PARITY_ODD = 1,        /* odd parity bit */
-    UART_PARITY_EVEN = 2        /* even parity bit */
-};
-
-enum uart_flow_ctl {
-    UART_FLOW_CTL_NONE = 0,     /* no flow control */
-    UART_FLOW_CTL_RTS_CTS = 1   /* RTS/CTS */
-};
-
-struct uart_conf {
-    uint32_t uc_speed;          /* baudrate in bps */
-    uint8_t uc_databits;        /* number of data bits */
-    uint8_t uc_stopbits;        /* number of stop bits */
-    enum uart_parity uc_parity;
-    enum uart_flow_ctl uc_flow_ctl;
-    uart_tx_char uc_tx_char;
-    uart_rx_char uc_rx_char;
-    uart_tx_done uc_tx_done;
-    void *uc_cb_arg;
-};
-
-/*
- * Tell driver that more data has been queued, and that the driver should
- * start asking for it.
- *
- * @param dev		Uart device in question
- */
-static inline void
-uart_start_tx(struct uart_dev *dev)
-{
-    dev->ud_funcs.uf_start_tx(dev);
-}
-
-/*
- * Tell driver that previous report on RX buffer shortage is now done,
- * and that app is ready to receive more data.
- *
- * @param dev		Uart device in question
- */
-static inline void
-uart_start_rx(struct uart_dev *dev)
-{
-    dev->ud_funcs.uf_start_rx(dev);
-}
-
-/*
- * Blocking transmit. ***Note that this should only be used with console.
- * And only when MCU is about to restart, to write final log messages***
- *
- * @param dev		Uart device in question
- */
-static inline void
-uart_blocking_tx(struct uart_dev *dev, uint8_t byte)
-{
-    dev->ud_funcs.uf_blocking_tx(dev, byte);
-}
-
-#endif /* __DRIVERS_UART_H_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/drivers/uart/pkg.yml
----------------------------------------------------------------------
diff --git a/drivers/uart/pkg.yml b/drivers/uart/pkg.yml
deleted file mode 100644
index 5b95e32..0000000
--- a/drivers/uart/pkg.yml
+++ /dev/null
@@ -1,27 +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.
-#
-
-pkg.name: drivers/uart
-pkg.description: UART driver interfaces
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-pkg.deps:
-pkg.req_apis: 
-    - UART_HW_IMPL

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/drivers/uart/src/uart.c
----------------------------------------------------------------------
diff --git a/drivers/uart/src/uart.c b/drivers/uart/src/uart.c
deleted file mode 100644
index f736fe1..0000000
--- a/drivers/uart/src/uart.c
+++ /dev/null
@@ -1,18 +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.
- */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/drivers/uart/uart_bitbang/include/uart_bitbang/uart_bitbang.h
----------------------------------------------------------------------
diff --git a/drivers/uart/uart_bitbang/include/uart_bitbang/uart_bitbang.h b/drivers/uart/uart_bitbang/include/uart_bitbang/uart_bitbang.h
deleted file mode 100644
index 23e2f80..0000000
--- a/drivers/uart/uart_bitbang/include/uart_bitbang/uart_bitbang.h
+++ /dev/null
@@ -1,32 +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.
- */
-
-#ifndef __UART_BITBANG_H__
-#define __UART_BITBANG_H__
-
-struct uart_bitbang_conf {
-    int ubc_rxpin;
-    int ubc_txpin;
-    uint32_t ubc_cputimer_freq;
-};
-
-struct os_dev;
-int uart_bitbang_init(struct os_dev *, void *);
-
-#endif /* __UART_BITBANG_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/drivers/uart/uart_bitbang/pkg.yml
----------------------------------------------------------------------
diff --git a/drivers/uart/uart_bitbang/pkg.yml b/drivers/uart/uart_bitbang/pkg.yml
deleted file mode 100644
index 217800a..0000000
--- a/drivers/uart/uart_bitbang/pkg.yml
+++ /dev/null
@@ -1,29 +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.
-#
-
-pkg.name: drivers/uart/uart_bitbang
-pkg.description: Async UART port with a bitbanger.
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-pkg.apis:
-   - UART_HW_IMPL
-pkg.deps:
-   - hw/hal
-   - drivers/uart

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/drivers/uart/uart_bitbang/src/uart_bitbang.c
----------------------------------------------------------------------
diff --git a/drivers/uart/uart_bitbang/src/uart_bitbang.c b/drivers/uart/uart_bitbang/src/uart_bitbang.c
deleted file mode 100644
index c20682e..0000000
--- a/drivers/uart/uart_bitbang/src/uart_bitbang.c
+++ /dev/null
@@ -1,346 +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 <inttypes.h>
-#include <string.h>
-#include <stdio.h>
-#include <assert.h>
-
-#include <hal/hal_gpio.h>
-#include <hal/hal_uart.h>
-#include <hal/hal_cputime.h>
-
-#include <os/os.h>
-#include <os/os_dev.h>
-
-#include <uart/uart.h>
-
-#include "uart_bitbang/uart_bitbang.h"
-
-/*
- * Async UART as a bitbanger.
- * Cannot run very fast, as it relies on cputimer to time sampling and
- * bit tx start times.
- */
-struct uart_bitbang {
-    int ub_bittime;             /* number of cputimer ticks per bit */
-    struct {
-        int pin;                /* RX pin */
-        struct cpu_timer timer;
-        uint32_t start;         /* cputime when byte rx started */
-        uint8_t byte;           /* receiving this byte */
-        uint8_t bits;           /* how many bits we've seen */
-        int false_irq;
-    } ub_rx;
-    struct {
-        int pin;                /* TX pin */
-        struct cpu_timer timer;
-        uint32_t start;         /* cputime when byte tx started */
-        uint8_t byte;           /* byte being transmitted */
-        uint8_t bits;           /* how many bits have been sent */
-    } ub_tx;
-
-    uint8_t ub_open:1;
-    uint8_t ub_rx_stall:1;
-    uint8_t ub_txing:1;
-    uint32_t ub_cputimer_freq;
-    hal_uart_rx_char ub_rx_func;
-    hal_uart_tx_char ub_tx_func;
-    hal_uart_tx_done ub_tx_done;
-    void *ub_func_arg;
-};
-
-/*
- * Bytes start with START bit (0) followed by 8 data bits and then the
- * STOP bit (1). STOP bit should be configurable. Data bits are sent LSB first.
- */
-static void
-uart_bitbang_tx_timer(void *arg)
-{
-    struct uart_bitbang *ub = (struct uart_bitbang *)arg;
-    uint32_t next = 0;
-    int data;
-
-    if (!ub->ub_txing || ub->ub_tx.bits > 9) {
-        if (ub->ub_tx.bits > 9) {
-            if (ub->ub_tx_done) {
-                ub->ub_tx_done(ub->ub_func_arg);
-            }
-        }
-        data = ub->ub_tx_func(ub->ub_func_arg);
-        if (data < 0) {
-            ub->ub_txing = 0;
-            return;
-        } else {
-            ub->ub_tx.byte = data;
-        }
-        /*
-         * Start bit
-         */
-        hal_gpio_write(ub->ub_tx.pin, 0);
-        ub->ub_tx.start = cputime_get32();
-        next = ub->ub_tx.start + ub->ub_bittime;
-        ub->ub_txing = 1;
-        ub->ub_tx.bits = 0;
-    } else {
-        if (ub->ub_tx.bits++ < 8) {
-            hal_gpio_write(ub->ub_tx.pin, ub->ub_tx.byte & 0x01);
-            ub->ub_tx.byte = ub->ub_tx.byte >> 1;
-            next = ub->ub_tx.start + (ub->ub_bittime * (ub->ub_tx.bits + 1));
-        } else {
-            /*
-             * STOP bit.
-             */
-            hal_gpio_write(ub->ub_tx.pin, 1);
-            next = ub->ub_tx.start + (ub->ub_bittime * 10);
-        }
-    }
-    cputime_timer_start(&ub->ub_tx.timer, next);
-}
-
-static void
-uart_bitbang_rx_timer(void *arg)
-{
-    struct uart_bitbang *ub = (struct uart_bitbang *)arg;
-    int val;
-
-    val = hal_gpio_read(ub->ub_rx.pin);
-
-    if (val) {
-        ub->ub_rx.byte = 0x80 | (ub->ub_rx.byte >> 1);
-    } else {
-        ub->ub_rx.byte = (ub->ub_rx.byte >> 1);
-    }
-    if (ub->ub_rx.bits == 7) {
-        val = ub->ub_rx_func(ub->ub_func_arg, ub->ub_rx.byte);
-        if (val) {
-            ub->ub_rx_stall = 1;
-        } else {
-            /*
-             * Re-enable GPIO IRQ after we've sampled last bit. STOP bit
-             * is ignored.
-             */
-            hal_gpio_irq_enable(ub->ub_rx.pin);
-        }
-    } else {
-        ub->ub_rx.bits++;
-        cputime_timer_start(&ub->ub_rx.timer,
-          ub->ub_rx.start + (ub->ub_bittime * (ub->ub_rx.bits + 1)) +
-          (ub->ub_bittime >> 1));
-    }
-}
-
-/*
- * Byte RX starts when we get transition from high to low.
- * We disable RX irq after we've seen start until end of RX of one byte.
- */
-static void
-uart_bitbang_isr(void *arg)
-{
-    struct uart_bitbang *ub = (struct uart_bitbang *)arg;
-    uint32_t time;
-
-    time = cputime_get32();
-    if (ub->ub_rx.start - time < (9 * ub->ub_bittime)) {
-        ++ub->ub_rx.false_irq;
-        return;
-    }
-    ub->ub_rx.start = time;
-    ub->ub_rx.byte = 0;
-    ub->ub_rx.bits = 0;
-
-    /*
-     * We try to sample in the middle of a bit. First sample is taken
-     * 1.5 bittimes after beginning of start bit.
-     */
-    cputime_timer_start(&ub->ub_rx.timer, time +
-      ub->ub_bittime + (ub->ub_bittime >> 1));
-
-    hal_gpio_irq_disable(ub->ub_rx.pin);
-}
-
-static void
-uart_bitbang_blocking_tx(struct uart_dev *dev, uint8_t data)
-{
-    struct uart_bitbang *ub;
-    int i;
-    uint32_t start, next;
-
-    ub = (struct uart_bitbang *)dev->ud_priv;
-    if (!ub->ub_open) {
-        return;
-    }
-    hal_gpio_write(ub->ub_tx.pin, 0);
-    start = cputime_get32();
-    next = start + ub->ub_bittime;
-    while (cputime_get32() < next);
-    for (i = 0; i < 8; i++) {
-        hal_gpio_write(ub->ub_tx.pin, data & 0x01);
-        data = data >> 1;
-        next = start + (ub->ub_bittime * i + 1);
-        while (cputime_get32() < next);
-    }
-    next = start + (ub->ub_bittime * 10);
-    hal_gpio_write(ub->ub_tx.pin, 1);
-    while (cputime_get32() < next);
-}
-
-static void
-uart_bitbang_start_tx(struct uart_dev *dev)
-{
-    struct uart_bitbang *ub;
-    int sr;
-
-    ub = (struct uart_bitbang *)dev->ud_priv;
-    if (!ub->ub_open) {
-        return;
-    }
-    if (!ub->ub_txing) {
-        OS_ENTER_CRITICAL(sr);
-        uart_bitbang_tx_timer(ub);
-        OS_EXIT_CRITICAL(sr);
-    }
-}
-
-static void
-uart_bitbang_start_rx(struct uart_dev *dev)
-{
-    struct uart_bitbang *ub;
-    int sr;
-    int rc;
-
-    ub = (struct uart_bitbang *)dev->ud_priv;
-    if (ub->ub_rx_stall) {
-        rc = ub->ub_rx_func(ub->ub_func_arg, ub->ub_rx.byte);
-        if (rc == 0) {
-            OS_ENTER_CRITICAL(sr);
-            ub->ub_rx_stall = 0;
-            OS_EXIT_CRITICAL(sr);
-
-            /*
-             * Start looking for start bit again.
-             */
-            hal_gpio_irq_enable(ub->ub_rx.pin);
-        }
-    }
-}
-
-static int
-uart_bitbang_config(struct uart_bitbang *ub, int32_t baudrate, uint8_t databits,
-  uint8_t stopbits, enum hal_uart_parity parity,
-  enum hal_uart_flow_ctl flow_ctl)
-{
-    if (databits != 8 || parity != HAL_UART_PARITY_NONE ||
-      flow_ctl != HAL_UART_FLOW_CTL_NONE) {
-        return -1;
-    }
-
-    assert(ub->ub_rx.pin != ub->ub_tx.pin); /* make sure it's initialized */
-
-    if (baudrate > 19200) {
-        return -1;
-    }
-    ub->ub_bittime = ub->ub_cputimer_freq / baudrate;
-
-    cputime_timer_init(&ub->ub_rx.timer, uart_bitbang_rx_timer, ub);
-    cputime_timer_init(&ub->ub_tx.timer, uart_bitbang_tx_timer, ub);
-
-    if (hal_gpio_init_out(ub->ub_tx.pin, 1)) {
-        return -1;
-    }
-
-    if (hal_gpio_irq_init(ub->ub_rx.pin, uart_bitbang_isr, ub,
-        GPIO_TRIG_FALLING, GPIO_PULL_UP)) {
-        return -1;
-    }
-    hal_gpio_irq_enable(ub->ub_rx.pin);
-
-    ub->ub_open = 1;
-    return 0;
-}
-
-static int
-uart_bitbang_open(struct os_dev *odev, uint32_t wait, void *arg)
-{
-    struct uart_dev *dev = (struct uart_dev *)odev;
-    struct uart_bitbang *ub;
-    struct uart_conf *uc;
-
-    ub = (struct uart_bitbang *)dev->ud_priv;
-    uc = (struct uart_conf *)arg;
-
-    ub->ub_rx_func = uc->uc_rx_char;
-    ub->ub_tx_func = uc->uc_tx_char;
-    ub->ub_tx_done = uc->uc_tx_done;
-    ub->ub_func_arg = uc->uc_cb_arg;
-
-    if (uart_bitbang_config(ub, uc->uc_speed, uc->uc_databits,
-        uc->uc_stopbits, uc->uc_parity, uc->uc_flow_ctl)) {
-        return OS_EINVAL;
-    }
-    return OS_OK;
-}
-
-static int
-uart_bitbang_close(struct os_dev *odev)
-{
-    struct uart_dev *dev = (struct uart_dev *)odev;
-    struct uart_bitbang *ub;
-    int sr;
-
-    ub = (struct uart_bitbang *)dev->ud_priv;
-    OS_ENTER_CRITICAL(sr);
-    hal_gpio_irq_disable(ub->ub_rx.pin);
-    hal_gpio_irq_release(ub->ub_rx.pin);
-    ub->ub_open = 0;
-    ub->ub_txing = 0;
-    ub->ub_rx_stall = 0;
-    cputime_timer_stop(&ub->ub_tx.timer);
-    cputime_timer_stop(&ub->ub_rx.timer);
-    OS_EXIT_CRITICAL(sr);
-    return OS_OK;
-}
-
-int
-uart_bitbang_init(struct os_dev *odev, void *arg)
-{
-    struct uart_dev *dev = (struct uart_dev *)odev;
-    struct uart_bitbang *ub;
-    struct uart_bitbang_conf *ubc;
-
-    ub = (struct uart_bitbang *)os_malloc(sizeof(struct uart_bitbang));
-    if (!ub) {
-        return OS_ENOMEM;
-    }
-    memset(ub, 0, sizeof(*ub));
-
-    ubc = (struct uart_bitbang_conf *)arg;
-    ub->ub_rx.pin = ubc->ubc_rxpin;
-    ub->ub_tx.pin = ubc->ubc_txpin;
-    ub->ub_cputimer_freq = ubc->ubc_cputimer_freq;
-
-    OS_DEV_SETHANDLERS(odev, uart_bitbang_open, uart_bitbang_close);
-
-    dev->ud_funcs.uf_start_tx = uart_bitbang_start_tx;
-    dev->ud_funcs.uf_start_rx = uart_bitbang_start_rx;
-    dev->ud_funcs.uf_blocking_tx = uart_bitbang_blocking_tx;
-    dev->ud_priv = ub;
-
-    return OS_OK;
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/drivers/uart/uart_hal/include/uart_hal/uart_hal.h
----------------------------------------------------------------------
diff --git a/drivers/uart/uart_hal/include/uart_hal/uart_hal.h b/drivers/uart/uart_hal/include/uart_hal/uart_hal.h
deleted file mode 100644
index 702e91d..0000000
--- a/drivers/uart/uart_hal/include/uart_hal/uart_hal.h
+++ /dev/null
@@ -1,26 +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.
- */
-
-#ifndef __DRIVERS_UART_HAL_H_
-#define __DRIVERS_UART_HAL_H_
-
-struct os_dev;
-int uart_hal_init(struct os_dev *, void *);
-
-#endif /* __DRIVERS_UART_HAL_H_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/drivers/uart/uart_hal/pkg.yml
----------------------------------------------------------------------
diff --git a/drivers/uart/uart_hal/pkg.yml b/drivers/uart/uart_hal/pkg.yml
deleted file mode 100644
index f7f7b46..0000000
--- a/drivers/uart/uart_hal/pkg.yml
+++ /dev/null
@@ -1,29 +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.
-#
-
-pkg.name: drivers/uart/uart_hal
-pkg.description: UART driver using HAL
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-pkg.apis:
-    - UART_HW_IMPL
-pkg.deps:
-    - hw/hal
-    - drivers/uart

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/drivers/uart/uart_hal/src/uart_hal.c
----------------------------------------------------------------------
diff --git a/drivers/uart/uart_hal/src/uart_hal.c b/drivers/uart/uart_hal/src/uart_hal.c
deleted file mode 100644
index 5617f6b..0000000
--- a/drivers/uart/uart_hal/src/uart_hal.c
+++ /dev/null
@@ -1,143 +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 <ctype.h>
-#include <assert.h>
-#include <string.h>
-
-#include <os/os.h>
-#include <os/os_dev.h>
-#include <hal/hal_uart.h>
-
-#include <uart/uart.h>
-
-#include "uart_hal/uart_hal.h"
-
-struct uart_hal_priv {
-    int unit;
-};
-
-static void
-uart_hal_start_tx(struct uart_dev *dev)
-{
-    struct uart_hal_priv *priv;
-
-    priv = dev->ud_priv;
-    assert(priv);
-
-    hal_uart_start_tx(priv->unit);
-}
-
-static void
-uart_hal_start_rx(struct uart_dev *dev)
-{
-    struct uart_hal_priv *priv;
-
-    priv = dev->ud_priv;
-
-    hal_uart_start_rx(priv->unit);
-}
-
-static void
-uart_hal_blocking_tx(struct uart_dev *dev, uint8_t byte)
-{
-    struct uart_hal_priv *priv;
-
-    priv = dev->ud_priv;
-
-    hal_uart_blocking_tx(priv->unit, byte);
-}
-
-static int
-uart_hal_open(struct os_dev *odev, uint32_t wait, void *arg)
-{
-    struct uart_hal_priv *priv;
-    struct uart_conf *uc;
-    int rc;
-
-    priv = ((struct uart_dev *)odev)->ud_priv;
-
-    uc = (struct uart_conf *)arg;
-    if (!uc) {
-        return OS_EINVAL;
-    }
-    if (odev->od_flags & OS_DEV_F_STATUS_OPEN) {
-        return OS_EBUSY;
-    }
-    hal_uart_init_cbs(priv->unit, uc->uc_tx_char, uc->uc_tx_done,
-      uc->uc_rx_char, uc->uc_cb_arg);
-
-    rc = hal_uart_config(priv->unit, uc->uc_speed, uc->uc_databits,
-      uc->uc_stopbits, uc->uc_parity, uc->uc_flow_ctl);
-    if (rc) {
-        return OS_EINVAL;
-    }
-    return OS_OK;
-}
-
-static int
-uart_hal_close(struct os_dev *odev)
-{
-    struct uart_hal_priv *priv;
-    int rc;
-
-    priv = ((struct uart_dev *)odev)->ud_priv;
-
-    rc = hal_uart_close(priv->unit);
-    if (rc) {
-        return OS_EINVAL;
-    }
-    return OS_OK;
-}
-
-/*
- * Arg points to BSP specific UART configuration.
- */
-int
-uart_hal_init(struct os_dev *odev, void *arg)
-{
-    struct uart_dev *dev;
-    struct uart_hal_priv *priv;
-    char ch;
-
-    priv = os_malloc(sizeof(struct uart_hal_priv));
-    if (!priv) {
-        return OS_ENOMEM;
-    }
-    priv->unit = -1;
-
-    ch = odev->od_name[strlen(odev->od_name) - 1];
-    if (!isdigit(ch)) {
-        return OS_EINVAL;
-    }
-    priv->unit = ch - '0';
-
-    dev = (struct uart_dev *)odev;
-
-    OS_DEV_SETHANDLERS(odev, uart_hal_open, uart_hal_close);
-
-    dev->ud_funcs.uf_start_tx = uart_hal_start_tx;
-    dev->ud_funcs.uf_start_rx = uart_hal_start_rx;
-    dev->ud_funcs.uf_blocking_tx = uart_hal_blocking_tx;
-    dev->ud_priv = priv;
-
-    hal_uart_init(priv->unit, arg);
-
-    return OS_OK;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/hw/bsp/arduino_primo_nrf52/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/arduino_primo_nrf52/pkg.yml b/hw/bsp/arduino_primo_nrf52/pkg.yml
index 5e1a8d1..c000e94 100644
--- a/hw/bsp/arduino_primo_nrf52/pkg.yml
+++ b/hw/bsp/arduino_primo_nrf52/pkg.yml
@@ -44,16 +44,16 @@ pkg.deps:
     - libs/baselibc
 
 pkg.deps.BLE_DEVICE:
-    - drivers/nimble/nrf52
+    - hw/drivers/nimble/nrf52
 
 pkg.deps.ADC_0:
-    - drivers/adc/adc_nrf52
+    - hw/drivers/adc/adc_nrf52
 
 pkg.deps.UART_0:
-    - drivers/uart/uart_hal
+    - hw/drivers/uart/uart_hal
 
 pkg.deps.UART_1:
-    - drivers/uart/uart_bitbang
+    - hw/drivers/uart/uart_bitbang
 
 pkg.syscfg_defs:
     BSP_NRF52:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/hw/bsp/bmd300eval/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/pkg.yml b/hw/bsp/bmd300eval/pkg.yml
index ad64d3a..d58bd63 100644
--- a/hw/bsp/bmd300eval/pkg.yml
+++ b/hw/bsp/bmd300eval/pkg.yml
@@ -43,16 +43,16 @@ pkg.deps:
     - libs/baselibc
 
 pkg.deps.BLE_DEVICE:
-    - drivers/nimble/nrf52
+    - hw/drivers/nimble/nrf52
 
 pkg.deps.ADC_0:
-    - drivers/adc/adc_nrf52
+    - hw/drivers/adc/adc_nrf52
 
 pkg.deps.UART_0:
-    - drivers/uart/uart_hal
+    - hw/drivers/uart/uart_hal
 
 pkg.deps.UART_1:
-    - drivers/uart/uart_bitbang
+    - hw/drivers/uart/uart_bitbang
 
 pkg.syscfg_defs:
     BSP_NRF52:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/hw/bsp/native/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/native/pkg.yml b/hw/bsp/native/pkg.yml
index 9f919a7..fad2eea 100644
--- a/hw/bsp/native/pkg.yml
+++ b/hw/bsp/native/pkg.yml
@@ -31,7 +31,7 @@ pkg.arch: sim
 pkg.compiler: compiler/sim
 pkg.deps:
     - hw/mcu/native
-    - drivers/uart/uart_hal
+    - hw/drivers/uart/uart_hal
 
 pkg.deps.BLE_DEVICE:
-    - drivers/nimble/native
+    - hw/drivers/nimble/native

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/hw/bsp/nrf51-arduino_101/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-arduino_101/pkg.yml b/hw/bsp/nrf51-arduino_101/pkg.yml
index 584fe0c..cbe5db9 100644
--- a/hw/bsp/nrf51-arduino_101/pkg.yml
+++ b/hw/bsp/nrf51-arduino_101/pkg.yml
@@ -41,16 +41,16 @@ pkg.deps:
     - libs/baselibc
 
 pkg.deps.BLE_DEVICE:
-    - drivers/nimble/nrf51
+    - hw/drivers/nimble/nrf51
 
 pkg.deps.ADC_0:
-    - drivers/adc/adc_nrf51
+    - hw/drivers/adc/adc_nrf51
 
 pkg.deps.UART_0:
-    - drivers/uart/uart_hal
+    - hw/drivers/uart/uart_hal
 
 pkg.deps.UART_1:
-    - drivers/uart/uart_bitbang
+    - hw/drivers/uart/uart_bitbang
 
 pkg.syscfg_defs:
     BSP_NRF51:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/hw/bsp/nrf51-blenano/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-blenano/pkg.yml b/hw/bsp/nrf51-blenano/pkg.yml
index 55b0671..ac54b16 100644
--- a/hw/bsp/nrf51-blenano/pkg.yml
+++ b/hw/bsp/nrf51-blenano/pkg.yml
@@ -43,16 +43,16 @@ pkg.deps:
     - libs/baselibc
 
 pkg.deps.BLE_DEVICE:
-    - drivers/nimble/nrf51
+    - hw/drivers/nimble/nrf51
 
 pkg.deps.ADC_0:
-    - drivers/adc/adc_nrf51
+    - hw/drivers/adc/adc_nrf51
 
 pkg.deps.UART_0:
-    - drivers/uart/uart_hal
+    - hw/drivers/uart/uart_hal
 
 pkg.deps.UART_1:
-    - drivers/uart/uart_bitbang
+    - hw/drivers/uart/uart_bitbang
 
 pkg.syscfg_defs:
     BSP_NRF51:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/hw/bsp/nrf51dk-16kbram/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/pkg.yml b/hw/bsp/nrf51dk-16kbram/pkg.yml
index ee7ce75..164e710 100644
--- a/hw/bsp/nrf51dk-16kbram/pkg.yml
+++ b/hw/bsp/nrf51dk-16kbram/pkg.yml
@@ -42,16 +42,16 @@ pkg.deps:
     - libs/baselibc
 
 pkg.deps.BLE_DEVICE:
-    - drivers/nimble/nrf51
+    - hw/drivers/nimble/nrf51
 
 pkg.deps.ADC_0:
-    - drivers/adc/adc_nrf51
+    - hw/drivers/adc/adc_nrf51
 
 pkg.deps.UART_0:
-    - drivers/uart/uart_hal
+    - hw/drivers/uart/uart_hal
 
 pkg.deps.UART_1:
-    - drivers/uart/uart_bitbang
+    - hw/drivers/uart/uart_bitbang
 
 pkg.syscfg_defs:
     BSP_NRF51:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/hw/bsp/nrf51dk/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/pkg.yml b/hw/bsp/nrf51dk/pkg.yml
index dbb0f80..8df1bac 100644
--- a/hw/bsp/nrf51dk/pkg.yml
+++ b/hw/bsp/nrf51dk/pkg.yml
@@ -42,16 +42,16 @@ pkg.deps:
     - libs/baselibc
 
 pkg.deps.BLE_DEVICE:
-    - drivers/nimble/nrf51
+    - hw/drivers/nimble/nrf51
 
 pkg.deps.ADC_0:
-    - drivers/adc/adc_nrf51
+    - hw/drivers/adc/adc_nrf51
 
 pkg.deps.UART_0:
-    - drivers/uart/uart_hal
+    - hw/drivers/uart/uart_hal
 
 pkg.deps.UART_1:
-    - drivers/uart/uart_bitbang
+    - hw/drivers/uart/uart_bitbang
 
 pkg.syscfg_defs:
     BSP_NRF51:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/hw/bsp/nrf52dk/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/pkg.yml b/hw/bsp/nrf52dk/pkg.yml
index f6ac2dd..69e520a 100644
--- a/hw/bsp/nrf52dk/pkg.yml
+++ b/hw/bsp/nrf52dk/pkg.yml
@@ -43,16 +43,16 @@ pkg.deps:
     - libs/baselibc
 
 pkg.deps.BLE_DEVICE:
-    - drivers/nimble/nrf52
+    - hw/drivers/nimble/nrf52
 
 pkg.deps.ADC_0:
-    - drivers/adc/adc_nrf52
+    - hw/drivers/adc/adc_nrf52
 
 pkg.deps.UART_0:
-    - drivers/uart/uart_hal
+    - hw/drivers/uart/uart_hal
 
 pkg.deps.UART_1:
-    - drivers/uart/uart_bitbang
+    - hw/drivers/uart/uart_bitbang
 
 pkg.syscfg_defs:
     BSP_NRF52:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/hw/bsp/nrf52pdk/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52pdk/pkg.yml b/hw/bsp/nrf52pdk/pkg.yml
index 9dfa6e6..c9c55f5 100644
--- a/hw/bsp/nrf52pdk/pkg.yml
+++ b/hw/bsp/nrf52pdk/pkg.yml
@@ -42,16 +42,16 @@ pkg.deps:
     - libs/baselibc
 
 pkg.deps.BLE_DEVICE:
-    - drivers/nimble/nrf52
+    - hw/drivers/nimble/nrf52
 
 pkg.deps.ADC_0:
-    - drivers/adc/adc_nrf52
+    - hw/drivers/adc/adc_nrf52
 
 pkg.deps.UART_0:
-    - drivers/uart/uart_hal
+    - hw/drivers/uart/uart_hal
 
 pkg.deps.UART_1:
-    - drivers/uart/uart_bitbang
+    - hw/drivers/uart/uart_bitbang
 
 pkg.syscfg_defs:
     BSP_NRF52:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/hw/bsp/olimex_stm32-e407_devboard/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/pkg.yml b/hw/bsp/olimex_stm32-e407_devboard/pkg.yml
index 3cd2cc0..a8c5b6e 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/pkg.yml
+++ b/hw/bsp/olimex_stm32-e407_devboard/pkg.yml
@@ -43,17 +43,17 @@ pkg.deps:
     - libs/baselibc
 
 pkg.deps.ADC_1:
-    - drivers/adc/adc_stm32f4
+    - hw/drivers/adc/adc_stm32f4
 pkg.deps.ADC_2:
-    - drivers/adc/adc_stm32f4
+    - hw/drivers/adc/adc_stm32f4
 pkg.deps.ADC_3:
-    - drivers/adc/adc_stm32f4
+    - hw/drivers/adc/adc_stm32f4
 
 pkg.deps.UART_0:
-    - drivers/uart/uart_hal
+    - hw/drivers/uart/uart_hal
 
 pkg.deps.UART_1:
-    - drivers/uart/uart_bitbang
+    - hw/drivers/uart/uart_bitbang
 
 pkg.syscfg_defs:
     CLOCK_FREQ:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/hw/drivers/adc/adc_nrf51/include/adc_nrf51/adc_nrf51.h
----------------------------------------------------------------------
diff --git a/hw/drivers/adc/adc_nrf51/include/adc_nrf51/adc_nrf51.h b/hw/drivers/adc/adc_nrf51/include/adc_nrf51/adc_nrf51.h
new file mode 100644
index 0000000..0006b89
--- /dev/null
+++ b/hw/drivers/adc/adc_nrf51/include/adc_nrf51/adc_nrf51.h
@@ -0,0 +1,30 @@
+/*
+ * 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 __ADC_NRF51_H__
+#define __ADC_NRF51_H__
+
+#include <adc/adc.h>
+
+#include <nrf.h>
+#include <nrf_adc.h>
+
+int nrf51_adc_dev_init(struct os_dev *, void *);
+
+#endif /* __ADC_NRF51_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0216c73e/hw/drivers/adc/adc_nrf51/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/drivers/adc/adc_nrf51/pkg.yml b/hw/drivers/adc/adc_nrf51/pkg.yml
new file mode 100644
index 0000000..03e4120
--- /dev/null
+++ b/hw/drivers/adc/adc_nrf51/pkg.yml
@@ -0,0 +1,28 @@
+#
+# 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/adc/adc_nrf51
+pkg.description: ADC driver for the NRF51
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+pkg.apis:
+    - ADC_HW_IMPL
+pkg.deps:
+   - hw/drivers/adc