Nordic nrf51 sdk sources. Mirrored from https://github.com/ARMmbed/nrf51-sdk.

Dependents:   nRF51822 nRF51822

Files at this revision

API Documentation at this revision

Comitter:
vcoubard
Date:
Thu Apr 07 17:37:46 2016 +0100
Parent:
20:a90c48eb1d30
Child:
22:67a8d2c0bbbf
Commit message:
Synchronized with git rev 9da4af9c
Author: Liyou Zhou
Port all modification made to noridc files

Changed in this revision

source/nordic_sdk/components/ble/common/ble_conn_params.c Show diff for this revision Revisions of this file
source/nordic_sdk/components/ble/common/ble_conn_params.cpp Show annotated file Show diff for this revision Revisions of this file
source/nordic_sdk/components/ble/device_manager/config/device_manager_cnfg.h Show annotated file Show diff for this revision Revisions of this file
source/nordic_sdk/components/ble/device_manager/device_manager_peripheral.c Show annotated file Show diff for this revision Revisions of this file
source/nordic_sdk/components/device/nrf51.h Show annotated file Show diff for this revision Revisions of this file
source/nordic_sdk/components/drivers_nrf/hal/nrf_delay.h Show annotated file Show diff for this revision Revisions of this file
source/nordic_sdk/components/libraries/bootloader_dfu/dfu_init_template.c Show annotated file Show diff for this revision Revisions of this file
source/nordic_sdk/components/softdevice/common/softdevice_handler/ble_stack_handler_types.h Show annotated file Show diff for this revision Revisions of this file
source/nordic_sdk/components/softdevice/s130/headers/ble_gap.h Show annotated file Show diff for this revision Revisions of this file
source/nordic_sdk/components/softdevice/s130/headers/ble_types.h Show annotated file Show diff for this revision Revisions of this file
source/nordic_sdk/components/softdevice/s130/headers/nrf_svc.h Show annotated file Show diff for this revision Revisions of this file
--- a/source/nordic_sdk/components/ble/common/ble_conn_params.c	Thu Apr 07 17:37:45 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,343 +0,0 @@
-/*
- * Copyright (c) Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright notice, this
- *   list of conditions and the following disclaimer in the documentation and/or
- *   other materials provided with the distribution.
- *
- *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
- *   contributors to this software may be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "ble_conn_params.h"
-#include <stdlib.h>
-#include "nordic_common.h"
-#include "ble_hci.h"
-#include "app_timer.h"
-#include "ble_srv_common.h"
-#include "app_util.h"
-
-
-static ble_conn_params_init_t m_conn_params_config;     /**< Configuration as specified by the application. */
-static ble_gap_conn_params_t  m_preferred_conn_params;  /**< Connection parameters preferred by the application. */
-static uint8_t                m_update_count;           /**< Number of Connection Parameter Update messages that has currently been sent. */
-static uint16_t               m_conn_handle;            /**< Current connection handle. */
-static ble_gap_conn_params_t  m_current_conn_params;    /**< Connection parameters received in the most recent Connect event. */
-static app_timer_id_t         m_conn_params_timer_id;   /**< Connection parameters timer. */
-
-static bool m_change_param = false;
-
-static bool is_conn_params_ok(ble_gap_conn_params_t * p_conn_params)
-{
-    // Check if interval is within the acceptable range.
-    // NOTE: Using max_conn_interval in the received event data because this contains
-    //       the client's connection interval.
-    if (
-        (p_conn_params->max_conn_interval >= m_preferred_conn_params.min_conn_interval)
-        && 
-        (p_conn_params->max_conn_interval <= m_preferred_conn_params.max_conn_interval)
-       )
-    {
-        return true;
-    }
-    else
-    {
-        return false;
-    }
-}
-
-
-static void update_timeout_handler(void * p_context)
-{
-    UNUSED_PARAMETER(p_context);
-
-    if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
-    {
-        // Check if we have reached the maximum number of attempts
-        m_update_count++;
-        if (m_update_count <= m_conn_params_config.max_conn_params_update_count)
-        {
-            uint32_t err_code;
-
-            // Parameters are not ok, send connection parameters update request.
-            err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params);
-            if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
-            {
-                m_conn_params_config.error_handler(err_code);
-            }
-        }
-        else
-        {
-            m_update_count = 0;
-
-            // Negotiation failed, disconnect automatically if this has been configured
-            if (m_conn_params_config.disconnect_on_fail)
-            {
-                uint32_t err_code;
-
-                err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
-                if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
-                {
-                    m_conn_params_config.error_handler(err_code);
-                }
-            }
-
-            // Notify the application that the procedure has failed
-            if (m_conn_params_config.evt_handler != NULL)
-            {
-                ble_conn_params_evt_t evt;
-
-                evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED;
-                m_conn_params_config.evt_handler(&evt);
-            }
-        }
-    }
-}
-
-
-uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init)
-{
-    uint32_t err_code;
-
-    m_conn_params_config = *p_init;
-    m_change_param = false;
-    if (p_init->p_conn_params != NULL)
-    {
-        m_preferred_conn_params = *p_init->p_conn_params;
-
-        // Set the connection params in stack
-        err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-    }
-    else
-    {
-        // Fetch the connection params from stack
-        err_code = sd_ble_gap_ppcp_get(&m_preferred_conn_params);
-        if (err_code != NRF_SUCCESS)
-        {
-            return err_code;
-        }
-    }
-
-    m_conn_handle  = BLE_CONN_HANDLE_INVALID;
-    m_update_count = 0;
-
-    return app_timer_create(&m_conn_params_timer_id,
-                            APP_TIMER_MODE_SINGLE_SHOT,
-                            update_timeout_handler);
-}
-
-
-uint32_t ble_conn_params_stop(void)
-{
-    return app_timer_stop(m_conn_params_timer_id);
-}
-
-
-static void conn_params_negotiation(void)
-{
-    // Start negotiation if the received connection parameters are not acceptable
-    if (!is_conn_params_ok(&m_current_conn_params))
-    {
-        uint32_t err_code;
-        uint32_t timeout_ticks;
-
-        if (m_change_param)
-        {
-            // Notify the application that the procedure has failed
-            if (m_conn_params_config.evt_handler != NULL)
-            {
-                ble_conn_params_evt_t evt;
-
-                evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED;
-                m_conn_params_config.evt_handler(&evt);
-            }
-        }
-        else
-        {
-            if (m_update_count == 0)
-            {
-                // First connection parameter update
-                timeout_ticks = m_conn_params_config.first_conn_params_update_delay;
-            }
-            else
-            {
-                timeout_ticks = m_conn_params_config.next_conn_params_update_delay;
-            }
-
-            err_code = app_timer_start(m_conn_params_timer_id, timeout_ticks, NULL);
-            if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
-            {
-                m_conn_params_config.error_handler(err_code);
-            }
-        }
-    }
-    else
-    {
-        // Notify the application that the procedure has succeded
-        if (m_conn_params_config.evt_handler != NULL)
-        {
-            ble_conn_params_evt_t evt;
-
-            evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED;
-            m_conn_params_config.evt_handler(&evt);
-        }
-    }
-    m_change_param = false;
-}
-
-
-static void on_connect(ble_evt_t * p_ble_evt)
-{
-    // Save connection parameters
-    m_conn_handle         = p_ble_evt->evt.gap_evt.conn_handle;
-    m_current_conn_params = p_ble_evt->evt.gap_evt.params.connected.conn_params;
-    m_update_count        = 0;  // Connection parameter negotiation should re-start every connection
-
-    // Check if we shall handle negotiation on connect
-    if (m_conn_params_config.start_on_notify_cccd_handle == BLE_GATT_HANDLE_INVALID)
-    {
-        conn_params_negotiation();
-    }
-}
-
-
-static void on_disconnect(ble_evt_t * p_ble_evt)
-{
-    uint32_t err_code;
-
-    m_conn_handle = BLE_CONN_HANDLE_INVALID;
-
-    // Stop timer if running
-    m_update_count = 0; // Connection parameters updates should happen during every connection
-
-    err_code = app_timer_stop(m_conn_params_timer_id);
-    if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
-    {
-        m_conn_params_config.error_handler(err_code);
-    }
-}
-
-
-static void on_write(ble_evt_t * p_ble_evt)
-{
-    ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
-
-    // Check if this the correct CCCD
-    if (
-        (p_evt_write->handle == m_conn_params_config.start_on_notify_cccd_handle)
-        &&
-        (p_evt_write->len == 2)
-       )
-    {
-        // Check if this is a 'start notification'
-        if (ble_srv_is_notification_enabled(p_evt_write->data))
-        {
-            // Do connection parameter negotiation if necessary
-            conn_params_negotiation();
-        }
-        else
-        {
-            uint32_t err_code;
-
-            // Stop timer if running
-            err_code = app_timer_stop(m_conn_params_timer_id);
-            if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
-            {
-                m_conn_params_config.error_handler(err_code);
-            }
-        }
-    }
-}
-
-
-static void on_conn_params_update(ble_evt_t * p_ble_evt)
-{
-    // Copy the parameters
-    m_current_conn_params = p_ble_evt->evt.gap_evt.params.conn_param_update.conn_params;
-
-    conn_params_negotiation();
-}
-
-
-void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt)
-{
-    switch (p_ble_evt->header.evt_id)
-    {
-        case BLE_GAP_EVT_CONNECTED:
-            on_connect(p_ble_evt);
-            break;
-
-        case BLE_GAP_EVT_DISCONNECTED:
-            on_disconnect(p_ble_evt);
-            break;
-
-        case BLE_GATTS_EVT_WRITE:
-            on_write(p_ble_evt);
-            break;
-
-        case BLE_GAP_EVT_CONN_PARAM_UPDATE:
-            on_conn_params_update(p_ble_evt);
-            break;
-
-        default:
-            // No implementation needed.
-            break;
-    }
-}
-
-
-uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t * new_params)
-{
-    uint32_t err_code;
-
-    m_preferred_conn_params = *new_params;
-    // Set the connection params in stack
-    err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params);
-    if (err_code == NRF_SUCCESS)
-    {
-        if (!is_conn_params_ok(&m_current_conn_params))
-        {
-            m_change_param = true;
-            err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params);
-            m_update_count = 1;
-        }
-        else
-        {
-            // Notify the application that the procedure has succeded
-            if (m_conn_params_config.evt_handler != NULL)
-            {
-                ble_conn_params_evt_t evt;
-
-                evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED;
-                m_conn_params_config.evt_handler(&evt);
-            }
-            err_code = NRF_SUCCESS;
-        }
-    }
-    return err_code;
-}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/nordic_sdk/components/ble/common/ble_conn_params.cpp	Thu Apr 07 17:37:46 2016 +0100
@@ -0,0 +1,382 @@
+/*
+ * Copyright (c) Nordic Semiconductor ASA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright notice, this
+ *   list of conditions and the following disclaimer in the documentation and/or
+ *   other materials provided with the distribution.
+ *
+ *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
+ *   contributors to this software may be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "ble_conn_params.h"
+#include <stdlib.h>
+#include "nordic_common.h"
+#include "ble_hci.h"
+#include "ble_srv_common.h"
+#include "app_util.h"
+
+#ifdef USE_APP_TIMER
+#include "app_timer.h"
+#else
+#include "mbed.h"
+#endif
+
+static ble_conn_params_init_t m_conn_params_config;     /**< Configuration as specified by the application. */
+static ble_gap_conn_params_t  m_preferred_conn_params;  /**< Connection parameters preferred by the application. */
+static uint8_t                m_update_count;           /**< Number of Connection Parameter Update messages that has currently been sent. */
+static uint16_t               m_conn_handle;            /**< Current connection handle. */
+static ble_gap_conn_params_t  m_current_conn_params;    /**< Connection parameters received in the most recent Connect event. */
+#ifdef USE_APP_TIMER
+static app_timer_id_t         m_conn_params_timer_id;   /**< Connection parameters timer. */
+#else
+static Ticker                 m_conn_params_timer;
+#endif
+
+static bool m_change_param = false;
+
+static bool is_conn_params_ok(ble_gap_conn_params_t * p_conn_params)
+{
+    // Check if interval is within the acceptable range.
+    // NOTE: Using max_conn_interval in the received event data because this contains
+    //       the client's connection interval.
+    if (
+        (p_conn_params->max_conn_interval >= m_preferred_conn_params.min_conn_interval)
+        && 
+        (p_conn_params->max_conn_interval <= m_preferred_conn_params.max_conn_interval)
+       )
+    {
+        return true;
+    }
+    else
+    {
+        return false;
+    }
+}
+
+
+#ifdef USE_APP_TIMER
+static void update_timeout_handler(void * p_context)
+{
+    UNUSED_PARAMETER(p_context);
+
+#else /* #if !USE_APP_TIMER */
+static void update_timeout_handler(void)
+{
+    m_conn_params_timer.detach(); /* this is supposed to be a single-shot timer callback */
+#endif /* #if !USE_APP_TIMER */
+    if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
+    {
+        // Check if we have reached the maximum number of attempts
+        m_update_count++;
+        if (m_update_count <= m_conn_params_config.max_conn_params_update_count)
+        {
+            uint32_t err_code;
+
+            // Parameters are not ok, send connection parameters update request.
+            err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params);
+            if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
+            {
+                m_conn_params_config.error_handler(err_code);
+            }
+        }
+        else
+        {
+            m_update_count = 0;
+
+            // Negotiation failed, disconnect automatically if this has been configured
+            if (m_conn_params_config.disconnect_on_fail)
+            {
+                uint32_t err_code;
+
+                err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
+                if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
+                {
+                    m_conn_params_config.error_handler(err_code);
+                }
+            }
+
+            // Notify the application that the procedure has failed
+            if (m_conn_params_config.evt_handler != NULL)
+            {
+                ble_conn_params_evt_t evt;
+
+                evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED;
+                m_conn_params_config.evt_handler(&evt);
+            }
+        }
+    }
+}
+
+
+uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init)
+{
+    uint32_t err_code;
+
+    m_conn_params_config = *p_init;
+    m_change_param = false;
+    if (p_init->p_conn_params != NULL)
+    {
+        m_preferred_conn_params = *p_init->p_conn_params;
+
+        // Set the connection params in stack
+        err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params);
+        if (err_code != NRF_SUCCESS)
+        {
+            return err_code;
+        }
+    }
+    else
+    {
+        // Fetch the connection params from stack
+        err_code = sd_ble_gap_ppcp_get(&m_preferred_conn_params);
+        if (err_code != NRF_SUCCESS)
+        {
+            return err_code;
+        }
+    }
+
+    m_conn_handle  = BLE_CONN_HANDLE_INVALID;
+    m_update_count = 0;
+
+#ifdef USE_APP_TIMER
+    return app_timer_create(&m_conn_params_timer_id,
+                            APP_TIMER_MODE_SINGLE_SHOT,
+                            update_timeout_handler);
+#else
+    return NRF_SUCCESS;
+#endif
+}
+
+
+uint32_t ble_conn_params_stop(void)
+{
+#ifdef USE_APP_TIMER
+    return app_timer_stop(m_conn_params_timer_id);
+#else /* #if !USE_APP_TIMER */
+    m_conn_params_timer.detach();
+    return NRF_SUCCESS;
+#endif /* #if !USE_APP_TIMER */
+}
+
+
+static void conn_params_negotiation(void)
+{
+    // Start negotiation if the received connection parameters are not acceptable
+    if (!is_conn_params_ok(&m_current_conn_params))
+    {
+#ifdef USE_APP_TIMER
+        uint32_t err_code;
+#endif
+        uint32_t timeout_ticks;
+
+        if (m_change_param)
+        {
+            // Notify the application that the procedure has failed
+            if (m_conn_params_config.evt_handler != NULL)
+            {
+                ble_conn_params_evt_t evt;
+
+                evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED;
+                m_conn_params_config.evt_handler(&evt);
+            }
+        }
+        else
+        {
+            if (m_update_count == 0)
+            {
+                // First connection parameter update
+                timeout_ticks = m_conn_params_config.first_conn_params_update_delay;
+            }
+            else
+            {
+                timeout_ticks = m_conn_params_config.next_conn_params_update_delay;
+            }
+
+#ifdef USE_APP_TIMER
+            err_code = app_timer_start(m_conn_params_timer_id, timeout_ticks, NULL);
+            if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
+            {
+                m_conn_params_config.error_handler(err_code);
+            }
+#else
+            m_conn_params_timer.attach(update_timeout_handler, timeout_ticks / 32768);
+#endif
+        }
+    }
+    else
+    {
+        // Notify the application that the procedure has succeded
+        if (m_conn_params_config.evt_handler != NULL)
+        {
+            ble_conn_params_evt_t evt;
+
+            evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED;
+            m_conn_params_config.evt_handler(&evt);
+        }
+    }
+    m_change_param = false;
+}
+
+
+static void on_connect(ble_evt_t * p_ble_evt)
+{
+    // Save connection parameters
+    m_conn_handle         = p_ble_evt->evt.gap_evt.conn_handle;
+    m_current_conn_params = p_ble_evt->evt.gap_evt.params.connected.conn_params;
+    m_update_count        = 0;  // Connection parameter negotiation should re-start every connection
+
+    // Check if we shall handle negotiation on connect
+    if (m_conn_params_config.start_on_notify_cccd_handle == BLE_GATT_HANDLE_INVALID)
+    {
+        conn_params_negotiation();
+    }
+}
+
+
+static void on_disconnect(ble_evt_t * p_ble_evt)
+{
+#ifdef USE_APP_TIMER
+    uint32_t err_code;
+#endif
+
+    m_conn_handle = BLE_CONN_HANDLE_INVALID;
+
+    // Stop timer if running
+    m_update_count = 0; // Connection parameters updates should happen during every connection
+
+#ifdef USE_APP_TIMER
+    err_code = app_timer_stop(m_conn_params_timer_id);
+    if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
+    {
+        m_conn_params_config.error_handler(err_code);
+    }
+#else
+    m_conn_params_timer.detach();
+#endif
+}
+
+
+static void on_write(ble_evt_t * p_ble_evt)
+{
+    ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
+
+    // Check if this the correct CCCD
+    if (
+        (p_evt_write->handle == m_conn_params_config.start_on_notify_cccd_handle)
+        &&
+        (p_evt_write->len == 2)
+       )
+    {
+        // Check if this is a 'start notification'
+        if (ble_srv_is_notification_enabled(p_evt_write->data))
+        {
+            // Do connection parameter negotiation if necessary
+            conn_params_negotiation();
+        }
+        else
+        {
+#ifdef USE_APP_TIMER
+            uint32_t err_code;
+
+            // Stop timer if running
+            err_code = app_timer_stop(m_conn_params_timer_id);
+            if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
+            {
+                m_conn_params_config.error_handler(err_code);
+            }
+#else /* #if !USE_APP_TIMER */
+            m_conn_params_timer.detach();
+#endif /* #if !USE_APP_TIMER */
+        }
+    }
+}
+
+
+static void on_conn_params_update(ble_evt_t * p_ble_evt)
+{
+    // Copy the parameters
+    m_current_conn_params = p_ble_evt->evt.gap_evt.params.conn_param_update.conn_params;
+
+    conn_params_negotiation();
+}
+
+
+void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt)
+{
+    switch (p_ble_evt->header.evt_id)
+    {
+        case BLE_GAP_EVT_CONNECTED:
+            on_connect(p_ble_evt);
+            break;
+
+        case BLE_GAP_EVT_DISCONNECTED:
+            on_disconnect(p_ble_evt);
+            break;
+
+        case BLE_GATTS_EVT_WRITE:
+            on_write(p_ble_evt);
+            break;
+
+        case BLE_GAP_EVT_CONN_PARAM_UPDATE:
+            on_conn_params_update(p_ble_evt);
+            break;
+
+        default:
+            // No implementation needed.
+            break;
+    }
+}
+
+
+uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t * new_params)
+{
+    uint32_t err_code;
+
+    m_preferred_conn_params = *new_params;
+    // Set the connection params in stack
+    err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params);
+    if (err_code == NRF_SUCCESS)
+    {
+        if (!is_conn_params_ok(&m_current_conn_params))
+        {
+            m_change_param = true;
+            err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params);
+            m_update_count = 1;
+        }
+        else
+        {
+            // Notify the application that the procedure has succeded
+            if (m_conn_params_config.evt_handler != NULL)
+            {
+                ble_conn_params_evt_t evt;
+
+                evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED;
+                m_conn_params_config.evt_handler(&evt);
+            }
+            err_code = NRF_SUCCESS;
+        }
+    }
+    return err_code;
+}
\ No newline at end of file
--- a/source/nordic_sdk/components/ble/device_manager/config/device_manager_cnfg.h	Thu Apr 07 17:37:45 2016 +0100
+++ b/source/nordic_sdk/components/ble/device_manager/config/device_manager_cnfg.h	Thu Apr 07 17:37:46 2016 +0100
@@ -85,7 +85,7 @@
  *       be stored. In such cases, application will be notified with DM_DEVICE_CONTEXT_FULL 
  *       as event result at the completion of the security procedure.
  */
