remove sd common files (not used)
This commit is contained in:
		@@ -1,430 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
 * Copyright (c) 2017 - 2018, 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, except as embedded into a Nordic
 | 
					 | 
				
			||||||
 *    Semiconductor ASA integrated circuit in a product or a software update for
 | 
					 | 
				
			||||||
 *    such product, 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 its
 | 
					 | 
				
			||||||
 *    contributors may be used to endorse or promote products derived from this
 | 
					 | 
				
			||||||
 *    software without specific prior written permission.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * 4. This software, with or without modification, must only be used with a
 | 
					 | 
				
			||||||
 *    Nordic Semiconductor ASA integrated circuit.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * 5. Any software provided in binary form under this license must not be reverse
 | 
					 | 
				
			||||||
 *    engineered, decompiled, modified and/or disassembled.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
 | 
					 | 
				
			||||||
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 | 
					 | 
				
			||||||
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 | 
					 | 
				
			||||||
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 "sdk_common.h"
 | 
					 | 
				
			||||||
#if NRF_MODULE_ENABLED(NRF_SDH)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "nrf_sdh.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <stdint.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "nrf_sdm.h"
 | 
					 | 
				
			||||||
#include "nrf_nvic.h"
 | 
					 | 
				
			||||||
#include "sdk_config.h"
 | 
					 | 
				
			||||||
#include "app_error.h"
 | 
					 | 
				
			||||||
#include "app_util_platform.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define NRF_LOG_MODULE_NAME nrf_sdh
 | 
					 | 
				
			||||||
#if NRF_SDH_LOG_ENABLED
 | 
					 | 
				
			||||||
    #define NRF_LOG_LEVEL       NRF_SDH_LOG_LEVEL
 | 
					 | 
				
			||||||
    #define NRF_LOG_INFO_COLOR  NRF_SDH_INFO_COLOR
 | 
					 | 
				
			||||||
    #define NRF_LOG_DEBUG_COLOR NRF_SDH_DEBUG_COLOR
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    #define NRF_LOG_LEVEL       0
 | 
					 | 
				
			||||||
#endif // NRF_SDH_LOG_ENABLED
 | 
					 | 
				
			||||||
#include "nrf_log.h"
 | 
					 | 
				
			||||||
NRF_LOG_MODULE_REGISTER();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Validate configuration options.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if (NRF_SDH_DISPATCH_MODEL == NRF_SDH_DISPATCH_MODEL_APPSH)
 | 
					 | 
				
			||||||
    #if (!APP_SCHEDULER_ENABLED)
 | 
					 | 
				
			||||||
        #error app_scheduler is required when NRF_SDH_DISPATCH_MODEL is set to NRF_SDH_DISPATCH_MODEL_APPSH
 | 
					 | 
				
			||||||
    #endif
 | 
					 | 
				
			||||||
    #include "app_scheduler.h"
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if (   (NRF_SDH_CLOCK_LF_SRC      == NRF_CLOCK_LF_SRC_RC)          \
 | 
					 | 
				
			||||||
     && (NRF_SDH_CLOCK_LF_ACCURACY != NRF_CLOCK_LF_ACCURACY_500_PPM))
 | 
					 | 
				
			||||||
    #warning Please select NRF_CLOCK_LF_ACCURACY_500_PPM when using NRF_CLOCK_LF_SRC_RC
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Create section "sdh_req_observers".
 | 
					 | 
				
			||||||
NRF_SECTION_SET_DEF(sdh_req_observers, nrf_sdh_req_observer_t, NRF_SDH_REQ_OBSERVER_PRIO_LEVELS);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Create section "sdh_state_observers".
 | 
					 | 
				
			||||||
NRF_SECTION_SET_DEF(sdh_state_observers, nrf_sdh_state_observer_t, NRF_SDH_STATE_OBSERVER_PRIO_LEVELS);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Create section "sdh_stack_observers".
 | 
					 | 
				
			||||||
NRF_SECTION_SET_DEF(sdh_stack_observers, nrf_sdh_stack_observer_t, NRF_SDH_STACK_OBSERVER_PRIO_LEVELS);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static bool m_nrf_sdh_enabled;   /**< Variable to indicate whether the SoftDevice is enabled. */
 | 
					 | 
				
			||||||
static bool m_nrf_sdh_suspended; /**< Variable to indicate whether this module is suspended. */
 | 
					 | 
				
			||||||
