update s140 to 6.0.0

This commit is contained in:
hathach 2018-04-02 14:59:19 +07:00
parent d362ad1c53
commit 9f6f48c586
39 changed files with 20011 additions and 17083 deletions

View File

@ -0,0 +1,430 @@
/**
* 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)

View File

@ -0,0 +1,305 @@
/**
* 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__
/** @} */

View File

@ -0,0 +1,324 @@
/**
* 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)

View File

@ -0,0 +1,184 @@
/**
* 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__
/** @} */

View File

@ -0,0 +1,118 @@
/**
* 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)

View File

@ -0,0 +1,143 @@
/**
* 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__
/** @} */

View File

@ -81,13 +81,13 @@ enum NRF_MBR_SVCS
/**@brief Possible values for ::sd_mbr_command_t.command */
enum NRF_MBR_COMMANDS
{
SD_MBR_COMMAND_COPY_BL, /**< Copy a new BootLoader. @see sd_mbr_command_copy_bl_t*/
SD_MBR_COMMAND_COPY_BL, /**< Copy a new BootLoader. @see ::sd_mbr_command_copy_bl_t*/
SD_MBR_COMMAND_COPY_SD, /**< Copy a new SoftDevice. @see ::sd_mbr_command_copy_sd_t*/
SD_MBR_COMMAND_INIT_SD, /**< Initialize forwarding interrupts to SD, and run reset function in SD*/
SD_MBR_COMMAND_INIT_SD, /**< Initialize forwarding interrupts to SD, and run reset function in SD. Does not require any parameters in ::sd_mbr_command_t params.*/
SD_MBR_COMMAND_COMPARE, /**< This command works like memcmp. @see ::sd_mbr_command_compare_t*/
SD_MBR_COMMAND_VECTOR_TABLE_BASE_SET, /**< Change the address the MBR starts after a reset @see ::sd_mbr_command_vector_table_base_set_t*/
SD_MBR_COMMAND_VECTOR_TABLE_BASE_SET, /**< Change the address the MBR starts after a reset. @see ::sd_mbr_command_vector_table_base_set_t*/
SD_MBR_COMMAND_RESERVED,
SD_MBR_COMMAND_IRQ_FORWARD_ADDRESS_SET, /**< Start forwarding all interrupts to this address @see ::sd_mbr_command_irq_forward_address_set_t*/
SD_MBR_COMMAND_IRQ_FORWARD_ADDRESS_SET, /**< Start forwarding all interrupts to this address. @see ::sd_mbr_command_irq_forward_address_set_t*/
};
/** @} */
@ -96,6 +96,7 @@ enum NRF_MBR_COMMANDS
* @{ */
/**@brief This command copies part of a new SoftDevice
*
* The destination area is erased before copying.
* If dst is in the middle of a flash page, that whole flash page will be erased.
* If (dst+len) is in the middle of a flash page, that whole flash page will be erased.
@ -127,14 +128,17 @@ typedef struct
/**@brief This command copies a new BootLoader.
* With this command, destination of BootLoader is always the address written in NRF_UICR->BOOTADDR.
*
* Destination is erased by this function.
* If (destination+bl_len) is in the middle of a flash page, that whole flash page will be erased.
* With this command, destination of BootLoader is always the address written in
* NRF_UICR->BOOTADDR.
*
* This function will use PROTENSET to protect the flash that is not intended to be written.
* Destination is erased by this function.
* If (destination+bl_len) is in the middle of a flash page, that whole flash page will be erased.
*
* On success, this function will not return. It will start the new BootLoader from reset-vector as normal.
* This function will use the flash protect peripheral (BPROT or ACL) to protect the flash that is
* not intended to be written.
*
* On success, this function will not return. It will start the new BootLoader from reset-vector as normal.
*
* @retval ::NRF_ERROR_INTERNAL indicates an internal error that should not happen.
* @retval ::NRF_ERROR_FORBIDDEN if NRF_UICR->BOOTADDR is not set.
@ -149,10 +153,12 @@ typedef struct
/**@brief Change the address the MBR starts after a reset
*
* Once this function has been called, this address is where the MBR will start to forward interrupts to after a reset.
* Once this function has been called, this address is where the MBR will start to forward
* interrupts to after a reset.
*
* To restore default forwarding this function should be called with @param address set to 0.
* The MBR will then start forwarding to interrupts to the address in NFR_UICR->BOOTADDR or to the SoftDevice if the BOOTADDR is not set.
* To restore default forwarding this function should be called with @ref address set to 0. The
* MBR will then start forwarding interrupts to the address in NFR_UICR->BOOTADDR or to the
* SoftDevice if the BOOTADDR is not set.
*
* On success, this function will not return. It will reset the device.
*
@ -166,6 +172,7 @@ typedef struct
} sd_mbr_command_vector_table_base_set_t;
/**@brief Sets the base address of the interrupt vector table for interrupts forwarded from the MBR
*
* Unlike sd_mbr_command_vector_table_base_set_t, this function does not reset, and it does not
* change where the MBR starts after reset.
*
@ -176,9 +183,15 @@ typedef struct
uint32_t address; /**< The base address of the interrupt vector table for forwarded interrupts.*/
} sd_mbr_command_irq_forward_address_set_t;
/**@brief Input structure containing data used when calling ::sd_mbr_command
*
* Depending on what command value that is set, the corresponding params value type must also be
* set. See @ref NRF_MBR_COMMANDS for command types and corresponding params value type. If command
* @ref SD_MBR_COMMAND_INIT_SD is set, it is not necessary to set any values under params.
*/
typedef struct
{
uint32_t command; /**< type of command to be issued see @ref NRF_MBR_COMMANDS. */
uint32_t command; /**< Type of command to be issued. See @ref NRF_MBR_COMMANDS. */
union
{
sd_mbr_command_copy_sd_t copy_sd; /**< Parameters for copy SoftDevice.*/
@ -186,7 +199,7 @@ typedef struct
sd_mbr_command_copy_bl_t copy_bl; /**< Parameters for copy BootLoader. Requires parameter page. */
sd_mbr_command_vector_table_base_set_t base_set; /**< Parameters for vector table base set. Requires parameter page.*/
sd_mbr_command_irq_forward_address_set_t irq_forward_address_set; /**< Parameters for irq forward address set*/
} params;
} params; /**< Command parameters. */
} sd_mbr_command_t;
/** @} */
@ -198,21 +211,22 @@ typedef struct
*
* Commands used when updating a SoftDevice and bootloader.
*
* The SD_MBR_COMMAND_COPY_BL and SD_MBR_COMMAND_VECTOR_TABLE_BASE_SET requires parameters to be
* retained by the MBR when resetting the IC. This is done in a separate flash page
* provided by the application. The UICR register UICR.NRFFW[1] must be set
* to an address corresponding to a page in the application flash space. This page will be cleared
* by the MBR and used to store the command before reset. When the UICR.NRFFW[1] field is set
* the page it refers to must not be used by the application. If the UICR.NRFFW[1] is set to
* 0xFFFFFFFF (the default) MBR commands which use flash will be unavailable and return
* NRF_ERROR_NO_MEM.
* The @ref SD_MBR_COMMAND_COPY_BL and @ref SD_MBR_COMMAND_VECTOR_TABLE_BASE_SET requires
* parameters to be retained by the MBR when resetting the IC. This is done in a separate flash
* page provided by the application. The UICR register UICR.NRFFW[1] must be set to an address
* corresponding to a page in the application flash space. This page will be cleared by the MBR and
* used to store the command before reset. When the UICR.NRFFW[1] field is set the page it refers
* to must not be used by the application. If the UICR.NRFFW[1] is set to 0xFFFFFFFF (the default)
* MBR commands which use flash will be unavailable and return @ref NRF_ERROR_NO_MEM.
*
* @param[in] param Pointer to a struct describing the command.
*
* @note For return values, see ::sd_mbr_command_copy_sd_t ::sd_mbr_command_copy_bl_t ::sd_mbr_command_compare_t ::sd_mbr_command_vector_table_base_set_t ::sd_mbr_command_irq_forward_address_set_t
* @note For return values, see ::sd_mbr_command_copy_sd_t, ::sd_mbr_command_copy_bl_t,
* ::sd_mbr_command_compare_t, ::sd_mbr_command_vector_table_base_set_t,
* ::sd_mbr_command_irq_forward_address_set_t
*
* @retval NRF_ERROR_NO_MEM if UICR.NRFFW[1] is not set (i.e. is 0xFFFFFFFF).
* @retval NRF_ERROR_INVALID_PARAM if an invalid command is given.
* @retval ::NRF_ERROR_NO_MEM if UICR.NRFFW[1] is not set (i.e. is 0xFFFFFFFF).
* @retval ::NRF_ERROR_INVALID_PARAM if an invalid command is given.
*/
SVCALL(SD_MBR_COMMAND, uint32_t, sd_mbr_command(sd_mbr_command_t* param));

View File

@ -0,0 +1,35 @@
Copyright (c) 2007 - 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.

View File