-#define DEVICE_MANAGER_MAX_BONDS         7
+#define DEVICE_MANAGER_MAX_BONDS         2
 
 
 /**
--- a/source/nordic_sdk/components/ble/device_manager/device_manager_peripheral.c	Thu Apr 07 17:37:45 2016 +0100
+++ b/source/nordic_sdk/components/ble/device_manager/device_manager_peripheral.c	Thu Apr 07 17:37:46 2016 +0100
@@ -31,7 +31,6 @@
  */
 
 #include "device_manager.h"
-#include "app_trace.h"
 #include "pstorage.h"
 #include "ble_hci.h"
 #include "app_error.h"
@@ -162,7 +161,7 @@
  * @note That if ENABLE_DEBUG_LOG_SUPPORT is disabled, having DM_DISABLE_LOGS has no effect.
  * @{
  */
-#define nDM_DISABLE_LOGS        /**< Enable this macro to disable any logs from this module. */
+#define DM_DISABLE_LOGS        /**< Enable this macro to disable any logs from this module. */
 
 #ifndef DM_DISABLE_LOGS
 #define DM_LOG  app_trace_log  /**< Used for logging details. */
--- a/source/nordic_sdk/components/device/nrf51.h	Thu Apr 07 17:37:45 2016 +0100
+++ b/source/nordic_sdk/components/device/nrf51.h	Thu Apr 07 17:37:46 2016 +0100
@@ -30,60 +30,6 @@
  *
  */
 
-
-/****************************************************************************************************//**
- * @file     nrf51.h
- *
- * @brief    CMSIS Cortex-M0 Peripheral Access Layer Header File for
- *           nrf51 from Nordic Semiconductor.
- *
- * @version  V522
- * @date     15. June 2015
- *
- * @note     Generated with SVDConv V2.81d 
- *           from CMSIS SVD File 'nrf51.xml' Version 522,
- *
- * @par      Copyright (c) 2013, Nordic Semiconductor ASA
- *           All rights reserved.
- *           
- *           Redistribution and use in source and binary forms, with or without
- *           modification, are permitted provided that the following conditions are met:
- *           
- *           * Redistributions of source code must retain the above copyright notice, this
- *           list of conditions and the following disclaimer.
- *           
- *           * Redistributions in binary form must reproduce the above copyright notice,
- *           this list of conditions and the following disclaimer in the documentation
- *           and/or other materials provided with the distribution.
- *           
- *           * Neither the name of Nordic Semiconductor ASA nor the names of its
- *           contributors may be used to endorse or promote products derived from
- *           this software without specific prior written permission.
- *           
- *           THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- *           AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- *           IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *           DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- *           FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- *           DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- *           SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- *           CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- *           OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *           OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *           
- *
- *******************************************************************************************************/
-
-
-
-/** @addtogroup Nordic Semiconductor
-  * @{
-  */
-
-/** @addtogroup nrf51
-  * @{
-  */
-
 #ifndef NRF51_H
 #define NRF51_H
 
--- a/source/nordic_sdk/components/drivers_nrf/hal/nrf_delay.h	Thu Apr 07 17:37:45 2016 +0100
+++ b/source/nordic_sdk/components/drivers_nrf/hal/nrf_delay.h	Thu Apr 07 17:37:46 2016 +0100
@@ -35,6 +35,8 @@
 
 #include "nrf.h"
 
+#define asm __ASM
+
 /*lint --e{438, 522} "Variable not used" "Function lacks side-effects" */
 #if defined ( __CC_ARM   )
 static __ASM void __INLINE nrf_delay_us(uint32_t volatile number_of_us)
--- a/source/nordic_sdk/components/libraries/bootloader_dfu/dfu_init_template.c	Thu Apr 07 17:37:45 2016 +0100
+++ b/source/nordic_sdk/components/libraries/bootloader_dfu/dfu_init_template.c	Thu Apr 07 17:37:46 2016 +0100
@@ -151,6 +151,7 @@
 
 uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len)
 {
+#if NEED_CRC_CHECK /* disabled for now */
     uint16_t image_crc;
     uint16_t received_crc;
     
@@ -169,6 +170,7 @@
     {
         return NRF_ERROR_INVALID_DATA;
     }
+#endif /* NEED_CRC_CHECK */
 
     return NRF_SUCCESS;
 }
