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/07/27 23:13:43 UTC

[14/51] [partial] incubator-mynewt-core git commit: add stm32 and nordic sdks based on new structure

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f06c2d2b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/uart/app_uart.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/uart/app_uart.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/uart/app_uart.h
new file mode 100644
index 0000000..8988cc8
--- /dev/null
+++ b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/uart/app_uart.h
@@ -0,0 +1,227 @@
+/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+/**@file
+ *
+ * @defgroup app_uart UART module
+ * @{
+ * @ingroup app_common
+ *
+ * @brief UART module interface.
+ */
+
+#ifndef APP_UART_H__
+#define APP_UART_H__
+
+#include <stdint.h>
+#include <stdbool.h>
+#include "app_util_platform.h"
+
+#define  UART_PIN_DISCONNECTED 0xFFFFFFFF /**< Value indicating that no pin is connected to this UART register. */
+
+/**@brief UART Flow Control modes for the peripheral.
+ */
+typedef enum
+{
+    APP_UART_FLOW_CONTROL_DISABLED, /**< UART Hw Flow Control is disabled. */
+    APP_UART_FLOW_CONTROL_ENABLED,  /**< Standard UART Hw Flow Control is enabled. */
+    APP_UART_FLOW_CONTROL_LOW_POWER /**< Specialized UART Hw Flow Control is used. The Low Power setting allows the \nRFXX to Power Off the UART module when CTS is in-active, and re-enabling the UART when the CTS signal becomes active. This allows the \nRFXX to safe power by only using the UART module when it is needed by the remote site. */
+} app_uart_flow_control_t;
+
+/**@brief UART communication structure holding configuration settings for the peripheral.
+ */
+typedef struct
+{
+    uint8_t                 rx_pin_no;    /**< RX pin number. */
+    uint8_t                 tx_pin_no;    /**< TX pin number. */
+    uint8_t                 rts_pin_no;   /**< RTS pin number, only used if flow control is enabled. */
+    uint8_t                 cts_pin_no;   /**< CTS pin number, only used if flow control is enabled. */
+    app_uart_flow_control_t flow_control; /**< Flow control setting, if flow control is used, the system will use low power UART mode, based on CTS signal. */
+    bool                    use_parity;   /**< Even parity if TRUE, no parity if FALSE. */
+    uint32_t                baud_rate;    /**< Baud rate configuration. */
+} app_uart_comm_params_t;
+
+/**@brief UART buffer for transmitting/receiving data.
+ */
+typedef struct
+{
+    uint8_t * rx_buf;      /**< Pointer to the RX buffer. */
+    uint32_t  rx_buf_size; /**< Size of the RX buffer. */
+    uint8_t * tx_buf;      /**< Pointer to the TX buffer. */
+    uint32_t  tx_buf_size; /**< Size of the TX buffer. */
+} app_uart_buffers_t;
+
+/**@brief Enumeration which defines events used by the UART module upon data reception or error.
+ *
+ * @details The event type is used to indicate the type of additional information in the event
+ * @ref app_uart_evt_t.
+ */
+typedef enum
+{
+    APP_UART_DATA_READY,          /**< An event indicating that UART data has been received. The data is available in the FIFO and can be fetched using @ref app_uart_get. */
+    APP_UART_FIFO_ERROR,          /**< An error in the FIFO module used by the app_uart module has occured. The FIFO error code is stored in app_uart_evt_t.data.error_code field. */
+    APP_UART_COMMUNICATION_ERROR, /**< An communication error has occured during reception. The error is stored in app_uart_evt_t.data.error_communication field. */
+    APP_UART_TX_EMPTY,            /**< An event indicating that UART has completed transmission of all available data in the TX FIFO. */
+    APP_UART_DATA,                /**< An event indicating that UART data has been received, and data is present in data field. This event is only used when no FIFO is configured. */
+} app_uart_evt_type_t;
+
+/**@brief Struct containing events from the UART module.
+ *
+ * @details The app_uart_evt_t is used to notify the application of asynchronous events when data
+ * are received on the UART peripheral or in case an error occured during data reception.
+ */
+typedef struct
+{
+    app_uart_evt_type_t evt_type; /**< Type of event. */
+    union
+    {
+        uint32_t error_communication; /**< Field used if evt_type is: APP_UART_COMMUNICATION_ERROR. This field contains the value in the ERRORSRC register for the UART peripheral. The UART_ERRORSRC_x defines from nrf5x_bitfields.h can be used to parse the error code. See also the \nRFXX Series Reference Manual for specification. */
+        uint32_t error_code;          /**< Field used if evt_type is: NRF_ERROR_x. Additional status/error code if the error event type is APP_UART_FIFO_ERROR. This error code refer to errors defined in nrf_error.h. */
+        uint8_t  value;               /**< Field used if evt_type is: NRF_ERROR_x. Additional status/error code if the error event type is APP_UART_FIFO_ERROR. This error code refer to errors defined in nrf_error.h. */
+    } data;
+} app_uart_evt_t;
+
+/**@brief Function for handling app_uart event callback.
+ *
+ * @details Upon an event in the app_uart module this callback function will be called to notify
+ *          the application about the event.
+ *
+ * @param[in]   p_app_uart_event Pointer to UART event.
+ */
+typedef void (* app_uart_event_handler_t) (app_uart_evt_t * p_app_uart_event);
+
+/**@brief Macro for safe initialization of the UART module in a single user instance when using
+ *        a FIFO together with UART.
+ *
+ * @param[in]   P_COMM_PARAMS   Pointer to a UART communication structure: app_uart_comm_params_t
+ * @param[in]   RX_BUF_SIZE     Size of desired RX buffer, must be a power of 2 or ZERO (No FIFO).
+ * @param[in]   TX_BUF_SIZE     Size of desired TX buffer, must be a power of 2 or ZERO (No FIFO).
+ * @param[in]   EVT_HANDLER   Event handler function to be called when an event occurs in the
+ *                              UART module.
+ * @param[in]   IRQ_PRIO        IRQ priority, app_irq_priority_t, for the UART module irq handler.
+ * @param[out]  ERR_CODE        The return value of the UART initialization function will be
+ *                              written to this parameter.
+ *
+ * @note Since this macro allocates a buffer and registers the module as a GPIOTE user when flow
+ *       control is enabled, it must only be called once.
+ */
+#define APP_UART_FIFO_INIT(P_COMM_PARAMS, RX_BUF_SIZE, TX_BUF_SIZE, EVT_HANDLER, IRQ_PRIO, ERR_CODE) \
+    do                                                                                             \
+    {                                                                                              \
+        app_uart_buffers_t buffers;                                                                \
+        static uint8_t     rx_buf[RX_BUF_SIZE];                                                    \
+        static uint8_t     tx_buf[TX_BUF_SIZE];                                                    \
+                                                                                                   \
+        buffers.rx_buf      = rx_buf;                                                              \
+        buffers.rx_buf_size = sizeof (rx_buf);                                                     \
+        buffers.tx_buf      = tx_buf;                                                              \
+        buffers.tx_buf_size = sizeof (tx_buf);                                                     \
+        ERR_CODE = app_uart_init(P_COMM_PARAMS, &buffers, EVT_HANDLER, IRQ_PRIO);                  \
+    } while (0)
+
+/**@brief Macro for safe initialization of the UART module in a single user instance.
+ *
+ * @param[in]   P_COMM_PARAMS   Pointer to a UART communication structure: app_uart_comm_params_t
+ * @param[in]   EVT_HANDLER   Event handler function to be called when an event occurs in the
+ *                              UART module.
+ * @param[in]   IRQ_PRIO        IRQ priority, app_irq_priority_t, for the UART module irq handler.
+ * @param[out]  ERR_CODE        The return value of the UART initialization function will be
+ *                              written to this parameter.
+ *
+ * @note Since this macro allocates registers the module as a GPIOTE user when flow control is
+ *       enabled, it must only be called once.
+ */
+#define APP_UART_INIT(P_COMM_PARAMS, EVT_HANDLER, IRQ_PRIO, ERR_CODE)                              \
+    do                                                                                             \
+    {                                                                                              \
+        ERR_CODE = app_uart_init(P_COMM_PARAMS, NULL, EVT_HANDLER, IRQ_PRIO);                      \
+    } while (0)
+
+/**@brief Function for initializing the UART module. Use this initialization when several instances of the UART
+ *        module are needed.
+ *
+ *
+ * @note Normally single initialization should be done using the APP_UART_INIT() or
+ *       APP_UART_INIT_FIFO() macro depending on whether the FIFO should be used by the UART, as
+ *       that will allocate the buffers needed by the UART module (including aligning the buffer
+ *       correctly).
+
+ * @param[in]     p_comm_params     Pin and communication parameters.
+ * @param[in]     p_buffers         RX and TX buffers, NULL is FIFO is not used.
+ * @param[in]     error_handler     Function to be called in case of an error.
+ * @param[in]     irq_priority      Interrupt priority level.
+ *
+ * @retval      NRF_SUCCESS               If successful initialization.
+ * @retval      NRF_ERROR_INVALID_LENGTH  If a provided buffer is not a power of two.
+ * @retval      NRF_ERROR_NULL            If one of the provided buffers is a NULL pointer.
+ *
+ * The below errors are propagated by the UART module to the caller upon registration when Hardware
+ * Flow Control is enabled. When Hardware Flow Control is not used, these errors cannot occur.
+ * @retval      NRF_ERROR_INVALID_STATE   The GPIOTE module is not in a valid state when registering
+ *                                        the UART module as a user.
+ * @retval      NRF_ERROR_INVALID_PARAM   The UART module provides an invalid callback function when
+ *                                        registering the UART module as a user.
+ *                                        Or the value pointed to by *p_uart_uid is not a valid
+ *                                        GPIOTE number.
+ * @retval      NRF_ERROR_NO_MEM          GPIOTE module has reached the maximum number of users.
+ */
+uint32_t app_uart_init(const app_uart_comm_params_t * p_comm_params,
+                       app_uart_buffers_t *           p_buffers,
+                       app_uart_event_handler_t       error_handler,
+                       app_irq_priority_t             irq_priority);
+
+/**@brief Function for getting a byte from the UART.
+ *
+ * @details This function will get the next byte from the RX buffer. If the RX buffer is empty
+ *          an error code will be returned and the app_uart module will generate an event upon
+ *          reception of the first byte which is added to the RX buffer.
+ *
+ * @param[out] p_byte    Pointer to an address where next byte received on the UART will be copied.
+ *
+ * @retval NRF_SUCCESS          If a byte has been received and pushed to the pointer provided.
+ * @retval NRF_ERROR_NOT_FOUND  If no byte is available in the RX buffer of the app_uart module.
+ */
+uint32_t app_uart_get(uint8_t * p_byte);
+
+/**@brief Function for putting a byte on the UART.
+ *
+ * @details This call is non-blocking.
+ *
+ * @param[in] byte   Byte to be transmitted on the UART.
+ *
+ * @retval NRF_SUCCESS        If the byte was successfully put on the TX buffer for transmission.
+ * @retval NRF_ERROR_NO_MEM   If no more space is available in the TX buffer.
+ *                            NRF_ERROR_NO_MEM may occur if flow control is enabled and CTS signal
+ *                            is high for a long period and the buffer fills up.
+ * @retval NRF_ERROR_INTERNAL If UART driver reported error.
+ */
+uint32_t app_uart_put(uint8_t byte);
+
+/**@brief Function for flushing the RX and TX buffers (Only valid if FIFO is used).
+ *        This function does nothing if FIFO is not used.
+ *
+ * @retval  NRF_SUCCESS  Flushing completed (Current implementation will always succeed).
+ */
+uint32_t app_uart_flush(void);
+
+/**@brief Function for closing the UART module.
+ *
+ * @retval  NRF_SUCCESS             If successfully closed.
+ * @retval  NRF_ERROR_INVALID_PARAM If an invalid user id is provided or the user id differs from
+ *                                  the current active user.
+ */
+uint32_t app_uart_close(void);
+
+
+#endif //APP_UART_H__
+
+/** @} */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f06c2d2b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/uart/app_uart_fifo.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/uart/app_uart_fifo.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/uart/app_uart_fifo.c
new file mode 100644
index 0000000..d4c1562
--- /dev/null
+++ b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/uart/app_uart_fifo.c
@@ -0,0 +1,191 @@
+/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+#include "app_uart.h"
+#include "app_fifo.h"
+#include "nrf_drv_uart.h"
+#include "nrf_assert.h"
+#include "sdk_common.h"
+
+static __INLINE uint32_t fifo_length(app_fifo_t * const fifo)
+{
+  uint32_t tmp = fifo->read_pos;
+  return fifo->write_pos - tmp;
+}
+
+#define FIFO_LENGTH(F) fifo_length(&F)              /**< Macro to calculate length of a FIFO. */
+
+
+static app_uart_event_handler_t   m_event_handler;            /**< Event handler function. */
+static uint8_t tx_buffer[1];
+static uint8_t rx_buffer[1];
+
+static app_fifo_t                  m_rx_fifo;                               /**< RX FIFO buffer for storing data received on the UART until the application fetches them using app_uart_get(). */
+static app_fifo_t                  m_tx_fifo;                               /**< TX FIFO buffer for storing data to be transmitted on the UART when TXD is ready. Data is put to the buffer on using app_uart_put(). */
+
+static void uart_event_handler(nrf_drv_uart_event_t * p_event, void* p_context)
+{
+    app_uart_evt_t app_uart_event;
+
+    if (p_event->type == NRF_DRV_UART_EVT_RX_DONE)
+    {
+        // Write received byte to FIFO
+        uint32_t err_code = app_fifo_put(&m_rx_fifo, p_event->data.rxtx.p_data[0]);
+        if (err_code != NRF_SUCCESS)
+        {
+            app_uart_event.evt_type          = APP_UART_FIFO_ERROR;
+            app_uart_event.data.error_code   = err_code;
+            m_event_handler(&app_uart_event);
+        }
+        // Notify that new data is available if this was first byte put in the buffer.
+        else if (FIFO_LENGTH(m_rx_fifo) == 1)
+        {
+            app_uart_event.evt_type = APP_UART_DATA_READY;
+            m_event_handler(&app_uart_event);
+        }
+        else
+        {
+            // Do nothing, only send event if first byte was added or overflow in FIFO occurred.
+        }
+        if (FIFO_LENGTH(m_rx_fifo) <= m_rx_fifo.buf_size_mask)
+        {
+            (void)nrf_drv_uart_rx(rx_buffer, 1);
+        }
+    }
+    else if (p_event->type == NRF_DRV_UART_EVT_ERROR)
+    {
+        app_uart_event.evt_type                 = APP_UART_COMMUNICATION_ERROR;
+        app_uart_event.data.error_communication = p_event->data.error.error_mask;
+        (void)nrf_drv_uart_rx(rx_buffer, 1);
+        m_event_handler(&app_uart_event);
+    }
+    else if (p_event->type == NRF_DRV_UART_EVT_TX_DONE)
+    {
+        // Get next byte from FIFO.
+        if (app_fifo_get(&m_tx_fifo, tx_buffer) == NRF_SUCCESS)
+        {
+            (void)nrf_drv_uart_tx(tx_buffer, 1);
+        }
+        if (FIFO_LENGTH(m_tx_fifo) == 0)
+        {
+            // Last byte from FIFO transmitted, notify the application.
+            app_uart_event.evt_type = APP_UART_TX_EMPTY;
+            m_event_handler(&app_uart_event);
+        }
+    }
+}
+
+uint32_t app_uart_init(const app_uart_comm_params_t * p_comm_params,
+                             app_uart_buffers_t *     p_buffers,
+                             app_uart_event_handler_t event_handler,
+                             app_irq_priority_t       irq_priority)
+{
+    uint32_t err_code;
+
+    m_event_handler = event_handler;
+
+    if (p_buffers == NULL)
+    {
+        return NRF_ERROR_INVALID_PARAM;
+    }
+
+    // Configure buffer RX buffer.
+    err_code = app_fifo_init(&m_rx_fifo, p_buffers->rx_buf, p_buffers->rx_buf_size);
+    VERIFY_SUCCESS(err_code);
+
+    // Configure buffer TX buffer.
+    err_code = app_fifo_init(&m_tx_fifo, p_buffers->tx_buf, p_buffers->tx_buf_size);
+    VERIFY_SUCCESS(err_code);
+
+    nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG;
+    config.baudrate = (nrf_uart_baudrate_t)p_comm_params->baud_rate;
+    config.hwfc = (p_comm_params->flow_control == APP_UART_FLOW_CONTROL_DISABLED) ?
+            NRF_UART_HWFC_DISABLED : NRF_UART_HWFC_ENABLED;
+    config.interrupt_priority = irq_priority;
+    config.parity = p_comm_params->use_parity ? NRF_UART_PARITY_INCLUDED : NRF_UART_PARITY_EXCLUDED;
+    config.pselcts = p_comm_params->cts_pin_no;
+    config.pselrts = p_comm_params->rts_pin_no;
+    config.pselrxd = p_comm_params->rx_pin_no;
+    config.pseltxd = p_comm_params->tx_pin_no;
+
+    err_code = nrf_drv_uart_init(&config, uart_event_handler);
+    VERIFY_SUCCESS(err_code);
+
+#ifdef NRF52
+    if (!config.use_easy_dma)
+#endif
+    {
+        nrf_drv_uart_rx_enable();
+    }
+    return nrf_drv_uart_rx(rx_buffer,1);
+}
+
+uint32_t app_uart_flush(void)
+{
+    uint32_t err_code;
+
+    err_code = app_fifo_flush(&m_rx_fifo);
+    VERIFY_SUCCESS(err_code);
+
+    err_code = app_fifo_flush(&m_tx_fifo);
+    VERIFY_SUCCESS(err_code);
+
+    return NRF_SUCCESS;
+}
+
+uint32_t app_uart_get(uint8_t * p_byte)
+{
+    ASSERT(p_byte);
+    // If FIFO was full new request to receive one byte was not scheduled. Must be done here.
+    if (FIFO_LENGTH(m_rx_fifo) == m_rx_fifo.buf_size_mask)
+    {
+        uint32_t err_code = nrf_drv_uart_rx(rx_buffer,1);
+        if (err_code != NRF_SUCCESS)
+        {
+            return NRF_ERROR_NOT_FOUND;
+        }
+    }
+    return app_fifo_get(&m_rx_fifo, p_byte);
+}
+
+uint32_t app_uart_put(uint8_t byte)
+{
+    uint32_t err_code;
+
+    err_code = app_fifo_put(&m_tx_fifo, byte);
+    if (err_code == NRF_SUCCESS)
+    {
+        // The new byte has been added to FIFO. It will be picked up from there
+        // (in 'uart_event_handler') when all preceding bytes are transmitted.
+        // But if UART is not transmitting anything at the moment, we must start
+        // a new transmission here.
+        if (!nrf_drv_uart_tx_in_progress())
+        {
+            // This operation should be almost always successful, since we've
+            // just added a byte to FIFO, but if some bigger delay occurred
+            // (some heavy interrupt handler routine has been executed) since
+            // that time, FIFO might be empty already.
+            if (app_fifo_get(&m_tx_fifo, tx_buffer) == NRF_SUCCESS)
+            {
+                err_code = nrf_drv_uart_tx(tx_buffer, 1);
+            }
+        }
+    }
+
+    return err_code;
+}
+
+uint32_t app_uart_close(void)
+{
+    nrf_drv_uart_uninit();
+    return NRF_SUCCESS;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f06c2d2b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/uart/retarget.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/uart/retarget.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/uart/retarget.c
new file mode 100644
index 0000000..a34fa1c
--- /dev/null
+++ b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/uart/retarget.c
@@ -0,0 +1,101 @@
+/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+#if !defined(NRF_LOG_USES_RTT) || NRF_LOG_USES_RTT != 1
+#if !defined(HAS_SIMPLE_UART_RETARGET)
+
+#include <stdio.h>
+#include <stdint.h>
+#include "app_uart.h"
+#include "nordic_common.h"
+#include "nrf_error.h"
+
+#if !defined(__ICCARM__)
+struct __FILE 
+{
+    int handle;
+};
+#endif
+
+FILE __stdout;
+FILE __stdin;
+
+
+#if defined(__CC_ARM) ||  defined(__ICCARM__)
+int fgetc(FILE * p_file)
+{
+    uint8_t input;
+    while (app_uart_get(&input) == NRF_ERROR_NOT_FOUND)
+    {
+        // No implementation needed.
+    }
+    return input;
+}
+
+
+int fputc(int ch, FILE * p_file)
+{
+    UNUSED_PARAMETER(p_file);
+
+    UNUSED_VARIABLE(app_uart_put((uint8_t)ch));
+    return ch;
+}
+
+#elif defined(__GNUC__)
+
+
+int _write(int file, const char * p_char, int len)
+{
+    int i;
+
+    UNUSED_PARAMETER(file);
+
+    for (i = 0; i < len; i++)
+    {
+        UNUSED_VARIABLE(app_uart_put(*p_char++));
+    }
+
+    return len;
+}
+
+
+int _read(int file, char * p_char, int len)
+{
+    UNUSED_PARAMETER(file);
+    while (app_uart_get((uint8_t *)p_char) == NRF_ERROR_NOT_FOUND)
+    {
+        // No implementation needed.
+    }
+
+    return 1;
+}
+#endif
+
+#if defined(__ICCARM__)
+
+__ATTRIBUTES size_t __write(int file, const unsigned char * p_char, size_t len)
+{
+    int i;
+
+    UNUSED_PARAMETER(file);
+
+    for (i = 0; i < len; i++)
+    {
+        UNUSED_VARIABLE(app_uart_put(*p_char++));
+    }
+
+    return len;
+}
+
+#endif
+#endif // !defined(HAS_SIMPLE_UART_RETARGET)
+#endif // NRF_LOG_USES_RTT != 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f06c2d2b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error.c
new file mode 100644
index 0000000..8d9aaa9
--- /dev/null
+++ b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error.c
@@ -0,0 +1,124 @@
+/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+/** @file
+ *
+ * @defgroup app_error Common application error handler
+ * @{
+ * @ingroup app_common
+ *
+ * @brief Common application error handler.
+ */
+
+#include "nrf.h"
+#include <stdio.h>
+#include "app_error.h"
+#include "nordic_common.h"
+#include "sdk_errors.h"
+#include "nrf_log.h"
+
+#ifdef DEBUG
+#include "bsp.h"
+#endif
+
+
+
+/**@brief Function for error handling, which is called when an error has occurred.
+ *
+ * @warning This handler is an example only and does not fit a final product. You need to analyze
+ *          how your product is supposed to react in case of error.
+ *
+ * @param[in] error_code  Error code supplied to the handler.
+ * @param[in] line_num    Line number where the handler is called.
+ * @param[in] p_file_name Pointer to the file name.
+ */
+
+/*lint -save -e14 */
+void app_error_handler(ret_code_t error_code, uint32_t line_num, const uint8_t * p_file_name)
+{
+    error_info_t error_info =
+    {
+        .line_num    = line_num,
+        .p_file_name = p_file_name,
+        .err_code    = error_code,
+    };
+    app_error_fault_handler(NRF_FAULT_ID_SDK_ERROR, 0, (uint32_t)(&error_info));
+
+    UNUSED_VARIABLE(error_info);
+}
+
+/*lint -save -e14 */
+void app_error_handler_bare(ret_code_t error_code)
+{
+    error_info_t error_info =
+    {
+        .line_num    = 0,
+        .p_file_name = NULL,
+        .err_code    = error_code,
+    };
+    app_error_fault_handler(NRF_FAULT_ID_SDK_ERROR, 0, (uint32_t)(&error_info));
+
+    UNUSED_VARIABLE(error_info);
+}
+
+
+void app_error_save_and_stop(uint32_t id, uint32_t pc, uint32_t info)
+{
+    /* static error variables - in order to prevent removal by optimizers */
+    static volatile struct
+    {
+        uint32_t        fault_id;
+        uint32_t        pc;
+        uint32_t        error_info;
+        assert_info_t * p_assert_info;
+        error_info_t  * p_error_info;
+        ret_code_t      err_code;
+        uint32_t        line_num;
+        const uint8_t * p_file_name;
+    } m_error_data = {0};
+
+    // The following variable helps Keil keep the call stack visible, in addition, it can be set to
+    // 0 in the debugger to continue executing code after the error check.
+    volatile bool loop = true;
+    UNUSED_VARIABLE(loop);
+
+    m_error_data.fault_id   = id;
+    m_error_data.pc         = pc;
+    m_error_data.error_info = info;
+
+    switch (id)
+    {
+        case NRF_FAULT_ID_SDK_ASSERT:
+            m_error_data.p_assert_info = (assert_info_t *)info;
+            m_error_data.line_num      = m_error_data.p_assert_info->line_num;
+            m_error_data.p_file_name   = m_error_data.p_assert_info->p_file_name;
+            break;
+
+        case NRF_FAULT_ID_SDK_ERROR:
+            m_error_data.p_error_info = (error_info_t *)info;
+            m_error_data.err_code     = m_error_data.p_error_info->err_code;
+            m_error_data.line_num     = m_error_data.p_error_info->line_num;
+            m_error_data.p_file_name  = m_error_data.p_error_info->p_file_name;
+            break;
+    }
+
+    UNUSED_VARIABLE(m_error_data);
+
+    // If printing is disrupted, remove the irq calls, or set the loop variable to 0 in the debugger.
+    __disable_irq();
+
+    while(loop);
+
+    __enable_irq();
+}
+
+/*lint -restore */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f06c2d2b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error.h
new file mode 100644
index 0000000..c87a6df
--- /dev/null
+++ b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error.h
@@ -0,0 +1,201 @@
+/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+/** @file
+ *
+ * @defgroup app_error Common application error handler
+ * @{
+ * @ingroup app_common
+ *
+ * @brief Common application error handler and macros for utilizing a common error handler.
+ */
+
+#ifndef APP_ERROR_H__
+#define APP_ERROR_H__
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include "nrf.h"
+#include "sdk_errors.h"
+#include "nordic_common.h"
+#include "nrf_log.h"
+#include "app_error_weak.h"
+
+#define NRF_FAULT_ID_SDK_RANGE_START 0x00004000 /**< The start of the range of error IDs defined in the SDK. */
+
+/**@defgroup APP_ERROR_FAULT_IDS Fault ID types
+ * @{ */
+#define NRF_FAULT_ID_SDK_ERROR       NRF_FAULT_ID_SDK_RANGE_START + 1 /**< An error stemming from a call to @ref APP_ERROR_CHECK or @ref APP_ERROR_CHECK_BOOL. The info parameter is a pointer to an @ref error_info_t variable. */
+#define NRF_FAULT_ID_SDK_ASSERT      NRF_FAULT_ID_SDK_RANGE_START + 2 /**< An error stemming from a call to ASSERT (nrf_assert.h). The info parameter is a pointer to an @ref assert_info_t variable. */
+/**@} */
+
+/**@brief Structure containing info about an error of the type @ref NRF_FAULT_ID_SDK_ERROR.
+ */
+typedef struct
+{
+    uint16_t        line_num;    /**< The line number where the error occurred. */
+    uint8_t const * p_file_name; /**< The file in which the error occurred. */
+    uint32_t        err_code;    /**< The error code representing the error that occurred. */
+} error_info_t;
+
+/**@brief Structure containing info about an error of the type @ref NRF_FAULT_ID_SDK_ASSERT.
+ */
+typedef struct
+{
+    uint16_t        line_num;    /**< The line number where the error occurred. */
+    uint8_t const * p_file_name; /**< The file in which the error occurred. */
+} assert_info_t;
+
+/**@brief Function for error handling, which is called when an error has occurred.
+ *
+ * @param[in] error_code  Error code supplied to the handler.
+ * @param[in] line_num    Line number where the handler is called.
+ * @param[in] p_file_name Pointer to the file name.
+ */
+void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name);
+
+/**@brief Function for error handling, which is called when an error has occurred.
+ *
+ * @param[in] error_code  Error code supplied to the handler.
+ */
+void app_error_handler_bare(ret_code_t error_code);
+
+/**@brief       Function for saving the parameters and entering an eternal loop, for debug purposes.
+ *
+ * @param[in] id    Fault identifier. See @ref NRF_FAULT_IDS.
+ * @param[in] pc    The program counter of the instruction that triggered the fault, or 0 if
+ *                  unavailable.
+ * @param[in] info  Optional additional information regarding the fault. Refer to each fault
+ *                  identifier for details.
+ */
+void app_error_save_and_stop(uint32_t id, uint32_t pc, uint32_t info);
+
+/**@brief       Function for printing all error info (using nrf_log).
+ *
+ * @details     Nrf_log library must be initialized using NRF_LOG_INIT macro before calling
+ *              this function.
+ *
+ * @param[in] id    Fault identifier. See @ref NRF_FAULT_IDS.
+ * @param[in] pc    The program counter of the instruction that triggered the fault, or 0 if
+ *                  unavailable.
+ * @param[in] info  Optional additional information regarding the fault. Refer to each fault
+ *                  identifier for details.
+ */
+static __INLINE void app_error_log(uint32_t id, uint32_t pc, uint32_t info)
+{
+    switch (id)
+    {
+        case NRF_FAULT_ID_SDK_ASSERT:
+            NRF_LOG(NRF_LOG_COLOR_RED "\n*** ASSERTION FAILED ***\n");
+            if (((assert_info_t *)(info))->p_file_name)
+            {
+                NRF_LOG_PRINTF(NRF_LOG_COLOR_WHITE "Line Number: %u\n", (unsigned int) ((assert_info_t *)(info))->line_num);
+                NRF_LOG_PRINTF("File Name:   %s\n", ((assert_info_t *)(info))->p_file_name);
+            }
+            NRF_LOG_PRINTF(NRF_LOG_COLOR_DEFAULT "\n");
+            break;
+
+        case NRF_FAULT_ID_SDK_ERROR:
+            NRF_LOG(NRF_LOG_COLOR_RED "\n*** APPLICATION ERROR *** \n" NRF_LOG_COLOR_WHITE);
+            if (((error_info_t *)(info))->p_file_name)
+            {
+                NRF_LOG_PRINTF("Line Number: %u\n", (unsigned int) ((error_info_t *)(info))->line_num);
+                NRF_LOG_PRINTF("File Name:   %s\n", ((error_info_t *)(info))->p_file_name);
+            }
+            NRF_LOG_PRINTF("Error Code:  0x%X\n" NRF_LOG_COLOR_DEFAULT "\n", (unsigned int) ((error_info_t *)(info))->err_code);
+            break;
+    }
+}
+
+/**@brief       Function for printing all error info (using printf).
+ *
+ * @param[in] id    Fault identifier. See @ref NRF_FAULT_IDS.
+ * @param[in] pc    The program counter of the instruction that triggered the fault, or 0 if
+ *                  unavailable.
+ * @param[in] info  Optional additional information regarding the fault. Refer to each fault
+ *                  identifier for details.
+ */
+//lint -save -e438
+static __INLINE void app_error_print(uint32_t id, uint32_t pc, uint32_t info)
+{
+    unsigned int tmp = id;
+    printf("app_error_print():\r\n");
+    printf("Fault identifier:  0x%X\r\n", tmp);
+    printf("Program counter:   0x%X\r\n", tmp = pc);
+    printf("Fault information: 0x%X\r\n", tmp = info);
+
+    switch (id)
+    {
+        case NRF_FAULT_ID_SDK_ASSERT:
+            printf("Line Number: %u\r\n", tmp = ((assert_info_t *)(info))->line_num);
+            printf("File Name:   %s\r\n",       ((assert_info_t *)(info))->p_file_name);
+            break;
+
+        case NRF_FAULT_ID_SDK_ERROR:
+            printf("Line Number: %u\r\n",   tmp = ((error_info_t *)(info))->line_num);
+            printf("File Name:   %s\r\n",         ((error_info_t *)(info))->p_file_name);
+            printf("Error Code:  0x%X\r\n", tmp = ((error_info_t *)(info))->err_code);
+            break;
+    }
+}
+//lint -restore
+
+
+/**@brief Macro for calling error handler function.
+ *
+ * @param[in] ERR_CODE Error code supplied to the error handler.
+ */
+#ifdef DEBUG
+#define APP_ERROR_HANDLER(ERR_CODE)                                    \
+    do                                                                 \
+    {                                                                  \
+        app_error_handler((ERR_CODE), __LINE__, (uint8_t*) __FILE__);  \
+    } while (0)
+#else
+#define APP_ERROR_HANDLER(ERR_CODE)                                    \
+    do                                                                 \
+    {                                                                  \
+        app_error_handler_bare((ERR_CODE));                            \
+    } while (0)
+#endif
+/**@brief Macro for calling error handler function if supplied error code any other than NRF_SUCCESS.
+ *
+ * @param[in] ERR_CODE Error code supplied to the error handler.
+ */
+#define APP_ERROR_CHECK(ERR_CODE)                           \
+    do                                                      \
+    {                                                       \
+        const uint32_t LOCAL_ERR_CODE = (ERR_CODE);         \
+        if (LOCAL_ERR_CODE != NRF_SUCCESS)                  \
+        {                                                   \
+            APP_ERROR_HANDLER(LOCAL_ERR_CODE);              \
+        }                                                   \
+    } while (0)
+
+/**@brief Macro for calling error handler function if supplied boolean value is false.
+ *
+ * @param[in] BOOLEAN_VALUE Boolean value to be evaluated.
+ */
+#define APP_ERROR_CHECK_BOOL(BOOLEAN_VALUE)                   \
+    do                                                        \
+    {                                                         \
+        const uint32_t LOCAL_BOOLEAN_VALUE = (BOOLEAN_VALUE); \
+        if (!LOCAL_BOOLEAN_VALUE)                             \
+        {                                                     \
+            APP_ERROR_HANDLER(0);                             \
+        }                                                     \
+    } while (0)
+
+#endif // APP_ERROR_H__
+
+/** @} */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f06c2d2b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error_weak.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error_weak.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error_weak.c
new file mode 100644
index 0000000..eccc0a6
--- /dev/null
+++ b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error_weak.c
@@ -0,0 +1,53 @@
+/* Copyright (c) 2016 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+#include "app_error.h"
+
+#ifdef DEBUG
+#include "bsp.h"
+#endif
+ 
+/*lint -save -e14 */
+
+/**
+ * Function is implemented as weak so that it can be overwritten by custom application error handler
+ * when needed.
+ */
+__WEAK void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
+{
+    // On assert, the system can only recover with a reset.
+#ifndef DEBUG
+    NVIC_SystemReset();
+#else
+
+#ifdef BSP_DEFINES_ONLY
+    LEDS_ON(LEDS_MASK);
+#else
+    UNUSED_VARIABLE(bsp_indication_set(BSP_INDICATE_FATAL_ERROR));
+    // This call can be used for debug purposes during application development.
+    // @note CAUTION: Activating this code will write the stack to flash on an error.
+    //                This function should NOT be used in a final product.
+    //                It is intended STRICTLY for development/debugging purposes.
+    //                The flash write will happen EVEN if the radio is active, thus interrupting
+    //                any communication.
+    //                Use with care. Uncomment the line below to use.
+    //ble_debug_assert_handler(error_code, line_num, p_file_name);
+#endif // BSP_DEFINES_ONLY
+
+    app_error_save_and_stop(id, pc, info);
+
+#endif // DEBUG
+}
+
+/*lint -restore */
+
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f06c2d2b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error_weak.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error_weak.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error_weak.h
new file mode 100644
index 0000000..551a431
--- /dev/null
+++ b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_error_weak.h
@@ -0,0 +1,51 @@
+/* Copyright (c) 2016 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+#ifndef APP_ERROR_WEAK_H__
+#define APP_ERROR_WEAK_H__
+
+/** @file
+ *
+ * @defgroup app_error Common application error handler
+ * @{
+ * @ingroup app_common
+ *
+ * @brief Common application error handler.
+ */
+ 
+/**@brief       Callback function for asserts in the SoftDevice.
+ *
+ * @details     A pointer to this function will be passed to the SoftDevice. This function will be
+ *              called by the SoftDevice if certain unrecoverable errors occur within the
+ *              application or SoftDevice.
+ *
+ *              See @ref nrf_fault_handler_t for more details.
+ *
+ * @param[in] id    Fault identifier. See @ref NRF_FAULT_IDS.
+ * @param[in] pc    The program counter of the instruction that triggered the fault, or 0 if
+ *                  unavailable.
+ * @param[in] info  Optional additional information regarding the fault. Refer to each fault
+ *                  identifier for details.
+ *
+ * @remarks Function is implemented as weak so that it can be overwritten by custom application
+ *          error handler when needed.
+ */
+#ifdef __CC_ARM
+	     void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info);
+#else
+__WEAK void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info);
+#endif
+
+
+/** @} */
+
+#endif // APP_ERROR_WEAK_H__

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f06c2d2b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util.h
new file mode 100644
index 0000000..774bc28
--- /dev/null
+++ b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util.h
@@ -0,0 +1,493 @@
+/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+/** @file
+ *
+ * @defgroup app_util Utility Functions and Definitions
+ * @{
+ * @ingroup app_common
+ *
+ * @brief Various types and definitions available to all applications.
+ */
+
+#ifndef APP_UTIL_H__
+#define APP_UTIL_H__
+
+#include <stdint.h>
+#include <stdbool.h>
+#include "compiler_abstraction.h"
+#include "nrf.h"
+
+//lint -save -e27 -e10 -e19
+#if defined ( __CC_ARM )
+extern char STACK$$Base;
+extern char STACK$$Length;
+#define STACK_BASE    &STACK$$Base
+#define STACK_TOP    ((void*)((uint32_t)STACK_BASE + (uint32_t)&STACK$$Length))
+#elif defined ( __ICCARM__ )
+extern char CSTACK$$Base;
+extern char CSTACK$$Length;
+#define STACK_BASE    &CSTACK$$Base
+#define STACK_TOP    ((void*)((uint32_t)STACK_BASE + (uint32_t)&CSTACK$$Length))
+#elif defined   ( __GNUC__ )
+extern uint32_t __StackTop;
+extern uint32_t __StackLimit;
+#define STACK_BASE    &__StackLimit
+#define STACK_TOP     &__StackTop
+#endif
+//lint -restore
+
+enum
+{
+    UNIT_0_625_MS = 625,                                /**< Number of microseconds in 0.625 milliseconds. */
+    UNIT_1_25_MS  = 1250,                               /**< Number of microseconds in 1.25 milliseconds. */
+    UNIT_10_MS    = 10000                               /**< Number of microseconds in 10 milliseconds. */
+};
+
+
+/**@brief Implementation specific macro for delayed macro expansion used in string concatenation
+*
+* @param[in]   lhs   Left hand side in concatenation
+* @param[in]   rhs   Right hand side in concatenation
+*/
+#define STRING_CONCATENATE_IMPL(lhs, rhs) lhs ## rhs
+
+
+/**@brief Macro used to concatenate string using delayed macro expansion
+*
+* @note This macro will delay concatenation until the expressions have been resolved
+*
+* @param[in]   lhs   Left hand side in concatenation
+* @param[in]   rhs   Right hand side in concatenation
+*/
+#define STRING_CONCATENATE(lhs, rhs) STRING_CONCATENATE_IMPL(lhs, rhs)
+
+
+// Disable lint-warnings/errors for STATIC_ASSERT
+//lint --emacro(10,STATIC_ASSERT)
+//lint --emacro(18,STATIC_ASSERT)
+//lint --emacro(19,STATIC_ASSERT)
+//lint --emacro(30,STATIC_ASSERT)
+//lint --emacro(37,STATIC_ASSERT)
+//lint --emacro(42,STATIC_ASSERT)
+//lint --emacro(26,STATIC_ASSERT)
+//lint --emacro(102,STATIC_ASSERT)
+//lint --emacro(533,STATIC_ASSERT)
+//lint --emacro(534,STATIC_ASSERT)
+//lint --emacro(132,STATIC_ASSERT)
+//lint --emacro(414,STATIC_ASSERT)
+//lint --emacro(578,STATIC_ASSERT)
+//lint --emacro(628,STATIC_ASSERT)
+//lint --emacro(648,STATIC_ASSERT)
+//lint --emacro(830,STATIC_ASSERT)
+
+
+/**@brief Macro for doing static (i.e. compile time) assertion.
+*
+* @note If the EXPR isn't resolvable, then the error message won't be shown.
+*
+* @note The output of STATIC_ASSERT will be different across different compilers.
+*
+* @param[in] EXPR Constant expression to be verified.
+*/
+#if defined ( __COUNTER__ )
+
+#define STATIC_ASSERT(EXPR) \
+    ;enum { STRING_CONCATENATE(static_assert_, __COUNTER__) = 1/(!!(EXPR)) }
+
+#else
+
+#define STATIC_ASSERT(EXPR) \
+    ;enum { STRING_CONCATENATE(assert_line_, __LINE__) = 1/(!!(EXPR)) }
+
+#endif
+
+
+/**@brief Implementation details for NUM_VAR_ARGS */
+#define NUM_VA_ARGS_IMPL(                              \
+    _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10,       \
+    _11, _12, _13, _14, _15, _16, _17, _18, _19, _20,  \
+    _21, _22, _23, _24, _25, _26, _27, _28, _29, _30,  \
+    _31, _32, _33, _34, _35, _36, _37, _38, _39, _40,  \
+    _41, _42, _43, _44, _45, _46, _47, _48, _49, _50,  \
+    _51, _52, _53, _54, _55, _56, _57, _58, _59, _60,  \
+    _61, _62, N, ...) N
+
+
+/**@brief Macro to get the number of arguments in a call variadic macro call
+ *
+ * param[in]    ...     List of arguments
+ *
+ * @retval  Number of variadic arguments in the argument list
+ */
+#define NUM_VA_ARGS(...) NUM_VA_ARGS_IMPL(__VA_ARGS__, 63, 62, 61,  \
+    60, 59, 58, 57, 56, 55, 54, 53, 52, 51,                         \
+    50, 49, 48, 47, 46, 45, 44, 43, 42, 41,                         \
+    40, 39, 38, 37, 36, 35, 34, 33, 32, 31,                         \
+    30, 29, 28, 27, 26, 25, 24, 23, 22, 21,                         \
+    20, 19, 18, 17, 16, 15, 14, 13, 12, 11,                         \
+    10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
+
+
+/**@brief type for holding an encoded (i.e. little endian) 16 bit unsigned integer. */
+typedef uint8_t uint16_le_t[2];
+
+/**@brief Type for holding an encoded (i.e. little endian) 32 bit unsigned integer. */
+typedef uint8_t uint32_le_t[4];
+
+/**@brief Byte array type. */
+typedef struct
+{
+    uint16_t  size;                 /**< Number of array entries. */
+    uint8_t * p_data;               /**< Pointer to array entries. */
+} uint8_array_t;
+
+
+/**@brief Macro for performing rounded integer division (as opposed to truncating the result).
+ *
+ * @param[in]   A   Numerator.
+ * @param[in]   B   Denominator.
+ *
+ * @return      Rounded (integer) result of dividing A by B.
+ */
+#define ROUNDED_DIV(A, B) (((A) + ((B) / 2)) / (B))
+
+
+/**@brief Macro for checking if an integer is a power of two.
+ *
+ * @param[in]   A   Number to be tested.
+ *
+ * @return      true if value is power of two.
+ * @return      false if value not power of two.
+ */
+#define IS_POWER_OF_TWO(A) ( ((A) != 0) && ((((A) - 1) & (A)) == 0) )
+
+
+/**@brief Macro for converting milliseconds to ticks.
+ *
+ * @param[in] TIME          Number of milliseconds to convert.
+ * @param[in] RESOLUTION    Unit to be converted to in [us/ticks].
+ */
+#define MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION))
+
+
+/**@brief Macro for performing integer division, making sure the result is rounded up.
+ *
+ * @details One typical use for this is to compute the number of objects with size B is needed to
+ *          hold A number of bytes.
+ *
+ * @param[in]   A   Numerator.
+ * @param[in]   B   Denominator.
+ *
+ * @return      Integer result of dividing A by B, rounded up.
+ */
+#define CEIL_DIV(A, B)      \
+    (((A) + (B) - 1) / (B))
+
+
+/**@brief Macro for creating a buffer aligned to 4 bytes.
+ *
+ * @param[in]   NAME        Name of the buffor.
+ * @param[in]   MIN_SIZE    Size of this buffor (it will be rounded up to multiples of 4 bytes).
+ */
+#define WORD_ALIGNED_MEM_BUFF(NAME, MIN_SIZE) static uint32_t NAME[CEIL_DIV(MIN_SIZE, sizeof(uint32_t))]
+
+
+/**@brief Macro for calculating the number of words that are needed to hold a number of bytes.
+ *
+ * @details Adds 3 and divides by 4.
+ *
+ * @param[in]  n_bytes  The number of bytes.
+ *
+ * @return The number of words that @p n_bytes take up (rounded up).
+ */
+#define BYTES_TO_WORDS(n_bytes) (((n_bytes) + 3) >> 2)
+
+
+/**@brief The number of bytes in a word.
+ */
+#define BYTES_PER_WORD (4)
+
+
+/**@brief Macro for increasing a number to the nearest (larger) multiple of another number.
+ *
+ * @param[in]  alignment  The number to align to.
+ * @param[in]  number     The number to align (increase).
+ *
+ * @return The aligned (increased) @p number.
+ */
+#define ALIGN_NUM(alignment, number) ((number - 1) + alignment - ((number - 1) % alignment))
+
+
+/**@brief Function for changing the value unit.
+ *
+ * @param[in]   value               Value to be rescaled.
+ * @param[in]   old_unit_reversal   Reversal of the incoming unit.
+ * @param[in]   new_unit_reversal   Reversal of the desired unit.
+ *
+ * @return      Number of bytes written.
+ */
+static __INLINE uint64_t value_rescale(uint32_t value, uint32_t old_unit_reversal, uint16_t new_unit_reversal)
+{
+    return (uint64_t)ROUNDED_DIV((uint64_t)value * new_unit_reversal, old_unit_reversal);
+}
+
+/**@brief Function for encoding a uint16 value.
+ *
+ * @param[in]   value            Value to be encoded.
+ * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
+ *
+ * @return      Number of bytes written.
+ */
+static __INLINE uint8_t uint16_encode(uint16_t value, uint8_t * p_encoded_data)
+{
+    p_encoded_data[0] = (uint8_t) ((value & 0x00FF) >> 0);
+    p_encoded_data[1] = (uint8_t) ((value & 0xFF00) >> 8);
+    return sizeof(uint16_t);
+}
+
+/**@brief Function for encoding a three-byte value.
+ *
+ * @param[in]   value            Value to be encoded.
+ * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
+ *
+ * @return      Number of bytes written.
+ */
+static __INLINE uint8_t uint24_encode(uint32_t value, uint8_t * p_encoded_data)
+{
+    p_encoded_data[0] = (uint8_t) ((value & 0x000000FF) >> 0);
+    p_encoded_data[1] = (uint8_t) ((value & 0x0000FF00) >> 8);
+    p_encoded_data[2] = (uint8_t) ((value & 0x00FF0000) >> 16);
+    return 3;
+}
+
+/**@brief Function for encoding a uint32 value.
+ *
+ * @param[in]   value            Value to be encoded.
+ * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
+ *
+ * @return      Number of bytes written.
+ */
+static __INLINE uint8_t uint32_encode(uint32_t value, uint8_t * p_encoded_data)
+{
+    p_encoded_data[0] = (uint8_t) ((value & 0x000000FF) >> 0);
+    p_encoded_data[1] = (uint8_t) ((value & 0x0000FF00) >> 8);
+    p_encoded_data[2] = (uint8_t) ((value & 0x00FF0000) >> 16);
+    p_encoded_data[3] = (uint8_t) ((value & 0xFF000000) >> 24);
+    return sizeof(uint32_t);
+}
+
+/**@brief Function for encoding a uint48 value.
+ *
+ * @param[in]   value            Value to be encoded.
+ * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
+ *
+ * @return      Number of bytes written.
+ */
+static __INLINE uint8_t uint48_encode(uint64_t value, uint8_t * p_encoded_data)
+{
+    p_encoded_data[0] = (uint8_t) ((value & 0x0000000000FF) >> 0);
+    p_encoded_data[1] = (uint8_t) ((value & 0x00000000FF00) >> 8);
+    p_encoded_data[2] = (uint8_t) ((value & 0x000000FF0000) >> 16);
+    p_encoded_data[3] = (uint8_t) ((value & 0x0000FF000000) >> 24);
+    p_encoded_data[4] = (uint8_t) ((value & 0x00FF00000000) >> 32);
+    p_encoded_data[5] = (uint8_t) ((value & 0xFF0000000000) >> 40);
+    return 6;
+}
+
+/**@brief Function for decoding a uint16 value.
+ *
+ * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
+ *
+ * @return      Decoded value.
+ */
+static __INLINE uint16_t uint16_decode(const uint8_t * p_encoded_data)
+{
+        return ( (((uint16_t)((uint8_t *)p_encoded_data)[0])) |
+                 (((uint16_t)((uint8_t *)p_encoded_data)[1]) << 8 ));
+}
+
+/**@brief Function for decoding a uint16 value in big-endian format.
+ *
+ * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
+ *
+ * @return      Decoded value.
+ */
+static __INLINE uint16_t uint16_big_decode(const uint8_t * p_encoded_data)
+{
+        return ( (((uint16_t)((uint8_t *)p_encoded_data)[0]) << 8 ) |
+                 (((uint16_t)((uint8_t *)p_encoded_data)[1])) );
+}
+
+/**@brief Function for decoding a three-byte value.
+ *
+ * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
+ *
+ * @return      Decoded value (uint32_t).
+ */
+static __INLINE uint32_t uint24_decode(const uint8_t * p_encoded_data)
+{
+    return ( (((uint32_t)((uint8_t *)p_encoded_data)[0]) << 0)  |
+             (((uint32_t)((uint8_t *)p_encoded_data)[1]) << 8)  |
+             (((uint32_t)((uint8_t *)p_encoded_data)[2]) << 16));
+}
+
+/**@brief Function for decoding a uint32 value.
+ *
+ * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
+ *
+ * @return      Decoded value.
+ */
+static __INLINE uint32_t uint32_decode(const uint8_t * p_encoded_data)
+{
+    return ( (((uint32_t)((uint8_t *)p_encoded_data)[0]) << 0)  |
+             (((uint32_t)((uint8_t *)p_encoded_data)[1]) << 8)  |
+             (((uint32_t)((uint8_t *)p_encoded_data)[2]) << 16) |
+             (((uint32_t)((uint8_t *)p_encoded_data)[3]) << 24 ));
+}
+
+/**@brief Function for decoding a uint32 value in big-endian format.
+ *
+ * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
+ *
+ * @return      Decoded value.
+ */
+static __INLINE uint32_t uint32_big_decode(const uint8_t * p_encoded_data)
+{
+    return ( (((uint32_t)((uint8_t *)p_encoded_data)[0]) << 24) |
+             (((uint32_t)((uint8_t *)p_encoded_data)[1]) << 16) |
+             (((uint32_t)((uint8_t *)p_encoded_data)[2]) << 8)  |
+             (((uint32_t)((uint8_t *)p_encoded_data)[3]) << 0) );
+}
+
+/**@brief Function for encoding a uint32 value in big-endian format.
+ *
+ * @param[in]   value            Value to be encoded.
+ * @param[out]  p_encoded_data   Buffer where the encoded data will be written.
+ *
+ * @return      Number of bytes written.
+ */
+static __INLINE uint8_t uint32_big_encode(uint32_t value, uint8_t * p_encoded_data)
+{
+#ifdef NRF51
+    p_encoded_data[0] = (uint8_t) ((value & 0xFF000000) >> 24);
+    p_encoded_data[1] = (uint8_t) ((value & 0x00FF0000) >> 16);
+    p_encoded_data[2] = (uint8_t) ((value & 0x0000FF00) >> 8);
+    p_encoded_data[3] = (uint8_t) ((value & 0x000000FF) >> 0);
+#elif NRF52
+    *(uint32_t *)p_encoded_data = __REV(value);
+#endif
+    return sizeof(uint32_t);
+}
+
+/**@brief Function for decoding a uint48 value.
+ *
+ * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
+ *
+ * @return      Decoded value. (uint64_t)
+ */
+static __INLINE uint64_t uint48_decode(const uint8_t * p_encoded_data)
+{
+    return ( (((uint64_t)((uint8_t *)p_encoded_data)[0]) << 0)  |
+             (((uint64_t)((uint8_t *)p_encoded_data)[1]) << 8)  |
+             (((uint64_t)((uint8_t *)p_encoded_data)[2]) << 16) |
+             (((uint64_t)((uint8_t *)p_encoded_data)[3]) << 24) |
+             (((uint64_t)((uint8_t *)p_encoded_data)[4]) << 32) |
+             (((uint64_t)((uint8_t *)p_encoded_data)[5]) << 40 ));
+}
+
+/** @brief Function for converting the input voltage (in milli volts) into percentage of 3.0 Volts.
+ *
+ *  @details The calculation is based on a linearized version of the battery's discharge
+ *           curve. 3.0V returns 100% battery level. The limit for power failure is 2.1V and
+ *           is considered to be the lower boundary.
+ *
+ *           The discharge curve for CR2032 is non-linear. In this model it is split into
+ *           4 linear sections:
+ *           - Section 1: 3.0V - 2.9V = 100% - 42% (58% drop on 100 mV)
+ *           - Section 2: 2.9V - 2.74V = 42% - 18% (24% drop on 160 mV)
+ *           - Section 3: 2.74V - 2.44V = 18% - 6% (12% drop on 300 mV)
+ *           - Section 4: 2.44V - 2.1V = 6% - 0% (6% drop on 340 mV)
+ *
+ *           These numbers are by no means accurate. Temperature and
+ *           load in the actual application is not accounted for!
+ *
+ *  @param[in] mvolts The voltage in mV
+ *
+ *  @return    Battery level in percent.
+*/
+static __INLINE uint8_t battery_level_in_percent(const uint16_t mvolts)
+{
+    uint8_t battery_level;
+
+    if (mvolts >= 3000)
+    {
+        battery_level = 100;
+    }
+    else if (mvolts > 2900)
+    {
+        battery_level = 100 - ((3000 - mvolts) * 58) / 100;
+    }
+    else if (mvolts > 2740)
+    {
+        battery_level = 42 - ((2900 - mvolts) * 24) / 160;
+    }
+    else if (mvolts > 2440)
+    {
+        battery_level = 18 - ((2740 - mvolts) * 12) / 300;
+    }
+    else if (mvolts > 2100)
+    {
+        battery_level = 6 - ((2440 - mvolts) * 6) / 340;
+    }
+    else
+    {
+        battery_level = 0;
+    }
+
+    return battery_level;
+}
+
+/**@brief Function for checking if a pointer value is aligned to a 4 byte boundary.
+ *
+ * @param[in]   p   Pointer value to be checked.
+ *
+ * @return      TRUE if pointer is aligned to a 4 byte boundary, FALSE otherwise.
+ */
+static __INLINE bool is_word_aligned(void const* p)
+{
+    return (((uintptr_t)p & 0x03) == 0);
+}
+
+/**
+ * @brief Function for checking if provided address is located in stack space.
+ *
+ * @param[in]   ptr Pointer to be checked.
+ *
+ * @return      true if address is in stack space, false otherwise.
+ */
+static __INLINE bool is_address_from_stack(void * ptr)
+{
+    if (((uint32_t)ptr >= (uint32_t)STACK_BASE) &&
+        ((uint32_t)ptr <  (uint32_t)STACK_TOP) )
+    {
+        return true;
+    }
+    else
+    {
+        return false;
+    }
+}
+
+#endif // APP_UTIL_H__
+
+/** @} */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f06c2d2b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util_bds.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util_bds.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util_bds.h
new file mode 100644
index 0000000..7547ad8
--- /dev/null
+++ b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util_bds.h
@@ -0,0 +1,413 @@
+/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+/** @file
+ *
+ * @defgroup app_util Utility Functions and Definitions
+ * @{
+ * @ingroup app_common
+ *
+ * @brief Various types and definitions available to all applications.
+ */
+
+#ifndef APP_UTIL_BDS_H__
+#define APP_UTIL_BDS_H__
+
+#include <stdint.h>
+#include <string.h>
+#include <stdbool.h>
+#include "compiler_abstraction.h"
+#include "app_util.h"
+#include "ble_srv_common.h"
+#include "nordic_common.h"
+    
+typedef uint8_t nibble_t;
+typedef uint32_t uint24_t;
+typedef uint64_t uint40_t;
+
+/**@brief IEEE 11073-20601 Regulatory Certification Data List Structure */
+typedef struct
+{
+    uint8_t *  p_list;                                          /**< Pointer the byte array containing the encoded opaque structure based on IEEE 11073-20601 specification. */
+    uint8_t    list_len;                                        /**< Length of the byte array. */
+} regcertdatalist_t;
+
+/**@brief SFLOAT format (IEEE-11073 16-bit FLOAT, meaning 4 bits for exponent (base 10) and 12 bits mantissa) */
+typedef struct
+{
+  int8_t exponent;                                             /**< Base 10 exponent, should be using only 4 bits */
+  int16_t mantissa;                                            /**< Mantissa, should be using only 12 bits */
+} sfloat_t;
+
+/**@brief Date and Time structure. */
+typedef struct
+{
+    uint16_t year;
+    uint8_t  month;
+    uint8_t  day;
+    uint8_t  hours;
+    uint8_t  minutes;
+    uint8_t  seconds;
+} ble_date_time_t;
+
+
+/**@brief Function for encoding a uint16 value.
+ *
+ * @param[in]   p_value          Value to be encoded.
+ * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
+ *
+ * @return      Number of bytes written.
+ */
+static __INLINE uint8_t bds_uint16_encode(const uint16_t * p_value, uint8_t * p_encoded_data)
+{
+    p_encoded_data[0] = (uint8_t) ((*p_value & 0x00FF) >> 0);
+    p_encoded_data[1] = (uint8_t) ((*p_value & 0xFF00) >> 8);
+    return sizeof(uint16_t);
+}
+
+static __INLINE uint8_t bds_int16_encode(const int16_t * p_value, uint8_t * p_encoded_data)
+{
+    uint16_t tmp = *p_value;
+    return bds_uint16_encode(&tmp, p_encoded_data);
+}
+
+/**@brief Function for encoding a uint24 value.
+ *
+ * @param[in]   p_value          Value to be encoded.
+ * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
+ *
+ * @return      Number of bytes written.
+ */
+static __INLINE uint8_t bds_uint24_encode(const uint32_t * p_value, uint8_t * p_encoded_data)
+{
+    p_encoded_data[0] = (uint8_t) ((*p_value & 0x000000FF) >> 0);
+    p_encoded_data[1] = (uint8_t) ((*p_value & 0x0000FF00) >> 8);
+    p_encoded_data[2] = (uint8_t) ((*p_value & 0x00FF0000) >> 16);
+    return (3);
+}
+
+    
+/**@brief Function for encoding a uint32 value.
+ *
+ * @param[in]   p_value          Value to be encoded.
+ * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
+ *
+ * @return      Number of bytes written.
+ */
+static __INLINE uint8_t bds_uint32_encode(const uint32_t * p_value, uint8_t * p_encoded_data)
+{
+    p_encoded_data[0] = (uint8_t) ((*p_value & 0x000000FF) >> 0);
+    p_encoded_data[1] = (uint8_t) ((*p_value & 0x0000FF00) >> 8);
+    p_encoded_data[2] = (uint8_t) ((*p_value & 0x00FF0000) >> 16);
+    p_encoded_data[3] = (uint8_t) ((*p_value & 0xFF000000) >> 24);
+    return sizeof(uint32_t);
+}
+
+    
+/**@brief Function for encoding a uint40 value.
+ *
+ * @param[in]   p_value          Value to be encoded.
+ * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
+ *
+ * @return      Number of bytes written.
+ */
+static __INLINE uint8_t bds_uint40_encode(const uint64_t * p_value, uint8_t * p_encoded_data)
+{
+    p_encoded_data[0] = (uint8_t) ((*p_value & 0x00000000000000FF) >> 0);
+    p_encoded_data[1] = (uint8_t) ((*p_value & 0x000000000000FF00) >> 8);
+    p_encoded_data[2] = (uint8_t) ((*p_value & 0x0000000000FF0000) >> 16);
+    p_encoded_data[3] = (uint8_t) ((*p_value & 0x00000000FF000000) >> 24);
+    p_encoded_data[4] = (uint8_t) ((*p_value & 0x000000FF00000000) >> 32);
+    return 5;
+}
+
+/**@brief Function for encoding a sfloat value.
+ *
+ * @param[in]   p_value          Value to be encoded.
+ * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
+ *
+ * @return      Number of bytes written.
+ */
+static __INLINE uint8_t bds_sfloat_encode(const sfloat_t * p_value, uint8_t * p_encoded_data)
+{
+    uint16_t encoded_val;
+
+    encoded_val = ((p_value->exponent << 12) & 0xF000) |
+                            ((p_value->mantissa <<  0) & 0x0FFF);
+
+    return(bds_uint16_encode(&encoded_val, p_encoded_data));
+}
+
+
+/**@brief Function for encoding a uint8_array value.
+ *
+ * @param[in]   p_value          Value to be encoded.
+ * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
+ */
+static __INLINE uint8_t bds_uint8_array_encode(const uint8_array_t * p_value, 
+                                               uint8_t             * p_encoded_data)
+{
+    memcpy(p_encoded_data, p_value->p_data, p_value->size);
+    return p_value->size;
+}    
+
+
+/**@brief Function for encoding a utf8_str value.
+ *
+ * @param[in]   p_value          Value to be encoded.
+ * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
+
+ */
+static __INLINE uint8_t bds_ble_srv_utf8_str_encode(const ble_srv_utf8_str_t * p_value,
+                                                    uint8_t                  * p_encoded_data)
+{
+    memcpy(p_encoded_data, p_value->p_str, p_value->length);
+    return p_value->length;
+}    
+
+/**@brief Function for encoding a regcertdatalist value.
+ *
+ * @param[in]   p_value          Value to be encoded.
+ * @param[out]  p_encoded_data   Buffer where the encoded data is to be written.
+
+ */
+static __INLINE uint8_t bds_regcertdatalist_encode(const regcertdatalist_t * p_value, 
+                                                   uint8_t                 * p_encoded_data)
+{
+    memcpy(p_encoded_data, p_value->p_list, p_value->list_len);
+    return p_value->list_len;
+}    
+
+
+/**@brief Function for decoding a date_time value.
+ *
+ * @param[in]   p_date_time    pointer to the date_time structure to encode.
+ * @param[in]   p_encoded_data pointer to the encoded data
+ * @return      length of the encoded field.
+ */
+static __INLINE uint8_t bds_ble_date_time_encode(const ble_date_time_t * p_date_time,
+                                                 uint8_t               * p_encoded_data)
+{
+    uint8_t len = bds_uint16_encode(&p_date_time->year, &p_encoded_data[0]);
+    
+    p_encoded_data[len++] = p_date_time->month;
+    p_encoded_data[len++] = p_date_time->day;
+    p_encoded_data[len++] = p_date_time->hours;
+    p_encoded_data[len++] = p_date_time->minutes;
+    p_encoded_data[len++] = p_date_time->seconds;
+    
+    return len;
+}
+
+
+/**@brief Function for decoding a uint16 value.
+ *
+ * @param[in]   len              length of the field to be decoded.
+ * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
+ * @param[in]   p_decoded_val    pointer to the decoded value
+ * @return      length of the decoded field.
+ */
+static __INLINE uint8_t bds_uint16_decode(const uint8_t len, 
+                                          const uint8_t * p_encoded_data, 
+                                          uint16_t      * p_decoded_val)
+{
+    UNUSED_VARIABLE(len);
+    *p_decoded_val = (((uint16_t)((uint8_t *)p_encoded_data)[0])) | 
+                     (((uint16_t)((uint8_t *)p_encoded_data)[1]) << 8 );
+    return (sizeof(uint16_t));
+}
+
+
+/**@brief Function for decoding a int16 value.
+ *
+ * @param[in]   len              length of the field to be decoded.
+ * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
+ * @param[in]   p_decoded_val    pointer to the decoded value
+ * @return      length of the decoded field.
+ */
+static __INLINE uint8_t bds_int16_decode(const uint8_t len, 
+                                         const uint8_t * p_encoded_data, 
+                                         int16_t       * p_decoded_val)
+{
+    UNUSED_VARIABLE(len);
+    uint16_t tmp = 0;
+    uint8_t retval = bds_uint16_decode(len, p_encoded_data, &tmp);
+    *p_decoded_val = (int16_t)tmp;
+    return retval;
+}
+
+
+/**@brief Function for decoding a uint24 value.
+ *
+ * @param[in]   len              length of the field to be decoded.
+ * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
+ * @param[in]   p_decoded_val    pointer to the decoded value
+ *
+ * @return      length of the decoded field.
+ */
+static __INLINE uint8_t bds_uint24_decode(const uint8_t len, 
+                                          const uint8_t * p_encoded_data, 
+                                          uint32_t      * p_decoded_val)
+{
+    UNUSED_VARIABLE(len);
+    *p_decoded_val = (((uint32_t)((uint8_t *)p_encoded_data)[0]) << 0)  |
+                     (((uint32_t)((uint8_t *)p_encoded_data)[1]) << 8)  |
+                     (((uint32_t)((uint8_t *)p_encoded_data)[2]) << 16);
+    return (3);
+}
+
+
+/**@brief Function for decoding a uint32 value.
+ *
+ * @param[in]   len              length of the field to be decoded.
+ * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
+ * @param[in]   p_decoded_val    pointer to the decoded value
+ *
+ * @return      length of the decoded field.
+ */
+static __INLINE uint8_t bds_uint32_decode(const uint8_t len, 
+                                          const uint8_t * p_encoded_data, 
+                                          uint32_t      * p_decoded_val)
+{
+    UNUSED_VARIABLE(len);
+    *p_decoded_val = (((uint32_t)((uint8_t *)p_encoded_data)[0]) << 0)  |
+                     (((uint32_t)((uint8_t *)p_encoded_data)[1]) << 8)  |
+                     (((uint32_t)((uint8_t *)p_encoded_data)[2]) << 16) |
+                     (((uint32_t)((uint8_t *)p_encoded_data)[3]) << 24 );
+    return (sizeof(uint32_t));
+}
+
+
+/**@brief Function for decoding a uint40 value.
+ *
+ * @param[in]   len              length of the field to be decoded.
+ * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
+ * @param[in]   p_decoded_val    pointer to the decoded value
+ *
+ * @return      length of the decoded field.
+ */
+static __INLINE uint8_t bds_uint40_decode(const uint8_t len, 
+                                          const uint8_t * p_encoded_data, 
+                                          uint64_t      * p_decoded_val)
+{
+    UNUSED_VARIABLE(len);
+    *p_decoded_val = (((uint64_t)((uint8_t *)p_encoded_data)[0]) << 0)  |
+                     (((uint64_t)((uint8_t *)p_encoded_data)[1]) << 8)  |
+                     (((uint64_t)((uint8_t *)p_encoded_data)[2]) << 16) |
+                     (((uint64_t)((uint8_t *)p_encoded_data)[3]) << 24 )|
+                     (((uint64_t)((uint8_t *)p_encoded_data)[4]) << 32 );
+    return (40);
+}
+
+
+/**@brief Function for decoding a sfloat value.
+ *
+ * @param[in]   len              length of the field to be decoded.
+ * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
+ * @param[in]   p_decoded_val    pointer to the decoded value
+ *
+ * @return      length of the decoded field.
+
+ */
+static __INLINE uint8_t bds_sfloat_decode(const uint8_t len, 
+                                          const uint8_t * p_encoded_data, 
+                                          sfloat_t      * p_decoded_val)
+{
+    
+    p_decoded_val->exponent = 0;
+    bds_uint16_decode(len, p_encoded_data, (uint16_t*)&p_decoded_val->mantissa);
+    p_decoded_val->exponent = (uint8_t)((p_decoded_val->mantissa & 0xF000) >> 12);
+    p_decoded_val->mantissa &= 0x0FFF;
+    return len;
+}
+
+
+/**@brief Function for decoding a uint8_array value.
+ *
+ * @param[in]   len              length of the field to be decoded.
+ * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
+ * @param[in]   p_decoded_val    pointer to the decoded value
+ *
+ * @return      length of the decoded field.
+ */
+static __INLINE uint8_t bds_uint8_array_decode(const uint8_t len, 
+                                               const uint8_t * p_encoded_data,
+                                               uint8_array_t * p_decoded_val)
+{
+    memcpy(p_decoded_val->p_data, p_encoded_data, len);
+    p_decoded_val->size = len;
+    return p_decoded_val->size;
+}   
+
+
+/**@brief Function for decoding a utf8_str value.
+ *
+ * @param[in]   len              length of the field to be decoded.
+ * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
+ * @param[in]   p_decoded_val    pointer to the decoded value
+ *
+ * @return      length of the decoded field.
+ */
+static __INLINE uint8_t bds_ble_srv_utf8_str_decode(const uint8_t      len, 
+                                                    const uint8_t      * p_encoded_data, 
+                                                    ble_srv_utf8_str_t * p_decoded_val)
+{
+    p_decoded_val->p_str = (uint8_t*)p_encoded_data;
+    p_decoded_val->length = len;
+    return p_decoded_val->length;
+}   
+
+
+/**@brief Function for decoding a regcertdatalist value.
+ *
+ * @param[in]   len              length of the field to be decoded.
+ * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
+ * @param[in]   p_decoded_val    pointer to the decoded value
+ *
+ * @return      length of the decoded field.
+ */
+static __INLINE uint8_t bds_regcertdatalist_decode(const uint8_t     len, 
+                                                   const uint8_t     * p_encoded_data, 
+                                                   regcertdatalist_t * p_decoded_val)
+{
+    memcpy(p_decoded_val->p_list, p_encoded_data, len);
+    p_decoded_val->list_len = len;
+    return p_decoded_val->list_len;
+}    
+
+
+/**@brief Function for decoding a date_time value.
+ *
+ * @param[in]   len              length of the field to be decoded.
+ * @param[in]   p_encoded_data   Buffer where the encoded data is stored.
+ * @param[in]   p_date_time      pointer to the decoded value
+ *
+ * @return      length of the decoded field.
+ */
+static __INLINE uint8_t bds_ble_date_time_decode(const uint8_t   len, 
+                                                 const uint8_t   * p_encoded_data, 
+                                                 ble_date_time_t * p_date_time)
+{
+    UNUSED_VARIABLE(len);
+    uint8_t pos          = bds_uint16_decode(len, &p_encoded_data[0], &p_date_time->year);
+    p_date_time->month   = p_encoded_data[pos++];
+    p_date_time->day     = p_encoded_data[pos++];
+    p_date_time->hours   = p_encoded_data[pos++];
+    p_date_time->minutes = p_encoded_data[pos++];
+    p_date_time->seconds = p_encoded_data[pos++];
+
+    return pos;
+}
+
+#endif // APP_UTIL_BDS_H__
+
+/** @} */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f06c2d2b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util_platform.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util_platform.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util_platform.c
new file mode 100644
index 0000000..5e8c0ad
--- /dev/null
+++ b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util_platform.c
@@ -0,0 +1,60 @@
+/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+#include "app_util_platform.h"
+
+static uint32_t m_in_critical_region = 0;
+
+void app_util_disable_irq(void)
+{
+    __disable_irq();    
+    m_in_critical_region++;    
+}
+
+void app_util_enable_irq(void)
+{
+    m_in_critical_region--;    
+    if (m_in_critical_region == 0)
+    {
+        __enable_irq();
+    }
+}
+
+void app_util_critical_region_enter(uint8_t *p_nested)
+{
+#ifdef NRF52
+    ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
+#endif
+
+#if defined(SOFTDEVICE_PRESENT)
+    /* return value can be safely ignored */
+    (void) sd_nvic_critical_region_enter(p_nested);
+#else
+    app_util_disable_irq();
+#endif
+}
+
+void app_util_critical_region_exit(uint8_t nested)
+{
+#ifdef NRF52
+    ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
+#endif
+
+#if defined(SOFTDEVICE_PRESENT)
+    /* return value can be safely ignored */
+    (void) sd_nvic_critical_region_exit(nested);
+#else
+    app_util_enable_irq();
+#endif
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f06c2d2b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util_platform.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util_platform.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util_platform.h
new file mode 100644
index 0000000..e0142ae
--- /dev/null
+++ b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/app_util_platform.h
@@ -0,0 +1,211 @@
+/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+/**@file
+ *
+ * @defgroup app_util_platform Utility Functions and Definitions (Platform)
+ * @{
+ * @ingroup app_common
+ *
+ * @brief Various types and definitions available to all applications when using SoftDevice.
+ */
+
+#ifndef APP_UTIL_PLATFORM_H__
+#define APP_UTIL_PLATFORM_H__
+
+#include <stdint.h>
+#include "compiler_abstraction.h"
+#include "nrf.h"
+#ifdef SOFTDEVICE_PRESENT
+#include "nrf_soc.h"
+#include "nrf_nvic.h"
+#endif
+#include "nrf_assert.h"
+#include "app_error.h"
+
+#if defined(NRF51)
+#define _PRIO_SD_HIGH       0
+#define _PRIO_APP_HIGH      1
+#define _PRIO_APP_MID       1
+#define _PRIO_SD_LOW        2
+#define _PRIO_APP_LOW       3
+#define _PRIO_APP_LOWEST    3
+#define _PRIO_THREAD        4
+#elif defined(NRF52)
+#define _PRIO_SD_HIGH       0
+#define _PRIO_SD_MID        1
+#define _PRIO_APP_HIGH      2
+#define _PRIO_APP_MID       3
+#define _PRIO_SD_LOW        4
+#define _PRIO_SD_LOWEST     5
+#define _PRIO_APP_LOW       6
+#define _PRIO_APP_LOWEST    7
+#define _PRIO_THREAD        15
+#else
+    #error "No platform defined"
+#endif
+
+/**@brief The interrupt priorities available to the application while the SoftDevice is active. */
+typedef enum
+{
+#ifdef SOFTDEVICE_PRESENT
+    APP_IRQ_PRIORITY_HIGHEST = _PRIO_SD_HIGH,
+#else
+    APP_IRQ_PRIORITY_HIGHEST = _PRIO_APP_HIGH,
+#endif
+    APP_IRQ_PRIORITY_HIGH    = _PRIO_APP_HIGH,
+#ifndef SOFTDEVICE_PRESENT
+    APP_IRQ_PRIORITY_MID     = _PRIO_SD_LOW,
+#else
+    APP_IRQ_PRIORITY_MID     = _PRIO_APP_MID,
+#endif
+    APP_IRQ_PRIORITY_LOW     = _PRIO_APP_LOW,
+    APP_IRQ_PRIORITY_LOWEST  = _PRIO_APP_LOWEST,
+    APP_IRQ_PRIORITY_THREAD  = _PRIO_THREAD     /**< "Interrupt level" when running in Thread Mode. */
+} app_irq_priority_t;
+
+/*@brief The privilege levels available to applications in Thread Mode */
+typedef enum
+{
+    APP_LEVEL_UNPRIVILEGED,
+    APP_LEVEL_PRIVILEGED
+} app_level_t;
+
+/**@cond NO_DOXYGEN */
+#define EXTERNAL_INT_VECTOR_OFFSET 16
+/**@endcond */
+
+#define PACKED(TYPE) __packed TYPE
+
+void app_util_critical_region_enter (uint8_t *p_nested);
+void app_util_critical_region_exit (uint8_t nested);
+
+/**@brief Macro for entering a critical region.
+ *
+ * @note Due to implementation details, there must exist one and only one call to
+ *       CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
+ *       in the same scope.
+ */
+#ifdef SOFTDEVICE_PRESENT
+#define CRITICAL_REGION_ENTER()                                                             \
+    {                                                                                       \
+        uint8_t __CR_NESTED = 0;                                                            \
+        app_util_critical_region_enter(&__CR_NESTED);
+#else
+#define CRITICAL_REGION_ENTER() app_util_critical_region_enter(NULL)
+#endif
+
+/**@brief Macro for leaving a critical region.
+ *
+ * @note Due to implementation details, there must exist one and only one call to
+ *       CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
+ *       in the same scope.
+ */
+#ifdef SOFTDEVICE_PRESENT
+#define CRITICAL_REGION_EXIT()                                                              \
+        app_util_critical_region_exit(__CR_NESTED);                                         \
+    }
+#else
+#define CRITICAL_REGION_EXIT() app_util_critical_region_exit(0)
+#endif 
+
+/* Workaround for Keil 4 */
+#ifndef IPSR_ISR_Msk
+#define IPSR_ISR_Msk                       (0x1FFUL /*<< IPSR_ISR_Pos*/)                  /*!< IPSR: ISR Mask */
+#endif
+       
+
+
+/**@brief Macro to enable anonymous unions from a certain point in the code.
+ */
+#if defined(__CC_ARM)
+    #define ANON_UNIONS_ENABLE _Pragma("push") \
+                               _Pragma("anon_unions")
+#elif defined(__ICCARM__)
+    #define ANON_UNIONS_ENABLE _Pragma("language=extended")
+#else
+    #define ANON_UNIONS_ENABLE
+    // No action will be taken.
+    // For GCC anonymous unions are enabled by default.
+#endif
+
+/**@brief Macro to disable anonymous unions from a certain point in the code.
+ * @note Call only after first calling @ref ANON_UNIONS_ENABLE.
+ */
+#if defined(__CC_ARM)
+    #define ANON_UNIONS_DISABLE _Pragma("pop")
+#elif defined(__ICCARM__)
+    #define ANON_UNIONS_DISABLE
+    // for IAR leave anonymous unions enabled
+#else
+    #define ANON_UNIONS_DISABLE
+    // No action will be taken.
+    // For GCC anonymous unions are enabled by default.
+#endif
+
+
+/* Workaround for Keil 4 */
+#ifndef CONTROL_nPRIV_Msk
+#define CONTROL_nPRIV_Msk                  (1UL /*<< CONTROL_nPRIV_Pos*/)                 /*!< CONTROL: nPRIV Mask */
+#endif
+
+/**@brief Function for finding the current interrupt level.
+ *
+ * @return   Current interrupt level.
+ * @retval   APP_IRQ_PRIORITY_HIGH    We are running in Application High interrupt level.
+ * @retval   APP_IRQ_PRIORITY_LOW     We are running in Application Low interrupt level.
+ * @retval   APP_IRQ_PRIORITY_THREAD  We are running in Thread Mode.
+ */
+static __INLINE uint8_t current_int_priority_get(void)
+{
+    uint32_t isr_vector_num = __get_IPSR() & IPSR_ISR_Msk ;
+    if (isr_vector_num > 0)
+    {
+        int32_t irq_type = ((int32_t)isr_vector_num - EXTERNAL_INT_VECTOR_OFFSET);
+        return (NVIC_GetPriority((IRQn_Type)irq_type) & 0xFF);
+    }
+    else
+    {
+        return APP_IRQ_PRIORITY_THREAD;
+    }
+}
+
+/**@brief Function for finding out the current privilege level.
+ *
+ * @return   Current privilege level.
+ * @retval   APP_LEVEL_UNPRIVILEGED    We are running in unprivileged level.
+ * @retval   APP_LEVEL_PRIVILEGED    We are running in privileged level.
+ */
+static __INLINE uint8_t privilege_level_get(void)
+{
+#if defined(NRF51)
+    /* the Cortex-M0 has no concept of privilege */
+    return APP_LEVEL_PRIVILEGED;
+#elif defined(NRF52)
+    uint32_t isr_vector_num = __get_IPSR() & IPSR_ISR_Msk ;
+    if (0 == isr_vector_num)
+    {
+        /* Thread Mode, check nPRIV */
+        int32_t control = __get_CONTROL();
+        return control & CONTROL_nPRIV_Msk ? APP_LEVEL_UNPRIVILEGED : APP_LEVEL_PRIVILEGED;
+    }
+    else
+    {
+        /* Handler Mode, always privileged */
+        return APP_LEVEL_PRIVILEGED;
+    }
+#endif
+}
+
+#endif // APP_UTIL_PLATFORM_H__
+
+/** @} */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f06c2d2b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/common.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/common.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/common.h
new file mode 100644
index 0000000..e08d52d
--- /dev/null
+++ b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/common.h
@@ -0,0 +1,38 @@
+ /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+#ifndef COMMON_H
+#define COMMON_H
+
+/*lint ++flb "Enter library region" */
+
+#include <stdbool.h>
+#include <stdint.h>
+
+/* @file
+* @brief Common header file for generic macros and definitions
+ *
+ */
+
+/*
+ * GPIO glue macros, this can be used to define a pin number in source/header file and use that macro for pin
+ * configuration using this expansion.
+ * example:
+ * #define RESET_PIN    8
+ * NRF_GPIO->PINCNF(RESET_PIN) = XXX  ;  // Expanded NRF_GPIO->PIN_CNF[8] = XXX
+ */
+#define PINX_GLUE(x, y, z)       x##y##_##z            /*!< first level glue for pin macros */
+#define PINCNF(p)                PINX_GLUE(PIN,p,CNF)  /*!< gpio configure pin number 'p' */
+#define PINOUT(p)                PINX_GLUE(PIN,p,OUT)  /*!< gpio out pin number 'p' */
+
+/*lint --flb "Leave library region" */
+#endif