@ -0,0 +1,165 @@
:020000040000FA
:1000000000040020990900002D0600007909000075
:1000100037060000410600004B060000000000000B
:10002000000000000000000000000000BD0900000A
:1000300055060000000000005F0600006906000091
:10004000730600007D060000870600009106000090
:100050009B060000A5060000AF060000B9060000E0
:10006000C3060000CD060000D7060000E106000030
:10007000EB060000F5060000FF060000090700007F
:10008000130700001D0700002707000031070000CC
:100090003B070000450700004F070000590700001C
:1000A000630700006D07000077070000810700006C
:1000B0008B070000950700009F070000A9070000BC
:1000C000B3070000BD070000C7070000D10700000C
:1000D000DB070000E5070000EF070000F90700005C
:1000E000030800000D0800001708000021080000A8
:1000F0002B080000350800003F08000049080000F8
:10010000530800001FB500F003F88DE80F001FBD75
:1001100000F038BC70B50B46010B184400F6FF70B8
:10012000040B4FF080500022090303692403406947
:1001300043431D1B104600F0E9F929462046BDE85F
:10014000704000F0E3B9F0B54FF6FF734FF4B475AB
:100150001A466E1E12E0A94201D3344600E00C4656
:10016000B1EB040130F8027B641E3B441A44F9D120
:100170009CB204EB134394B204EB12420029EAD17F
:1001800098B200EB134002EB124140EA0140F0BD8F
:10019000C34992B00446D1E90001CDE91001FF2224
:1001A0004021684600F094FB94E80F008DE80F00B2
:1001B000684610A902E004C841F8042D8842FAD12B
:1001C00010216846FFF7BFFF1090AA208DF8440069
:1001D00000F0FAF800F0DDF84FF01024A0691022CA
:1001E0006946803000F0DEF8A069082210A900F00E
:1001F000D9F800F0C2F870B504460068A94D072888
:1002000069D2DFE800F033041929561E2500D4E92D
:10021000026564682946304600F0FDF82A4621460A
:10022000304600F0BFF8AA002146304600F024FB1B
:10023000002800D0032070BD00F0D6FB4FF48050A2
:1002400007E0201D00F0C6F80028F4D100F0CCFB38
:1002500060682860002070BD241D94E807009200AB
:1002600000F00AFB0028F6D00E2070BD00F0BEF8AA
:100270000028FAD1D4E9010100EB81034FF080504E
:10028000026945696A43934209D84FF010225369C5
:1002900003EB81030169406941438B4201D9092085
:1002A00070BD5069401C01D10F2070BD2046FFF782
:1002B0006FFF00F09BF80028F7D1201D00F08AF8AE
:1002C0000028F2D160680028F0D100F07DF800F03D
:1002D00060F800F052F8072070BD10B50C461828E1
:1002E00002D00120086010BD2068FFF784FF206065
:1002F00010BD4FF01024A069401C05D0A569A66967
:1003000080353079AA2808D06069401C2DD06069FA
:100310000068401C29D060692CE010212846FFF7B6
:1003200012FF316881421CD1A16901F18002C03104
:1003300005E030B108CA51F8040D984201D10120FE
:1003400000E000208A42F4D158B1286810B1042896
:1003500003D0FEE7284600F070F85249686808604C
:1003600008E000F016F800F008F84FF4805001683B
:10037000491C01D000F012FBFEE7BFF34F8F4A4843
:1003800001684A4A01F4E06111430160BFF34F8FF5
:10039000FEE74FF010208169491C02D0806900F00F
:1003A0008CB870472DE9F04117460D4606460024EB
:1003B00006E03046296800F093F8641C2D1D361DB8
:1003C000BC42F6D3BDE8F0814FF0102080694FF4B5
:1003D00080519FE64FF080510A69496900684A439D
:1003E000824201D810207047002070474FF08050A3
:1003F0000169406941434FF01020826902F5805243
:10040000914201D2092070478069401C01D0002030
:1004100070470420704770B50C4605464FF480665F
:1004200008E0284600F049F8B44205D3A4F58064FA
:1004300005F58055002CF4D170BD4168044609B122
:10044000012600E000264FF010256869A26892009E
:1004500000F012FAF8B1A06881006869FFF75AFE4F
:10046000BEB16E694FF08050A56864680169426949
:100470005143A1420DD9016940694143A94208D9BC
:1004800029463046FFF7C7FF2A4621463046FFF788
:1004900089FFFFF772FFFFF797FFFFF77AFFF8E793
:1004A0000C0A0000000000200CED00E00400FA053A
:1004B000144801680029FCD07047134A02211160DA
:1004C00010490B68002BFCD00F4B1B1D18600868EF
:1004D0000028FCD00020106008680028FCD070477D
:1004E000094B10B501221A60064A1468002CFCD092
:1004F000016010680028FCD00020186010680028F7
:10050000FCD010BD00E4014004E5014070B50C468C
:10051000054600F073F810B900F07EF828B12146C6
:100520002846BDE8704000F007B821462846BDE8DF
:10053000704000F037B800007FB5002200920192B1
:10054000029203920A0B000B6946012302440AE05F
:10055000440900F01F0651F8245003FA06F635430B
:1005600041F82450401C8242F2D80D490868009A94
:1005700010430860081D0168019A1143016000F0F2
:100580003DF800280AD0064910310868029A104345
:100590000860091D0868039A104308607FBD0000C9
:1005A0000006004030B50F4C002200BF04EB0213E0
:1005B000D3F800582DB9D3F8045815B9D3F8085812
:1005C0001DB1521C082AF1D330BD082AFCD204EB1D
:1005D0000212C2F80008C3F804180220C3F8080881
:1005E00030BD000000E001404FF08050D0F83001F5
:1005F000082801D000207047012070474FF080503C
:10060000D0F83011062905D0D0F83001401C01D0B7
:1006100000207047012070474FF08050D0F8300123
:100620000A2801D0002070470120704708208F4918
:1006300009680958084710208C4909680958084773
:1006400014208A4909680958084718208749096809
:100650000958084730208549096809580847382053
:1006600082490968095808473C20804909680958A7
:10067000084740207D4909680958084744207B49BC
:1006800009680958084748207849096809580847FF
:100690004C20764909680958084750207349096871
:1006A00009580847542071490968095808475820D3
:1006B0006E490968095808475C206C49096809585F
:1006C0000847602069490968095808476420674954
:1006D00009680958084768206449096809580847A3
:1006E0006C20624909680958084770205F49096809
:1006F0000958084774205D49096809580847782057
:100700005A490968095808477C2058490968095816
:1007100008478020554909680958084784205349EB
:100720000968095808478820504909680958084746
:100730008C204E4909680958084790204B490968A0
:1007400009580847942049490968095808479820DA
:1007500046490968095808479C20444909680958CE
:100760000847A0204149096809580847A4203F4983
:10077000096809580847A8203C49096809580847EA
:10078000AC203A49096809580847B0203749096838
:1007900009580847B4203549096809580847B8205E
:1007A0003249096809580847BC2030490968095886
:1007B0000847C0202D49096809580847C4202B491B
:1007C000096809580847C82028490968095808478E
:1007D000CC202649096809580847D02023490968D0
:1007E00009580847D4202149096809580847D820E2
:1007F0001E49096809580847DC201C49096809583E
:100800000847E0201949096809580847E4201749B2
:10081000096809580847E820144909680958084731
:10082000EC201249096809580847F0200F49096867
:1008300009580847F4200D49096809580847F82065
:100840000A49096809580847FC20084909680958F5
:1008500008475FF480700549096809580847000097
:1008600003480449024A034B70470000000000207F
:10087000180A0000180A000040EA010310B59B079F
:100880000FD1042A0DD310C808C9121F9C42F8D0FA
:1008900020BA19BA884201D9012010BD4FF0FF30AB
:1008A00010BD1AB1D30703D0521C07E0002010BDC1
:1008B00010F8013B11F8014B1B1B07D110F8013B4D
:1008C00011F8014B1B1B01D1921EF1D1184610BD2E
:1008D00002F0FF0343EA032242EA024200F005B8B5
:1008E0007047704770474FF000020429C0F0128033
:1008F00010F0030C00F01B80CCF1040CBCF1020FD3
:1009000018BF00F8012BA8BF20F8022BA1EB0C01A7
:1009100000F00DB85FEAC17C24BF00F8012B00F89D
:10092000012B48BF00F8012B70474FF0000200B5C3
:10093000134694469646203922BFA0E80C50A0E802
:100940000C50B1F12001BFF4F7AF090728BFA0E8B0
:100950000C5048BF0CC05DF804EB890028BF40F87C
:10096000042B08BF704748BF20F8022B11F0804FBE
:1009700018BF00F8012B7047014B1B68DB68184754
:100980000000002009480A497047FFF7FBFFFFF706
:10099000B9FB00BD20BFFDE7064B1847064A1060B3
:1009A000016881F30888406800470000180A0000C9
:1009B000180A0000F3020000000000201EF0040FDF
:1009C0000CBFEFF30881EFF30981886902380078E2
:1009D000182803D100E00000074A1047074A1268B0
:1009E0002C3212681047000000B5054B1B68054A01
:1009F0009B58984700BD0000DB020000000000206B
:100A0000080A0000040000000010000000000000C0
:080A100000FFFFFF0090D0037E
:040000050000099955
:00000001FF

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012 - 2017, Nordic Semiconductor ASA
* Copyright (c) 2012 - 2018, Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -49,8 +49,10 @@
#ifndef BLE_H__
#define BLE_H__
#include "ble_ranges.h"
#include "ble_types.h"
#include <stdint.h>
#include "nrf_svc.h"
#include "nrf_error.h"
#include "ble_err.h"
#include "ble_gap.h"
#include "ble_l2cap.h"
#include "ble_gatt.h"
@ -86,8 +88,8 @@ enum BLE_COMMON_SVCS
*/
enum BLE_COMMON_EVTS
{
BLE_EVT_USER_MEM_REQUEST = BLE_EVT_BASE, /**< User Memory request. @ref ble_evt_user_mem_request_t */
BLE_EVT_USER_MEM_RELEASE, /**< User Memory release. @ref ble_evt_user_mem_release_t */
BLE_EVT_USER_MEM_REQUEST = BLE_EVT_BASE + 0, /**< User Memory request. @ref ble_evt_user_mem_request_t */
BLE_EVT_USER_MEM_RELEASE = BLE_EVT_BASE + 1, /**< User Memory release. @ref ble_evt_user_mem_release_t */
};
/**@brief BLE Connection Configuration IDs.
@ -96,11 +98,11 @@ enum BLE_COMMON_EVTS
*/
enum BLE_CONN_CFGS
{
BLE_CONN_CFG_GAP = BLE_CONN_CFG_BASE, /**< BLE GAP specific connection configuration. */
BLE_CONN_CFG_GATTC, /**< BLE GATTC specific connection configuration. */
BLE_CONN_CFG_GATTS, /**< BLE GATTS specific connection configuration. */
BLE_CONN_CFG_GATT, /**< BLE GATT specific connection configuration. */
BLE_CONN_CFG_L2CAP, /**< BLE L2CAP specific connection configuration. */
BLE_CONN_CFG_GAP = BLE_CONN_CFG_BASE + 0, /**< BLE GAP specific connection configuration. */
BLE_CONN_CFG_GATTC = BLE_CONN_CFG_BASE + 1, /**< BLE GATTC specific connection configuration. */
BLE_CONN_CFG_GATTS = BLE_CONN_CFG_BASE + 2, /**< BLE GATTS specific connection configuration. */
BLE_CONN_CFG_GATT = BLE_CONN_CFG_BASE + 3, /**< BLE GATT specific connection configuration. */
BLE_CONN_CFG_L2CAP = BLE_CONN_CFG_BASE + 4, /**< BLE L2CAP specific connection configuration. */
};
/**@brief BLE Common Configuration IDs.
@ -117,8 +119,8 @@ enum BLE_COMMON_CFGS
*/
enum BLE_COMMON_OPTS
{
BLE_COMMON_OPT_PA_LNA = BLE_OPT_BASE, /**< PA and LNA options */
BLE_COMMON_OPT_CONN_EVT_EXT, /**< Extended connection events option */
BLE_COMMON_OPT_PA_LNA = BLE_OPT_BASE + 0, /**< PA and LNA options */
BLE_COMMON_OPT_CONN_EVT_EXT = BLE_OPT_BASE + 1, /**< Extended connection events option */
};
/** @} */
@ -138,13 +140,9 @@ enum BLE_COMMON_OPTS
* @note The highest value used for @ref ble_gatt_conn_cfg_t::att_mtu in any connection configuration shall be used as a parameter.
* If that value has not been configured for any connections then @ref BLE_GATT_ATT_MTU_DEFAULT must be used instead.
*/
#define BLE_EVT_LEN_MAX(ATT_MTU) (BLE_MAX( \
sizeof(ble_evt_t), \
BLE_MAX( \
offsetof(ble_evt_t, evt.gattc_evt.params.rel_disc_rsp.includes) + ((ATT_MTU) - 2) / 6 * sizeof(ble_gattc_include_t), \
offsetof(ble_evt_t, evt.gattc_evt.params.attr_info_disc_rsp.info.attr_info16) + ((ATT_MTU) - 2) / 4 * sizeof(ble_gattc_attr_info16_t) \
) \
))
#define BLE_EVT_LEN_MAX(ATT_MTU) ( \
offsetof(ble_evt_t, evt.gattc_evt.params.prim_srvc_disc_rsp.services) + ((ATT_MTU) - 1) / 4 * sizeof(ble_gattc_service_t) \
)
/** @defgroup BLE_USER_MEM_TYPES User Memory Types
* @{ */
@ -304,7 +302,10 @@ typedef union
* In the case that no configurations has been set, or fewer connection configurations has been set than enabled connections,
* the default connection configuration will be automatically added for the remaining connections.
* When creating connections with the default configuration, @ref BLE_CONN_CFG_TAG_DEFAULT should be used in
* place of @ref ble_conn_cfg_t::conn_cfg_tag. See @ref sd_ble_gap_adv_start() and @ref sd_ble_gap_connect()"
* place of @ref ble_conn_cfg_t::conn_cfg_tag.
*
* @sa sd_ble_gap_adv_start()
* @sa sd_ble_gap_connect()
*
* @mscs
* @mmsc{@ref BLE_CONN_CFG}
@ -313,8 +314,9 @@ typedef union
*/
typedef struct
{
uint8_t conn_cfg_tag; /**< The application chosen tag it can use with the @ref sd_ble_gap_adv_start() and @ref sd_ble_gap_connect()
calls to select this configuration when creating a connection.
uint8_t conn_cfg_tag; /**< The application chosen tag it can use with the
@ref sd_ble_gap_adv_start() and @ref sd_ble_gap_connect() calls
to select this configuration when creating a connection.
Must be different for all connection configurations added and not @ref BLE_CONN_CFG_TAG_DEFAULT. */
union {
ble_gap_conn_cfg_t gap_conn_cfg; /**< GAP connection configuration, cfg_id is @ref BLE_CONN_CFG_GAP. */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012 - 2017, Nordic Semiconductor ASA
* Copyright (c) 2012 - 2018, Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -65,7 +65,7 @@ extern "C" {
#define BLE_ERROR_NOT_ENABLED (NRF_ERROR_STK_BASE_NUM+0x001) /**< @ref sd_ble_enable has not been called. */
#define BLE_ERROR_INVALID_CONN_HANDLE (NRF_ERROR_STK_BASE_NUM+0x002) /**< Invalid connection handle. */
#define BLE_ERROR_INVALID_ATTR_HANDLE (NRF_ERROR_STK_BASE_NUM+0x003) /**< Invalid attribute handle. */
#define BLE_ERROR_NO_TX_PACKETS (NRF_ERROR_STK_BASE_NUM+0x004) /**< Not enough application packets available on this connection. */
#define BLE_ERROR_INVALID_ADV_HANDLE (NRF_ERROR_STK_BASE_NUM+0x004) /**< Invalid advertising handle. */
#define BLE_ERROR_INVALID_ROLE (NRF_ERROR_STK_BASE_NUM+0x005) /**< Invalid role. */
#define BLE_ERROR_BLOCKED_BY_OTHER_LINKS (NRF_ERROR_STK_BASE_NUM+0x006) /**< The attempt to change link settings failed due to the scheduling of other links. */
/** @} */

View File

@ -45,8 +45,13 @@
#ifndef BLE_GATT_H__
#define BLE_GATT_H__
#include "ble_types.h"
#include <stdint.h>
#include "nrf_svc.h"
#include "nrf_error.h"
#include "ble_hci.h"
#include "ble_ranges.h"
#include "ble_types.h"
#include "ble_err.h"
#ifdef __cplusplus
extern "C" {

View File

@ -45,12 +45,14 @@
#ifndef BLE_GATTC_H__
#define BLE_GATTC_H__
#include "ble_gatt.h"
#include "ble_types.h"
#include "ble_ranges.h"
#include <stdint.h>
#include "nrf.h"
#include "nrf_svc.h"
#include "nrf_error.h"
#include "nrf.h"
#include "ble_ranges.h"
#include "ble_types.h"
#include "ble_err.h"
#include "ble_gatt.h"
#ifdef __cplusplus
extern "C" {
@ -372,6 +374,7 @@ typedef struct
* @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
* @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
* @retval ::NRF_ERROR_BUSY Client procedure already in progress.
* @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
*/
SVCALL(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER, uint32_t, sd_ble_gattc_primary_services_discover(uint16_t conn_handle, uint16_t start_handle, ble_uuid_t const *p_srvc_uuid));
@ -398,6 +401,7 @@ SVCALL(SD_BLE_GATTC_PRIMARY_SERVICES_DISCOVER, uint32_t, sd_ble_gattc_primary_se
* @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
* @retval ::NRF_ERROR_BUSY Client procedure already in progress.
* @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
*/
SVCALL(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER, uint32_t, sd_ble_gattc_relationships_discover(uint16_t conn_handle, ble_gattc_handle_range_t const *p_handle_range));
@ -426,6 +430,7 @@ SVCALL(SD_BLE_GATTC_RELATIONSHIPS_DISCOVER, uint32_t, sd_ble_gattc_relationships
* @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
* @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @retval ::NRF_ERROR_BUSY Client procedure already in progress.
* @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
*/
SVCALL(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER, uint32_t, sd_ble_gattc_characteristics_discover(uint16_t conn_handle, ble_gattc_handle_range_t const *p_handle_range));
@ -451,6 +456,7 @@ SVCALL(SD_BLE_GATTC_CHARACTERISTICS_DISCOVER, uint32_t, sd_ble_gattc_characteris
* @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
* @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @retval ::NRF_ERROR_BUSY Client procedure already in progress.
* @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
*/
SVCALL(SD_BLE_GATTC_DESCRIPTORS_DISCOVER, uint32_t, sd_ble_gattc_descriptors_discover(uint16_t conn_handle, ble_gattc_handle_range_t const *p_handle_range));
@ -477,6 +483,7 @@ SVCALL(SD_BLE_GATTC_DESCRIPTORS_DISCOVER, uint32_t, sd_ble_gattc_descriptors_dis
* @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
* @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @retval ::NRF_ERROR_BUSY Client procedure already in progress.
* @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
*/
SVCALL(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ, uint32_t, sd_ble_gattc_char_value_by_uuid_read(uint16_t conn_handle, ble_uuid_t const *p_uuid, ble_gattc_handle_range_t const *p_handle_range));
@ -503,6 +510,7 @@ SVCALL(SD_BLE_GATTC_CHAR_VALUE_BY_UUID_READ, uint32_t, sd_ble_gattc_char_value_b
* @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
* @retval ::NRF_ERROR_BUSY Client procedure already in progress.
* @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
*/
SVCALL(SD_BLE_GATTC_READ, uint32_t, sd_ble_gattc_read(uint16_t conn_handle, uint16_t handle, uint16_t offset));
@ -528,6 +536,7 @@ SVCALL(SD_BLE_GATTC_READ, uint32_t, sd_ble_gattc_read(uint16_t conn_handle, uint
* @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State.
* @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @retval ::NRF_ERROR_BUSY Client procedure already in progress.
* @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
*/
SVCALL(SD_BLE_GATTC_CHAR_VALUES_READ, uint32_t, sd_ble_gattc_char_values_read(uint16_t conn_handle, uint16_t const *p_handles, uint16_t handle_count));
@ -574,6 +583,7 @@ SVCALL(SD_BLE_GATTC_CHAR_VALUES_READ, uint32_t, sd_ble_gattc_char_values_read(ui
* @retval ::NRF_ERROR_BUSY For write with response, procedure already in progress. Wait for a @ref BLE_GATTC_EVT_WRITE_RSP event and retry.
* @retval ::NRF_ERROR_RESOURCES Too many writes without responses queued.
* Wait for a @ref BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE event and retry.
* @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
*/
SVCALL(SD_BLE_GATTC_WRITE, uint32_t, sd_ble_gattc_write(uint16_t conn_handle, ble_gattc_write_params_t const *p_write_params));
@ -591,6 +601,7 @@ SVCALL(SD_BLE_GATTC_WRITE, uint32_t, sd_ble_gattc_write(uint16_t conn_handle, bl
* @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State or no Indication pending to be confirmed.
* @retval ::BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle.
* @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
*/
SVCALL(SD_BLE_GATTC_HV_CONFIRM, uint32_t, sd_ble_gattc_hv_confirm(uint16_t conn_handle, uint16_t handle));
@ -608,6 +619,7 @@ SVCALL(SD_BLE_GATTC_HV_CONFIRM, uint32_t, sd_ble_gattc_hv_confirm(uint16_t conn_
* @retval ::NRF_ERROR_INVALID_STATE Invalid connection state
* @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @retval ::NRF_ERROR_BUSY Client procedure already in progress.
* @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
*/
SVCALL(SD_BLE_GATTC_ATTR_INFO_DISCOVER, uint32_t, sd_ble_gattc_attr_info_discover(uint16_t conn_handle, ble_gattc_handle_range_t const * p_handle_range));
@ -640,6 +652,7 @@ SVCALL(SD_BLE_GATTC_ATTR_INFO_DISCOVER, uint32_t, sd_ble_gattc_attr_info_discove
* @retval ::NRF_ERROR_INVALID_STATE Invalid connection state or an ATT_MTU exchange was already requested once.
* @retval ::NRF_ERROR_INVALID_PARAM Invalid Client RX MTU size supplied.
* @retval ::NRF_ERROR_BUSY Client procedure already in progress.
* @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
*/
SVCALL(SD_BLE_GATTC_EXCHANGE_MTU_REQUEST, uint32_t, sd_ble_gattc_exchange_mtu_request(uint16_t conn_handle, uint16_t client_rx_mtu));

View File

@ -45,12 +45,15 @@
#ifndef BLE_GATTS_H__
#define BLE_GATTS_H__
#include "ble_types.h"
#include "ble_ranges.h"
#include "ble_l2cap.h"
#include "ble_gap.h"
#include "ble_gatt.h"
#include <stdint.h>
#include "nrf_svc.h"
#include "nrf_error.h"
#include "ble_hci.h"
#include "ble_ranges.h"
#include "ble_types.h"
#include "ble_err.h"
#include "ble_gatt.h"
#include "ble_gap.h"
#ifdef __cplusplus
extern "C" {
@ -286,7 +289,7 @@ typedef struct
uint16_t handle; /**< Characteristic Value Handle. */
uint8_t type; /**< Indication or Notification, see @ref BLE_GATT_HVX_TYPES. */
uint16_t offset; /**< Offset within the attribute value. */
uint16_t *p_len; /**< Length in bytes to be written, length in bytes written after successful return. */
uint16_t *p_len; /**< Length in bytes to be written, length in bytes written after return. */
uint8_t const *p_data; /**< Actual data content, use NULL to use the current attribute value. */
} ble_gatts_hvx_params_t;
@ -546,8 +549,8 @@ SVCALL(SD_BLE_GATTS_VALUE_SET, uint32_t, sd_ble_gatts_value_set(uint16_t conn_ha
/**@brief Get the value of a given attribute.
*
* @note If the attribute value is longer than the size of the supplied buffer,
* p_len will return the total attribute value length (excluding offset),
* and not the number of bytes actually returned in p_data.
* @ref ble_gatts_value_t::len will return the total attribute value length (excluding offset),
* and not the number of bytes actually returned in @ref ble_gatts_value_t::p_value.
* The application may use this information to allocate a suitable buffer size.
*
* @note When retrieving system attribute values with this function, the connection handle
@ -576,7 +579,7 @@ SVCALL(SD_BLE_GATTS_VALUE_GET, uint32_t, sd_ble_gatts_value_get(uint16_t conn_ha
* @note The local attribute value may be updated even if an outgoing packet is not sent to the peer due to an error during execution.
* The Attribute Table has been updated if one of the following error codes is returned: @ref NRF_ERROR_INVALID_STATE, @ref NRF_ERROR_BUSY,
* @ref NRF_ERROR_FORBIDDEN, @ref BLE_ERROR_GATTS_SYS_ATTR_MISSING and @ref NRF_ERROR_RESOURCES.
* The caller can check whether the value has been updated by looking at the contents of *(p_hvx_params->p_len).
* The caller can check whether the value has been updated by looking at the contents of *(@ref ble_gatts_hvx_params_t::p_len).
*
* @note Only one indication procedure can be ongoing per connection at a time.
* If the application tries to indicate an attribute value while another indication procedure is ongoing,
@ -604,9 +607,12 @@ SVCALL(SD_BLE_GATTS_VALUE_GET, uint32_t, sd_ble_gatts_value_get(uint16_t conn_ha
* @mmsc{@ref BLE_GATTS_HVX_DISABLED_MSC}
* @endmscs
*
* @param[in] conn_handle Connection handle.
* @param[in] p_hvx_params Pointer to an HVx parameters structure. If the p_data member contains a non-NULL pointer the attribute value will be updated with
* the contents pointed by it before sending the notification or indication.
* @param[in] conn_handle Connection handle.
* @param[in,out] p_hvx_params Pointer to an HVx parameters structure. If @ref ble_gatts_hvx_params_t::p_data
* contains a non-NULL pointer the attribute value will be updated with the contents
* pointed by it before sending the notification or indication. If the attribute value
* is updated, @ref ble_gatts_hvx_params_t::p_len is updated by the SoftDevice to
* contain the number of actual bytes written, else it will be set to 0.
*
* @retval ::NRF_SUCCESS Successfully queued a notification or indication for transmission, and optionally updated the attribute value.
* @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
@ -625,6 +631,7 @@ SVCALL(SD_BLE_GATTS_VALUE_GET, uint32_t, sd_ble_gatts_value_get(uint16_t conn_ha
* @retval ::BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value.
* @retval ::NRF_ERROR_RESOURCES Too many notifications queued.
* Wait for a @ref BLE_GATTS_EVT_HVN_TX_COMPLETE event and retry.
* @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
*/
SVCALL(SD_BLE_GATTS_HVX, uint32_t, sd_ble_gatts_hvx(uint16_t conn_handle, ble_gatts_hvx_params_t const *p_hvx_params));
@ -660,6 +667,7 @@ SVCALL(SD_BLE_GATTS_HVX, uint32_t, sd_ble_gatts_hvx(uint16_t conn_handle, ble_ga
* @retval ::BLE_ERROR_INVALID_ATTR_HANDLE Invalid attribute handle(s) supplied, handles must be in the range populated by the application.
* @retval ::NRF_ERROR_BUSY Procedure already in progress.
* @retval ::BLE_ERROR_GATTS_SYS_ATTR_MISSING System attributes missing, use @ref sd_ble_gatts_sys_attr_set to set them to a known value.
* @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
*/
SVCALL(SD_BLE_GATTS_SERVICE_CHANGED, uint32_t, sd_ble_gatts_service_changed(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle));
@ -692,6 +700,7 @@ SVCALL(SD_BLE_GATTS_SERVICE_CHANGED, uint32_t, sd_ble_gatts_service_changed(uint
* @retval ::NRF_ERROR_INVALID_PARAM Authorization op invalid,
* handle supplied does not match requested handle,
* or invalid data to be written provided by the application.
* @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
*/
SVCALL(SD_BLE_GATTS_RW_AUTHORIZE_REPLY, uint32_t, sd_ble_gatts_rw_authorize_reply(uint16_t conn_handle, ble_gatts_rw_authorize_reply_params_t const *p_rw_authorize_reply_params));
@ -813,7 +822,7 @@ SVCALL(SD_BLE_GATTS_ATTR_GET, uint32_t, sd_ble_gatts_attr_get(uint16_t handle, b
* @param[in] server_rx_mtu Server RX MTU size.
* - The minimum value is @ref BLE_GATT_ATT_MTU_DEFAULT.
* - The maximum value is @ref ble_gatt_conn_cfg_t::att_mtu in the connection configuration
used for this connection.
* used for this connection.
* - The value must be equal to Client RX MTU size given in @ref sd_ble_gattc_exchange_mtu_request
* if an ATT_MTU exchange has already been performed in the other direction.
*
@ -821,6 +830,7 @@ SVCALL(SD_BLE_GATTS_ATTR_GET, uint32_t, sd_ble_gatts_attr_get(uint16_t handle, b
* @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle.
* @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State or no ATT_MTU exchange request pending.
* @retval ::NRF_ERROR_INVALID_PARAM Invalid Server RX MTU size supplied.
* @retval ::NRF_ERROR_TIMEOUT There has been a GATT procedure timeout. No new GATT procedure can be performed without reestablishing the connection.
*/
SVCALL(SD_BLE_GATTS_EXCHANGE_MTU_REPLY, uint32_t, sd_ble_gatts_exchange_mtu_reply(uint16_t conn_handle, uint16_t server_rx_mtu));
/** @} */

View File

@ -45,10 +45,12 @@
#ifndef BLE_L2CAP_H__
#define BLE_L2CAP_H__
#include "ble_types.h"
#include "ble_ranges.h"
#include "ble_err.h"
#include <stdint.h>
#include "nrf_svc.h"
#include "nrf_error.h"
#include "ble_ranges.h"
#include "ble_types.h"
#include "ble_err.h"
#ifdef __cplusplus
extern "C" {
@ -82,32 +84,32 @@ extern "C" {
/**@brief L2CAP API SVC numbers. */
enum BLE_L2CAP_SVCS
{
SD_BLE_L2CAP_CH_SETUP = BLE_L2CAP_SVC_BASE, /**< Set up an L2CAP channel. */
SD_BLE_L2CAP_CH_RELEASE, /**< Release an L2CAP channel. */
SD_BLE_L2CAP_CH_RX, /**< Receive an SDU on an L2CAP channel. */
SD_BLE_L2CAP_CH_TX, /**< Transmit an SDU on an L2CAP channel. */
SD_BLE_L2CAP_CH_FLOW_CONTROL, /**< Advanced SDU reception flow control. */
SD_BLE_L2CAP_CH_SETUP = BLE_L2CAP_SVC_BASE + 0, /**< Set up an L2CAP channel. */
SD_BLE_L2CAP_CH_RELEASE = BLE_L2CAP_SVC_BASE + 1, /**< Release an L2CAP channel. */
SD_BLE_L2CAP_CH_RX = BLE_L2CAP_SVC_BASE + 2, /**< Receive an SDU on an L2CAP channel. */
SD_BLE_L2CAP_CH_TX = BLE_L2CAP_SVC_BASE + 3, /**< Transmit an SDU on an L2CAP channel. */
SD_BLE_L2CAP_CH_FLOW_CONTROL = BLE_L2CAP_SVC_BASE + 4, /**< Advanced SDU reception flow control. */
};
/**@brief L2CAP Event IDs. */
enum BLE_L2CAP_EVTS
{
BLE_L2CAP_EVT_CH_SETUP_REQUEST = BLE_L2CAP_EVT_BASE, /**< L2CAP Channel Setup Request event.
\n See @ref ble_l2cap_evt_ch_setup_request_t. */
BLE_L2CAP_EVT_CH_SETUP_REFUSED, /**< L2CAP Channel Setup Refused event.
\n See @ref ble_l2cap_evt_ch_setup_refused_t. */
BLE_L2CAP_EVT_CH_SETUP, /**< L2CAP Channel Setup Completed event.
\n See @ref ble_l2cap_evt_ch_setup_t. */
BLE_L2CAP_EVT_CH_RELEASED, /**< L2CAP Channel Released event.
\n No additional event structure applies. */
BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED, /**< L2CAP Channel SDU data buffer released event.
\n See @ref ble_l2cap_evt_ch_sdu_buf_released_t. */
BLE_L2CAP_EVT_CH_CREDIT, /**< L2CAP Channel Credit received.
\n See @ref ble_l2cap_evt_ch_credit_t. */
BLE_L2CAP_EVT_CH_RX, /**< L2CAP Channel SDU received.
\n See @ref ble_l2cap_evt_ch_rx_t. */
BLE_L2CAP_EVT_CH_TX, /**< L2CAP Channel SDU transmitted.
\n See @ref ble_l2cap_evt_ch_tx_t. */
BLE_L2CAP_EVT_CH_SETUP_REQUEST = BLE_L2CAP_EVT_BASE + 0, /**< L2CAP Channel Setup Request event.
\n See @ref ble_l2cap_evt_ch_setup_request_t. */
BLE_L2CAP_EVT_CH_SETUP_REFUSED = BLE_L2CAP_EVT_BASE + 1, /**< L2CAP Channel Setup Refused event.
\n See @ref ble_l2cap_evt_ch_setup_refused_t. */
BLE_L2CAP_EVT_CH_SETUP = BLE_L2CAP_EVT_BASE + 2, /**< L2CAP Channel Setup Completed event.
\n See @ref ble_l2cap_evt_ch_setup_t. */
BLE_L2CAP_EVT_CH_RELEASED = BLE_L2CAP_EVT_BASE + 3, /**< L2CAP Channel Released event.
\n No additional event structure applies. */
BLE_L2CAP_EVT_CH_SDU_BUF_RELEASED = BLE_L2CAP_EVT_BASE + 4, /**< L2CAP Channel SDU data buffer released event.
\n See @ref ble_l2cap_evt_ch_sdu_buf_released_t. */
BLE_L2CAP_EVT_CH_CREDIT = BLE_L2CAP_EVT_BASE + 5, /**< L2CAP Channel Credit received.
\n See @ref ble_l2cap_evt_ch_credit_t. */
BLE_L2CAP_EVT_CH_RX = BLE_L2CAP_EVT_BASE + 6, /**< L2CAP Channel SDU received.
\n See @ref ble_l2cap_evt_ch_rx_t. */
BLE_L2CAP_EVT_CH_TX = BLE_L2CAP_EVT_BASE + 7, /**< L2CAP Channel SDU transmitted.
\n See @ref ble_l2cap_evt_ch_tx_t. */
};
/** @} */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012 - 2017, Nordic Semiconductor ASA
* Copyright (c) 2012 - 2018, Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -67,15 +67,15 @@ extern "C" {
#define BLE_SVC_LAST 0x6B /**< Common BLE SVC last. */
#define BLE_GAP_SVC_BASE 0x6C /**< GAP BLE SVC base. */
#define BLE_GAP_SVC_LAST 0x93 /**< GAP BLE SVC last. */
#define BLE_GAP_SVC_LAST 0x9A /**< GAP BLE SVC last. */
#define BLE_GATTC_SVC_BASE 0x94 /**< GATTC BLE SVC base. */
#define BLE_GATTC_SVC_LAST 0x9F /**< GATTC BLE SVC last. */
#define BLE_GATTC_SVC_BASE 0x9B /**< GATTC BLE SVC base. */
#define BLE_GATTC_SVC_LAST 0xA7 /**< GATTC BLE SVC last. */
#define BLE_GATTS_SVC_BASE 0xA0 /**< GATTS BLE SVC base. */
#define BLE_GATTS_SVC_LAST 0xAF /**< GATTS BLE SVC last. */
#define BLE_GATTS_SVC_BASE 0xA8 /**< GATTS BLE SVC base. */
#define BLE_GATTS_SVC_LAST 0xB7 /**< GATTS BLE SVC last. */
#define BLE_L2CAP_SVC_BASE 0xB0 /**< L2CAP BLE SVC base. */
#define BLE_L2CAP_SVC_BASE 0xB8 /**< L2CAP BLE SVC base. */
#define BLE_L2CAP_SVC_LAST 0xBF /**< L2CAP BLE SVC last. */

View File

@ -0,0 +1,242 @@
/*
* Copyright (c) 2014 - 2017, 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.
*/
/**
@defgroup nrf_mbr_api Master Boot Record API
@{
@brief APIs for updating SoftDevice and BootLoader
*/
#ifndef NRF_MBR_H__
#define NRF_MBR_H__
#include "nrf_svc.h"
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @addtogroup NRF_MBR_DEFINES Defines
* @{ */
/**@brief MBR SVC Base number. */
#define MBR_SVC_BASE (0x18)
/**@brief Page size in words. */
#define MBR_PAGE_SIZE_IN_WORDS (1024)
/** @brief The size that must be reserved for the MBR when a SoftDevice is written to flash.
This is the offset where the first byte of the SoftDevice hex file is written.*/
#define MBR_SIZE (0x1000)
/** @} */
/** @addtogroup NRF_MBR_ENUMS Enumerations
* @{ */
/**@brief nRF Master Boot Record API SVC numbers. */
enum NRF_MBR_SVCS
{
SD_MBR_COMMAND = MBR_SVC_BASE, /**< ::sd_mbr_command */
};
/**@brief Possible values for ::sd_mbr_command_t.command */
enum NRF_MBR_COMMANDS
{
SD_MBR_COMMAND_COPY_BL, /**< Copy a new BootLoader. @see ::sd_mbr_command_copy_bl_t*/
SD_MBR_COMMAND_COPY_SD, /**< Copy a new SoftDevice. @see ::sd_mbr_command_copy_sd_t*/
SD_MBR_COMMAND_INIT_SD, /**< Initialize forwarding interrupts to SD, and run reset function in SD. Does not require any parameters in ::sd_mbr_command_t params.*/
SD_MBR_COMMAND_COMPARE, /**< This command works like memcmp. @see ::sd_mbr_command_compare_t*/
SD_MBR_COMMAND_VECTOR_TABLE_BASE_SET, /**< Change the address the MBR starts after a reset. @see ::sd_mbr_command_vector_table_base_set_t*/
SD_MBR_COMMAND_RESERVED,
SD_MBR_COMMAND_IRQ_FORWARD_ADDRESS_SET, /**< Start forwarding all interrupts to this address. @see ::sd_mbr_command_irq_forward_address_set_t*/
};
/** @} */
/** @addtogroup NRF_MBR_TYPES Types
* @{ */
/**@brief This command copies part of a new SoftDevice
*
* The destination area is erased before copying.
* If dst is in the middle of a flash page, that whole flash page will be erased.
* If (dst+len) is in the middle of a flash page, that whole flash page will be erased.
*
* The user of this function is responsible for setting the BPROT registers.
*
* @retval ::NRF_SUCCESS indicates that the contents of the memory blocks where copied correctly.
* @retval ::NRF_ERROR_INTERNAL indicates that the contents of the memory blocks where not verified correctly after copying.
*/
typedef struct
{
uint32_t *src; /**< Pointer to the source of data to be copied.*/
uint32_t *dst; /**< Pointer to the destination where the content is to be copied.*/
uint32_t len; /**< Number of 32 bit words to copy. Must be a multiple of @ref MBR_PAGE_SIZE_IN_WORDS words.*/
} sd_mbr_command_copy_sd_t;
/**@brief This command works like memcmp, but takes the length in words.
*
* @retval ::NRF_SUCCESS indicates that the contents of both memory blocks are equal.
* @retval ::NRF_ERROR_NULL indicates that the contents of the memory blocks are not equal.
*/
typedef struct
{
uint32_t *ptr1; /**< Pointer to block of memory. */
uint32_t *ptr2; /**< Pointer to block of memory. */
uint32_t len; /**< Number of 32 bit words to compare.*/
} sd_mbr_command_compare_t;
/**@brief This command copies a new BootLoader.
*
* With this command, destination of BootLoader is always the address written in
* NRF_UICR->BOOTADDR.
*
* Destination is erased by this function.
* If (destination+bl_len) is in the middle of a flash page, that whole flash page will be erased.
*
* This function will use the flash protect peripheral (BPROT or ACL) to protect the flash that is
* not intended to be written.
*
* On success, this function will not return. It will start the new BootLoader from reset-vector as normal.
*
* @retval ::NRF_ERROR_INTERNAL indicates an internal error that should not happen.
* @retval ::NRF_ERROR_FORBIDDEN if NRF_UICR->BOOTADDR is not set.
* @retval ::NRF_ERROR_INVALID_LENGTH if parameters attempts to read or write outside flash area.
* @retval ::NRF_ERROR_NO_MEM if no parameter page is provided (see SoftDevice Specification for more info)
*/
typedef struct
{
uint32_t *bl_src; /**< Pointer to the source of the Bootloader to be be copied.*/
uint32_t bl_len; /**< Number of 32 bit words to copy for BootLoader. */
} sd_mbr_command_copy_bl_t;
/**@brief Change the address the MBR starts after a reset
*
* Once this function has been called, this address is where the MBR will start to forward
* interrupts to after a reset.
*
* To restore default forwarding this function should be called with @ref address set to 0. The
* MBR will then start forwarding interrupts to the address in NFR_UICR->BOOTADDR or to the
* SoftDevice if the BOOTADDR is not set.
*
* On success, this function will not return. It will reset the device.
*
* @retval ::NRF_ERROR_INTERNAL indicates an internal error that should not happen.
* @retval ::NRF_ERROR_INVALID_ADDR if parameter address is outside of the flash size.
* @retval ::NRF_ERROR_NO_MEM if no parameter page is provided (see SoftDevice Specification for more info)
*/
typedef struct
{
uint32_t address; /**< The base address of the interrupt vector table for forwarded interrupts.*/
} sd_mbr_command_vector_table_base_set_t;
/**@brief Sets the base address of the interrupt vector table for interrupts forwarded from the MBR
*
* Unlike sd_mbr_command_vector_table_base_set_t, this function does not reset, and it does not
* change where the MBR starts after reset.
*
* @retval ::NRF_SUCCESS
*/
typedef struct
{
uint32_t address; /**< The base address of the interrupt vector table for forwarded interrupts.*/
} sd_mbr_command_irq_forward_address_set_t;
/**@brief Input structure containing data used when calling ::sd_mbr_command
*
* Depending on what command value that is set, the corresponding params value type must also be
* set. See @ref NRF_MBR_COMMANDS for command types and corresponding params value type. If command
* @ref SD_MBR_COMMAND_INIT_SD is set, it is not necessary to set any values under params.
*/
typedef struct
{
uint32_t command; /**< Type of command to be issued. See @ref NRF_MBR_COMMANDS. */
union
{
sd_mbr_command_copy_sd_t copy_sd; /**< Parameters for copy SoftDevice.*/
sd_mbr_command_compare_t compare; /**< Parameters for verify.*/
sd_mbr_command_copy_bl_t copy_bl; /**< Parameters for copy BootLoader. Requires parameter page. */
sd_mbr_command_vector_table_base_set_t base_set; /**< Parameters for vector table base set. Requires parameter page.*/
sd_mbr_command_irq_forward_address_set_t irq_forward_address_set; /**< Parameters for irq forward address set*/
} params; /**< Command parameters. */
} sd_mbr_command_t;
/** @} */
/** @addtogroup NRF_MBR_FUNCTIONS Functions
* @{ */
/**@brief Issue Master Boot Record commands
*
* Commands used when updating a SoftDevice and bootloader.
*
* The @ref SD_MBR_COMMAND_COPY_BL and @ref SD_MBR_COMMAND_VECTOR_TABLE_BASE_SET requires
* parameters to be retained by the MBR when resetting the IC. This is done in a separate flash
* page provided by the application. The UICR register UICR.NRFFW[1] must be set to an address
* corresponding to a page in the application flash space. This page will be cleared by the MBR and
* used to store the command before reset. When the UICR.NRFFW[1] field is set the page it refers
* to must not be used by the application. If the UICR.NRFFW[1] is set to 0xFFFFFFFF (the default)
* MBR commands which use flash will be unavailable and return @ref NRF_ERROR_NO_MEM.
*
* @param[in] param Pointer to a struct describing the command.
*
* @note For return values, see ::sd_mbr_command_copy_sd_t, ::sd_mbr_command_copy_bl_t,
* ::sd_mbr_command_compare_t, ::sd_mbr_command_vector_table_base_set_t,
* ::sd_mbr_command_irq_forward_address_set_t
*
* @retval ::NRF_ERROR_NO_MEM if UICR.NRFFW[1] is not set (i.e. is 0xFFFFFFFF).
* @retval ::NRF_ERROR_INVALID_PARAM if an invalid command is given.
*/
SVCALL(SD_MBR_COMMAND, uint32_t, sd_mbr_command(sd_mbr_command_t* param));
/** @} */
#ifdef __cplusplus
}
#endif
#endif // NRF_MBR_H__
/**
@}
*/

View File

@ -57,7 +57,8 @@
#include <stdint.h>
#include "nrf.h"
#include "nrf_svc.h"
#include "nrf_error.h"
#include "nrf_error_soc.h"
#ifdef __cplusplus
@ -85,7 +86,7 @@ extern "C" {
| (1U << CCM_AAR_IRQn) \
| (1U << TEMP_IRQn) \
| (1U << __NRF_NVIC_NVMC_IRQn) \
| (1U << (uint32_t)SWI5_EGU5_IRQn) \
| (1U << (uint32_t)SWI5_IRQn) \
))
/**@brief Interrupts used by the SoftDevice, with IRQn in the range 32-63. */

View File

@ -0,0 +1,59 @@
/**
* Copyright (c) 2015 - 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.
*
*/
#ifndef NRF_SD_DEF_H__
#define NRF_SD_DEF_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SD_PPI_CHANNELS_USED 0xFFFE0000uL /**< PPI channels utilized by SotfDevice (not available to the application). */
#define SD_PPI_GROUPS_USED 0x0000000CuL /**< PPI groups utilized by SoftDevice (not available to the application). */
#define SD_TIMERS_USED 0x00000001uL /**< Timers used by SoftDevice. */
#define SD_SWI_USED 0x0000003CuL /**< Software interrupts used by SoftDevice */
#ifdef __cplusplus
}
#endif
#endif /* NRF_SD_DEF_H__ */

View File

@ -47,10 +47,12 @@
#ifndef NRF_SDM_H__
#define NRF_SDM_H__
#include "nrf_svc.h"
#include <stdint.h>
#include "nrf.h"
#include "nrf_soc.h"
#include "nrf_svc.h"
#include "nrf_error.h"
#include "nrf_error_sdm.h"
#include "nrf_soc.h"
#ifdef __cplusplus
extern "C" {
@ -65,7 +67,7 @@ extern "C" {
#endif
/** @brief The major version for the SoftDevice binary distributed with this header file. */
#define SD_MAJOR_VERSION (0)
#define SD_MAJOR_VERSION (6)
/** @brief The minor version for the SoftDevice binary distributed with this header file. */
#define SD_MINOR_VERSION (0)
@ -306,6 +308,7 @@ typedef void (*nrf_fault_handler_t)(uint32_t id, uint32_t pc, uint32_t info);
* @retval ::NRF_ERROR_INVALID_STATE SoftDevice is already enabled, and the clock source and fault handler cannot be updated.
* @retval ::NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION SoftDevice interrupt is already enabled, or an enabled interrupt has an illegal priority level.
* @retval ::NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN Unknown low frequency clock source selected.
* @retval ::NRF_ERROR_INVALID_PARAM Invalid clock source configuration supplied in p_clock_lf_cfg.
*/
SVCALL(SD_SOFTDEVICE_ENABLE, uint32_t, sd_softdevice_enable(nrf_clock_lf_cfg_t const * p_clock_lf_cfg, nrf_fault_handler_t fault_handler));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
* Copyright (c) 2015 - 2018, Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -48,10 +48,9 @@
#define NRF_SOC_H__
#include <stdint.h>
#include <stdbool.h>
#include "nrf_svc.h"
#include "nrf.h"
#include "nrf_svc.h"
#include "nrf_error.h"
#include "nrf_error_soc.h"
#ifdef __cplusplus
@ -63,7 +62,7 @@ extern "C" {
/**@brief The number of the lowest SVC number reserved for the SoC library. */
#define SOC_SVC_BASE (0x20) /**< Base value for SVCs that are available when the SoftDevice is disabled. */
#define SOC_SVC_BASE_NOT_AVAILABLE (0x2B) /**< Base value for SVCs that are not available when the SoftDevice is disabled. */
#define SOC_SVC_BASE_NOT_AVAILABLE (0x2C) /**< Base value for SVCs that are not available when the SoftDevice is disabled. */
/**@brief Guaranteed time for application to process radio inactive notification. */
#define NRF_RADIO_NOTIFICATION_INACTIVE_GUARANTEED_TIME_US (62)
@ -81,11 +80,11 @@ extern "C" {
#define SOC_ECB_CLEARTEXT_LENGTH (16) /**< ECB cleartext length. */
#define SOC_ECB_CIPHERTEXT_LENGTH (SOC_ECB_CLEARTEXT_LENGTH) /**< ECB ciphertext length. */
#define SD_EVT_IRQn (SWI2_EGU2_IRQn) /**< SoftDevice Event IRQ number. Used for both protocol events and SoC events. */
#define SD_EVT_IRQHandler (SWI2_EGU2_IRQHandler) /**< SoftDevice Event IRQ handler. Used for both protocol events and SoC events.
#define SD_EVT_IRQn (SWI2_IRQn) /**< SoftDevice Event IRQ number. Used for both protocol events and SoC events. */
#define SD_EVT_IRQHandler (SWI2_IRQHandler) /**< SoftDevice Event IRQ handler. Used for both protocol events and SoC events.
The default interrupt priority for this handler is set to 4 */
#define RADIO_NOTIFICATION_IRQn (SWI1_EGU1_IRQn) /**< The radio notification IRQ number. */
#define RADIO_NOTIFICATION_IRQHandler (SWI1_EGU1_IRQHandler) /**< The radio notification IRQ handler.
#define RADIO_NOTIFICATION_IRQn (SWI1_IRQn) /**< The radio notification IRQ number. */
#define RADIO_NOTIFICATION_IRQHandler (SWI1_IRQHandler) /**< The radio notification IRQ handler.
The default interrupt priority for this handler is set to 4 */
#define NRF_RADIO_LENGTH_MIN_US (100) /**< The shortest allowed radio timeslot, in microseconds. */
#define NRF_RADIO_LENGTH_MAX_US (100000) /**< The longest allowed radio timeslot, in microseconds. */
@ -104,53 +103,55 @@ extern "C" {
/**@brief The SVC numbers used by the SVC functions in the SoC library. */
enum NRF_SOC_SVCS
{
SD_PPI_CHANNEL_ENABLE_GET = SOC_SVC_BASE,
SD_PPI_CHANNEL_ENABLE_SET,
SD_PPI_CHANNEL_ENABLE_CLR,
SD_PPI_CHANNEL_ASSIGN,
SD_PPI_GROUP_TASK_ENABLE,
SD_PPI_GROUP_TASK_DISABLE,
SD_PPI_GROUP_ASSIGN,
SD_PPI_GROUP_GET,
SD_FLASH_PAGE_ERASE,
SD_FLASH_WRITE,
SD_FLASH_PROTECT,
SD_MUTEX_NEW = SOC_SVC_BASE_NOT_AVAILABLE,
SD_MUTEX_ACQUIRE,
SD_MUTEX_RELEASE,
SD_RAND_APPLICATION_POOL_CAPACITY_GET,
SD_RAND_APPLICATION_BYTES_AVAILABLE_GET,
SD_RAND_APPLICATION_VECTOR_GET,
SD_POWER_MODE_SET,
SD_POWER_SYSTEM_OFF,
SD_POWER_RESET_REASON_GET,
SD_POWER_RESET_REASON_CLR,
SD_POWER_POF_ENABLE,
SD_POWER_POF_THRESHOLD_SET,
SD_POWER_RAM_POWER_SET,
SD_POWER_RAM_POWER_CLR,
SD_POWER_RAM_POWER_GET,
SD_POWER_GPREGRET_SET,
SD_POWER_GPREGRET_CLR,
SD_POWER_GPREGRET_GET,
SD_POWER_DCDC_MODE_SET,
SD_APP_EVT_WAIT,
SD_CLOCK_HFCLK_REQUEST,
SD_CLOCK_HFCLK_RELEASE,
SD_CLOCK_HFCLK_IS_RUNNING,
SD_RADIO_NOTIFICATION_CFG_SET,
SD_ECB_BLOCK_ENCRYPT,
SD_ECB_BLOCKS_ENCRYPT,
SD_RADIO_SESSION_OPEN,
SD_RADIO_SESSION_CLOSE,
SD_RADIO_REQUEST,
SD_EVT_GET,
SD_TEMP_GET,
SD_POWER_USBPWRRDY_ENABLE,
SD_POWER_USBDETECTED_ENABLE,
SD_POWER_USBREMOVED_ENABLE,
SD_POWER_USBREGSTATUS_GET,
SVC_SOC_LAST
SD_PPI_CHANNEL_ENABLE_GET = SOC_SVC_BASE,
SD_PPI_CHANNEL_ENABLE_SET = SOC_SVC_BASE + 1,
SD_PPI_CHANNEL_ENABLE_CLR = SOC_SVC_BASE + 2,
SD_PPI_CHANNEL_ASSIGN = SOC_SVC_BASE + 3,
SD_PPI_GROUP_TASK_ENABLE = SOC_SVC_BASE + 4,
SD_PPI_GROUP_TASK_DISABLE = SOC_SVC_BASE + 5,
SD_PPI_GROUP_ASSIGN = SOC_SVC_BASE + 6,
SD_PPI_GROUP_GET = SOC_SVC_BASE + 7,
SD_FLASH_PAGE_ERASE = SOC_SVC_BASE + 8,
SD_FLASH_WRITE = SOC_SVC_BASE + 9,
SD_PROTECTED_REGISTER_WRITE = SOC_SVC_BASE + 11,
SD_MUTEX_NEW = SOC_SVC_BASE_NOT_AVAILABLE,
SD_MUTEX_ACQUIRE = SOC_SVC_BASE_NOT_AVAILABLE + 1,
SD_MUTEX_RELEASE = SOC_SVC_BASE_NOT_AVAILABLE + 2,
SD_RAND_APPLICATION_POOL_CAPACITY_GET = SOC_SVC_BASE_NOT_AVAILABLE + 3,
SD_RAND_APPLICATION_BYTES_AVAILABLE_GET = SOC_SVC_BASE_NOT_AVAILABLE + 4,
SD_RAND_APPLICATION_VECTOR_GET = SOC_SVC_BASE_NOT_AVAILABLE + 5,
SD_POWER_MODE_SET = SOC_SVC_BASE_NOT_AVAILABLE + 6,
SD_POWER_SYSTEM_OFF = SOC_SVC_BASE_NOT_AVAILABLE + 7,
SD_POWER_RESET_REASON_GET = SOC_SVC_BASE_NOT_AVAILABLE + 8,
SD_POWER_RESET_REASON_CLR = SOC_SVC_BASE_NOT_AVAILABLE + 9,
SD_POWER_POF_ENABLE = SOC_SVC_BASE_NOT_AVAILABLE + 10,
SD_POWER_POF_THRESHOLD_SET = SOC_SVC_BASE_NOT_AVAILABLE + 11,
SD_POWER_POF_THRESHOLDVDDH_SET = SOC_SVC_BASE_NOT_AVAILABLE + 12,
SD_POWER_RAM_POWER_SET = SOC_SVC_BASE_NOT_AVAILABLE + 13,
SD_POWER_RAM_POWER_CLR = SOC_SVC_BASE_NOT_AVAILABLE + 14,
SD_POWER_RAM_POWER_GET = SOC_SVC_BASE_NOT_AVAILABLE + 15,
SD_POWER_GPREGRET_SET = SOC_SVC_BASE_NOT_AVAILABLE + 16,
SD_POWER_GPREGRET_CLR = SOC_SVC_BASE_NOT_AVAILABLE + 17,
SD_POWER_GPREGRET_GET = SOC_SVC_BASE_NOT_AVAILABLE + 18,
SD_POWER_DCDC_MODE_SET = SOC_SVC_BASE_NOT_AVAILABLE + 19,
SD_POWER_DCDC0_MODE_SET = SOC_SVC_BASE_NOT_AVAILABLE + 20,
SD_APP_EVT_WAIT = SOC_SVC_BASE_NOT_AVAILABLE + 21,
SD_CLOCK_HFCLK_REQUEST = SOC_SVC_BASE_NOT_AVAILABLE + 22,
SD_CLOCK_HFCLK_RELEASE = SOC_SVC_BASE_NOT_AVAILABLE + 23,
SD_CLOCK_HFCLK_IS_RUNNING = SOC_SVC_BASE_NOT_AVAILABLE + 24,
SD_RADIO_NOTIFICATION_CFG_SET = SOC_SVC_BASE_NOT_AVAILABLE + 25,
SD_ECB_BLOCK_ENCRYPT = SOC_SVC_BASE_NOT_AVAILABLE + 26,
SD_ECB_BLOCKS_ENCRYPT = SOC_SVC_BASE_NOT_AVAILABLE + 27,
SD_RADIO_SESSION_OPEN = SOC_SVC_BASE_NOT_AVAILABLE + 28,
SD_RADIO_SESSION_CLOSE = SOC_SVC_BASE_NOT_AVAILABLE + 29,
SD_RADIO_REQUEST = SOC_SVC_BASE_NOT_AVAILABLE + 30,
SD_EVT_GET = SOC_SVC_BASE_NOT_AVAILABLE + 31,
SD_TEMP_GET = SOC_SVC_BASE_NOT_AVAILABLE + 32,
SD_POWER_USBPWRRDY_ENABLE = SOC_SVC_BASE_NOT_AVAILABLE + 33,
SD_POWER_USBDETECTED_ENABLE = SOC_SVC_BASE_NOT_AVAILABLE + 34,
SD_POWER_USBREMOVED_ENABLE = SOC_SVC_BASE_NOT_AVAILABLE + 35,
SD_POWER_USBREGSTATUS_GET = SOC_SVC_BASE_NOT_AVAILABLE + 36,
SVC_SOC_LAST = SOC_SVC_BASE_NOT_AVAILABLE + 37
};
/**@brief Possible values of a ::nrf_mutex_t. */
@ -185,6 +186,27 @@ enum NRF_POWER_THRESHOLDS
NRF_POWER_THRESHOLD_V28 /**< 2.8 Volts power failure threshold. */
};
/**@brief Power failure thresholds for high voltage */
enum NRF_POWER_THRESHOLDVDDHS
{
NRF_POWER_THRESHOLDVDDH_V27, /**< 2.7 Volts power failure threshold. */
NRF_POWER_THRESHOLDVDDH_V28, /**< 2.8 Volts power failure threshold. */
NRF_POWER_THRESHOLDVDDH_V29, /**< 2.9 Volts power failure threshold. */
NRF_POWER_THRESHOLDVDDH_V30, /**< 3.0 Volts power failure threshold. */
NRF_POWER_THRESHOLDVDDH_V31, /**< 3.1 Volts power failure threshold. */
NRF_POWER_THRESHOLDVDDH_V32, /**< 3.2 Volts power failure threshold. */
NRF_POWER_THRESHOLDVDDH_V33, /**< 3.3 Volts power failure threshold. */
NRF_POWER_THRESHOLDVDDH_V34, /**< 3.4 Volts power failure threshold. */
NRF_POWER_THRESHOLDVDDH_V35, /**< 3.5 Volts power failure threshold. */
NRF_POWER_THRESHOLDVDDH_V36, /**< 3.6 Volts power failure threshold. */
NRF_POWER_THRESHOLDVDDH_V37, /**< 3.7 Volts power failure threshold. */
NRF_POWER_THRESHOLDVDDH_V38, /**< 3.8 Volts power failure threshold. */
NRF_POWER_THRESHOLDVDDH_V39, /**< 3.9 Volts power failure threshold. */
NRF_POWER_THRESHOLDVDDH_V40, /**< 4.0 Volts power failure threshold. */
NRF_POWER_THRESHOLDVDDH_V41, /**< 4.1 Volts power failure threshold. */
NRF_POWER_THRESHOLDVDDH_V42 /**< 4.2 Volts power failure threshold. */
};
/**@brief DC/DC converter modes. */
enum NRF_POWER_DCDC_MODES
@ -524,7 +546,11 @@ SVCALL(SD_POWER_USBREMOVED_ENABLE, uint32_t, sd_power_usbremoved_enable(uint8_t
*/
SVCALL(SD_POWER_USBREGSTATUS_GET, uint32_t, sd_power_usbregstatus_get(uint32_t * usbregstatus));
/**@brief Sets the power-fail threshold value.
/**@brief Sets the power failure comparator threshold value.
*
* @note: Power failure comparator threshold setting. This setting applies both for normal voltage
* mode (supply connected to both VDD and VDDH) and high voltage mode (supply connected to
* VDDH only).
*
* @param[in] threshold The power-fail threshold value to use, see @ref NRF_POWER_THRESHOLDS.
*
@ -533,6 +559,19 @@ SVCALL(SD_POWER_USBREGSTATUS_GET, uint32_t, sd_power_usbregstatus_get(uint32_t *
*/
SVCALL(SD_POWER_POF_THRESHOLD_SET, uint32_t, sd_power_pof_threshold_set(uint8_t threshold));
/**@brief Sets the power failure comparator threshold value for high voltage.
*
* @note: Power failure comparator threshold setting for high voltage mode (supply connected to
* VDDH only). This setting does not apply for normal voltage mode (supply connected to both
* VDD and VDDH).
*
* @param[in] threshold The power-fail threshold value to use, see @ref NRF_POWER_THRESHOLDVDDHS.
*
* @retval ::NRF_SUCCESS The power failure threshold was set.
* @retval ::NRF_ERROR_SOC_POWER_POF_THRESHOLD_UNKNOWN The power failure threshold is unknown.
*/
SVCALL(SD_POWER_POF_THRESHOLDVDDH_SET, uint32_t, sd_power_pof_thresholdvddh_set(uint8_t threshold));
/**@brief Writes the NRF_POWER->RAM[index].POWERSET register.
*
* @param[in] index Contains the index in the NRF_POWER->RAM[index].POWERSET register to write to.
@ -587,9 +626,7 @@ SVCALL(SD_POWER_GPREGRET_CLR, uint32_t, sd_power_gpregret_clr(uint32_t gpregret_
*/
SVCALL(SD_POWER_GPREGRET_GET, uint32_t, sd_power_gpregret_get(uint32_t gpregret_id, uint32_t *p_gpregret));
/**@brief Sets the DCDC mode.
*
* Enable or disable the DCDC peripheral.
/**@brief Enable or disable the DC/DC regulator for the regulator stage 1 (REG1).
*
* @param[in] dcdc_mode The mode of the DCDC, see @ref NRF_POWER_DCDC_MODES.
*
@ -598,6 +635,17 @@ SVCALL(SD_POWER_GPREGRET_GET, uint32_t, sd_power_gpregret_get(uint32_t gpregret_
*/
SVCALL(SD_POWER_DCDC_MODE_SET, uint32_t, sd_power_dcdc_mode_set(uint8_t dcdc_mode));
/**@brief Enable or disable the DC/DC regulator for the regulator stage 0 (REG0).
*
* For more details on the REG0 stage, please see product specification.
*
* @param[in] dcdc_mode The mode of the DCDC0, see @ref NRF_POWER_DCDC_MODES.
*
* @retval ::NRF_SUCCESS
* @retval ::NRF_ERROR_INVALID_PARAM The dcdc_mode is invalid.
*/
SVCALL(SD_POWER_DCDC0_MODE_SET, uint32_t, sd_power_dcdc0_mode_set(uint8_t dcdc_mode));
/**@brief Request the high frequency crystal oscillator.
*
* Will start the high frequency crystal oscillator, the startup time of the crystal varies
@ -839,6 +887,8 @@ SVCALL(SD_TEMP_GET, uint32_t, sd_temp_get(int32_t * p_temp));
* and the command parameters).
* - The data in the p_src buffer should not be modified before the @ref NRF_EVT_FLASH_OPERATION_SUCCESS
* or the @ref NRF_EVT_FLASH_OPERATION_ERROR have been received if the SoftDevice is enabled.
* - This call will make the SoftDevice trigger a hardfault when the page is written, if it is
* protected.
*
*
* @param[in] p_dst Pointer to start of flash location to be written.
@ -849,7 +899,7 @@ SVCALL(SD_TEMP_GET, uint32_t, sd_temp_get(int32_t * p_temp));
* @retval ::NRF_ERROR_INVALID_ADDR Tried to write to a non existing flash address, or p_dst or p_src was unaligned.
* @retval ::NRF_ERROR_BUSY The previous command has not yet completed.
* @retval ::NRF_ERROR_INVALID_LENGTH Size was 0, or higher than the maximum allowed size.
* @retval ::NRF_ERROR_FORBIDDEN Tried to write to or read from protected location.
* @retval ::NRF_ERROR_FORBIDDEN Tried to write to an address outside the application flash area.
* @retval ::NRF_SUCCESS The command was accepted.
*/
SVCALL(SD_FLASH_WRITE, uint32_t, sd_flash_write(uint32_t * p_dst, uint32_t const * p_src, uint32_t size));
@ -872,6 +922,8 @@ SVCALL(SD_FLASH_WRITE, uint32_t, sd_flash_write(uint32_t * p_dst, uint32_t const
* they will not interfere with the flash access. This means that all interrupts will be blocked
* for a predictable time (depending on the NVMC specification in the device's Product Specification
* and the command parameters).
* - This call will make the SoftDevice trigger a hardfault when the page is erased, if it is
* protected.
*
*
* @param[in] page_number Page number of the page to erase
@ -879,29 +931,12 @@ SVCALL(SD_FLASH_WRITE, uint32_t, sd_flash_write(uint32_t * p_dst, uint32_t const
* @retval ::NRF_ERROR_INTERNAL If a new session could not be opened due to an internal error.
* @retval ::NRF_ERROR_INVALID_ADDR Tried to erase to a non existing flash page.
* @retval ::NRF_ERROR_BUSY The previous command has not yet completed.
* @retval ::NRF_ERROR_FORBIDDEN Tried to erase a protected page.
* @retval ::NRF_ERROR_FORBIDDEN Tried to erase a page outside the application flash area.
* @retval ::NRF_SUCCESS The command was accepted.
*/
SVCALL(SD_FLASH_PAGE_ERASE, uint32_t, sd_flash_page_erase(uint32_t page_number));
/**@brief Flash Protection set
*
* Commands to set the flash protection configuration registers.
This sets the CONFIGx registers of the BPROT peripheral.
*
* @note To read the values read them directly. They are only write-protected.
*
* @param[in] block_cfg0 Value to be written to the configuration register.
* @param[in] block_cfg1 Value to be written to the configuration register.
* @param[in] block_cfg2 Value to be written to the configuration register.
* @param[in] block_cfg3 Value to be written to the configuration register.
*
* @retval ::NRF_ERROR_FORBIDDEN Tried to protect the SoftDevice.
* @retval ::NRF_ERROR_NOT_SUPPORTED Not supported for the device.
* @retval ::NRF_SUCCESS Values successfully written to configuration registers.
*/
SVCALL(SD_FLASH_PROTECT, uint32_t, sd_flash_protect(uint32_t block_cfg0, uint32_t block_cfg1, uint32_t block_cfg2, uint32_t block_cfg3));
/**@brief Opens a session for radio timeslot requests.
*
@ -970,6 +1005,27 @@ SVCALL(SD_FLASH_PROTECT, uint32_t, sd_flash_protect(uint32_t block_cfg0, uint32_
*/
SVCALL(SD_RADIO_REQUEST, uint32_t, sd_radio_request(nrf_radio_request_t const * p_request));
/**@brief Write register protected by the SoftDevice
*
* This function writes to a register that is write-protected by the SoftDevice. Please refer to your
* SoftDevice Specification for more details about which registers that are protected by SoftDevice.
* This function can write to the following protected peripheral:
* - ACL
*
* @note Protected registers may be read directly.
* @note Register that are write-once will return @ref NRF_SUCCESS on second set, even the value in
* the register has not changed. See the Product Specification for more details about register
* properties.
*
* @param[in] p_register Pointer to register to be written.
* @param[in] value Value to be written to the register.
*
* @retval ::NRF_ERROR_INVALID_ADDR This function can not write to the reguested register.
* @retval ::NRF_SUCCESS Value successfully written to register.
*
*/
SVCALL(SD_PROTECTED_REGISTER_WRITE, uint32_t, sd_protected_register_write(volatile uint32_t * p_register, uint32_t value));
/**@} */
#ifdef __cplusplus

View File

@ -0,0 +1,90 @@
/*
* Copyright (c) 2012 - 2017, 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.
*/
#ifndef NRF_SVC__
#define NRF_SVC__
#include "stdint.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef SVCALL_AS_NORMAL_FUNCTION
#define SVCALL(number, return_type, signature) return_type signature
#else
#ifndef SVCALL
#if defined (__CC_ARM)
#define SVCALL(number, return_type, signature) return_type __svc(number) signature
#elif defined (__GNUC__)
#ifdef __cplusplus
#define GCC_CAST_CPP (uint16_t)
#else
#define GCC_CAST_CPP
#endif
#define SVCALL(number, return_type, signature) \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wreturn-type\"") \
__attribute__((naked)) \
__attribute__((unused)) \
static return_type signature \
{ \
__asm( \
"svc %0\n" \
"bx r14" : : "I" (GCC_CAST_CPP number) : "r0" \
); \
} \
_Pragma("GCC diagnostic pop")
#elif defined (__ICCARM__)
#define PRAGMA(x) _Pragma(#x)
#define SVCALL(number, return_type, signature) \
PRAGMA(swi_number = (number)) \
__swi return_type signature;
#else
#define SVCALL(number, return_type, signature) return_type signature
#endif
#endif // SVCALL
#endif // SVCALL_AS_NORMAL_FUNCTION
#ifdef __cplusplus
}
#endif
#endif // NRF_SVC__

View File

@ -0,0 +1,35 @@
Copyright (c) 2007 - 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 diff suppressed because it is too large Load Diff