static bool m_nrf_sdh_continue;  /**< Variable to indicate whether enable/disable process was started. */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Function for notifying request observers.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param[in]   evt     Type of request event.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static ret_code_t sdh_request_observer_notify(nrf_sdh_req_evt_t req)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    nrf_section_iter_t iter;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    NRF_LOG_DEBUG("State request: 0x%08X", req);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for (nrf_section_iter_init(&iter, &sdh_req_observers);
 | 
					 | 
				
			||||||
         nrf_section_iter_get(&iter) != NULL;
 | 
					 | 
				
			||||||
         nrf_section_iter_next(&iter))
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        nrf_sdh_req_observer_t    * p_observer;
 | 
					 | 
				
			||||||
        nrf_sdh_req_evt_handler_t   handler;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        p_observer = (nrf_sdh_req_observer_t *) nrf_section_iter_get(&iter);
 | 
					 | 
				
			||||||
        handler    = p_observer->handler;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (handler(req, p_observer->p_context))
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            NRF_LOG_DEBUG("Notify observer 0x%08X => ready", p_observer);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Process is stopped.
 | 
					 | 
				
			||||||
            NRF_LOG_DEBUG("Notify observer 0x%08X => blocking", p_observer);
 | 
					 | 
				
			||||||
            return NRF_ERROR_BUSY;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return NRF_SUCCESS;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Function for stage request observers.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param[in]   evt Type of stage event.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static void sdh_state_observer_notify(nrf_sdh_state_evt_t evt)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    nrf_section_iter_t iter;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    NRF_LOG_DEBUG("State change: 0x%08X", evt);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for (nrf_section_iter_init(&iter, &sdh_state_observers);
 | 
					 | 
				
			||||||
         nrf_section_iter_get(&iter) != NULL;
 | 
					 | 
				
			||||||
         nrf_section_iter_next(&iter))
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        nrf_sdh_state_observer_t    * p_observer;
 | 
					 | 
				
			||||||
        nrf_sdh_state_evt_handler_t   handler;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        p_observer = (nrf_sdh_state_observer_t *) nrf_section_iter_get(&iter);
 | 
					 | 
				
			||||||
        handler    = p_observer->handler;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        handler(evt, p_observer->p_context);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void softdevices_evt_irq_enable(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
#ifdef SOFTDEVICE_PRESENT
 | 
					 | 
				
			||||||
    ret_code_t ret_code = sd_nvic_EnableIRQ((IRQn_Type)SD_EVT_IRQn);
 | 
					 | 
				
			||||||
    APP_ERROR_CHECK(ret_code);
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    // In case of serialization, NVIC must be accessed directly.
 | 
					 | 
				
			||||||
    NVIC_EnableIRQ(SD_EVT_IRQn);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void softdevice_evt_irq_disable(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
#ifdef SOFTDEVICE_PRESENT
 | 
					 | 
				
			||||||
    ret_code_t ret_code = sd_nvic_DisableIRQ((IRQn_Type)SD_EVT_IRQn);
 | 
					 | 
				
			||||||
    APP_ERROR_CHECK(ret_code);
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    // In case of serialization, NVIC must be accessed directly.
 | 
					 | 
				
			||||||
    NVIC_DisableIRQ(SD_EVT_IRQn);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef S140
 | 
					 | 
				
			||||||
static void swi_interrupt_priority_workaround(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    // The priority of SoftDevice SWI SD_EVT_IRQn and RADIO_NOTIFICATION_IRQn in
 | 
					 | 
				
			||||||
    // S132 v5.0.0, S112 v5.0.0, S212 v5.0.0 and S332 v5.0.0 is set to 6.
 | 
					 | 
				
			||||||
    // Change it to APP_IRQ_PRIORITY_LOWEST (7) so that they do not preempt peripherals' interrupts.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef SOFTDEVICE_PRESENT
 | 
					 | 
				
			||||||
    ret_code_t ret_code;
 | 
					 | 
				
			||||||
    ret_code = sd_nvic_SetPriority(SD_EVT_IRQn, APP_IRQ_PRIORITY_LOWEST);
 | 
					 | 
				
			||||||
    APP_ERROR_CHECK(ret_code);
 | 
					 | 
				
			||||||
    ret_code = sd_nvic_SetPriority(RADIO_NOTIFICATION_IRQn, APP_IRQ_PRIORITY_LOWEST);
 | 
					 | 
				
			||||||
    APP_ERROR_CHECK(ret_code);
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    // In case of serialization, NVIC must be accessed directly.
 | 
					 | 
				
			||||||
    NVIC_SetPriority(SD_EVT_IRQn, APP_IRQ_PRIORITY_LOWEST);
 | 
					 | 
				
			||||||
    NVIC_SetPriority(RADIO_NOTIFICATION_IRQn, APP_IRQ_PRIORITY_LOWEST);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ret_code_t nrf_sdh_enable_request(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    ret_code_t ret_code;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (m_nrf_sdh_enabled)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return NRF_ERROR_INVALID_STATE;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_nrf_sdh_continue = true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Notify observers about SoftDevice enable request.
 | 
					 | 
				
			||||||
    if (sdh_request_observer_notify(NRF_SDH_EVT_ENABLE_REQUEST) == NRF_ERROR_BUSY)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Enable process was stopped.
 | 
					 | 
				
			||||||
        return NRF_SUCCESS;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Notify observers about starting SoftDevice enable process.
 | 
					 | 
				
			||||||
    sdh_state_observer_notify(NRF_SDH_EVT_STATE_ENABLE_PREPARE);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    nrf_clock_lf_cfg_t const clock_lf_cfg =
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        .source       = NRF_SDH_CLOCK_LF_SRC,
 | 
					 | 
				
			||||||
        .rc_ctiv      = NRF_SDH_CLOCK_LF_RC_CTIV,
 | 
					 | 
				
			||||||
        .rc_temp_ctiv = NRF_SDH_CLOCK_LF_RC_TEMP_CTIV,
 | 
					 | 
				
			||||||
        .accuracy     = NRF_SDH_CLOCK_LF_ACCURACY
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    CRITICAL_REGION_ENTER();
 | 
					 | 
				
			||||||
#ifdef ANT_LICENSE_KEY
 | 
					 | 
				
			||||||
    ret_code = sd_softdevice_enable(&clock_lf_cfg, app_error_fault_handler, ANT_LICENSE_KEY);
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    ret_code = sd_softdevice_enable(&clock_lf_cfg, app_error_fault_handler);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    m_nrf_sdh_enabled = (ret_code == NRF_SUCCESS);
 | 
					 | 
				
			||||||
    CRITICAL_REGION_EXIT();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (ret_code != NRF_SUCCESS)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return ret_code;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_nrf_sdh_continue  = false;
 | 
					 | 
				
			||||||
    m_nrf_sdh_suspended = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef S140
 | 
					 | 
				
			||||||
    // Set the interrupt priority after enabling the SoftDevice, since
 | 
					 | 
				
			||||||
    // sd_softdevice_enable() sets the SoftDevice interrupt priority.
 | 
					 | 
				
			||||||
    swi_interrupt_priority_workaround();
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Enable event interrupt.
 | 
					 | 
				
			||||||
    // Interrupt priority has already been set by the stack.
 | 
					 | 
				
			||||||
    softdevices_evt_irq_enable();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Notify observers about a finished SoftDevice enable process.
 | 
					 | 
				
			||||||
    sdh_state_observer_notify(NRF_SDH_EVT_STATE_ENABLED);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return NRF_SUCCESS;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ret_code_t nrf_sdh_disable_request(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    ret_code_t ret_code;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (!m_nrf_sdh_enabled)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return NRF_ERROR_INVALID_STATE;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_nrf_sdh_continue = true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Notify observers about SoftDevice disable request.
 | 
					 | 
				
			||||||
    if (sdh_request_observer_notify(NRF_SDH_EVT_DISABLE_REQUEST) == NRF_ERROR_BUSY)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Disable process was stopped.
 | 
					 | 
				
			||||||
        return NRF_SUCCESS;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Notify observers about starting SoftDevice disable process.
 | 
					 | 
				
			||||||
    sdh_state_observer_notify(NRF_SDH_EVT_STATE_DISABLE_PREPARE);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    CRITICAL_REGION_ENTER();
 | 
					 | 
				
			||||||
    ret_code          = sd_softdevice_disable();
 | 
					 | 
				
			||||||
    m_nrf_sdh_enabled = false;
 | 
					 | 
				
			||||||
    CRITICAL_REGION_EXIT();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (ret_code != NRF_SUCCESS)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return ret_code;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_nrf_sdh_continue = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    softdevice_evt_irq_disable();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Notify observers about a finished SoftDevice enable process.
 | 
					 | 
				
			||||||
    sdh_state_observer_notify(NRF_SDH_EVT_STATE_DISABLED);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return NRF_SUCCESS;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ret_code_t nrf_sdh_request_continue(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    if (!m_nrf_sdh_continue)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return NRF_ERROR_INVALID_STATE;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (m_nrf_sdh_enabled)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return nrf_sdh_disable_request();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return nrf_sdh_enable_request();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool nrf_sdh_is_enabled(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    return m_nrf_sdh_enabled;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void nrf_sdh_suspend(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    if (!m_nrf_sdh_enabled)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    softdevice_evt_irq_disable();
 | 
					 | 
				
			||||||
    m_nrf_sdh_suspended = true;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void nrf_sdh_resume(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    if ((!m_nrf_sdh_suspended) || (!m_nrf_sdh_enabled))
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Force calling ISR again to make sure that events not previously pulled have been processed.
 | 
					 | 
				
			||||||
#ifdef SOFTDEVICE_PRESENT
 | 
					 | 
				
			||||||
    ret_code_t ret_code = sd_nvic_SetPendingIRQ((IRQn_Type)SD_EVT_IRQn);
 | 
					 | 
				
			||||||
    APP_ERROR_CHECK(ret_code);
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    NVIC_SetPendingIRQ((IRQn_Type)SD_EVT_IRQn);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    softdevices_evt_irq_enable();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    m_nrf_sdh_suspended = false;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
bool nrf_sdh_is_suspended(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    return (!m_nrf_sdh_enabled) || (m_nrf_sdh_suspended);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void nrf_sdh_evts_poll(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    nrf_section_iter_t iter;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Notify observers about pending SoftDevice event.
 | 
					 | 
				
			||||||
    for (nrf_section_iter_init(&iter, &sdh_stack_observers);
 | 
					 | 
				
			||||||
         nrf_section_iter_get(&iter) != NULL;
 | 
					 | 
				
			||||||
         nrf_section_iter_next(&iter))
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        nrf_sdh_stack_observer_t    * p_observer;
 | 
					 | 
				
			||||||
        nrf_sdh_stack_evt_handler_t   handler;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        p_observer = (nrf_sdh_stack_observer_t *) nrf_section_iter_get(&iter);
 | 
					 | 
				
			||||||
        handler    = p_observer->handler;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        handler(p_observer->p_context);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if (NRF_SDH_DISPATCH_MODEL == NRF_SDH_DISPATCH_MODEL_INTERRUPT)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void SD_EVT_IRQHandler(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    nrf_sdh_evts_poll();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#elif (NRF_SDH_DISPATCH_MODEL == NRF_SDH_DISPATCH_MODEL_APPSH)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Function for polling SoftDevice events.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @note    This function is compatible with @ref app_sched_event_handler_t.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param[in]   p_event_data Pointer to the event data.
 | 
					 | 
				
			||||||
 * @param[in]   event_size   Size of the event data.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static void appsh_events_poll(void * p_event_data, uint16_t event_size)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    UNUSED_PARAMETER(p_event_data);
 | 
					 | 
				
			||||||
    UNUSED_PARAMETER(event_size);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    nrf_sdh_evts_poll();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void SD_EVT_IRQHandler(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    ret_code_t ret_code = app_sched_event_put(NULL, 0, appsh_events_poll);
 | 
					 | 
				
			||||||
    APP_ERROR_CHECK(ret_code);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#elif (NRF_SDH_DISPATCH_MODEL == NRF_SDH_DISPATCH_MODEL_POLLING)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#error "Unknown SoftDevice handler dispatch model."
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif // NRF_SDH_DISPATCH_MODEL
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif // NRF_MODULE_ENABLED(NRF_SDH)
 | 
					 | 
				
			||||||
@@ -1,305 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
 * Copyright (c) 2017 - 2018, 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, except as embedded into a Nordic
 | 
					 | 
				
			||||||
 *    Semiconductor ASA integrated circuit in a product or a software update for
 | 
					 | 
				
			||||||
 *    such product, 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 its
 | 
					 | 
				
			||||||
 *    contributors may be used to endorse or promote products derived from this
 | 
					 | 
				
			||||||
 *    software without specific prior written permission.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * 4. This software, with or without modification, must only be used with a
 | 
					 | 
				
			||||||
 *    Nordic Semiconductor ASA integrated circuit.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * 5. Any software provided in binary form under this license must not be reverse
 | 
					 | 
				
			||||||
 *    engineered, decompiled, modified and/or disassembled.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
 | 
					 | 
				
			||||||
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 | 
					 | 
				
			||||||
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 | 
					 | 
				
			||||||
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** @file
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @defgroup nrf_sdh SoftDevice Handler
 | 
					 | 
				
			||||||
 * @{
 | 
					 | 
				
			||||||
 * @ingroup  app_common
 | 
					 | 
				
			||||||
 * @brief    API for initializing and disabling the SoftDevice.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef NRF_SDH_H__
 | 
					 | 
				
			||||||
#define NRF_SDH_H__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <stdbool.h>
 | 
					 | 
				
			||||||
#include "sdk_config.h"
 | 
					 | 
				
			||||||
#include "sdk_errors.h"
 | 
					 | 
				
			||||||
#include "nrf_section_iter.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
extern "C" {
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * @name Softdevice Handler dispatch models
 | 
					 | 
				
			||||||
 * @{
 | 
					 | 
				
			||||||
 * @ingroup  nrf_sdh */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   SoftDevice events are passed to the application from the interrupt context. */
 | 
					 | 
				
			||||||
#define NRF_SDH_DISPATCH_MODEL_INTERRUPT  0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   SoftDevice events are passed to the application using @ref app_scheduler.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @note    @ref app_scheduler must be initialized before enabling the SoftDevice handler.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define NRF_SDH_DISPATCH_MODEL_APPSH      1
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   SoftDevice events are polled manually using @ref nrf_sdh_evts_poll().
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @note    In this mode, a user application can also implement SD_EVT_IRQHandler() to receive a
 | 
					 | 
				
			||||||
 *          notification about incoming events.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define NRF_SDH_DISPATCH_MODEL_POLLING    2
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** @} */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * @name SoftDevice Handler state change requests
 | 
					 | 
				
			||||||
 * @{
 | 
					 | 
				
			||||||
 * @ingroup  nrf_sdh */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   SoftDevice Handler state requests. */
 | 
					 | 
				
			||||||
typedef enum
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    NRF_SDH_EVT_ENABLE_REQUEST,     //!< Request to enable the SoftDevice.
 | 
					 | 
				
			||||||
    NRF_SDH_EVT_DISABLE_REQUEST,    //!< Request to disable the SoftDevice.
 | 
					 | 
				
			||||||
} nrf_sdh_req_evt_t;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   SoftDevice Handler state request handler.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @retval  true    If ready for the SoftDevice to change state.
 | 
					 | 
				
			||||||
 * @retval  false   If not ready for the SoftDevice to change state.
 | 
					 | 
				
			||||||
 *                  If false is returned, the state change is aborted.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
typedef bool (*nrf_sdh_req_evt_handler_t)(nrf_sdh_req_evt_t request, void * p_context);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   SoftDevice Handler state request observer. */
 | 
					 | 
				
			||||||
typedef struct
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    nrf_sdh_req_evt_handler_t handler;      //!< Request handler.
 | 
					 | 
				
			||||||
    void *                    p_context;    //!< A parameter to the handler function.
 | 
					 | 
				
			||||||
} const nrf_sdh_req_observer_t;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Macro for registering a SoftDevice state change request observer.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * An observer of SoftDevice state change requests receives requests to change the state of the
 | 
					 | 
				
			||||||
 * SoftDevice from enabled to disabled and vice versa. These requests may or may not be acknowledged
 | 
					 | 
				
			||||||
 * by the observer, depending on the value returned by its request handler function. Thus, a
 | 
					 | 
				
			||||||
 * request observer has the capability to defer the change of state of the SoftDevice. If it does
 | 
					 | 
				
			||||||
 * so, it has the responsibility to call @ref nrf_sdh_request_continue when it is ready to let the
 | 
					 | 
				
			||||||
 * SoftDevice change its state. If such capability is not necessary and you only need to be informed
 | 
					 | 
				
			||||||
 * about changes of the SoftDevice state, use the @ref NRF_SDH_STATE_OBSERVER macro instead.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @note    This macro places the observer in a section named "sdh_req_observers".
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param[in]   _observer   Name of the observer.
 | 
					 | 
				
			||||||
 * @param[in]   _prio       Priority of the observer's event handler.
 | 
					 | 
				
			||||||
 *                          The smaller the number, the higher the priority.
 | 
					 | 
				
			||||||
 * @hideinitializer
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define NRF_SDH_REQUEST_OBSERVER(_observer, _prio)                                                  \
 | 
					 | 
				
			||||||
STATIC_ASSERT(NRF_SDH_ENABLED, "NRF_SDH_ENABLED not set!");                                         \
 | 
					 | 
				
			||||||
STATIC_ASSERT(_prio < NRF_SDH_REQ_OBSERVER_PRIO_LEVELS, "Priority level unavailable.");             \
 | 
					 | 
				
			||||||
/*lint -esym(528,*_observer) -esym(529,*_observer) : Symbol not referenced. */                      \
 | 
					 | 
				
			||||||
NRF_SECTION_SET_ITEM_REGISTER(sdh_req_observers, _prio, nrf_sdh_req_observer_t const _observer)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** @} */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * @name SoftDevice Handler state events
 | 
					 | 
				
			||||||
 * @{
 | 
					 | 
				
			||||||
 * @ingroup  nrf_sdh */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   SoftDevice Handler state events. */
 | 
					 | 
				
			||||||
typedef enum
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    NRF_SDH_EVT_STATE_ENABLE_PREPARE,   //!< SoftDevice is going to be enabled.
 | 
					 | 
				
			||||||
    NRF_SDH_EVT_STATE_ENABLED,          //!< SoftDevice is enabled.
 | 
					 | 
				
			||||||
    NRF_SDH_EVT_STATE_DISABLE_PREPARE,  //!< SoftDevice is going to be disabled.
 | 
					 | 
				
			||||||
    NRF_SDH_EVT_STATE_DISABLED,         //!< SoftDevice is disabled.
 | 
					 | 
				
			||||||
} nrf_sdh_state_evt_t;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   SoftDevice Handler state event handler. */
 | 
					 | 
				
			||||||
typedef void (*nrf_sdh_state_evt_handler_t)(nrf_sdh_state_evt_t state, void * p_context);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   SoftDevice Handler state observer. */
 | 
					 | 
				
			||||||
typedef struct
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    nrf_sdh_state_evt_handler_t   handler;      //!< State event handler.
 | 
					 | 
				
			||||||
    void                        * p_context;    //!< A parameter to the event handler.
 | 
					 | 
				
			||||||
} const nrf_sdh_state_observer_t;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Macro for registering a SoftDevice state observer.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * A SoftDevice state observer receives events when the SoftDevice state has changed or is
 | 
					 | 
				
			||||||
 * about to change. These events are only meant to inform the state observer, which, contrary
 | 
					 | 
				
			||||||
 * to a state change request observer, does not have the capability to defer the change of state.
 | 
					 | 
				
			||||||
 * If such capability is required, use the @ref NRF_SDH_REQUEST_OBSERVER macro instead.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 *  This macro places the observer in a section named "sdh_state_observers".
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param[in]   _observer   Name of the observer.
 | 
					 | 
				
			||||||
 * @param[in]   _prio       Priority of the observer's event handler.
 | 
					 | 
				
			||||||
 *                          The smaller the number, the higher the priority.
 | 
					 | 
				
			||||||
 * @hideinitializer
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define NRF_SDH_STATE_OBSERVER(_observer, _prio)                                                           \
 | 
					 | 
				
			||||||
STATIC_ASSERT(NRF_SDH_ENABLED, "NRF_SDH_ENABLED not set!");                                                \
 | 
					 | 
				
			||||||
STATIC_ASSERT(_prio < NRF_SDH_STATE_OBSERVER_PRIO_LEVELS, "Priority level unavailable.");                  \
 | 
					 | 
				
			||||||
/*lint -esym(528,*_observer) -esym(529,*_observer) : Symbol not referenced. */                             \
 | 
					 | 
				
			||||||
NRF_SECTION_SET_ITEM_REGISTER(sdh_state_observers, _prio, static nrf_sdh_state_observer_t const _observer)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** @} */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * @name SoftDevice stack events
 | 
					 | 
				
			||||||
 * @{
 | 
					 | 
				
			||||||
 * @ingroup  nrf_sdh */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   SoftDevice stack event handler. */
 | 
					 | 
				
			||||||
typedef void (*nrf_sdh_stack_evt_handler_t)(void * p_evt);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   SoftDevice stack event observer. */
 | 
					 | 
				
			||||||
typedef struct
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    nrf_sdh_stack_evt_handler_t handler;    //!< SoftDevice event handler.
 | 
					 | 
				
			||||||
    void *                      p_context;  //!< A parameter to the event handler.
 | 
					 | 
				
			||||||
} const nrf_sdh_stack_observer_t;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Macro for registering a SoftDevice stack events observer.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * A SoftDevice stack event observer receives all events from the SoftDevice. These events can be
 | 
					 | 
				
			||||||
 * either BLE, ANT, or SoC events. If you need to receive BLE, ANT, or SoC events separately, use the
 | 
					 | 
				
			||||||
 * @ref NRF_SDH_BLE_OBSERVER, @ref NRF_SDH_ANT_OBSERVER, or @ref NRF_SDH_SOC_OBSERVER macros
 | 
					 | 
				
			||||||
 * respectively.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @note    This macro places the observer in a section named "sdh_stack_observers".
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param[in]   _observer   Name of the observer.
 | 
					 | 
				
			||||||
 * @param[in]   _prio       Priority of the observer's event handler.
 | 
					 | 
				
			||||||
 *                          The smaller the number, the higher the priority.
 | 
					 | 
				
			||||||
 ** @hideinitializer
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define NRF_SDH_STACK_OBSERVER(_observer, _prio)                                                          \
 | 
					 | 
				
			||||||
STATIC_ASSERT(NRF_SDH_ENABLED, "NRF_SDH_ENABLED not set!");                                               \
 | 
					 | 
				
			||||||
STATIC_ASSERT(_prio < NRF_SDH_STACK_OBSERVER_PRIO_LEVELS, "Priority level unavailable.");                 \
 | 
					 | 
				
			||||||
/*lint -esym(528,*_observer) -esym(529,*_observer) : Symbol not referenced. */                            \
 | 
					 | 
				
			||||||
NRF_SECTION_SET_ITEM_REGISTER(sdh_stack_observers, _prio, static nrf_sdh_stack_observer_t const _observer)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** @} */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Function for requesting to enable the SoftDevice.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This function issues a @ref NRF_SDH_EVT_ENABLE_REQUEST request to all observers that
 | 
					 | 
				
			||||||
 * were registered using the @ref NRF_SDH_REQUEST_OBSERVER macro. The observers may or
 | 
					 | 
				
			||||||
 * may not acknowledge the request. If all observers acknowledge the request, the
 | 
					 | 
				
			||||||
 * SoftDevice will be enabled. Otherwise, the process will be stopped and the observers
 | 
					 | 
				
			||||||
 * that did not acknowledge have the responsibility to restart it by calling
 | 
					 | 
				
			||||||
 * @ref nrf_sdh_request_continue when they are ready for the SoftDevice to change state.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @retval  NRF_SUCCESS                 The process is started.
 | 
					 | 
				
			||||||
 * @retval  NRF_ERROR_INVALID_STATE     The SoftDevice is already enabled.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
ret_code_t nrf_sdh_enable_request(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Function for requesting to disable the SoftDevice.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This function issues a @ref NRF_SDH_EVT_DISABLE_REQUEST request to all observers that
 | 
					 | 
				
			||||||
 * were registered using the @ref NRF_SDH_REQUEST_OBSERVER macro. The observers may or
 | 
					 | 
				
			||||||
 * may not acknowledge the request. If all observers acknowledge the request, the
 | 
					 | 
				
			||||||
 * SoftDevice will be disabled. Otherwise, the process will be stopped and the observers
 | 
					 | 
				
			||||||
 * that did not acknowledge have the responsibility to restart it by calling
 | 
					 | 
				
			||||||
 * @ref nrf_sdh_request_continue when they are ready for the SoftDevice to change state.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @retval  NRF_SUCCESS                 The process is started.
 | 
					 | 
				
			||||||
 * @retval  NRF_ERROR_INVALID_STATE     The SoftDevice is already disabled.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
ret_code_t nrf_sdh_disable_request(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Function for restarting the SoftDevice Enable/Disable process.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Modules which did not acknowledge a @ref NRF_SDH_EVT_ENABLE_REQUEST or
 | 
					 | 
				
			||||||
 * @ref NRF_SDH_EVT_DISABLE_REQUEST request must call this function to restart the
 | 
					 | 
				
			||||||
 * SoftDevice state change process.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @retval  NRF_SUCCESS                 The process is restarted.
 | 
					 | 
				
			||||||
 * @retval  NRF_ERROR_INVALID_STATE     No state change request was pending.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
ret_code_t nrf_sdh_request_continue(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Function for retrieving the SoftDevice state.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @retval  true    If the SoftDevice is enabled.
 | 
					 | 
				
			||||||
 * @retval  false   If the SoftDevice is disabled.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
bool nrf_sdh_is_enabled(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Function for stopping the incoming stack events.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This function disables the SoftDevice interrupt. To resume polling for events,
 | 
					 | 
				
			||||||
 * call @ref nrf_sdh_resume.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
void nrf_sdh_suspend(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Function for resuming polling incoming events from the SoftDevice. */
 | 
					 | 
				
			||||||
void nrf_sdh_resume(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Function for retrieving the information about the module state.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @retval  true    The SoftDevice handler is paused, and it will not fetch events from the stack.
 | 
					 | 
				
			||||||
 * @retval  false   The SoftDevice handler is running, and it will fetch and dispatch events from
 | 
					 | 
				
			||||||
 *                  the stack to the registered stack observers.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
bool nrf_sdh_is_suspended(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Function for polling stack events from the SoftDevice.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * The events are passed to the application using the registered event handlers.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @note    @ref NRF_SDH_DISPATCH_MODEL_POLLING must be selected to use this function.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
void nrf_sdh_evts_poll(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif // NRF_SDH_H__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** @} */
 | 
					 | 
				
			||||||
@@ -1,324 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
 * Copyright (c) 2017 - 2018, 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, except as embedded into a Nordic
 | 
					 | 
				
			||||||
 *    Semiconductor ASA integrated circuit in a product or a software update for
 | 
					 | 
				
			||||||
 *    such product, 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 its
 | 
					 | 
				
			||||||
 *    contributors may be used to endorse or promote products derived from this
 | 
					 | 
				
			||||||
 *    software without specific prior written permission.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * 4. This software, with or without modification, must only be used with a
 | 
					 | 
				
			||||||
 *    Nordic Semiconductor ASA integrated circuit.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * 5. Any software provided in binary form under this license must not be reverse
 | 
					 | 
				
			||||||
 *    engineered, decompiled, modified and/or disassembled.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
 | 
					 | 
				
			||||||
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 | 
					 | 
				
			||||||
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 | 
					 | 
				
			||||||
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 "sdk_common.h"
 | 
					 | 
				
			||||||
#if NRF_MODULE_ENABLED(NRF_SDH_BLE)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "nrf_sdh_ble.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "nrf_sdh.h"
 | 
					 | 
				
			||||||
#include "app_error.h"
 | 
					 | 
				
			||||||
#include "nrf_strerror.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define NRF_LOG_MODULE_NAME nrf_sdh_ble
 | 
					 | 
				
			||||||
#if NRF_SDH_BLE_LOG_ENABLED
 | 
					 | 
				
			||||||
    #define NRF_LOG_LEVEL       NRF_SDH_BLE_LOG_LEVEL
 | 
					 | 
				
			||||||
    #define NRF_LOG_INFO_COLOR  NRF_SDH_BLE_INFO_COLOR
 | 
					 | 
				
			||||||
    #define NRF_LOG_DEBUG_COLOR NRF_SDH_BLE_DEBUG_COLOR
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    #define NRF_LOG_LEVEL       0
 | 
					 | 
				
			||||||
#endif // NRF_SDH_BLE_LOG_ENABLED
 | 
					 | 
				
			||||||
#include "nrf_log.h"
 | 
					 | 
				
			||||||
NRF_LOG_MODULE_REGISTER();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Create section set "sdh_ble_observers".
 | 
					 | 
				
			||||||
NRF_SECTION_SET_DEF(sdh_ble_observers, nrf_sdh_ble_evt_observer_t, NRF_SDH_BLE_OBSERVER_PRIO_LEVELS);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//lint -save -e10 -e19 -e40 -e27 Illegal character (0x24)
 | 
					 | 
				
			||||||
#if defined(__CC_ARM)
 | 
					 | 
				
			||||||
    extern uint32_t  Image$$RW_IRAM1$$Base;
 | 
					 | 
				
			||||||
    uint32_t const * const m_ram_start = &Image$$RW_IRAM1$$Base;
 | 
					 | 
				
			||||||
#elif defined(__ICCARM__)
 | 
					 | 
				
			||||||
    extern uint32_t  __ICFEDIT_region_RAM_start__;
 | 
					 | 
				
			||||||
    uint32_t const * const m_ram_start = &__ICFEDIT_region_RAM_start__;
 | 
					 | 
				
			||||||
#elif defined(__SES_ARM)
 | 
					 | 
				
			||||||
    extern uint32_t  __app_ram_start__;
 | 
					 | 
				
			||||||
    uint32_t const * const m_ram_start = &__app_ram_start__;
 | 
					 | 
				
			||||||
#elif defined(__GNUC__)
 | 
					 | 
				
			||||||
    extern uint32_t  __data_start__;
 | 
					 | 
				
			||||||
    uint32_t const * const m_ram_start = &__data_start__;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
//lint -restore
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define RAM_START       0x20000000
 | 
					 | 
				
			||||||
#define APP_RAM_START   (uint32_t)m_ram_start
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static bool m_stack_is_enabled;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ret_code_t nrf_sdh_ble_app_ram_start_get(uint32_t * p_app_ram_start)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    if (p_app_ram_start == NULL)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return NRF_ERROR_NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    *p_app_ram_start = APP_RAM_START;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return NRF_SUCCESS;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ret_code_t nrf_sdh_ble_default_cfg_set(uint8_t conn_cfg_tag, uint32_t * p_ram_start)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    uint32_t ret_code;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ret_code = nrf_sdh_ble_app_ram_start_get(p_ram_start);
 | 
					 | 
				
			||||||
    if (ret_code != NRF_SUCCESS)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return ret_code;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef S112
 | 
					 | 
				
			||||||
    STATIC_ASSERT(NRF_SDH_BLE_CENTRAL_LINK_COUNT == 0, "When using s112, NRF_SDH_BLE_CENTRAL_LINK_COUNT must be 0.");
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Overwrite some of the default settings of the BLE stack.
 | 
					 | 
				
			||||||
    // If any of the calls to sd_ble_cfg_set() fail, log the error but carry on so that
 | 
					 | 
				
			||||||
    // wrong RAM settings can be caught by nrf_sdh_ble_enable() and a meaningful error
 | 
					 | 
				
			||||||
    // message will be printed to the user suggesting the correct value.
 | 
					 | 
				
			||||||
    ble_cfg_t ble_cfg;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if (NRF_SDH_BLE_TOTAL_LINK_COUNT != 0)
 | 
					 | 
				
			||||||
    // Configure the connection count.
 | 
					 | 
				
			||||||
    memset(&ble_cfg, 0, sizeof(ble_cfg));
 | 
					 | 
				
			||||||
    ble_cfg.conn_cfg.conn_cfg_tag                     = conn_cfg_tag;
 | 
					 | 
				
			||||||
    ble_cfg.conn_cfg.params.gap_conn_cfg.conn_count   = NRF_SDH_BLE_TOTAL_LINK_COUNT;
 | 
					 | 
				
			||||||
    ble_cfg.conn_cfg.params.gap_conn_cfg.event_length = NRF_SDH_BLE_GAP_EVENT_LENGTH;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ret_code = sd_ble_cfg_set(BLE_CONN_CFG_GAP, &ble_cfg, *p_ram_start);
 | 
					 | 
				
			||||||
    if (ret_code != NRF_SUCCESS)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        NRF_LOG_ERROR("sd_ble_cfg_set() returned %s when attempting to set BLE_CONN_CFG_GAP.",
 | 
					 | 
				
			||||||
                      nrf_strerror_get(ret_code));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Configure the connection roles.
 | 
					 | 
				
			||||||
    memset(&ble_cfg, 0, sizeof(ble_cfg));
 | 
					 | 
				
			||||||
    ble_cfg.gap_cfg.role_count_cfg.periph_role_count  = NRF_SDH_BLE_PERIPHERAL_LINK_COUNT;
 | 
					 | 
				
			||||||
#ifndef S112
 | 
					 | 
				
			||||||
    ble_cfg.gap_cfg.role_count_cfg.central_role_count = NRF_SDH_BLE_CENTRAL_LINK_COUNT;
 | 
					 | 
				
			||||||
    ble_cfg.gap_cfg.role_count_cfg.central_sec_count  = MIN(NRF_SDH_BLE_CENTRAL_LINK_COUNT,
 | 
					 | 
				
			||||||
                                                            BLE_GAP_ROLE_COUNT_CENTRAL_SEC_DEFAULT);
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ret_code = sd_ble_cfg_set(BLE_GAP_CFG_ROLE_COUNT, &ble_cfg, *p_ram_start);
 | 
					 | 
				
			||||||
    if (ret_code != NRF_SUCCESS)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        NRF_LOG_ERROR("sd_ble_cfg_set() returned %s when attempting to set BLE_GAP_CFG_ROLE_COUNT.",
 | 
					 | 
				
			||||||
                      nrf_strerror_get(ret_code));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Configure the maximum ATT MTU.
 | 
					 | 
				
			||||||
#if (NRF_SDH_BLE_GATT_MAX_MTU_SIZE != 23)
 | 
					 | 
				
			||||||
    memset(&ble_cfg, 0x00, sizeof(ble_cfg));
 | 
					 | 
				
			||||||
    ble_cfg.conn_cfg.conn_cfg_tag                 = conn_cfg_tag;
 | 
					 | 
				
			||||||
    ble_cfg.conn_cfg.params.gatt_conn_cfg.att_mtu = NRF_SDH_BLE_GATT_MAX_MTU_SIZE;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ret_code = sd_ble_cfg_set(BLE_CONN_CFG_GATT, &ble_cfg, *p_ram_start);
 | 
					 | 
				
			||||||
    if (ret_code != NRF_SUCCESS)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        NRF_LOG_ERROR("sd_ble_cfg_set() returned %s when attempting to set BLE_CONN_CFG_GATT.",
 | 
					 | 
				
			||||||
                      nrf_strerror_get(ret_code));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
#endif  // NRF_SDH_BLE_GATT_MAX_MTU_SIZE != 23
 | 
					 | 
				
			||||||
#endif  // NRF_SDH_BLE_TOTAL_LINK_COUNT != 0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Configure number of custom UUIDS.
 | 
					 | 
				
			||||||
    memset(&ble_cfg, 0, sizeof(ble_cfg));
 | 
					 | 
				
			||||||
    ble_cfg.common_cfg.vs_uuid_cfg.vs_uuid_count = NRF_SDH_BLE_VS_UUID_COUNT;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ret_code = sd_ble_cfg_set(BLE_COMMON_CFG_VS_UUID, &ble_cfg, *p_ram_start);
 | 
					 | 
				
			||||||
    if (ret_code != NRF_SUCCESS)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        NRF_LOG_ERROR("sd_ble_cfg_set() returned %s when attempting to set BLE_COMMON_CFG_VS_UUID.",
 | 
					 | 
				
			||||||
                      nrf_strerror_get(ret_code));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Configure the GATTS attribute table.
 | 
					 | 
				
			||||||
    memset(&ble_cfg, 0x00, sizeof(ble_cfg));
 | 
					 | 
				
			||||||
    ble_cfg.gatts_cfg.attr_tab_size.attr_tab_size = NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ret_code = sd_ble_cfg_set(BLE_GATTS_CFG_ATTR_TAB_SIZE, &ble_cfg, *p_ram_start);
 | 
					 | 
				
			||||||
    if (ret_code != NRF_SUCCESS)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        NRF_LOG_ERROR("sd_ble_cfg_set() returned %s when attempting to set BLE_GATTS_CFG_ATTR_TAB_SIZE.",
 | 
					 | 
				
			||||||
                      nrf_strerror_get(ret_code));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Configure Service Changed characteristic.
 | 
					 | 
				
			||||||
    memset(&ble_cfg, 0x00, sizeof(ble_cfg));
 | 
					 | 
				
			||||||
    ble_cfg.gatts_cfg.service_changed.service_changed = NRF_SDH_BLE_SERVICE_CHANGED;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ret_code = sd_ble_cfg_set(BLE_GATTS_CFG_SERVICE_CHANGED, &ble_cfg, *p_ram_start);
 | 
					 | 
				
			||||||
    if (ret_code != NRF_SUCCESS)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        NRF_LOG_ERROR("sd_ble_cfg_set() returned %s when attempting to set BLE_GATTS_CFG_SERVICE_CHANGED.",
 | 
					 | 
				
			||||||
                      nrf_strerror_get(ret_code));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return NRF_SUCCESS;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Function for finding the end address of the RAM. */
 | 
					 | 
				
			||||||
static uint32_t ram_end_address_get(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    uint32_t ram_total_size;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef NRF51
 | 
					 | 
				
			||||||
    uint32_t block_size = NRF_FICR->SIZERAMBLOCKS;
 | 
					 | 
				
			||||||
    ram_total_size      = block_size * NRF_FICR->NUMRAMBLOCK;
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    ram_total_size      = NRF_FICR->INFO.RAM * 1024;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return RAM_START + ram_total_size;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ret_code_t nrf_sdh_ble_enable(uint32_t * const p_app_ram_start)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    // Start of RAM, obtained from linker symbol.
 | 
					 | 
				
			||||||
    uint32_t const app_ram_start_link = *p_app_ram_start;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ret_code_t ret_code = sd_ble_enable(p_app_ram_start);
 | 
					 | 
				
			||||||
    if (*p_app_ram_start > app_ram_start_link)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        NRF_LOG_WARNING("Insufficient RAM allocated for the SoftDevice.");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        NRF_LOG_WARNING("Change the RAM start location from 0x%x to 0x%x.",
 | 
					 | 
				
			||||||
                        app_ram_start_link, *p_app_ram_start);
 | 
					 | 
				
			||||||
        NRF_LOG_WARNING("Maximum RAM size for application is 0x%x.",
 | 
					 | 
				
			||||||
                        ram_end_address_get() - (*p_app_ram_start));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        NRF_LOG_DEBUG("RAM starts at 0x%x", app_ram_start_link);
 | 
					 | 
				
			||||||
        if (*p_app_ram_start != app_ram_start_link)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            NRF_LOG_DEBUG("RAM start location can be adjusted to 0x%x.", *p_app_ram_start);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            NRF_LOG_DEBUG("RAM size for application can be adjusted to 0x%x.",
 | 
					 | 
				
			||||||
                          ram_end_address_get() - (*p_app_ram_start));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (ret_code == NRF_SUCCESS)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        m_stack_is_enabled = true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        NRF_LOG_ERROR("sd_ble_enable() returned %s.", nrf_strerror_get(ret_code));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return ret_code;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief       Function for polling BLE events.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param[in]   p_context   Context of the observer.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static void nrf_sdh_ble_evts_poll(void * p_context)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    UNUSED_VARIABLE(p_context);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ret_code_t ret_code;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (!m_stack_is_enabled)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    while (true)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        /*lint -save -e(587) */
 | 
					 | 
				
			||||||
        __ALIGN(4) uint8_t evt_buffer[NRF_SDH_BLE_EVT_BUF_SIZE];
 | 
					 | 
				
			||||||
        /*lint -restore */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        ble_evt_t * p_ble_evt;
 | 
					 | 
				
			||||||
        uint16_t    evt_len = (uint16_t)sizeof(evt_buffer);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        ret_code = sd_ble_evt_get(evt_buffer, &evt_len);
 | 
					 | 
				
			||||||
        if (ret_code != NRF_SUCCESS)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        p_ble_evt = (ble_evt_t *)evt_buffer;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        NRF_LOG_DEBUG("BLE event: 0x%x.", p_ble_evt->header.evt_id);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Forward the event to BLE observers.
 | 
					 | 
				
			||||||
        nrf_section_iter_t  iter;
 | 
					 | 
				
			||||||
        for (nrf_section_iter_init(&iter, &sdh_ble_observers);
 | 
					 | 
				
			||||||
             nrf_section_iter_get(&iter) != NULL;
 | 
					 | 
				
			||||||
             nrf_section_iter_next(&iter))
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            nrf_sdh_ble_evt_observer_t * p_observer;
 | 
					 | 
				
			||||||
            nrf_sdh_ble_evt_handler_t    handler;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            p_observer = (nrf_sdh_ble_evt_observer_t *)nrf_section_iter_get(&iter);
 | 
					 | 
				
			||||||
            handler    = p_observer->handler;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            handler(p_ble_evt, p_observer->p_context);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (ret_code != NRF_ERROR_NOT_FOUND)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        APP_ERROR_HANDLER(ret_code);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
NRF_SDH_STACK_OBSERVER(m_nrf_sdh_ble_evts_poll, NRF_SDH_BLE_STACK_OBSERVER_PRIO) =
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    .handler   = nrf_sdh_ble_evts_poll,
 | 
					 | 
				
			||||||
    .p_context = NULL,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif // NRF_MODULE_ENABLED(NRF_SDH_BLE)
 | 
					 | 
				
			||||||
@@ -1,184 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
 * Copyright (c) 2017 - 2018, 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, except as embedded into a Nordic
 | 
					 | 
				
			||||||
 *    Semiconductor ASA integrated circuit in a product or a software update for
 | 
					 | 
				
			||||||
 *    such product, 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 its
 | 
					 | 
				
			||||||
 *    contributors may be used to endorse or promote products derived from this
 | 
					 | 
				
			||||||
 *    software without specific prior written permission.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * 4. This software, with or without modification, must only be used with a
 | 
					 | 
				
			||||||
 *    Nordic Semiconductor ASA integrated circuit.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * 5. Any software provided in binary form under this license must not be reverse
 | 
					 | 
				
			||||||
 *    engineered, decompiled, modified and/or disassembled.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
 | 
					 | 
				
			||||||
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 | 
					 | 
				
			||||||
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 | 
					 | 
				
			||||||
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@file
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @defgroup nrf_sdh_ble BLE support in SoftDevice Handler
 | 
					 | 
				
			||||||
 * @{
 | 
					 | 
				
			||||||
 * @ingroup  nrf_sdh
 | 
					 | 
				
			||||||
 * @brief    This file contains the declarations of types and functions required for BLE stack
 | 
					 | 
				
			||||||
 * support.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef NRF_SDH_BLE_H__
 | 
					 | 
				
			||||||
#define NRF_SDH_BLE_H__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "app_util.h"
 | 
					 | 
				
			||||||
#include "ble.h"
 | 
					 | 
				
			||||||
#include "nrf_section_iter.h"
 | 
					 | 
				
			||||||
#include "sdk_config.h"
 | 
					 | 
				
			||||||
#include "sdk_errors.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <stdint.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
extern "C" {
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** @brief  Size of the buffer for a BLE event. */
 | 
					 | 
				
			||||||
#define NRF_SDH_BLE_EVT_BUF_SIZE BLE_EVT_LEN_MAX(NRF_SDH_BLE_GATT_MAX_MTU_SIZE)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if !(defined(__LINT__))
 | 
					 | 
				
			||||||
/**@brief   Macro for registering @ref nrf_sdh_soc_evt_observer_t. Modules that want to be
 | 
					 | 
				
			||||||
 *          notified about SoC events must register the handler using this macro.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @details This macro places the observer in a section named "sdh_soc_observers".
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param[in]   _name       Observer name.
 | 
					 | 
				
			||||||
 * @param[in]   _prio       Priority of the observer event handler.
 | 
					 | 
				
			||||||
 *                          The smaller the number, the higher the priority.
 | 
					 | 
				
			||||||
 * @param[in]   _handler    BLE event handler.
 | 
					 | 
				
			||||||
 * @param[in]   _context    Parameter to the event handler.
 | 
					 | 
				
			||||||
 * @hideinitializer
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define NRF_SDH_BLE_OBSERVER(_name, _prio, _handler, _context)                                      \
 | 
					 | 
				
			||||||
STATIC_ASSERT(NRF_SDH_BLE_ENABLED, "NRF_SDH_BLE_ENABLED not set!");                                 \
 | 
					 | 
				
			||||||
STATIC_ASSERT(_prio < NRF_SDH_BLE_OBSERVER_PRIO_LEVELS, "Priority level unavailable.");             \
 | 
					 | 
				
			||||||
NRF_SECTION_SET_ITEM_REGISTER(sdh_ble_observers, _prio, static nrf_sdh_ble_evt_observer_t _name) =  \
 | 
					 | 
				
			||||||
{                                                                                                   \
 | 
					 | 
				
			||||||
    .handler   = _handler,                                                                          \
 | 
					 | 
				
			||||||
    .p_context = _context                                                                           \
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Macro for registering an array of @ref nrf_sdh_ble_evt_observer_t.
 | 
					 | 
				
			||||||
 *          Modules that want to be notified about SoC events must register the handler using
 | 
					 | 
				
			||||||
 *          this macro.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Each observer's handler will be dispatched an event with its relative context from @p _context.
 | 
					 | 
				
			||||||
 * This macro places the observer in a section named "sdh_ble_observers".
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param[in]   _name       Observer name.
 | 
					 | 
				
			||||||
 * @param[in]   _prio       Priority of the observer event handler.
 | 
					 | 
				
			||||||
 *                          The smaller the number, the higher the priority.
 | 
					 | 
				
			||||||
 * @param[in]   _handler    BLE event handler.
 | 
					 | 
				
			||||||
 * @param[in]   _context    An array of parameters to the event handler.
 | 
					 | 
				
			||||||
 * @param[in]   _cnt        Number of observers to register.
 | 
					 | 
				
			||||||
 * @hideinitializer
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define NRF_SDH_BLE_OBSERVERS(_name, _prio, _handler, _context, _cnt)                                    \
 | 
					 | 
				
			||||||
STATIC_ASSERT(NRF_SDH_BLE_ENABLED, "NRF_SDH_BLE_ENABLED not set!");                                      \
 | 
					 | 
				
			||||||
STATIC_ASSERT(_prio < NRF_SDH_BLE_OBSERVER_PRIO_LEVELS, "Priority level unavailable.");                  \
 | 
					 | 
				
			||||||
NRF_SECTION_SET_ITEM_REGISTER(sdh_ble_observers, _prio, static nrf_sdh_ble_evt_observer_t _name[_cnt]) = \
 | 
					 | 
				
			||||||
{                                                                                                        \
 | 
					 | 
				
			||||||
    MACRO_REPEAT_FOR(_cnt, HANDLER_SET, _handler, _context)                                              \
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if !(defined(DOXYGEN))
 | 
					 | 
				
			||||||
#define HANDLER_SET(_idx, _handler, _context)                                                       \
 | 
					 | 
				
			||||||
{                                                                                                   \
 | 
					 | 
				
			||||||
    .handler   = _handler,                                                                          \
 | 
					 | 
				
			||||||
    .p_context = _context[_idx],                                                                    \
 | 
					 | 
				
			||||||
},
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#else // __LINT__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Swallow semicolons */
 | 
					 | 
				
			||||||
/*lint -save -esym(528, *) -esym(529, *) : Symbol not referenced. */
 | 
					 | 
				
			||||||
#define NRF_SDH_BLE_OBSERVER(A, B, C, D)     static int semicolon_swallow_##A
 | 
					 | 
				
			||||||
#define NRF_SDH_BLE_OBSERVERS(A, B, C, D, E) static int semicolon_swallow_##A
 | 
					 | 
				
			||||||
/*lint -restore */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   BLE stack event handler. */
 | 
					 | 
				
			||||||
typedef void (*nrf_sdh_ble_evt_handler_t)(ble_evt_t const * p_ble_evt, void * p_context);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   BLE event observer. */
 | 
					 | 
				
			||||||
typedef struct
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    nrf_sdh_ble_evt_handler_t handler;      //!< BLE event handler.
 | 
					 | 
				
			||||||
    void *                    p_context;    //!< A parameter to the event handler.
 | 
					 | 
				
			||||||
} const nrf_sdh_ble_evt_observer_t;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Function for retrieving the address of the start of application's RAM.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param[out]  p_app_ram_start     Address of the start of application's RAM.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @retval  NRF_SUCCESS     If the address was successfully retrieved.
 | 
					 | 
				
			||||||
 * @retval  NRF_ERROR_NULL  If @p p_app_ram_start was @c NULL.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
ret_code_t nrf_sdh_ble_app_ram_start_get(uint32_t * p_app_ram_start);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Set the default BLE stack configuration.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This function configures the BLE stack with the settings specified in the
 | 
					 | 
				
			||||||
 * SoftDevice handler BLE configuration. The following configurations will be set:
 | 
					 | 
				
			||||||
 * - Number of peripheral links
 | 
					 | 
				
			||||||
 * - Number of central links
 | 
					 | 
				
			||||||
 * - ATT MTU size (for the given connection)
 | 
					 | 
				
			||||||
 * - Vendor specific UUID count
 | 
					 | 
				
			||||||
 * - GATTS Attribute table size
 | 
					 | 
				
			||||||
 * - Service changed
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param[in]   conn_cfg_tag    The connection to configure.
 | 
					 | 
				
			||||||
 * @param[out]  p_ram_start     Application RAM start address.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
ret_code_t nrf_sdh_ble_default_cfg_set(uint8_t conn_cfg_tag, uint32_t * p_ram_start);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Function for configuring and enabling the BLE stack.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param[in]   p_app_ram_start     Address of the start of application's RAM.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
ret_code_t nrf_sdh_ble_enable(uint32_t * p_app_ram_start);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif // NRF_SDH_BLE_H__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** @} */
 | 
					 | 
				
			||||||
@@ -1,118 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
 * Copyright (c) 2017 - 2018, 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, except as embedded into a Nordic
 | 
					 | 
				
			||||||
 *    Semiconductor ASA integrated circuit in a product or a software update for
 | 
					 | 
				
			||||||
 *    such product, 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 its
 | 
					 | 
				
			||||||
 *    contributors may be used to endorse or promote products derived from this
 | 
					 | 
				
			||||||
 *    software without specific prior written permission.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * 4. This software, with or without modification, must only be used with a
 | 
					 | 
				
			||||||
 *    Nordic Semiconductor ASA integrated circuit.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * 5. Any software provided in binary form under this license must not be reverse
 | 
					 | 
				
			||||||
 *    engineered, decompiled, modified and/or disassembled.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
 | 
					 | 
				
			||||||
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 | 
					 | 
				
			||||||
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 | 
					 | 
				
			||||||
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 "sdk_common.h"
 | 
					 | 
				
			||||||
#if NRF_MODULE_ENABLED(NRF_SDH_SOC)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "nrf_sdh_soc.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "nrf_sdh.h"
 | 
					 | 
				
			||||||
#include "nrf_soc.h"
 | 
					 | 
				
			||||||
#include "app_error.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define NRF_LOG_MODULE_NAME nrf_sdh_soc
 | 
					 | 
				
			||||||
#if NRF_SDH_SOC_LOG_ENABLED
 | 
					 | 
				
			||||||
    #define NRF_LOG_LEVEL       NRF_SDH_SOC_LOG_LEVEL
 | 
					 | 
				
			||||||
    #define NRF_LOG_INFO_COLOR  NRF_SDH_SOC_INFO_COLOR
 | 
					 | 
				
			||||||
    #define NRF_LOG_DEBUG_COLOR NRF_SDH_SOC_DEBUG_COLOR
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    #define NRF_LOG_LEVEL       0
 | 
					 | 
				
			||||||
#endif // NRF_SDH_SOC_LOG_ENABLED
 | 
					 | 
				
			||||||
#include "nrf_log.h"
 | 
					 | 
				
			||||||
NRF_LOG_MODULE_REGISTER();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Create section set "sdh_soc_observers".
 | 
					 | 
				
			||||||
NRF_SECTION_SET_DEF(sdh_soc_observers, nrf_sdh_soc_evt_observer_t, NRF_SDH_SOC_OBSERVER_PRIO_LEVELS);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Function for polling SoC events.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param[in]   p_context   Context of the observer.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static void nrf_sdh_soc_evts_poll(void * p_context)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    ret_code_t ret_code;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    UNUSED_VARIABLE(p_context);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    while (true)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        uint32_t evt_id;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        ret_code = sd_evt_get(&evt_id);
 | 
					 | 
				
			||||||
        if (ret_code != NRF_SUCCESS)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        NRF_LOG_DEBUG("SoC event: 0x%x.", evt_id);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Forward the event to SoC observers.
 | 
					 | 
				
			||||||
        nrf_section_iter_t  iter;
 | 
					 | 
				
			||||||
        for (nrf_section_iter_init(&iter, &sdh_soc_observers);
 | 
					 | 
				
			||||||
             nrf_section_iter_get(&iter) != NULL;
 | 
					 | 
				
			||||||
             nrf_section_iter_next(&iter))
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            nrf_sdh_soc_evt_observer_t * p_observer;
 | 
					 | 
				
			||||||
            nrf_sdh_soc_evt_handler_t    handler;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            p_observer = (nrf_sdh_soc_evt_observer_t *) nrf_section_iter_get(&iter);
 | 
					 | 
				
			||||||
            handler    = p_observer->handler;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            handler(evt_id, p_observer->p_context);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (ret_code != NRF_ERROR_NOT_FOUND)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        APP_ERROR_HANDLER(ret_code);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
NRF_SDH_STACK_OBSERVER(m_nrf_sdh_soc_evts_poll, NRF_SDH_SOC_STACK_OBSERVER_PRIO) =
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    .handler   = nrf_sdh_soc_evts_poll,
 | 
					 | 
				
			||||||
    .p_context = NULL,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif // NRF_MODULE_ENABLED(NRF_SDH_SOC)
 | 
					 | 
				
			||||||
@@ -1,143 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
 * Copyright (c) 2017 - 2018, 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, except as embedded into a Nordic
 | 
					 | 
				
			||||||
 *    Semiconductor ASA integrated circuit in a product or a software update for
 | 
					 | 
				
			||||||
 *    such product, 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 its
 | 
					 | 
				
			||||||
 *    contributors may be used to endorse or promote products derived from this
 | 
					 | 
				
			||||||
 *    software without specific prior written permission.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * 4. This software, with or without modification, must only be used with a
 | 
					 | 
				
			||||||
 *    Nordic Semiconductor ASA integrated circuit.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * 5. Any software provided in binary form under this license must not be reverse
 | 
					 | 
				
			||||||
 *    engineered, decompiled, modified and/or disassembled.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
 | 
					 | 
				
			||||||
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 | 
					 | 
				
			||||||
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 | 
					 | 
				
			||||||
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@file
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @defgroup nrf_sdh_soc SoC support in SoftDevice Handler
 | 
					 | 
				
			||||||
 * @{
 | 
					 | 
				
			||||||
 * @ingroup  nrf_sdh
 | 
					 | 
				
			||||||
 * @brief    This file contains the declarations of types and functions required for SoftDevice Handler
 | 
					 | 
				
			||||||
 * SoC support.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifndef NRF_SDH_SOC_H__
 | 
					 | 
				
			||||||
#define NRF_SDH_SOC_H__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "sdk_common.h"
 | 
					 | 
				
			||||||
#include "nrf_section_iter.h"
 | 
					 | 
				
			||||||
#include "nrf_soc.h"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
extern "C" {
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if !(defined(__LINT__))
 | 
					 | 
				
			||||||
/**@brief   Macro for registering @ref nrf_sdh_soc_evt_observer_t. Modules that want to be
 | 
					 | 
				
			||||||
 *          notified about SoC events must register the handler using this macro.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @details This macro places the observer in a section named "sdh_soc_observers".
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param[in]   _name       Observer name.
 | 
					 | 
				
			||||||
 * @param[in]   _prio       Priority of the observer event handler.
 | 
					 | 
				
			||||||
 *                          The smaller the number, the higher the priority.
 | 
					 | 
				
			||||||
 * @param[in]   _handler    SoC event handler.
 | 
					 | 
				
			||||||
 * @param[in]   _context    Parameter to the event handler.
 | 
					 | 
				
			||||||
 * @hideinitializer
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define NRF_SDH_SOC_OBSERVER(_name, _prio, _handler, _context)                                      \
 | 
					 | 
				
			||||||
STATIC_ASSERT(NRF_SDH_SOC_ENABLED, "NRF_SDH_SOC_ENABLED not set!");                                 \
 | 
					 | 
				
			||||||
STATIC_ASSERT(_prio < NRF_SDH_SOC_OBSERVER_PRIO_LEVELS, "Priority level unavailable.");             \
 | 
					 | 
				
			||||||
NRF_SECTION_SET_ITEM_REGISTER(sdh_soc_observers, _prio, static nrf_sdh_soc_evt_observer_t _name) =  \
 | 
					 | 
				
			||||||
{                                                                                                   \
 | 
					 | 
				
			||||||
    .handler   = _handler,                                                                          \
 | 
					 | 
				
			||||||
    .p_context = _context                                                                           \
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   Macro for registering an array of @ref nrf_sdh_soc_evt_observer_t.
 | 
					 | 
				
			||||||
 *          Modules that want to be notified about SoC events must register the handler using
 | 
					 | 
				
			||||||
 *          this macro.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Each observer's handler will be dispatched an event with its relative context from @p _context.
 | 
					 | 
				
			||||||
 * This macro places the observer in a section named "sdh_soc_observers".
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * @param[in]   _name       Observer name.
 | 
					 | 
				
			||||||
 * @param[in]   _prio       Priority of the observer event handler.
 | 
					 | 
				
			||||||
 *                          The smaller the number, the higher the priority.
 | 
					 | 
				
			||||||
 * @param[in]   _handler    SoC event handler.
 | 
					 | 
				
			||||||
 * @param[in]   _context    An array of parameters to the event handler.
 | 
					 | 
				
			||||||
 * @param[in]   _cnt        Number of observers to register.
 | 
					 | 
				
			||||||
 * @hideinitializer
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
#define NRF_SDH_SOC_EVENT_OBSERVERS(_name, _prio, _handler, _context, _cnt)                              \
 | 
					 | 
				
			||||||
STATIC_ASSERT(NRF_SDH_SOC_ENABLED, "NRF_SDH_SOC_ENABLED not set!");                                      \
 | 
					 | 
				
			||||||
STATIC_ASSERT(_prio < NRF_SDH_SOC_OBSERVER_PRIO_LEVELS, "Priority level unavailable.");                  \
 | 
					 | 
				
			||||||
NRF_SECTION_SET_ITEM_REGISTER(sdh_soc_observers, _prio, static nrf_sdh_soc_evt_observer_t _name[_cnt]) = \
 | 
					 | 
				
			||||||
{                                                                                                        \
 | 
					 | 
				
			||||||
    MACRO_REPEAT_FOR(_cnt, HANDLER_SET, _handler, _context)                                              \
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#if !(defined(DOXYGEN))
 | 
					 | 
				
			||||||
#define HANDLER_SET(_idx, _handler, _context)                                                       \
 | 
					 | 
				
			||||||
{                                                                                                   \
 | 
					 | 
				
			||||||
    .handler   = _handler,                                                                          \
 | 
					 | 
				
			||||||
    .p_context = _context[_idx],                                                                    \
 | 
					 | 
				
			||||||
},
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#else // __LINT__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Swallow semicolons */
 | 
					 | 
				
			||||||
/*lint -save -esym(528, *) -esym(529, *) : Symbol not referenced. */
 | 
					 | 
				
			||||||
#define NRF_SDH_SOC_OBSERVER(A, B, C, D)     static int semicolon_swallow_##A
 | 
					 | 
				
			||||||
#define NRF_SDH_SOC_OBSERVERS(A, B, C, D, E) static int semicolon_swallow_##A
 | 
					 | 
				
			||||||
/*lint -restore */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   SoC event handler. */
 | 
					 | 
				
			||||||
typedef void (*nrf_sdh_soc_evt_handler_t) (uint32_t evt_id, void * p_context);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**@brief   SoC event observer. */
 | 
					 | 
				
			||||||
typedef struct
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    nrf_sdh_soc_evt_handler_t   handler;    //!< SoC event handler.
 | 
					 | 
				
			||||||
    void                      * p_context;  //!< A parameter to the event handler.
 | 
					 | 
				
			||||||
} const nrf_sdh_soc_evt_observer_t;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif // NRF_SDH_SOC_H__
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** @} */
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user