--- a/source/nordic_sdk/components/softdevice/common/softdevice_handler/ble_stack_handler_types.h	Thu Apr 07 17:37:45 2016 +0100
+++ b/source/nordic_sdk/components/softdevice/common/softdevice_handler/ble_stack_handler_types.h	Thu Apr 07 17:37:46 2016 +0100
@@ -42,6 +42,7 @@
 #ifndef BLE_STACK_HANDLER_TYPES_H__
 #define BLE_STACK_HANDLER_TYPES_H__
 
+#define BLE_STACK_SUPPORT_REQD
 #ifdef BLE_STACK_SUPPORT_REQD
 
 #include <stdlib.h>
--- a/source/nordic_sdk/components/softdevice/s130/headers/ble_gap.h	Thu Apr 07 17:37:45 2016 +0100
+++ b/source/nordic_sdk/components/softdevice/s130/headers/ble_gap.h	Thu Apr 07 17:37:46 2016 +0100
@@ -547,7 +547,9 @@
 {
   ble_gap_addr_t        peer_addr;              /**< Bluetooth address of the peer device. */
   ble_gap_addr_t        own_addr;               /**< Bluetooth address of the local device used during connection setup. */
+#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
   uint8_t               role;                   /**< BLE role for this connection, see @ref BLE_GAP_ROLES */
+#endif
   uint8_t               irk_match :1;           /**< If 1, peer device's address resolved using an IRK. */
   uint8_t               irk_match_idx  :7;      /**< Index in IRK list where the address was matched. */
   ble_gap_conn_params_t conn_params;            /**< GAP Connection Parameters. */
--- a/source/nordic_sdk/components/softdevice/s130/headers/ble_types.h	Thu Apr 07 17:37:45 2016 +0100
+++ b/source/nordic_sdk/components/softdevice/s130/headers/ble_types.h	Thu Apr 07 17:37:46 2016 +0100
@@ -54,6 +54,7 @@
 /** @} */
 
 
+#if 0 /* The following have been duplicated in blecommon.h */
 /** @defgroup BLE_UUID_VALUES Assigned Values for BLE UUIDs
  * @{ */
 /* Generic UUIDs, applicable to all services */
@@ -79,6 +80,7 @@
 #define BLE_UUID_GAP_CHARACTERISTIC_RECONN_ADDR       0x2A03 /**< Reconnection Address Characteristic. */
 #define BLE_UUID_GAP_CHARACTERISTIC_PPCP              0x2A04 /**< Peripheral Preferred Connection Parameters Characteristic. */
 /** @} */
+#endif /* The following have been duplicated in blecommon.h */
 
 
 /** @defgroup BLE_UUID_TYPES Types of UUID
@@ -89,6 +91,7 @@
 /** @} */
 
 
+#if 0 /* The following have been duplicated in blecommon.h */
 /** @defgroup BLE_APPEARANCES Bluetooth Appearance values
  *  @note Retrieved from http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml
  * @{ */
@@ -142,6 +145,7 @@
 #define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_POD          5187 /**< Location Pod (Outdoor Sports Activity subtype). */
 #define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_AND_NAV_POD  5188 /**< Location and Navigation Pod (Outdoor Sports Activity subtype). */
 /** @} */
+#endif /* The following have been duplicated in blecommon.h */
 
 /** @brief Set .type and .uuid fields of ble_uuid_struct to specified uuid value. */
 #define BLE_UUID_BLE_ASSIGN(instance, value) do {\
--- a/source/nordic_sdk/components/softdevice/s130/headers/nrf_svc.h	Thu Apr 07 17:37:45 2016 +0100
+++ b/source/nordic_sdk/components/softdevice/s130/headers/nrf_svc.h	Thu Apr 07 17:37:46 2016 +0100
@@ -43,13 +43,14 @@
 #elif defined (__GNUC__)
 #define SVCALL(number, return_type, signature) \
   _Pragma("GCC diagnostic ignored \"-Wunused-function\"") \
+  _Pragma("GCC diagnostic ignored \"-Wunused-parameter\"") \
   _Pragma("GCC diagnostic push") \
   _Pragma("GCC diagnostic ignored \"-Wreturn-type\"") \
   __attribute__((naked)) static return_type signature \
   { \
     __asm( \
         "svc %0\n" \
-        "bx r14" : : "I" (number) : "r0" \
+        "bx r14" : : "I" ((uint32_t) number) : "r0" \
     ); \
   }    \
   _Pragma("GCC diagnostic pop")