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 */ /**@brief Possible values for ::sd_mbr_command_t.command */
enum NRF_MBR_COMMANDS 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_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_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_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 /**@brief This command copies part of a new SoftDevice
*
* The destination area is erased before copying. * 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 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. * 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. /**@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. * With this command, destination of BootLoader is always the address written in
* If (destination+bl_len) is in the middle of a flash page, that whole flash page will be erased. * 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_INTERNAL indicates an internal error that should not happen.
* @retval ::NRF_ERROR_FORBIDDEN if NRF_UICR->BOOTADDR is not set. * @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 /**@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. * To restore default forwarding this function should be called with @ref address set to 0. The
* 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. * 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. * 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; } sd_mbr_command_vector_table_base_set_t;
/**@brief Sets the base address of the interrupt vector table for interrupts forwarded from the MBR /**@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 * 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. * 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.*/ uint32_t address; /**< The base address of the interrupt vector table for forwarded interrupts.*/
} sd_mbr_command_irq_forward_address_set_t; } 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 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 union
{ {
sd_mbr_command_copy_sd_t copy_sd; /**< Parameters for copy SoftDevice.*/ 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_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_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*/ 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; } sd_mbr_command_t;
/** @} */ /** @} */
@ -198,21 +211,22 @@ typedef struct
* *
* Commands used when updating a SoftDevice and bootloader. * 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 * The @ref SD_MBR_COMMAND_COPY_BL and @ref SD_MBR_COMMAND_VECTOR_TABLE_BASE_SET requires
* retained by the MBR when resetting the IC. This is done in a separate flash page * parameters to be retained by the MBR when resetting the IC. This is done in a separate flash
* provided by the application. The UICR register UICR.NRFFW[1] must be set * page provided by the application. The UICR register UICR.NRFFW[1] must be set to an address
* to an address corresponding to a page in the application flash space. This page will be cleared * corresponding to a page in the application flash space. This page will be cleared by the MBR and
* by the MBR and used to store the command before reset. When the UICR.NRFFW[1] field is set * used to store the command before reset. When the UICR.NRFFW[1] field is set the page it refers
* the page it refers to must not be used by the application. If the UICR.NRFFW[1] is set to * to must not be used by the application. If the UICR.NRFFW[1] is set to 0xFFFFFFFF (the default)
* 0xFFFFFFFF (the default) MBR commands which use flash will be unavailable and return * MBR commands which use flash will be unavailable and return @ref NRF_ERROR_NO_MEM.
* NRF_ERROR_NO_MEM.
* *
* @param[in] param Pointer to a struct describing the command. * @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_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_INVALID_PARAM if an invalid command is given.
*/ */
SVCALL(SD_MBR_COMMAND, uint32_t, sd_mbr_command(sd_mbr_command_t* param)); SVCALL(SD_MBR_COMMAND, uint32_t, sd_mbr_command(sd_mbr_command_t* param));

View File

@ -1,90 +1,90 @@
/* /*
* Copyright (c) 2012 - 2017, Nordic Semiconductor ASA * Copyright (c) 2012 - 2017, Nordic Semiconductor ASA
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* *
* 2. Redistributions in binary form, except as embedded into a Nordic * 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for * Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of * such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other * conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. * materials provided with the distribution.
* *
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its * 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 * contributors may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* *
* 4. This software, with or without modification, must only be used with a * 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit. * Nordic Semiconductor ASA integrated circuit.
* *
* 5. Any software provided in binary form under this license must not be reverse * 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled. * engineered, decompiled, modified and/or disassembled.
* *
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * 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. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef NRF_SVC__ #ifndef NRF_SVC__
#define NRF_SVC__ #define NRF_SVC__
#include "stdint.h" #include "stdint.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifdef SVCALL_AS_NORMAL_FUNCTION #ifdef SVCALL_AS_NORMAL_FUNCTION
#define SVCALL(number, return_type, signature) return_type signature #define SVCALL(number, return_type, signature) return_type signature
#else #else
#ifndef SVCALL #ifndef SVCALL
#if defined (__CC_ARM) #if defined (__CC_ARM)
#define SVCALL(number, return_type, signature) return_type __svc(number) signature #define SVCALL(number, return_type, signature) return_type __svc(number) signature
#elif defined (__GNUC__) #elif defined (__GNUC__)
#ifdef __cplusplus #ifdef __cplusplus
#define GCC_CAST_CPP (uint16_t) #define GCC_CAST_CPP (uint16_t)
#else #else
#define GCC_CAST_CPP #define GCC_CAST_CPP
#endif #endif
#define SVCALL(number, return_type, signature) \ #define SVCALL(number, return_type, signature) \
_Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wreturn-type\"") \ _Pragma("GCC diagnostic ignored \"-Wreturn-type\"") \
__attribute__((naked)) \ __attribute__((naked)) \
__attribute__((unused)) \ __attribute__((unused)) \
static return_type signature \ static return_type signature \
{ \ { \
__asm( \ __asm( \
"svc %0\n" \ "svc %0\n" \
"bx r14" : : "I" (GCC_CAST_CPP number) : "r0" \ "bx r14" : : "I" (GCC_CAST_CPP number) : "r0" \
); \ ); \
} \ } \
_Pragma("GCC diagnostic pop") _Pragma("GCC diagnostic pop")
#elif defined (__ICCARM__) #elif defined (__ICCARM__)
#define PRAGMA(x) _Pragma(#x) #define PRAGMA(x) _Pragma(#x)
#define SVCALL(number, return_type, signature) \ #define SVCALL(number, return_type, signature) \
PRAGMA(swi_number = (number)) \ PRAGMA(swi_number = (number)) \
__swi return_type signature; __swi return_type signature;
#else #else
#define SVCALL(number, return_type, signature) return_type signature #define SVCALL(number, return_type, signature) return_type signature
#endif #endif
#endif // SVCALL #endif // SVCALL
#endif // SVCALL_AS_NORMAL_FUNCTION #endif // SVCALL_AS_NORMAL_FUNCTION
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif // NRF_SVC__ #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.

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,93 +1,93 @@
/* /*
* Copyright (c) 2012 - 2017, Nordic Semiconductor ASA * Copyright (c) 2012 - 2018, Nordic Semiconductor ASA
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* *
* 2. Redistributions in binary form, except as embedded into a Nordic * 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for * Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of * such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other * conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. * materials provided with the distribution.
* *
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its * 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 * contributors may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* *
* 4. This software, with or without modification, must only be used with a * 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit. * Nordic Semiconductor ASA integrated circuit.
* *
* 5. Any software provided in binary form under this license must not be reverse * 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled. * engineered, decompiled, modified and/or disassembled.
* *
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * 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. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/** /**
@addtogroup BLE_COMMON @addtogroup BLE_COMMON
@{ @{
@addtogroup nrf_error @addtogroup nrf_error
@{ @{
@ingroup BLE_COMMON @ingroup BLE_COMMON
@} @}
@defgroup ble_err General error codes @defgroup ble_err General error codes
@{ @{
@brief General error code definitions for the BLE API. @brief General error code definitions for the BLE API.
@ingroup BLE_COMMON @ingroup BLE_COMMON
*/ */
#ifndef NRF_BLE_ERR_H__ #ifndef NRF_BLE_ERR_H__
#define NRF_BLE_ERR_H__ #define NRF_BLE_ERR_H__
#include "nrf_error.h" #include "nrf_error.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* @defgroup BLE_ERRORS Error Codes /* @defgroup BLE_ERRORS Error Codes
* @{ */ * @{ */
#define BLE_ERROR_NOT_ENABLED (NRF_ERROR_STK_BASE_NUM+0x001) /**< @ref sd_ble_enable has not been called. */ #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_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_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_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. */ #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. */
/** @} */ /** @} */
/** @defgroup BLE_ERROR_SUBRANGES Module specific error code subranges /** @defgroup BLE_ERROR_SUBRANGES Module specific error code subranges
* @brief Assignment of subranges for module specific error codes. * @brief Assignment of subranges for module specific error codes.
* @note For specific error codes, see ble_<module>.h or ble_error_<module>.h. * @note For specific error codes, see ble_<module>.h or ble_error_<module>.h.
* @{ */ * @{ */
#define NRF_L2CAP_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x100) /**< L2CAP specific errors. */ #define NRF_L2CAP_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x100) /**< L2CAP specific errors. */
#define NRF_GAP_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x200) /**< GAP specific errors. */ #define NRF_GAP_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x200) /**< GAP specific errors. */
#define NRF_GATTC_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x300) /**< GATT client specific errors. */ #define NRF_GATTC_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x300) /**< GATT client specific errors. */
#define NRF_GATTS_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x400) /**< GATT server specific errors. */ #define NRF_GATTS_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x400) /**< GATT server specific errors. */
/** @} */ /** @} */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif
/** /**
@} @}
@} @}
*/ */

View File

@ -1,223 +1,228 @@
/* /*
* Copyright (c) 2013 - 2017, Nordic Semiconductor ASA * Copyright (c) 2013 - 2017, Nordic Semiconductor ASA
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* *
* 2. Redistributions in binary form, except as embedded into a Nordic * 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for * Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of * such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other * conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. * materials provided with the distribution.
* *
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its * 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 * contributors may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* *
* 4. This software, with or without modification, must only be used with a * 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit. * Nordic Semiconductor ASA integrated circuit.
* *
* 5. Any software provided in binary form under this license must not be reverse * 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled. * engineered, decompiled, modified and/or disassembled.
* *
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * 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. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/** /**
@addtogroup BLE_GATT Generic Attribute Profile (GATT) Common @addtogroup BLE_GATT Generic Attribute Profile (GATT) Common
@{ @{
@brief Common definitions and prototypes for the GATT interfaces. @brief Common definitions and prototypes for the GATT interfaces.
*/ */
#ifndef BLE_GATT_H__ #ifndef BLE_GATT_H__
#define BLE_GATT_H__ #define BLE_GATT_H__
#include "ble_types.h" #include <stdint.h>
#include "ble_ranges.h" #include "nrf_svc.h"
#include "nrf_error.h"
#ifdef __cplusplus #include "ble_hci.h"
extern "C" { #include "ble_ranges.h"
#endif #include "ble_types.h"
#include "ble_err.h"
/** @addtogroup BLE_GATT_DEFINES Defines
* @{ */ #ifdef __cplusplus
extern "C" {
/** @brief Default ATT MTU, in bytes. */ #endif
#define BLE_GATT_ATT_MTU_DEFAULT 23
/** @addtogroup BLE_GATT_DEFINES Defines
/**@brief Invalid Attribute Handle. */ * @{ */
#define BLE_GATT_HANDLE_INVALID 0x0000
/** @brief Default ATT MTU, in bytes. */
/**@brief First Attribute Handle. */ #define BLE_GATT_ATT_MTU_DEFAULT 23
#define BLE_GATT_HANDLE_START 0x0001
/**@brief Invalid Attribute Handle. */
/**@brief Last Attribute Handle. */ #define BLE_GATT_HANDLE_INVALID 0x0000
#define BLE_GATT_HANDLE_END 0xFFFF
/**@brief First Attribute Handle. */
/** @defgroup BLE_GATT_TIMEOUT_SOURCES GATT Timeout sources #define BLE_GATT_HANDLE_START 0x0001
* @{ */
#define BLE_GATT_TIMEOUT_SRC_PROTOCOL 0x00 /**< ATT Protocol timeout. */ /**@brief Last Attribute Handle. */
/** @} */ #define BLE_GATT_HANDLE_END 0xFFFF
/** @defgroup BLE_GATT_WRITE_OPS GATT Write operations /** @defgroup BLE_GATT_TIMEOUT_SOURCES GATT Timeout sources
* @{ */ * @{ */
#define BLE_GATT_OP_INVALID 0x00 /**< Invalid Operation. */ #define BLE_GATT_TIMEOUT_SRC_PROTOCOL 0x00 /**< ATT Protocol timeout. */
#define BLE_GATT_OP_WRITE_REQ 0x01 /**< Write Request. */ /** @} */
#define BLE_GATT_OP_WRITE_CMD 0x02 /**< Write Command. */
#define BLE_GATT_OP_SIGN_WRITE_CMD 0x03 /**< Signed Write Command. */ /** @defgroup BLE_GATT_WRITE_OPS GATT Write operations
#define BLE_GATT_OP_PREP_WRITE_REQ 0x04 /**< Prepare Write Request. */ * @{ */
#define BLE_GATT_OP_EXEC_WRITE_REQ 0x05 /**< Execute Write Request. */ #define BLE_GATT_OP_INVALID 0x00 /**< Invalid Operation. */
/** @} */ #define BLE_GATT_OP_WRITE_REQ 0x01 /**< Write Request. */
#define BLE_GATT_OP_WRITE_CMD 0x02 /**< Write Command. */
/** @defgroup BLE_GATT_EXEC_WRITE_FLAGS GATT Execute Write flags #define BLE_GATT_OP_SIGN_WRITE_CMD 0x03 /**< Signed Write Command. */
* @{ */ #define BLE_GATT_OP_PREP_WRITE_REQ 0x04 /**< Prepare Write Request. */
#define BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL 0x00 /**< Cancel prepared write. */ #define BLE_GATT_OP_EXEC_WRITE_REQ 0x05 /**< Execute Write Request. */
#define BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE 0x01 /**< Execute prepared write. */ /** @} */
/** @} */
/** @defgroup BLE_GATT_EXEC_WRITE_FLAGS GATT Execute Write flags
/** @defgroup BLE_GATT_HVX_TYPES GATT Handle Value operations * @{ */
* @{ */ #define BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL 0x00 /**< Cancel prepared write. */
#define BLE_GATT_HVX_INVALID 0x00 /**< Invalid Operation. */ #define BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE 0x01 /**< Execute prepared write. */
#define BLE_GATT_HVX_NOTIFICATION 0x01 /**< Handle Value Notification. */ /** @} */
#define BLE_GATT_HVX_INDICATION 0x02 /**< Handle Value Indication. */
/** @} */ /** @defgroup BLE_GATT_HVX_TYPES GATT Handle Value operations
* @{ */
/** @defgroup BLE_GATT_STATUS_CODES GATT Status Codes #define BLE_GATT_HVX_INVALID 0x00 /**< Invalid Operation. */
* @{ */ #define BLE_GATT_HVX_NOTIFICATION 0x01 /**< Handle Value Notification. */
#define BLE_GATT_STATUS_SUCCESS 0x0000 /**< Success. */ #define BLE_GATT_HVX_INDICATION 0x02 /**< Handle Value Indication. */
#define BLE_GATT_STATUS_UNKNOWN 0x0001 /**< Unknown or not applicable status. */ /** @} */
#define BLE_GATT_STATUS_ATTERR_INVALID 0x0100 /**< ATT Error: Invalid Error Code. */
#define BLE_GATT_STATUS_ATTERR_INVALID_HANDLE 0x0101 /**< ATT Error: Invalid Attribute Handle. */ /** @defgroup BLE_GATT_STATUS_CODES GATT Status Codes
#define BLE_GATT_STATUS_ATTERR_READ_NOT_PERMITTED 0x0102 /**< ATT Error: Read not permitted. */ * @{ */
#define BLE_GATT_STATUS_ATTERR_WRITE_NOT_PERMITTED 0x0103 /**< ATT Error: Write not permitted. */ #define BLE_GATT_STATUS_SUCCESS 0x0000 /**< Success. */
#define BLE_GATT_STATUS_ATTERR_INVALID_PDU 0x0104 /**< ATT Error: Used in ATT as Invalid PDU. */ #define BLE_GATT_STATUS_UNKNOWN 0x0001 /**< Unknown or not applicable status. */
#define BLE_GATT_STATUS_ATTERR_INSUF_AUTHENTICATION 0x0105 /**< ATT Error: Authenticated link required. */ #define BLE_GATT_STATUS_ATTERR_INVALID 0x0100 /**< ATT Error: Invalid Error Code. */
#define BLE_GATT_STATUS_ATTERR_REQUEST_NOT_SUPPORTED 0x0106 /**< ATT Error: Used in ATT as Request Not Supported. */ #define BLE_GATT_STATUS_ATTERR_INVALID_HANDLE 0x0101 /**< ATT Error: Invalid Attribute Handle. */
#define BLE_GATT_STATUS_ATTERR_INVALID_OFFSET 0x0107 /**< ATT Error: Offset specified was past the end of the attribute. */ #define BLE_GATT_STATUS_ATTERR_READ_NOT_PERMITTED 0x0102 /**< ATT Error: Read not permitted. */
#define BLE_GATT_STATUS_ATTERR_INSUF_AUTHORIZATION 0x0108 /**< ATT Error: Used in ATT as Insufficient Authorization. */ #define BLE_GATT_STATUS_ATTERR_WRITE_NOT_PERMITTED 0x0103 /**< ATT Error: Write not permitted. */
#define BLE_GATT_STATUS_ATTERR_PREPARE_QUEUE_FULL 0x0109 /**< ATT Error: Used in ATT as Prepare Queue Full. */ #define BLE_GATT_STATUS_ATTERR_INVALID_PDU 0x0104 /**< ATT Error: Used in ATT as Invalid PDU. */
#define BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND 0x010A /**< ATT Error: Used in ATT as Attribute not found. */ #define BLE_GATT_STATUS_ATTERR_INSUF_AUTHENTICATION 0x0105 /**< ATT Error: Authenticated link required. */
#define BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_LONG 0x010B /**< ATT Error: Attribute cannot be read or written using read/write blob requests. */ #define BLE_GATT_STATUS_ATTERR_REQUEST_NOT_SUPPORTED 0x0106 /**< ATT Error: Used in ATT as Request Not Supported. */
#define BLE_GATT_STATUS_ATTERR_INSUF_ENC_KEY_SIZE 0x010C /**< ATT Error: Encryption key size used is insufficient. */ #define BLE_GATT_STATUS_ATTERR_INVALID_OFFSET 0x0107 /**< ATT Error: Offset specified was past the end of the attribute. */
#define BLE_GATT_STATUS_ATTERR_INVALID_ATT_VAL_LENGTH 0x010D /**< ATT Error: Invalid value size. */ #define BLE_GATT_STATUS_ATTERR_INSUF_AUTHORIZATION 0x0108 /**< ATT Error: Used in ATT as Insufficient Authorization. */
#define BLE_GATT_STATUS_ATTERR_UNLIKELY_ERROR 0x010E /**< ATT Error: Very unlikely error. */ #define BLE_GATT_STATUS_ATTERR_PREPARE_QUEUE_FULL 0x0109 /**< ATT Error: Used in ATT as Prepare Queue Full. */
#define BLE_GATT_STATUS_ATTERR_INSUF_ENCRYPTION 0x010F /**< ATT Error: Encrypted link required. */ #define BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND 0x010A /**< ATT Error: Used in ATT as Attribute not found. */
#define BLE_GATT_STATUS_ATTERR_UNSUPPORTED_GROUP_TYPE 0x0110 /**< ATT Error: Attribute type is not a supported grouping attribute. */ #define BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_LONG 0x010B /**< ATT Error: Attribute cannot be read or written using read/write blob requests. */
#define BLE_GATT_STATUS_ATTERR_INSUF_RESOURCES 0x0111 /**< ATT Error: Encrypted link required. */ #define BLE_GATT_STATUS_ATTERR_INSUF_ENC_KEY_SIZE 0x010C /**< ATT Error: Encryption key size used is insufficient. */
#define BLE_GATT_STATUS_ATTERR_RFU_RANGE1_BEGIN 0x0112 /**< ATT Error: Reserved for Future Use range #1 begin. */ #define BLE_GATT_STATUS_ATTERR_INVALID_ATT_VAL_LENGTH 0x010D /**< ATT Error: Invalid value size. */
#define BLE_GATT_STATUS_ATTERR_RFU_RANGE1_END 0x017F /**< ATT Error: Reserved for Future Use range #1 end. */ #define BLE_GATT_STATUS_ATTERR_UNLIKELY_ERROR 0x010E /**< ATT Error: Very unlikely error. */
#define BLE_GATT_STATUS_ATTERR_APP_BEGIN 0x0180 /**< ATT Error: Application range begin. */ #define BLE_GATT_STATUS_ATTERR_INSUF_ENCRYPTION 0x010F /**< ATT Error: Encrypted link required. */
#define BLE_GATT_STATUS_ATTERR_APP_END 0x019F /**< ATT Error: Application range end. */ #define BLE_GATT_STATUS_ATTERR_UNSUPPORTED_GROUP_TYPE 0x0110 /**< ATT Error: Attribute type is not a supported grouping attribute. */
#define BLE_GATT_STATUS_ATTERR_RFU_RANGE2_BEGIN 0x01A0 /**< ATT Error: Reserved for Future Use range #2 begin. */ #define BLE_GATT_STATUS_ATTERR_INSUF_RESOURCES 0x0111 /**< ATT Error: Encrypted link required. */
#define BLE_GATT_STATUS_ATTERR_RFU_RANGE2_END 0x01DF /**< ATT Error: Reserved for Future Use range #2 end. */ #define BLE_GATT_STATUS_ATTERR_RFU_RANGE1_BEGIN 0x0112 /**< ATT Error: Reserved for Future Use range #1 begin. */
#define BLE_GATT_STATUS_ATTERR_RFU_RANGE3_BEGIN 0x01E0 /**< ATT Error: Reserved for Future Use range #3 begin. */ #define BLE_GATT_STATUS_ATTERR_RFU_RANGE1_END 0x017F /**< ATT Error: Reserved for Future Use range #1 end. */
#define BLE_GATT_STATUS_ATTERR_RFU_RANGE3_END 0x01FC /**< ATT Error: Reserved for Future Use range #3 end. */ #define BLE_GATT_STATUS_ATTERR_APP_BEGIN 0x0180 /**< ATT Error: Application range begin. */
#define BLE_GATT_STATUS_ATTERR_CPS_CCCD_CONFIG_ERROR 0x01FD /**< ATT Common Profile and Service Error: Client Characteristic Configuration Descriptor improperly configured. */ #define BLE_GATT_STATUS_ATTERR_APP_END 0x019F /**< ATT Error: Application range end. */
#define BLE_GATT_STATUS_ATTERR_CPS_PROC_ALR_IN_PROG 0x01FE /**< ATT Common Profile and Service Error: Procedure Already in Progress. */ #define BLE_GATT_STATUS_ATTERR_RFU_RANGE2_BEGIN 0x01A0 /**< ATT Error: Reserved for Future Use range #2 begin. */
#define BLE_GATT_STATUS_ATTERR_CPS_OUT_OF_RANGE 0x01FF /**< ATT Common Profile and Service Error: Out Of Range. */ #define BLE_GATT_STATUS_ATTERR_RFU_RANGE2_END 0x01DF /**< ATT Error: Reserved for Future Use range #2 end. */
/** @} */ #define BLE_GATT_STATUS_ATTERR_RFU_RANGE3_BEGIN 0x01E0 /**< ATT Error: Reserved for Future Use range #3 begin. */
#define BLE_GATT_STATUS_ATTERR_RFU_RANGE3_END 0x01FC /**< ATT Error: Reserved for Future Use range #3 end. */
#define BLE_GATT_STATUS_ATTERR_CPS_CCCD_CONFIG_ERROR 0x01FD /**< ATT Common Profile and Service Error: Client Characteristic Configuration Descriptor improperly configured. */
/** @defgroup BLE_GATT_CPF_FORMATS Characteristic Presentation Formats #define BLE_GATT_STATUS_ATTERR_CPS_PROC_ALR_IN_PROG 0x01FE /**< ATT Common Profile and Service Error: Procedure Already in Progress. */
* @note Found at http://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml #define BLE_GATT_STATUS_ATTERR_CPS_OUT_OF_RANGE 0x01FF /**< ATT Common Profile and Service Error: Out Of Range. */
* @{ */ /** @} */
#define BLE_GATT_CPF_FORMAT_RFU 0x00 /**< Reserved For Future Use. */
#define BLE_GATT_CPF_FORMAT_BOOLEAN 0x01 /**< Boolean. */
#define BLE_GATT_CPF_FORMAT_2BIT 0x02 /**< Unsigned 2-bit integer. */ /** @defgroup BLE_GATT_CPF_FORMATS Characteristic Presentation Formats
#define BLE_GATT_CPF_FORMAT_NIBBLE 0x03 /**< Unsigned 4-bit integer. */ * @note Found at http://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
#define BLE_GATT_CPF_FORMAT_UINT8 0x04 /**< Unsigned 8-bit integer. */ * @{ */
#define BLE_GATT_CPF_FORMAT_UINT12 0x05 /**< Unsigned 12-bit integer. */ #define BLE_GATT_CPF_FORMAT_RFU 0x00 /**< Reserved For Future Use. */
#define BLE_GATT_CPF_FORMAT_UINT16 0x06 /**< Unsigned 16-bit integer. */ #define BLE_GATT_CPF_FORMAT_BOOLEAN 0x01 /**< Boolean. */
#define BLE_GATT_CPF_FORMAT_UINT24 0x07 /**< Unsigned 24-bit integer. */ #define BLE_GATT_CPF_FORMAT_2BIT 0x02 /**< Unsigned 2-bit integer. */
#define BLE_GATT_CPF_FORMAT_UINT32 0x08 /**< Unsigned 32-bit integer. */ #define BLE_GATT_CPF_FORMAT_NIBBLE 0x03 /**< Unsigned 4-bit integer. */
#define BLE_GATT_CPF_FORMAT_UINT48 0x09 /**< Unsigned 48-bit integer. */ #define BLE_GATT_CPF_FORMAT_UINT8 0x04 /**< Unsigned 8-bit integer. */
#define BLE_GATT_CPF_FORMAT_UINT64 0x0A /**< Unsigned 64-bit integer. */ #define BLE_GATT_CPF_FORMAT_UINT12 0x05 /**< Unsigned 12-bit integer. */
#define BLE_GATT_CPF_FORMAT_UINT128 0x0B /**< Unsigned 128-bit integer. */ #define BLE_GATT_CPF_FORMAT_UINT16 0x06 /**< Unsigned 16-bit integer. */
#define BLE_GATT_CPF_FORMAT_SINT8 0x0C /**< Signed 2-bit integer. */ #define BLE_GATT_CPF_FORMAT_UINT24 0x07 /**< Unsigned 24-bit integer. */
#define BLE_GATT_CPF_FORMAT_SINT12 0x0D /**< Signed 12-bit integer. */ #define BLE_GATT_CPF_FORMAT_UINT32 0x08 /**< Unsigned 32-bit integer. */
#define BLE_GATT_CPF_FORMAT_SINT16 0x0E /**< Signed 16-bit integer. */ #define BLE_GATT_CPF_FORMAT_UINT48 0x09 /**< Unsigned 48-bit integer. */
#define BLE_GATT_CPF_FORMAT_SINT24 0x0F /**< Signed 24-bit integer. */ #define BLE_GATT_CPF_FORMAT_UINT64 0x0A /**< Unsigned 64-bit integer. */
#define BLE_GATT_CPF_FORMAT_SINT32 0x10 /**< Signed 32-bit integer. */ #define BLE_GATT_CPF_FORMAT_UINT128 0x0B /**< Unsigned 128-bit integer. */
#define BLE_GATT_CPF_FORMAT_SINT48 0x11 /**< Signed 48-bit integer. */ #define BLE_GATT_CPF_FORMAT_SINT8 0x0C /**< Signed 2-bit integer. */
#define BLE_GATT_CPF_FORMAT_SINT64 0x12 /**< Signed 64-bit integer. */ #define BLE_GATT_CPF_FORMAT_SINT12 0x0D /**< Signed 12-bit integer. */
#define BLE_GATT_CPF_FORMAT_SINT128 0x13 /**< Signed 128-bit integer. */ #define BLE_GATT_CPF_FORMAT_SINT16 0x0E /**< Signed 16-bit integer. */
#define BLE_GATT_CPF_FORMAT_FLOAT32 0x14 /**< IEEE-754 32-bit floating point. */ #define BLE_GATT_CPF_FORMAT_SINT24 0x0F /**< Signed 24-bit integer. */
#define BLE_GATT_CPF_FORMAT_FLOAT64 0x15 /**< IEEE-754 64-bit floating point. */ #define BLE_GATT_CPF_FORMAT_SINT32 0x10 /**< Signed 32-bit integer. */
#define BLE_GATT_CPF_FORMAT_SFLOAT 0x16 /**< IEEE-11073 16-bit SFLOAT. */ #define BLE_GATT_CPF_FORMAT_SINT48 0x11 /**< Signed 48-bit integer. */
#define BLE_GATT_CPF_FORMAT_FLOAT 0x17 /**< IEEE-11073 32-bit FLOAT. */ #define BLE_GATT_CPF_FORMAT_SINT64 0x12 /**< Signed 64-bit integer. */
#define BLE_GATT_CPF_FORMAT_DUINT16 0x18 /**< IEEE-20601 format. */ #define BLE_GATT_CPF_FORMAT_SINT128 0x13 /**< Signed 128-bit integer. */
#define BLE_GATT_CPF_FORMAT_UTF8S 0x19 /**< UTF-8 string. */ #define BLE_GATT_CPF_FORMAT_FLOAT32 0x14 /**< IEEE-754 32-bit floating point. */
#define BLE_GATT_CPF_FORMAT_UTF16S 0x1A /**< UTF-16 string. */ #define BLE_GATT_CPF_FORMAT_FLOAT64 0x15 /**< IEEE-754 64-bit floating point. */
#define BLE_GATT_CPF_FORMAT_STRUCT 0x1B /**< Opaque Structure. */ #define BLE_GATT_CPF_FORMAT_SFLOAT 0x16 /**< IEEE-11073 16-bit SFLOAT. */
/** @} */ #define BLE_GATT_CPF_FORMAT_FLOAT 0x17 /**< IEEE-11073 32-bit FLOAT. */
#define BLE_GATT_CPF_FORMAT_DUINT16 0x18 /**< IEEE-20601 format. */
/** @defgroup BLE_GATT_CPF_NAMESPACES GATT Bluetooth Namespaces #define BLE_GATT_CPF_FORMAT_UTF8S 0x19 /**< UTF-8 string. */
* @{ #define BLE_GATT_CPF_FORMAT_UTF16S 0x1A /**< UTF-16 string. */
*/ #define BLE_GATT_CPF_FORMAT_STRUCT 0x1B /**< Opaque Structure. */
#define BLE_GATT_CPF_NAMESPACE_BTSIG 0x01 /**< Bluetooth SIG defined Namespace. */ /** @} */
#define BLE_GATT_CPF_NAMESPACE_DESCRIPTION_UNKNOWN 0x0000 /**< Namespace Description Unknown. */
/** @} */ /** @defgroup BLE_GATT_CPF_NAMESPACES GATT Bluetooth Namespaces
* @{
/** @} */ */
#define BLE_GATT_CPF_NAMESPACE_BTSIG 0x01 /**< Bluetooth SIG defined Namespace. */
/** @addtogroup BLE_GATT_STRUCTURES Structures #define BLE_GATT_CPF_NAMESPACE_DESCRIPTION_UNKNOWN 0x0000 /**< Namespace Description Unknown. */
* @{ */ /** @} */
/** /** @} */
* @brief BLE GATT connection configuration parameters, set with @ref sd_ble_cfg_set.
* /** @addtogroup BLE_GATT_STRUCTURES Structures
* @retval ::NRF_ERROR_INVALID_PARAM att_mtu is smaller than @ref BLE_GATT_ATT_MTU_DEFAULT. * @{ */
*/
typedef struct /**
{ * @brief BLE GATT connection configuration parameters, set with @ref sd_ble_cfg_set.
uint16_t att_mtu; /**< Maximum size of ATT packet the SoftDevice can send or receive. *
The default and minimum value is @ref BLE_GATT_ATT_MTU_DEFAULT. * @retval ::NRF_ERROR_INVALID_PARAM att_mtu is smaller than @ref BLE_GATT_ATT_MTU_DEFAULT.
@mscs */
@mmsc{@ref BLE_GATTC_MTU_EXCHANGE} typedef struct
@mmsc{@ref BLE_GATTS_MTU_EXCHANGE} {
@endmscs uint16_t att_mtu; /**< Maximum size of ATT packet the SoftDevice can send or receive.
*/ The default and minimum value is @ref BLE_GATT_ATT_MTU_DEFAULT.
} ble_gatt_conn_cfg_t; @mscs
@mmsc{@ref BLE_GATTC_MTU_EXCHANGE}
/**@brief GATT Characteristic Properties. */ @mmsc{@ref BLE_GATTS_MTU_EXCHANGE}
typedef struct @endmscs
{ */
/* Standard properties */ } ble_gatt_conn_cfg_t;
uint8_t broadcast :1; /**< Broadcasting of the value permitted. */
uint8_t read :1; /**< Reading the value permitted. */ /**@brief GATT Characteristic Properties. */
uint8_t write_wo_resp :1; /**< Writing the value with Write Command permitted. */ typedef struct
uint8_t write :1; /**< Writing the value with Write Request permitted. */ {
uint8_t notify :1; /**< Notification of the value permitted. */ /* Standard properties */
uint8_t indicate :1; /**< Indications of the value permitted. */ uint8_t broadcast :1; /**< Broadcasting of the value permitted. */
uint8_t auth_signed_wr :1; /**< Writing the value with Signed Write Command permitted. */ uint8_t read :1; /**< Reading the value permitted. */
} ble_gatt_char_props_t; uint8_t write_wo_resp :1; /**< Writing the value with Write Command permitted. */
uint8_t write :1; /**< Writing the value with Write Request permitted. */
/**@brief GATT Characteristic Extended Properties. */ uint8_t notify :1; /**< Notification of the value permitted. */
typedef struct uint8_t indicate :1; /**< Indications of the value permitted. */
{ uint8_t auth_signed_wr :1; /**< Writing the value with Signed Write Command permitted. */
/* Extended properties */ } ble_gatt_char_props_t;
uint8_t reliable_wr :1; /**< Writing the value with Queued Write operations permitted. */
uint8_t wr_aux :1; /**< Writing the Characteristic User Description descriptor permitted. */ /**@brief GATT Characteristic Extended Properties. */
} ble_gatt_char_ext_props_t; typedef struct
{
/** @} */ /* Extended properties */
uint8_t reliable_wr :1; /**< Writing the value with Queued Write operations permitted. */
#ifdef __cplusplus uint8_t wr_aux :1; /**< Writing the Characteristic User Description descriptor permitted. */
} } ble_gatt_char_ext_props_t;
#endif
#endif // BLE_GATT_H__ /** @} */
/** @} */ #ifdef __cplusplus
}
#endif
#endif // BLE_GATT_H__
/** @} */

View File

@ -1,135 +1,135 @@
/* /*
* Copyright (c) 2012 - 2017, Nordic Semiconductor ASA * Copyright (c) 2012 - 2017, Nordic Semiconductor ASA
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* *
* 2. Redistributions in binary form, except as embedded into a Nordic * 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for * Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of * such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other * conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. * materials provided with the distribution.
* *
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its * 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 * contributors may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* *
* 4. This software, with or without modification, must only be used with a * 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit. * Nordic Semiconductor ASA integrated circuit.
* *
* 5. Any software provided in binary form under this license must not be reverse * 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled. * engineered, decompiled, modified and/or disassembled.
* *
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * 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. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/** /**
@addtogroup BLE_COMMON @addtogroup BLE_COMMON
@{ @{
*/ */
#ifndef BLE_HCI_H__ #ifndef BLE_HCI_H__
#define BLE_HCI_H__ #define BLE_HCI_H__
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/** @defgroup BLE_HCI_STATUS_CODES Bluetooth status codes /** @defgroup BLE_HCI_STATUS_CODES Bluetooth status codes
* @{ */ * @{ */
#define BLE_HCI_STATUS_CODE_SUCCESS 0x00 /**< Success. */ #define BLE_HCI_STATUS_CODE_SUCCESS 0x00 /**< Success. */
#define BLE_HCI_STATUS_CODE_UNKNOWN_BTLE_COMMAND 0x01 /**< Unknown BLE Command. */ #define BLE_HCI_STATUS_CODE_UNKNOWN_BTLE_COMMAND 0x01 /**< Unknown BLE Command. */
#define BLE_HCI_STATUS_CODE_UNKNOWN_CONNECTION_IDENTIFIER 0x02 /**< Unknown Connection Identifier. */ #define BLE_HCI_STATUS_CODE_UNKNOWN_CONNECTION_IDENTIFIER 0x02 /**< Unknown Connection Identifier. */
/*0x03 Hardware Failure /*0x03 Hardware Failure
0x04 Page Timeout 0x04 Page Timeout
*/ */
#define BLE_HCI_AUTHENTICATION_FAILURE 0x05 /**< Authentication Failure. */ #define BLE_HCI_AUTHENTICATION_FAILURE 0x05 /**< Authentication Failure. */
#define BLE_HCI_STATUS_CODE_PIN_OR_KEY_MISSING 0x06 /**< Pin or Key missing. */ #define BLE_HCI_STATUS_CODE_PIN_OR_KEY_MISSING 0x06 /**< Pin or Key missing. */
#define BLE_HCI_MEMORY_CAPACITY_EXCEEDED 0x07 /**< Memory Capacity Exceeded. */ #define BLE_HCI_MEMORY_CAPACITY_EXCEEDED 0x07 /**< Memory Capacity Exceeded. */
#define BLE_HCI_CONNECTION_TIMEOUT 0x08 /**< Connection Timeout. */ #define BLE_HCI_CONNECTION_TIMEOUT 0x08 /**< Connection Timeout. */
/*0x09 Connection Limit Exceeded /*0x09 Connection Limit Exceeded
0x0A Synchronous Connection Limit To A Device Exceeded 0x0A Synchronous Connection Limit To A Device Exceeded
0x0B ACL Connection Already Exists*/ 0x0B ACL Connection Already Exists*/
#define BLE_HCI_STATUS_CODE_COMMAND_DISALLOWED 0x0C /**< Command Disallowed. */ #define BLE_HCI_STATUS_CODE_COMMAND_DISALLOWED 0x0C /**< Command Disallowed. */
/*0x0D Connection Rejected due to Limited Resources /*0x0D Connection Rejected due to Limited Resources
0x0E Connection Rejected Due To Security Reasons 0x0E Connection Rejected Due To Security Reasons
0x0F Connection Rejected due to Unacceptable BD_ADDR 0x0F Connection Rejected due to Unacceptable BD_ADDR
0x10 Connection Accept Timeout Exceeded 0x10 Connection Accept Timeout Exceeded
0x11 Unsupported Feature or Parameter Value*/ 0x11 Unsupported Feature or Parameter Value*/
#define BLE_HCI_STATUS_CODE_INVALID_BTLE_COMMAND_PARAMETERS 0x12 /**< Invalid BLE Command Parameters. */ #define BLE_HCI_STATUS_CODE_INVALID_BTLE_COMMAND_PARAMETERS 0x12 /**< Invalid BLE Command Parameters. */
#define BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION 0x13 /**< Remote User Terminated Connection. */ #define BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION 0x13 /**< Remote User Terminated Connection. */
#define BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES 0x14 /**< Remote Device Terminated Connection due to low resources.*/ #define BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_LOW_RESOURCES 0x14 /**< Remote Device Terminated Connection due to low resources.*/
#define BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF 0x15 /**< Remote Device Terminated Connection due to power off. */ #define BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF 0x15 /**< Remote Device Terminated Connection due to power off. */
#define BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION 0x16 /**< Local Host Terminated Connection. */ #define BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION 0x16 /**< Local Host Terminated Connection. */
/* /*
0x17 Repeated Attempts 0x17 Repeated Attempts
0x18 Pairing Not Allowed 0x18 Pairing Not Allowed
0x19 Unknown LMP PDU 0x19 Unknown LMP PDU
*/ */
#define BLE_HCI_UNSUPPORTED_REMOTE_FEATURE 0x1A /**< Unsupported Remote Feature. */ #define BLE_HCI_UNSUPPORTED_REMOTE_FEATURE 0x1A /**< Unsupported Remote Feature. */
/* /*
0x1B SCO Offset Rejected 0x1B SCO Offset Rejected
0x1C SCO Interval Rejected 0x1C SCO Interval Rejected
0x1D SCO Air Mode Rejected*/ 0x1D SCO Air Mode Rejected*/
#define BLE_HCI_STATUS_CODE_INVALID_LMP_PARAMETERS 0x1E /**< Invalid LMP Parameters. */ #define BLE_HCI_STATUS_CODE_INVALID_LMP_PARAMETERS 0x1E /**< Invalid LMP Parameters. */
#define BLE_HCI_STATUS_CODE_UNSPECIFIED_ERROR 0x1F /**< Unspecified Error. */ #define BLE_HCI_STATUS_CODE_UNSPECIFIED_ERROR 0x1F /**< Unspecified Error. */
/*0x20 Unsupported LMP Parameter Value /*0x20 Unsupported LMP Parameter Value
0x21 Role Change Not Allowed 0x21 Role Change Not Allowed
*/ */
#define BLE_HCI_STATUS_CODE_LMP_RESPONSE_TIMEOUT 0x22 /**< LMP Response Timeout. */ #define BLE_HCI_STATUS_CODE_LMP_RESPONSE_TIMEOUT 0x22 /**< LMP Response Timeout. */
#define BLE_HCI_STATUS_CODE_LMP_ERROR_TRANSACTION_COLLISION 0x23 /**< LMP Error Transaction Collision/LL Procedure Collision. */ #define BLE_HCI_STATUS_CODE_LMP_ERROR_TRANSACTION_COLLISION 0x23 /**< LMP Error Transaction Collision/LL Procedure Collision. */
#define BLE_HCI_STATUS_CODE_LMP_PDU_NOT_ALLOWED 0x24 /**< LMP PDU Not Allowed. */ #define BLE_HCI_STATUS_CODE_LMP_PDU_NOT_ALLOWED 0x24 /**< LMP PDU Not Allowed. */
/*0x25 Encryption Mode Not Acceptable /*0x25 Encryption Mode Not Acceptable
0x26 Link Key Can Not be Changed 0x26 Link Key Can Not be Changed
0x27 Requested QoS Not Supported 0x27 Requested QoS Not Supported
*/ */
#define BLE_HCI_INSTANT_PASSED 0x28 /**< Instant Passed. */ #define BLE_HCI_INSTANT_PASSED 0x28 /**< Instant Passed. */
#define BLE_HCI_PAIRING_WITH_UNIT_KEY_UNSUPPORTED 0x29 /**< Pairing with Unit Key Unsupported. */ #define BLE_HCI_PAIRING_WITH_UNIT_KEY_UNSUPPORTED 0x29 /**< Pairing with Unit Key Unsupported. */
#define BLE_HCI_DIFFERENT_TRANSACTION_COLLISION 0x2A /**< Different Transaction Collision. */ #define BLE_HCI_DIFFERENT_TRANSACTION_COLLISION 0x2A /**< Different Transaction Collision. */
/* /*
0x2B Reserved 0x2B Reserved
0x2C QoS Unacceptable Parameter 0x2C QoS Unacceptable Parameter
0x2D QoS Rejected 0x2D QoS Rejected
0x2E Channel Classification Not Supported 0x2E Channel Classification Not Supported
0x2F Insufficient Security 0x2F Insufficient Security
*/ */
#define BLE_HCI_PARAMETER_OUT_OF_MANDATORY_RANGE 0x30 /**< Parameter Out Of Mandatory Range. */ #define BLE_HCI_PARAMETER_OUT_OF_MANDATORY_RANGE 0x30 /**< Parameter Out Of Mandatory Range. */
/* /*
0x31 Reserved 0x31 Reserved
0x32 Role Switch Pending 0x32 Role Switch Pending
0x33 Reserved 0x33 Reserved
0x34 Reserved Slot Violation 0x34 Reserved Slot Violation
0x35 Role Switch Failed 0x35 Role Switch Failed
0x36 Extended Inquiry Response Too Large 0x36 Extended Inquiry Response Too Large
0x37 Secure Simple Pairing Not Supported By Host. 0x37 Secure Simple Pairing Not Supported By Host.
0x38 Host Busy - Pairing 0x38 Host Busy - Pairing
0x39 Connection Rejected due to No Suitable Channel Found*/ 0x39 Connection Rejected due to No Suitable Channel Found*/
#define BLE_HCI_CONTROLLER_BUSY 0x3A /**< Controller Busy. */ #define BLE_HCI_CONTROLLER_BUSY 0x3A /**< Controller Busy. */
#define BLE_HCI_CONN_INTERVAL_UNACCEPTABLE 0x3B /**< Connection Interval Unacceptable. */ #define BLE_HCI_CONN_INTERVAL_UNACCEPTABLE 0x3B /**< Connection Interval Unacceptable. */
#define BLE_HCI_DIRECTED_ADVERTISER_TIMEOUT 0x3C /**< Directed Advertisement Timeout. */ #define BLE_HCI_DIRECTED_ADVERTISER_TIMEOUT 0x3C /**< Directed Advertisement Timeout. */
#define BLE_HCI_CONN_TERMINATED_DUE_TO_MIC_FAILURE 0x3D /**< Connection Terminated due to MIC Failure. */ #define BLE_HCI_CONN_TERMINATED_DUE_TO_MIC_FAILURE 0x3D /**< Connection Terminated due to MIC Failure. */
#define BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED 0x3E /**< Connection Failed to be Established. */ #define BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED 0x3E /**< Connection Failed to be Established. */
/** @} */ /** @} */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif // BLE_HCI_H__ #endif // BLE_HCI_H__
/** @} */ /** @} */

View File

@ -1,156 +1,156 @@
/* /*
* Copyright (c) 2012 - 2017, Nordic Semiconductor ASA * Copyright (c) 2012 - 2018, Nordic Semiconductor ASA
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* *
* 2. Redistributions in binary form, except as embedded into a Nordic * 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for * Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of * such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other * conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. * materials provided with the distribution.
* *
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its * 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 * contributors may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* *
* 4. This software, with or without modification, must only be used with a * 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit. * Nordic Semiconductor ASA integrated circuit.
* *
* 5. Any software provided in binary form under this license must not be reverse * 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled. * engineered, decompiled, modified and/or disassembled.
* *
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * 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. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/** /**
@addtogroup BLE_COMMON @addtogroup BLE_COMMON
@{ @{
@defgroup ble_ranges Module specific SVC, event and option number subranges @defgroup ble_ranges Module specific SVC, event and option number subranges
@{ @{
@brief Definition of SVC, event and option number subranges for each API module. @brief Definition of SVC, event and option number subranges for each API module.
@note @note
SVCs, event and option numbers are split into subranges for each API module. SVCs, event and option numbers are split into subranges for each API module.
Each module receives its entire allocated range of SVC calls, whether implemented or not, Each module receives its entire allocated range of SVC calls, whether implemented or not,
but return BLE_ERROR_NOT_SUPPORTED for unimplemented or undefined calls in its range. but return BLE_ERROR_NOT_SUPPORTED for unimplemented or undefined calls in its range.
Note that the symbols BLE_<module>_SVC_LAST is the end of the allocated SVC range, Note that the symbols BLE_<module>_SVC_LAST is the end of the allocated SVC range,
rather than the last SVC function call actually defined and implemented. rather than the last SVC function call actually defined and implemented.
Specific SVC, event and option values are defined in each module's ble_<module>.h file, Specific SVC, event and option values are defined in each module's ble_<module>.h file,
which defines names of each individual SVC code based on the range start value. which defines names of each individual SVC code based on the range start value.
*/ */
#ifndef BLE_RANGES_H__ #ifndef BLE_RANGES_H__
#define BLE_RANGES_H__ #define BLE_RANGES_H__
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define BLE_SVC_BASE 0x60 /**< Common BLE SVC base. */ #define BLE_SVC_BASE 0x60 /**< Common BLE SVC base. */
#define BLE_SVC_LAST 0x6B /**< Common BLE SVC last. */ #define BLE_SVC_LAST 0x6B /**< Common BLE SVC last. */
#define BLE_GAP_SVC_BASE 0x6C /**< GAP BLE SVC base. */ #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_BASE 0x9B /**< GATTC BLE SVC base. */
#define BLE_GATTC_SVC_LAST 0x9F /**< GATTC BLE SVC last. */ #define BLE_GATTC_SVC_LAST 0xA7 /**< GATTC BLE SVC last. */
#define BLE_GATTS_SVC_BASE 0xA0 /**< GATTS BLE SVC base. */ #define BLE_GATTS_SVC_BASE 0xA8 /**< GATTS BLE SVC base. */
#define BLE_GATTS_SVC_LAST 0xAF /**< GATTS BLE SVC last. */ #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. */ #define BLE_L2CAP_SVC_LAST 0xBF /**< L2CAP BLE SVC last. */
#define BLE_EVT_INVALID 0x00 /**< Invalid BLE Event. */ #define BLE_EVT_INVALID 0x00 /**< Invalid BLE Event. */
#define BLE_EVT_BASE 0x01 /**< Common BLE Event base. */ #define BLE_EVT_BASE 0x01 /**< Common BLE Event base. */
#define BLE_EVT_LAST 0x0F /**< Common BLE Event last. */ #define BLE_EVT_LAST 0x0F /**< Common BLE Event last. */
#define BLE_GAP_EVT_BASE 0x10 /**< GAP BLE Event base. */ #define BLE_GAP_EVT_BASE 0x10 /**< GAP BLE Event base. */
#define BLE_GAP_EVT_LAST 0x2F /**< GAP BLE Event last. */ #define BLE_GAP_EVT_LAST 0x2F /**< GAP BLE Event last. */
#define BLE_GATTC_EVT_BASE 0x30 /**< GATTC BLE Event base. */ #define BLE_GATTC_EVT_BASE 0x30 /**< GATTC BLE Event base. */
#define BLE_GATTC_EVT_LAST 0x4F /**< GATTC BLE Event last. */ #define BLE_GATTC_EVT_LAST 0x4F /**< GATTC BLE Event last. */
#define BLE_GATTS_EVT_BASE 0x50 /**< GATTS BLE Event base. */ #define BLE_GATTS_EVT_BASE 0x50 /**< GATTS BLE Event base. */
#define BLE_GATTS_EVT_LAST 0x6F /**< GATTS BLE Event last. */ #define BLE_GATTS_EVT_LAST 0x6F /**< GATTS BLE Event last. */
#define BLE_L2CAP_EVT_BASE 0x70 /**< L2CAP BLE Event base. */ #define BLE_L2CAP_EVT_BASE 0x70 /**< L2CAP BLE Event base. */
#define BLE_L2CAP_EVT_LAST 0x8F /**< L2CAP BLE Event last. */ #define BLE_L2CAP_EVT_LAST 0x8F /**< L2CAP BLE Event last. */
#define BLE_OPT_INVALID 0x00 /**< Invalid BLE Option. */ #define BLE_OPT_INVALID 0x00 /**< Invalid BLE Option. */
#define BLE_OPT_BASE 0x01 /**< Common BLE Option base. */ #define BLE_OPT_BASE 0x01 /**< Common BLE Option base. */
#define BLE_OPT_LAST 0x1F /**< Common BLE Option last. */ #define BLE_OPT_LAST 0x1F /**< Common BLE Option last. */
#define BLE_GAP_OPT_BASE 0x20 /**< GAP BLE Option base. */ #define BLE_GAP_OPT_BASE 0x20 /**< GAP BLE Option base. */
#define BLE_GAP_OPT_LAST 0x3F /**< GAP BLE Option last. */ #define BLE_GAP_OPT_LAST 0x3F /**< GAP BLE Option last. */
#define BLE_GATT_OPT_BASE 0x40 /**< GATT BLE Option base. */ #define BLE_GATT_OPT_BASE 0x40 /**< GATT BLE Option base. */
#define BLE_GATT_OPT_LAST 0x5F /**< GATT BLE Option last. */ #define BLE_GATT_OPT_LAST 0x5F /**< GATT BLE Option last. */
#define BLE_GATTC_OPT_BASE 0x60 /**< GATTC BLE Option base. */ #define BLE_GATTC_OPT_BASE 0x60 /**< GATTC BLE Option base. */
#define BLE_GATTC_OPT_LAST 0x7F /**< GATTC BLE Option last. */ #define BLE_GATTC_OPT_LAST 0x7F /**< GATTC BLE Option last. */
#define BLE_GATTS_OPT_BASE 0x80 /**< GATTS BLE Option base. */ #define BLE_GATTS_OPT_BASE 0x80 /**< GATTS BLE Option base. */
#define BLE_GATTS_OPT_LAST 0x9F /**< GATTS BLE Option last. */ #define BLE_GATTS_OPT_LAST 0x9F /**< GATTS BLE Option last. */
#define BLE_L2CAP_OPT_BASE 0xA0 /**< L2CAP BLE Option base. */ #define BLE_L2CAP_OPT_BASE 0xA0 /**< L2CAP BLE Option base. */
#define BLE_L2CAP_OPT_LAST 0xBF /**< L2CAP BLE Option last. */ #define BLE_L2CAP_OPT_LAST 0xBF /**< L2CAP BLE Option last. */
#define BLE_CFG_INVALID 0x00 /**< Invalid BLE configuration. */ #define BLE_CFG_INVALID 0x00 /**< Invalid BLE configuration. */
#define BLE_CFG_BASE 0x01 /**< Common BLE configuration base. */ #define BLE_CFG_BASE 0x01 /**< Common BLE configuration base. */
#define BLE_CFG_LAST 0x1F /**< Common BLE configuration last. */ #define BLE_CFG_LAST 0x1F /**< Common BLE configuration last. */
#define BLE_CONN_CFG_BASE 0x20 /**< BLE connection configuration base. */ #define BLE_CONN_CFG_BASE 0x20 /**< BLE connection configuration base. */
#define BLE_CONN_CFG_LAST 0x3F /**< BLE connection configuration last. */ #define BLE_CONN_CFG_LAST 0x3F /**< BLE connection configuration last. */
#define BLE_GAP_CFG_BASE 0x40 /**< GAP BLE configuration base. */ #define BLE_GAP_CFG_BASE 0x40 /**< GAP BLE configuration base. */
#define BLE_GAP_CFG_LAST 0x5F /**< GAP BLE configuration last. */ #define BLE_GAP_CFG_LAST 0x5F /**< GAP BLE configuration last. */
#define BLE_GATT_CFG_BASE 0x60 /**< GATT BLE configuration base. */ #define BLE_GATT_CFG_BASE 0x60 /**< GATT BLE configuration base. */
#define BLE_GATT_CFG_LAST 0x7F /**< GATT BLE configuration last. */ #define BLE_GATT_CFG_LAST 0x7F /**< GATT BLE configuration last. */
#define BLE_GATTC_CFG_BASE 0x80 /**< GATTC BLE configuration base. */ #define BLE_GATTC_CFG_BASE 0x80 /**< GATTC BLE configuration base. */
#define BLE_GATTC_CFG_LAST 0x9F /**< GATTC BLE configuration last. */ #define BLE_GATTC_CFG_LAST 0x9F /**< GATTC BLE configuration last. */
#define BLE_GATTS_CFG_BASE 0xA0 /**< GATTS BLE configuration base. */ #define BLE_GATTS_CFG_BASE 0xA0 /**< GATTS BLE configuration base. */
#define BLE_GATTS_CFG_LAST 0xBF /**< GATTS BLE configuration last. */ #define BLE_GATTS_CFG_LAST 0xBF /**< GATTS BLE configuration last. */
#define BLE_L2CAP_CFG_BASE 0xC0 /**< L2CAP BLE configuration base. */ #define BLE_L2CAP_CFG_BASE 0xC0 /**< L2CAP BLE configuration base. */
#define BLE_L2CAP_CFG_LAST 0xDF /**< L2CAP BLE configuration last. */ #define BLE_L2CAP_CFG_LAST 0xDF /**< L2CAP BLE configuration last. */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* BLE_RANGES_H__ */ #endif /* BLE_RANGES_H__ */
/** /**
@} @}
@} @}
*/ */

View File

@ -1,215 +1,215 @@
/* /*
* Copyright (c) 2012 - 2017, Nordic Semiconductor ASA * Copyright (c) 2012 - 2017, Nordic Semiconductor ASA
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* *
* 2. Redistributions in binary form, except as embedded into a Nordic * 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for * Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of * such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other * conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. * materials provided with the distribution.
* *
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its * 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 * contributors may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* *
* 4. This software, with or without modification, must only be used with a * 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit. * Nordic Semiconductor ASA integrated circuit.
* *
* 5. Any software provided in binary form under this license must not be reverse * 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled. * engineered, decompiled, modified and/or disassembled.
* *
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * 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. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/** /**
@addtogroup BLE_COMMON @addtogroup BLE_COMMON
@{ @{
@defgroup ble_types Common types and macro definitions @defgroup ble_types Common types and macro definitions
@{ @{
@brief Common types and macro definitions for the BLE SoftDevice. @brief Common types and macro definitions for the BLE SoftDevice.
*/ */
#ifndef BLE_TYPES_H__ #ifndef BLE_TYPES_H__
#define BLE_TYPES_H__ #define BLE_TYPES_H__
#include <stdint.h> #include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/** @addtogroup BLE_TYPES_DEFINES Defines /** @addtogroup BLE_TYPES_DEFINES Defines
* @{ */ * @{ */
/** @defgroup BLE_CONN_HANDLES BLE Connection Handles /** @defgroup BLE_CONN_HANDLES BLE Connection Handles
* @{ */ * @{ */
#define BLE_CONN_HANDLE_INVALID 0xFFFF /**< Invalid Connection Handle. */ #define BLE_CONN_HANDLE_INVALID 0xFFFF /**< Invalid Connection Handle. */
#define BLE_CONN_HANDLE_ALL 0xFFFE /**< Applies to all Connection Handles. */ #define BLE_CONN_HANDLE_ALL 0xFFFE /**< Applies to all Connection Handles. */
/** @} */ /** @} */
/** @defgroup BLE_UUID_VALUES Assigned Values for BLE UUIDs /** @defgroup BLE_UUID_VALUES Assigned Values for BLE UUIDs
* @{ */ * @{ */
/* Generic UUIDs, applicable to all services */ /* Generic UUIDs, applicable to all services */
#define BLE_UUID_UNKNOWN 0x0000 /**< Reserved UUID. */ #define BLE_UUID_UNKNOWN 0x0000 /**< Reserved UUID. */
#define BLE_UUID_SERVICE_PRIMARY 0x2800 /**< Primary Service. */ #define BLE_UUID_SERVICE_PRIMARY 0x2800 /**< Primary Service. */
#define BLE_UUID_SERVICE_SECONDARY 0x2801 /**< Secondary Service. */ #define BLE_UUID_SERVICE_SECONDARY 0x2801 /**< Secondary Service. */
#define BLE_UUID_SERVICE_INCLUDE 0x2802 /**< Include. */ #define BLE_UUID_SERVICE_INCLUDE 0x2802 /**< Include. */
#define BLE_UUID_CHARACTERISTIC 0x2803 /**< Characteristic. */ #define BLE_UUID_CHARACTERISTIC 0x2803 /**< Characteristic. */
#define BLE_UUID_DESCRIPTOR_CHAR_EXT_PROP 0x2900 /**< Characteristic Extended Properties Descriptor. */ #define BLE_UUID_DESCRIPTOR_CHAR_EXT_PROP 0x2900 /**< Characteristic Extended Properties Descriptor. */
#define BLE_UUID_DESCRIPTOR_CHAR_USER_DESC 0x2901 /**< Characteristic User Description Descriptor. */ #define BLE_UUID_DESCRIPTOR_CHAR_USER_DESC 0x2901 /**< Characteristic User Description Descriptor. */
#define BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG 0x2902 /**< Client Characteristic Configuration Descriptor. */ #define BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG 0x2902 /**< Client Characteristic Configuration Descriptor. */
#define BLE_UUID_DESCRIPTOR_SERVER_CHAR_CONFIG 0x2903 /**< Server Characteristic Configuration Descriptor. */ #define BLE_UUID_DESCRIPTOR_SERVER_CHAR_CONFIG 0x2903 /**< Server Characteristic Configuration Descriptor. */
#define BLE_UUID_DESCRIPTOR_CHAR_PRESENTATION_FORMAT 0x2904 /**< Characteristic Presentation Format Descriptor. */ #define BLE_UUID_DESCRIPTOR_CHAR_PRESENTATION_FORMAT 0x2904 /**< Characteristic Presentation Format Descriptor. */
#define BLE_UUID_DESCRIPTOR_CHAR_AGGREGATE_FORMAT 0x2905 /**< Characteristic Aggregate Format Descriptor. */ #define BLE_UUID_DESCRIPTOR_CHAR_AGGREGATE_FORMAT 0x2905 /**< Characteristic Aggregate Format Descriptor. */
/* GATT specific UUIDs */ /* GATT specific UUIDs */
#define BLE_UUID_GATT 0x1801 /**< Generic Attribute Profile. */ #define BLE_UUID_GATT 0x1801 /**< Generic Attribute Profile. */
#define BLE_UUID_GATT_CHARACTERISTIC_SERVICE_CHANGED 0x2A05 /**< Service Changed Characteristic. */ #define BLE_UUID_GATT_CHARACTERISTIC_SERVICE_CHANGED 0x2A05 /**< Service Changed Characteristic. */
/* GAP specific UUIDs */ /* GAP specific UUIDs */
#define BLE_UUID_GAP 0x1800 /**< Generic Access Profile. */ #define BLE_UUID_GAP 0x1800 /**< Generic Access Profile. */
#define BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME 0x2A00 /**< Device Name Characteristic. */ #define BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME 0x2A00 /**< Device Name Characteristic. */
#define BLE_UUID_GAP_CHARACTERISTIC_APPEARANCE 0x2A01 /**< Appearance Characteristic. */ #define BLE_UUID_GAP_CHARACTERISTIC_APPEARANCE 0x2A01 /**< Appearance Characteristic. */
#define BLE_UUID_GAP_CHARACTERISTIC_RECONN_ADDR 0x2A03 /**< Reconnection Address Characteristic. */ #define BLE_UUID_GAP_CHARACTERISTIC_RECONN_ADDR 0x2A03 /**< Reconnection Address Characteristic. */
#define BLE_UUID_GAP_CHARACTERISTIC_PPCP 0x2A04 /**< Peripheral Preferred Connection Parameters Characteristic. */ #define BLE_UUID_GAP_CHARACTERISTIC_PPCP 0x2A04 /**< Peripheral Preferred Connection Parameters Characteristic. */
#define BLE_UUID_GAP_CHARACTERISTIC_CAR 0x2AA6 /**< Central Address Resolution Characteristic. */ #define BLE_UUID_GAP_CHARACTERISTIC_CAR 0x2AA6 /**< Central Address Resolution Characteristic. */
#define BLE_UUID_GAP_CHARACTERISTIC_RPA_ONLY 0x2AC9 /**< Resolvable Private Address Only Characteristic. */ #define BLE_UUID_GAP_CHARACTERISTIC_RPA_ONLY 0x2AC9 /**< Resolvable Private Address Only Characteristic. */
/** @} */ /** @} */
/** @defgroup BLE_UUID_TYPES Types of UUID /** @defgroup BLE_UUID_TYPES Types of UUID
* @{ */ * @{ */
#define BLE_UUID_TYPE_UNKNOWN 0x00 /**< Invalid UUID type. */ #define BLE_UUID_TYPE_UNKNOWN 0x00 /**< Invalid UUID type. */
#define BLE_UUID_TYPE_BLE 0x01 /**< Bluetooth SIG UUID (16-bit). */ #define BLE_UUID_TYPE_BLE 0x01 /**< Bluetooth SIG UUID (16-bit). */
#define BLE_UUID_TYPE_VENDOR_BEGIN 0x02 /**< Vendor UUID types start at this index (128-bit). */ #define BLE_UUID_TYPE_VENDOR_BEGIN 0x02 /**< Vendor UUID types start at this index (128-bit). */
/** @} */ /** @} */
/** @defgroup BLE_APPEARANCES Bluetooth Appearance values /** @defgroup BLE_APPEARANCES Bluetooth Appearance values
* @note Retrieved from http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml * @note Retrieved from http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml
* @{ */ * @{ */
#define BLE_APPEARANCE_UNKNOWN 0 /**< Unknown. */ #define BLE_APPEARANCE_UNKNOWN 0 /**< Unknown. */
#define BLE_APPEARANCE_GENERIC_PHONE 64 /**< Generic Phone. */ #define BLE_APPEARANCE_GENERIC_PHONE 64 /**< Generic Phone. */
#define BLE_APPEARANCE_GENERIC_COMPUTER 128 /**< Generic Computer. */ #define BLE_APPEARANCE_GENERIC_COMPUTER 128 /**< Generic Computer. */
#define BLE_APPEARANCE_GENERIC_WATCH 192 /**< Generic Watch. */ #define BLE_APPEARANCE_GENERIC_WATCH 192 /**< Generic Watch. */
#define BLE_APPEARANCE_WATCH_SPORTS_WATCH 193 /**< Watch: Sports Watch. */ #define BLE_APPEARANCE_WATCH_SPORTS_WATCH 193 /**< Watch: Sports Watch. */
#define BLE_APPEARANCE_GENERIC_CLOCK 256 /**< Generic Clock. */ #define BLE_APPEARANCE_GENERIC_CLOCK 256 /**< Generic Clock. */
#define BLE_APPEARANCE_GENERIC_DISPLAY 320 /**< Generic Display. */ #define BLE_APPEARANCE_GENERIC_DISPLAY 320 /**< Generic Display. */
#define BLE_APPEARANCE_GENERIC_REMOTE_CONTROL 384 /**< Generic Remote Control. */ #define BLE_APPEARANCE_GENERIC_REMOTE_CONTROL 384 /**< Generic Remote Control. */
#define BLE_APPEARANCE_GENERIC_EYE_GLASSES 448 /**< Generic Eye-glasses. */ #define BLE_APPEARANCE_GENERIC_EYE_GLASSES 448 /**< Generic Eye-glasses. */
#define BLE_APPEARANCE_GENERIC_TAG 512 /**< Generic Tag. */ #define BLE_APPEARANCE_GENERIC_TAG 512 /**< Generic Tag. */
#define BLE_APPEARANCE_GENERIC_KEYRING 576 /**< Generic Keyring. */ #define BLE_APPEARANCE_GENERIC_KEYRING 576 /**< Generic Keyring. */
#define BLE_APPEARANCE_GENERIC_MEDIA_PLAYER 640 /**< Generic Media Player. */ #define BLE_APPEARANCE_GENERIC_MEDIA_PLAYER 640 /**< Generic Media Player. */
#define BLE_APPEARANCE_GENERIC_BARCODE_SCANNER 704 /**< Generic Barcode Scanner. */ #define BLE_APPEARANCE_GENERIC_BARCODE_SCANNER 704 /**< Generic Barcode Scanner. */
#define BLE_APPEARANCE_GENERIC_THERMOMETER 768 /**< Generic Thermometer. */ #define BLE_APPEARANCE_GENERIC_THERMOMETER 768 /**< Generic Thermometer. */
#define BLE_APPEARANCE_THERMOMETER_EAR 769 /**< Thermometer: Ear. */ #define BLE_APPEARANCE_THERMOMETER_EAR 769 /**< Thermometer: Ear. */
#define BLE_APPEARANCE_GENERIC_HEART_RATE_SENSOR 832 /**< Generic Heart rate Sensor. */ #define BLE_APPEARANCE_GENERIC_HEART_RATE_SENSOR 832 /**< Generic Heart rate Sensor. */
#define BLE_APPEARANCE_HEART_RATE_SENSOR_HEART_RATE_BELT 833 /**< Heart Rate Sensor: Heart Rate Belt. */ #define BLE_APPEARANCE_HEART_RATE_SENSOR_HEART_RATE_BELT 833 /**< Heart Rate Sensor: Heart Rate Belt. */
#define BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE 896 /**< Generic Blood Pressure. */ #define BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE 896 /**< Generic Blood Pressure. */
#define BLE_APPEARANCE_BLOOD_PRESSURE_ARM 897 /**< Blood Pressure: Arm. */ #define BLE_APPEARANCE_BLOOD_PRESSURE_ARM 897 /**< Blood Pressure: Arm. */
#define BLE_APPEARANCE_BLOOD_PRESSURE_WRIST 898 /**< Blood Pressure: Wrist. */ #define BLE_APPEARANCE_BLOOD_PRESSURE_WRIST 898 /**< Blood Pressure: Wrist. */
#define BLE_APPEARANCE_GENERIC_HID 960 /**< Human Interface Device (HID). */ #define BLE_APPEARANCE_GENERIC_HID 960 /**< Human Interface Device (HID). */
#define BLE_APPEARANCE_HID_KEYBOARD 961 /**< Keyboard (HID Subtype). */ #define BLE_APPEARANCE_HID_KEYBOARD 961 /**< Keyboard (HID Subtype). */
#define BLE_APPEARANCE_HID_MOUSE 962 /**< Mouse (HID Subtype). */ #define BLE_APPEARANCE_HID_MOUSE 962 /**< Mouse (HID Subtype). */
#define BLE_APPEARANCE_HID_JOYSTICK 963 /**< Joystick (HID Subtype). */ #define BLE_APPEARANCE_HID_JOYSTICK 963 /**< Joystick (HID Subtype). */
#define BLE_APPEARANCE_HID_GAMEPAD 964 /**< Gamepad (HID Subtype). */ #define BLE_APPEARANCE_HID_GAMEPAD 964 /**< Gamepad (HID Subtype). */
#define BLE_APPEARANCE_HID_DIGITIZERSUBTYPE 965 /**< Digitizer Tablet (HID Subtype). */ #define BLE_APPEARANCE_HID_DIGITIZERSUBTYPE 965 /**< Digitizer Tablet (HID Subtype). */
#define BLE_APPEARANCE_HID_CARD_READER 966 /**< Card Reader (HID Subtype). */ #define BLE_APPEARANCE_HID_CARD_READER 966 /**< Card Reader (HID Subtype). */
#define BLE_APPEARANCE_HID_DIGITAL_PEN 967 /**< Digital Pen (HID Subtype). */ #define BLE_APPEARANCE_HID_DIGITAL_PEN 967 /**< Digital Pen (HID Subtype). */
#define BLE_APPEARANCE_HID_BARCODE 968 /**< Barcode Scanner (HID Subtype). */ #define BLE_APPEARANCE_HID_BARCODE 968 /**< Barcode Scanner (HID Subtype). */
#define BLE_APPEARANCE_GENERIC_GLUCOSE_METER 1024 /**< Generic Glucose Meter. */ #define BLE_APPEARANCE_GENERIC_GLUCOSE_METER 1024 /**< Generic Glucose Meter. */
#define BLE_APPEARANCE_GENERIC_RUNNING_WALKING_SENSOR 1088 /**< Generic Running Walking Sensor. */ #define BLE_APPEARANCE_GENERIC_RUNNING_WALKING_SENSOR 1088 /**< Generic Running Walking Sensor. */
#define BLE_APPEARANCE_RUNNING_WALKING_SENSOR_IN_SHOE 1089 /**< Running Walking Sensor: In-Shoe. */ #define BLE_APPEARANCE_RUNNING_WALKING_SENSOR_IN_SHOE 1089 /**< Running Walking Sensor: In-Shoe. */
#define BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_SHOE 1090 /**< Running Walking Sensor: On-Shoe. */ #define BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_SHOE 1090 /**< Running Walking Sensor: On-Shoe. */
#define BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_HIP 1091 /**< Running Walking Sensor: On-Hip. */ #define BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_HIP 1091 /**< Running Walking Sensor: On-Hip. */
#define BLE_APPEARANCE_GENERIC_CYCLING 1152 /**< Generic Cycling. */ #define BLE_APPEARANCE_GENERIC_CYCLING 1152 /**< Generic Cycling. */
#define BLE_APPEARANCE_CYCLING_CYCLING_COMPUTER 1153 /**< Cycling: Cycling Computer. */ #define BLE_APPEARANCE_CYCLING_CYCLING_COMPUTER 1153 /**< Cycling: Cycling Computer. */
#define BLE_APPEARANCE_CYCLING_SPEED_SENSOR 1154 /**< Cycling: Speed Sensor. */ #define BLE_APPEARANCE_CYCLING_SPEED_SENSOR 1154 /**< Cycling: Speed Sensor. */
#define BLE_APPEARANCE_CYCLING_CADENCE_SENSOR 1155 /**< Cycling: Cadence Sensor. */ #define BLE_APPEARANCE_CYCLING_CADENCE_SENSOR 1155 /**< Cycling: Cadence Sensor. */
#define BLE_APPEARANCE_CYCLING_POWER_SENSOR 1156 /**< Cycling: Power Sensor. */ #define BLE_APPEARANCE_CYCLING_POWER_SENSOR 1156 /**< Cycling: Power Sensor. */
#define BLE_APPEARANCE_CYCLING_SPEED_CADENCE_SENSOR 1157 /**< Cycling: Speed and Cadence Sensor. */ #define BLE_APPEARANCE_CYCLING_SPEED_CADENCE_SENSOR 1157 /**< Cycling: Speed and Cadence Sensor. */
#define BLE_APPEARANCE_GENERIC_PULSE_OXIMETER 3136 /**< Generic Pulse Oximeter. */ #define BLE_APPEARANCE_GENERIC_PULSE_OXIMETER 3136 /**< Generic Pulse Oximeter. */
#define BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP 3137 /**< Fingertip (Pulse Oximeter subtype). */ #define BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP 3137 /**< Fingertip (Pulse Oximeter subtype). */
#define BLE_APPEARANCE_PULSE_OXIMETER_WRIST_WORN 3138 /**< Wrist Worn(Pulse Oximeter subtype). */ #define BLE_APPEARANCE_PULSE_OXIMETER_WRIST_WORN 3138 /**< Wrist Worn(Pulse Oximeter subtype). */
#define BLE_APPEARANCE_GENERIC_WEIGHT_SCALE 3200 /**< Generic Weight Scale. */ #define BLE_APPEARANCE_GENERIC_WEIGHT_SCALE 3200 /**< Generic Weight Scale. */
#define BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS_ACT 5184 /**< Generic Outdoor Sports Activity. */ #define BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS_ACT 5184 /**< Generic Outdoor Sports Activity. */
#define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_DISP 5185 /**< Location Display Device (Outdoor Sports Activity subtype). */ #define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_DISP 5185 /**< Location Display Device (Outdoor Sports Activity subtype). */
#define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_AND_NAV_DISP 5186 /**< Location and Navigation Display Device (Outdoor Sports Activity subtype). */ #define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_AND_NAV_DISP 5186 /**< Location and Navigation Display Device (Outdoor Sports Activity subtype). */
#define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_POD 5187 /**< Location Pod (Outdoor Sports Activity subtype). */ #define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_POD 5187 /**< Location Pod (Outdoor Sports Activity subtype). */
#define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_AND_NAV_POD 5188 /**< Location and Navigation Pod (Outdoor Sports Activity subtype). */ #define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_AND_NAV_POD 5188 /**< Location and Navigation Pod (Outdoor Sports Activity subtype). */
/** @} */ /** @} */
/** @brief Set .type and .uuid fields of ble_uuid_struct to specified UUID value. */ /** @brief Set .type and .uuid fields of ble_uuid_struct to specified UUID value. */
#define BLE_UUID_BLE_ASSIGN(instance, value) do {\ #define BLE_UUID_BLE_ASSIGN(instance, value) do {\
instance.type = BLE_UUID_TYPE_BLE; \ instance.type = BLE_UUID_TYPE_BLE; \
instance.uuid = value;} while(0) instance.uuid = value;} while(0)
/** @brief Copy type and uuid members from src to dst ble_uuid_t pointer. Both pointers must be valid/non-null. */ /** @brief Copy type and uuid members from src to dst ble_uuid_t pointer. Both pointers must be valid/non-null. */
#define BLE_UUID_COPY_PTR(dst, src) do {\ #define BLE_UUID_COPY_PTR(dst, src) do {\
(dst)->type = (src)->type; \ (dst)->type = (src)->type; \
(dst)->uuid = (src)->uuid;} while(0) (dst)->uuid = (src)->uuid;} while(0)
/** @brief Copy type and uuid members from src to dst ble_uuid_t struct. */ /** @brief Copy type and uuid members from src to dst ble_uuid_t struct. */
#define BLE_UUID_COPY_INST(dst, src) do {\ #define BLE_UUID_COPY_INST(dst, src) do {\
(dst).type = (src).type; \ (dst).type = (src).type; \
(dst).uuid = (src).uuid;} while(0) (dst).uuid = (src).uuid;} while(0)
/** @brief Compare for equality both type and uuid members of two (valid, non-null) ble_uuid_t pointers. */ /** @brief Compare for equality both type and uuid members of two (valid, non-null) ble_uuid_t pointers. */
#define BLE_UUID_EQ(p_uuid1, p_uuid2) \ #define BLE_UUID_EQ(p_uuid1, p_uuid2) \
(((p_uuid1)->type == (p_uuid2)->type) && ((p_uuid1)->uuid == (p_uuid2)->uuid)) (((p_uuid1)->type == (p_uuid2)->type) && ((p_uuid1)->uuid == (p_uuid2)->uuid))
/** @brief Compare for difference both type and uuid members of two (valid, non-null) ble_uuid_t pointers. */ /** @brief Compare for difference both type and uuid members of two (valid, non-null) ble_uuid_t pointers. */
#define BLE_UUID_NEQ(p_uuid1, p_uuid2) \ #define BLE_UUID_NEQ(p_uuid1, p_uuid2) \
(((p_uuid1)->type != (p_uuid2)->type) || ((p_uuid1)->uuid != (p_uuid2)->uuid)) (((p_uuid1)->type != (p_uuid2)->type) || ((p_uuid1)->uuid != (p_uuid2)->uuid))
/** @} */ /** @} */
/** @addtogroup BLE_TYPES_STRUCTURES Structures /** @addtogroup BLE_TYPES_STRUCTURES Structures
* @{ */ * @{ */
/** @brief 128 bit UUID values. */ /** @brief 128 bit UUID values. */
typedef struct typedef struct
{ {
uint8_t uuid128[16]; /**< Little-Endian UUID bytes. */ uint8_t uuid128[16]; /**< Little-Endian UUID bytes. */
} ble_uuid128_t; } ble_uuid128_t;
/** @brief Bluetooth Low Energy UUID type, encapsulates both 16-bit and 128-bit UUIDs. */ /** @brief Bluetooth Low Energy UUID type, encapsulates both 16-bit and 128-bit UUIDs. */
typedef struct typedef struct
{ {
uint16_t uuid; /**< 16-bit UUID value or octets 12-13 of 128-bit UUID. */ uint16_t uuid; /**< 16-bit UUID value or octets 12-13 of 128-bit UUID. */
uint8_t type; /**< UUID type, see @ref BLE_UUID_TYPES. If type is @ref BLE_UUID_TYPE_UNKNOWN, the value of uuid is undefined. */ uint8_t type; /**< UUID type, see @ref BLE_UUID_TYPES. If type is @ref BLE_UUID_TYPE_UNKNOWN, the value of uuid is undefined. */
} ble_uuid_t; } ble_uuid_t;
/**@brief Data structure. */ /**@brief Data structure. */
typedef struct typedef struct
{ {
uint8_t *p_data; /**< Pointer to the data buffer provided to/from the application. */ uint8_t *p_data; /**< Pointer to the data buffer provided to/from the application. */
uint16_t len; /**< Length of the data buffer, in bytes. */ uint16_t len; /**< Length of the data buffer, in bytes. */
} ble_data_t; } ble_data_t;
/** @} */ /** @} */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* BLE_TYPES_H__ */ #endif /* BLE_TYPES_H__ */
/** /**
@} @}
@} @}
*/ */

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

@ -1,90 +1,90 @@
/* /*
* Copyright (c) 2014 - 2017, Nordic Semiconductor ASA * Copyright (c) 2014 - 2017, Nordic Semiconductor ASA
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* *
* 2. Redistributions in binary form, except as embedded into a Nordic * 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for * Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of * such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other * conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. * materials provided with the distribution.
* *
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its * 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 * contributors may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* *
* 4. This software, with or without modification, must only be used with a * 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit. * Nordic Semiconductor ASA integrated circuit.
* *
* 5. Any software provided in binary form under this license must not be reverse * 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled. * engineered, decompiled, modified and/or disassembled.
* *
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * 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. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/** /**
@defgroup nrf_error SoftDevice Global Error Codes @defgroup nrf_error SoftDevice Global Error Codes
@{ @{
@brief Global Error definitions @brief Global Error definitions
*/ */
/* Header guard */ /* Header guard */
#ifndef NRF_ERROR_H__ #ifndef NRF_ERROR_H__
#define NRF_ERROR_H__ #define NRF_ERROR_H__
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/** @defgroup NRF_ERRORS_BASE Error Codes Base number definitions /** @defgroup NRF_ERRORS_BASE Error Codes Base number definitions
* @{ */ * @{ */
#define NRF_ERROR_BASE_NUM (0x0) ///< Global error base #define NRF_ERROR_BASE_NUM (0x0) ///< Global error base
#define NRF_ERROR_SDM_BASE_NUM (0x1000) ///< SDM error base #define NRF_ERROR_SDM_BASE_NUM (0x1000) ///< SDM error base
#define NRF_ERROR_SOC_BASE_NUM (0x2000) ///< SoC error base #define NRF_ERROR_SOC_BASE_NUM (0x2000) ///< SoC error base
#define NRF_ERROR_STK_BASE_NUM (0x3000) ///< STK error base #define NRF_ERROR_STK_BASE_NUM (0x3000) ///< STK error base
/** @} */ /** @} */
#define NRF_SUCCESS (NRF_ERROR_BASE_NUM + 0) ///< Successful command #define NRF_SUCCESS (NRF_ERROR_BASE_NUM + 0) ///< Successful command
#define NRF_ERROR_SVC_HANDLER_MISSING (NRF_ERROR_BASE_NUM + 1) ///< SVC handler is missing #define NRF_ERROR_SVC_HANDLER_MISSING (NRF_ERROR_BASE_NUM + 1) ///< SVC handler is missing
#define NRF_ERROR_SOFTDEVICE_NOT_ENABLED (NRF_ERROR_BASE_NUM + 2) ///< SoftDevice has not been enabled #define NRF_ERROR_SOFTDEVICE_NOT_ENABLED (NRF_ERROR_BASE_NUM + 2) ///< SoftDevice has not been enabled
#define NRF_ERROR_INTERNAL (NRF_ERROR_BASE_NUM + 3) ///< Internal Error #define NRF_ERROR_INTERNAL (NRF_ERROR_BASE_NUM + 3) ///< Internal Error
#define NRF_ERROR_NO_MEM (NRF_ERROR_BASE_NUM + 4) ///< No Memory for operation #define NRF_ERROR_NO_MEM (NRF_ERROR_BASE_NUM + 4) ///< No Memory for operation
#define NRF_ERROR_NOT_FOUND (NRF_ERROR_BASE_NUM + 5) ///< Not found #define NRF_ERROR_NOT_FOUND (NRF_ERROR_BASE_NUM + 5) ///< Not found
#define NRF_ERROR_NOT_SUPPORTED (NRF_ERROR_BASE_NUM + 6) ///< Not supported #define NRF_ERROR_NOT_SUPPORTED (NRF_ERROR_BASE_NUM + 6) ///< Not supported
#define NRF_ERROR_INVALID_PARAM (NRF_ERROR_BASE_NUM + 7) ///< Invalid Parameter #define NRF_ERROR_INVALID_PARAM (NRF_ERROR_BASE_NUM + 7) ///< Invalid Parameter
#define NRF_ERROR_INVALID_STATE (NRF_ERROR_BASE_NUM + 8) ///< Invalid state, operation disallowed in this state #define NRF_ERROR_INVALID_STATE (NRF_ERROR_BASE_NUM + 8) ///< Invalid state, operation disallowed in this state
#define NRF_ERROR_INVALID_LENGTH (NRF_ERROR_BASE_NUM + 9) ///< Invalid Length #define NRF_ERROR_INVALID_LENGTH (NRF_ERROR_BASE_NUM + 9) ///< Invalid Length
#define NRF_ERROR_INVALID_FLAGS (NRF_ERROR_BASE_NUM + 10) ///< Invalid Flags #define NRF_ERROR_INVALID_FLAGS (NRF_ERROR_BASE_NUM + 10) ///< Invalid Flags
#define NRF_ERROR_INVALID_DATA (NRF_ERROR_BASE_NUM + 11) ///< Invalid Data #define NRF_ERROR_INVALID_DATA (NRF_ERROR_BASE_NUM + 11) ///< Invalid Data
#define NRF_ERROR_DATA_SIZE (NRF_ERROR_BASE_NUM + 12) ///< Invalid Data size #define NRF_ERROR_DATA_SIZE (NRF_ERROR_BASE_NUM + 12) ///< Invalid Data size
#define NRF_ERROR_TIMEOUT (NRF_ERROR_BASE_NUM + 13) ///< Operation timed out #define NRF_ERROR_TIMEOUT (NRF_ERROR_BASE_NUM + 13) ///< Operation timed out
#define NRF_ERROR_NULL (NRF_ERROR_BASE_NUM + 14) ///< Null Pointer #define NRF_ERROR_NULL (NRF_ERROR_BASE_NUM + 14) ///< Null Pointer
#define NRF_ERROR_FORBIDDEN (NRF_ERROR_BASE_NUM + 15) ///< Forbidden Operation #define NRF_ERROR_FORBIDDEN (NRF_ERROR_BASE_NUM + 15) ///< Forbidden Operation
#define NRF_ERROR_INVALID_ADDR (NRF_ERROR_BASE_NUM + 16) ///< Bad Memory Address #define NRF_ERROR_INVALID_ADDR (NRF_ERROR_BASE_NUM + 16) ///< Bad Memory Address
#define NRF_ERROR_BUSY (NRF_ERROR_BASE_NUM + 17) ///< Busy #define NRF_ERROR_BUSY (NRF_ERROR_BASE_NUM + 17) ///< Busy
#define NRF_ERROR_CONN_COUNT (NRF_ERROR_BASE_NUM + 18) ///< Maximum connection count exceeded. #define NRF_ERROR_CONN_COUNT (NRF_ERROR_BASE_NUM + 18) ///< Maximum connection count exceeded.
#define NRF_ERROR_RESOURCES (NRF_ERROR_BASE_NUM + 19) ///< Not enough resources for operation #define NRF_ERROR_RESOURCES (NRF_ERROR_BASE_NUM + 19) ///< Not enough resources for operation
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif // NRF_ERROR_H__ #endif // NRF_ERROR_H__
/** /**
@} @}
*/ */

View File

@ -1,70 +1,70 @@
/* /*
* Copyright (c) 2012 - 2017, Nordic Semiconductor ASA * Copyright (c) 2012 - 2017, Nordic Semiconductor ASA
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* *
* 2. Redistributions in binary form, except as embedded into a Nordic * 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for * Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of * such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other * conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. * materials provided with the distribution.
* *
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its * 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 * contributors may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* *
* 4. This software, with or without modification, must only be used with a * 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit. * Nordic Semiconductor ASA integrated circuit.
* *
* 5. Any software provided in binary form under this license must not be reverse * 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled. * engineered, decompiled, modified and/or disassembled.
* *
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * 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. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/** /**
@addtogroup nrf_sdm_api @addtogroup nrf_sdm_api
@{ @{
@defgroup nrf_sdm_error SoftDevice Manager Error Codes @defgroup nrf_sdm_error SoftDevice Manager Error Codes
@{ @{
@brief Error definitions for the SDM API @brief Error definitions for the SDM API
*/ */
/* Header guard */ /* Header guard */
#ifndef NRF_ERROR_SDM_H__ #ifndef NRF_ERROR_SDM_H__
#define NRF_ERROR_SDM_H__ #define NRF_ERROR_SDM_H__
#include "nrf_error.h" #include "nrf_error.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN (NRF_ERROR_SDM_BASE_NUM + 0) ///< Unknown LFCLK source. #define NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN (NRF_ERROR_SDM_BASE_NUM + 0) ///< Unknown LFCLK source.
#define NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION (NRF_ERROR_SDM_BASE_NUM + 1) ///< Incorrect interrupt configuration (can be caused by using illegal priority levels, or having enabled SoftDevice interrupts). #define NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION (NRF_ERROR_SDM_BASE_NUM + 1) ///< Incorrect interrupt configuration (can be caused by using illegal priority levels, or having enabled SoftDevice interrupts).
#define NRF_ERROR_SDM_INCORRECT_CLENR0 (NRF_ERROR_SDM_BASE_NUM + 2) ///< Incorrect CLENR0 (can be caused by erroneous SoftDevice flashing). #define NRF_ERROR_SDM_INCORRECT_CLENR0 (NRF_ERROR_SDM_BASE_NUM + 2) ///< Incorrect CLENR0 (can be caused by erroneous SoftDevice flashing).
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif // NRF_ERROR_SDM_H__ #endif // NRF_ERROR_SDM_H__
/** /**
@} @}
@} @}
*/ */

View File

@ -1,85 +1,85 @@
/* /*
* Copyright (c) 2012 - 2017, Nordic Semiconductor ASA * Copyright (c) 2012 - 2017, Nordic Semiconductor ASA
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* *
* 2. Redistributions in binary form, except as embedded into a Nordic * 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for * Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of * such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other * conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. * materials provided with the distribution.
* *
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its * 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 * contributors may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* *
* 4. This software, with or without modification, must only be used with a * 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit. * Nordic Semiconductor ASA integrated circuit.
* *
* 5. Any software provided in binary form under this license must not be reverse * 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled. * engineered, decompiled, modified and/or disassembled.
* *
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * 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. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/** /**
@addtogroup nrf_soc_api @addtogroup nrf_soc_api
@{ @{
@defgroup nrf_soc_error SoC Library Error Codes @defgroup nrf_soc_error SoC Library Error Codes
@{ @{
@brief Error definitions for the SoC library @brief Error definitions for the SoC library
*/ */
/* Header guard */ /* Header guard */
#ifndef NRF_ERROR_SOC_H__ #ifndef NRF_ERROR_SOC_H__
#define NRF_ERROR_SOC_H__ #define NRF_ERROR_SOC_H__
#include "nrf_error.h" #include "nrf_error.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* Mutex Errors */ /* Mutex Errors */
#define NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN (NRF_ERROR_SOC_BASE_NUM + 0) ///< Mutex already taken #define NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN (NRF_ERROR_SOC_BASE_NUM + 0) ///< Mutex already taken
/* NVIC errors */ /* NVIC errors */
#define NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE (NRF_ERROR_SOC_BASE_NUM + 1) ///< NVIC interrupt not available #define NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE (NRF_ERROR_SOC_BASE_NUM + 1) ///< NVIC interrupt not available
#define NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED (NRF_ERROR_SOC_BASE_NUM + 2) ///< NVIC interrupt priority not allowed #define NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED (NRF_ERROR_SOC_BASE_NUM + 2) ///< NVIC interrupt priority not allowed
#define NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN (NRF_ERROR_SOC_BASE_NUM + 3) ///< NVIC should not return #define NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN (NRF_ERROR_SOC_BASE_NUM + 3) ///< NVIC should not return
/* Power errors */ /* Power errors */
#define NRF_ERROR_SOC_POWER_MODE_UNKNOWN (NRF_ERROR_SOC_BASE_NUM + 4) ///< Power mode unknown #define NRF_ERROR_SOC_POWER_MODE_UNKNOWN (NRF_ERROR_SOC_BASE_NUM + 4) ///< Power mode unknown
#define NRF_ERROR_SOC_POWER_POF_THRESHOLD_UNKNOWN (NRF_ERROR_SOC_BASE_NUM + 5) ///< Power POF threshold unknown #define NRF_ERROR_SOC_POWER_POF_THRESHOLD_UNKNOWN (NRF_ERROR_SOC_BASE_NUM + 5) ///< Power POF threshold unknown
#define NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN (NRF_ERROR_SOC_BASE_NUM + 6) ///< Power off should not return #define NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN (NRF_ERROR_SOC_BASE_NUM + 6) ///< Power off should not return
/* Rand errors */ /* Rand errors */
#define NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES (NRF_ERROR_SOC_BASE_NUM + 7) ///< RAND not enough values #define NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES (NRF_ERROR_SOC_BASE_NUM + 7) ///< RAND not enough values
/* PPI errors */ /* PPI errors */
#define NRF_ERROR_SOC_PPI_INVALID_CHANNEL (NRF_ERROR_SOC_BASE_NUM + 8) ///< Invalid PPI Channel #define NRF_ERROR_SOC_PPI_INVALID_CHANNEL (NRF_ERROR_SOC_BASE_NUM + 8) ///< Invalid PPI Channel
#define NRF_ERROR_SOC_PPI_INVALID_GROUP (NRF_ERROR_SOC_BASE_NUM + 9) ///< Invalid PPI Group #define NRF_ERROR_SOC_PPI_INVALID_GROUP (NRF_ERROR_SOC_BASE_NUM + 9) ///< Invalid PPI Group
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif // NRF_ERROR_SOC_H__ #endif // NRF_ERROR_SOC_H__
/** /**
@} @}
@} @}
*/ */

View File

@ -1,485 +1,486 @@
/* /*
* Copyright (c) 2016 - 2017, Nordic Semiconductor ASA * Copyright (c) 2016 - 2017, Nordic Semiconductor ASA
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* *
* 2. Redistributions in binary form, except as embedded into a Nordic * 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for * Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of * such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other * conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. * materials provided with the distribution.
* *
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its * 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 * contributors may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* *
* 4. This software, with or without modification, must only be used with a * 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit. * Nordic Semiconductor ASA integrated circuit.
* *
* 5. Any software provided in binary form under this license must not be reverse * 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled. * engineered, decompiled, modified and/or disassembled.
* *
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * 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. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/** /**
* @defgroup nrf_nvic_api SoftDevice NVIC API * @defgroup nrf_nvic_api SoftDevice NVIC API
* @{ * @{
* *
* @note In order to use this module, the following code has to be added to a .c file: * @note In order to use this module, the following code has to be added to a .c file:
* \code * \code
* nrf_nvic_state_t nrf_nvic_state = {0}; * nrf_nvic_state_t nrf_nvic_state = {0};
* \endcode * \endcode
* *
* @note Definitions and declarations starting with __ (double underscore) in this header file are * @note Definitions and declarations starting with __ (double underscore) in this header file are
* not intended for direct use by the application. * not intended for direct use by the application.
* *
* @brief APIs for the accessing NVIC when using a SoftDevice. * @brief APIs for the accessing NVIC when using a SoftDevice.
* *
*/ */
#ifndef NRF_NVIC_H__ #ifndef NRF_NVIC_H__
#define NRF_NVIC_H__ #define NRF_NVIC_H__
#include <stdint.h> #include <stdint.h>
#include "nrf.h" #include "nrf.h"
#include "nrf_svc.h"
#include "nrf_error_soc.h" #include "nrf_error.h"
#include "nrf_error_soc.h"
#ifdef __cplusplus
extern "C" { #ifdef __cplusplus
#endif extern "C" {
#endif
/**@addtogroup NRF_NVIC_DEFINES Defines
* @{ */ /**@addtogroup NRF_NVIC_DEFINES Defines
* @{ */
/**@defgroup NRF_NVIC_ISER_DEFINES SoftDevice NVIC internal definitions
* @{ */ /**@defgroup NRF_NVIC_ISER_DEFINES SoftDevice NVIC internal definitions
* @{ */
#define __NRF_NVIC_NVMC_IRQn (30) /**< The peripheral ID of the NVMC. IRQ numbers are used to identify peripherals, but the NVMC doesn't have an IRQ number in the MDK. */
#define __NRF_NVIC_NVMC_IRQn (30) /**< The peripheral ID of the NVMC. IRQ numbers are used to identify peripherals, but the NVMC doesn't have an IRQ number in the MDK. */
#define __NRF_NVIC_ISER_COUNT (2) /**< The number of ISER/ICER registers in the NVIC that are used. */
#define __NRF_NVIC_ISER_COUNT (2) /**< The number of ISER/ICER registers in the NVIC that are used. */
/**@brief Interrupts used by the SoftDevice, with IRQn in the range 0-31. */
#define __NRF_NVIC_SD_IRQS_0 ((uint32_t)( \ /**@brief Interrupts used by the SoftDevice, with IRQn in the range 0-31. */
(1U << POWER_CLOCK_IRQn) \ #define __NRF_NVIC_SD_IRQS_0 ((uint32_t)( \
| (1U << RADIO_IRQn) \ (1U << POWER_CLOCK_IRQn) \
| (1U << RTC0_IRQn) \ | (1U << RADIO_IRQn) \
| (1U << TIMER0_IRQn) \ | (1U << RTC0_IRQn) \
| (1U << RNG_IRQn) \ | (1U << TIMER0_IRQn) \
| (1U << ECB_IRQn) \ | (1U << RNG_IRQn) \
| (1U << CCM_AAR_IRQn) \ | (1U << ECB_IRQn) \
| (1U << TEMP_IRQn) \ | (1U << CCM_AAR_IRQn) \
| (1U << __NRF_NVIC_NVMC_IRQn) \ | (1U << TEMP_IRQn) \
| (1U << (uint32_t)SWI5_EGU5_IRQn) \ | (1U << __NRF_NVIC_NVMC_IRQn) \
)) | (1U << (uint32_t)SWI5_IRQn) \
))
/**@brief Interrupts used by the SoftDevice, with IRQn in the range 32-63. */
#define __NRF_NVIC_SD_IRQS_1 ((uint32_t)0) /**@brief Interrupts used by the SoftDevice, with IRQn in the range 32-63. */
#define __NRF_NVIC_SD_IRQS_1 ((uint32_t)0)
/**@brief Interrupts available for to application, with IRQn in the range 0-31. */
#define __NRF_NVIC_APP_IRQS_0 (~__NRF_NVIC_SD_IRQS_0) /**@brief Interrupts available for to application, with IRQn in the range 0-31. */
#define __NRF_NVIC_APP_IRQS_0 (~__NRF_NVIC_SD_IRQS_0)
/**@brief Interrupts available for to application, with IRQn in the range 32-63. */
#define __NRF_NVIC_APP_IRQS_1 (~__NRF_NVIC_SD_IRQS_1) /**@brief Interrupts available for to application, with IRQn in the range 32-63. */
#define __NRF_NVIC_APP_IRQS_1 (~__NRF_NVIC_SD_IRQS_1)
/**@} */
/**@} */
/**@} */
/**@} */
/**@addtogroup NRF_NVIC_VARIABLES Variables
* @{ */ /**@addtogroup NRF_NVIC_VARIABLES Variables
* @{ */
/**@brief Type representing the state struct for the SoftDevice NVIC module. */
typedef struct /**@brief Type representing the state struct for the SoftDevice NVIC module. */
{ typedef struct
uint32_t volatile __irq_masks[__NRF_NVIC_ISER_COUNT]; /**< IRQs enabled by the application in the NVIC. */ {
uint32_t volatile __cr_flag; /**< Non-zero if already in a critical region */ uint32_t volatile __irq_masks[__NRF_NVIC_ISER_COUNT]; /**< IRQs enabled by the application in the NVIC. */
} nrf_nvic_state_t; uint32_t volatile __cr_flag; /**< Non-zero if already in a critical region */
} nrf_nvic_state_t;
/**@brief Variable keeping the state for the SoftDevice NVIC module. This must be declared in an
* application source file. */ /**@brief Variable keeping the state for the SoftDevice NVIC module. This must be declared in an
extern nrf_nvic_state_t nrf_nvic_state; * application source file. */
extern nrf_nvic_state_t nrf_nvic_state;
/**@} */
/**@} */
/**@addtogroup NRF_NVIC_INTERNAL_FUNCTIONS SoftDevice NVIC internal functions
* @{ */ /**@addtogroup NRF_NVIC_INTERNAL_FUNCTIONS SoftDevice NVIC internal functions
* @{ */
/**@brief Disables IRQ interrupts globally, including the SoftDevice's interrupts.
* /**@brief Disables IRQ interrupts globally, including the SoftDevice's interrupts.
* @retval The value of PRIMASK prior to disabling the interrupts. *
*/ * @retval The value of PRIMASK prior to disabling the interrupts.
__STATIC_INLINE int __sd_nvic_irq_disable(void); */
__STATIC_INLINE int __sd_nvic_irq_disable(void);
/**@brief Enables IRQ interrupts globally, including the SoftDevice's interrupts.
*/ /**@brief Enables IRQ interrupts globally, including the SoftDevice's interrupts.
__STATIC_INLINE void __sd_nvic_irq_enable(void); */
__STATIC_INLINE void __sd_nvic_irq_enable(void);
/**@brief Checks if IRQn is available to application
* @param[in] IRQn IRQ to check /**@brief Checks if IRQn is available to application
* * @param[in] IRQn IRQ to check
* @retval 1 (true) if the IRQ to check is available to the application *
*/ * @retval 1 (true) if the IRQ to check is available to the application
__STATIC_INLINE uint32_t __sd_nvic_app_accessible_irq(IRQn_Type IRQn); */
__STATIC_INLINE uint32_t __sd_nvic_app_accessible_irq(IRQn_Type IRQn);
/**@brief Checks if priority is available to application
* @param[in] priority priority to check /**@brief Checks if priority is available to application
* * @param[in] priority priority to check
* @retval 1 (true) if the priority to check is available to the application *
*/ * @retval 1 (true) if the priority to check is available to the application
__STATIC_INLINE uint32_t __sd_nvic_is_app_accessible_priority(uint32_t priority); */
__STATIC_INLINE uint32_t __sd_nvic_is_app_accessible_priority(uint32_t priority);
/**@} */
/**@} */
/**@addtogroup NRF_NVIC_FUNCTIONS SoftDevice NVIC public functions
* @{ */ /**@addtogroup NRF_NVIC_FUNCTIONS SoftDevice NVIC public functions
* @{ */
/**@brief Enable External Interrupt.
* @note Corresponds to NVIC_EnableIRQ in CMSIS. /**@brief Enable External Interrupt.
* * @note Corresponds to NVIC_EnableIRQ in CMSIS.
* @pre IRQn is valid and not reserved by the stack. *
* * @pre IRQn is valid and not reserved by the stack.
* @param[in] IRQn See the NVIC_EnableIRQ documentation in CMSIS. *
* * @param[in] IRQn See the NVIC_EnableIRQ documentation in CMSIS.
* @retval ::NRF_SUCCESS The interrupt was enabled. *
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE The interrupt is not available for the application. * @retval ::NRF_SUCCESS The interrupt was enabled.
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED The interrupt has a priority not available for the application. * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE The interrupt is not available for the application.
*/ * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED The interrupt has a priority not available for the application.
__STATIC_INLINE uint32_t sd_nvic_EnableIRQ(IRQn_Type IRQn); */
__STATIC_INLINE uint32_t sd_nvic_EnableIRQ(IRQn_Type IRQn);
/**@brief Disable External Interrupt.
* @note Corresponds to NVIC_DisableIRQ in CMSIS. /**@brief Disable External Interrupt.
* * @note Corresponds to NVIC_DisableIRQ in CMSIS.
* @pre IRQn is valid and not reserved by the stack. *
* * @pre IRQn is valid and not reserved by the stack.
* @param[in] IRQn See the NVIC_DisableIRQ documentation in CMSIS. *
* * @param[in] IRQn See the NVIC_DisableIRQ documentation in CMSIS.
* @retval ::NRF_SUCCESS The interrupt was disabled. *
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE The interrupt is not available for the application. * @retval ::NRF_SUCCESS The interrupt was disabled.
*/ * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE The interrupt is not available for the application.
__STATIC_INLINE uint32_t sd_nvic_DisableIRQ(IRQn_Type IRQn); */
__STATIC_INLINE uint32_t sd_nvic_DisableIRQ(IRQn_Type IRQn);
/**@brief Get Pending Interrupt.
* @note Corresponds to NVIC_GetPendingIRQ in CMSIS. /**@brief Get Pending Interrupt.
* * @note Corresponds to NVIC_GetPendingIRQ in CMSIS.
* @pre IRQn is valid and not reserved by the stack. *
* * @pre IRQn is valid and not reserved by the stack.
* @param[in] IRQn See the NVIC_GetPendingIRQ documentation in CMSIS. *
* @param[out] p_pending_irq Return value from NVIC_GetPendingIRQ. * @param[in] IRQn See the NVIC_GetPendingIRQ documentation in CMSIS.
* * @param[out] p_pending_irq Return value from NVIC_GetPendingIRQ.
* @retval ::NRF_SUCCESS The interrupt is available for the application. *
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE IRQn is not available for the application. * @retval ::NRF_SUCCESS The interrupt is available for the application.
*/ * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE IRQn is not available for the application.
__STATIC_INLINE uint32_t sd_nvic_GetPendingIRQ(IRQn_Type IRQn, uint32_t * p_pending_irq); */
__STATIC_INLINE uint32_t sd_nvic_GetPendingIRQ(IRQn_Type IRQn, uint32_t * p_pending_irq);
/**@brief Set Pending Interrupt.
* @note Corresponds to NVIC_SetPendingIRQ in CMSIS. /**@brief Set Pending Interrupt.
* * @note Corresponds to NVIC_SetPendingIRQ in CMSIS.
* @pre IRQn is valid and not reserved by the stack. *
* * @pre IRQn is valid and not reserved by the stack.
* @param[in] IRQn See the NVIC_SetPendingIRQ documentation in CMSIS. *
* * @param[in] IRQn See the NVIC_SetPendingIRQ documentation in CMSIS.
* @retval ::NRF_SUCCESS The interrupt is set pending. *
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE IRQn is not available for the application. * @retval ::NRF_SUCCESS The interrupt is set pending.
*/ * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE IRQn is not available for the application.
__STATIC_INLINE uint32_t sd_nvic_SetPendingIRQ(IRQn_Type IRQn); */
__STATIC_INLINE uint32_t sd_nvic_SetPendingIRQ(IRQn_Type IRQn);
/**@brief Clear Pending Interrupt.
* @note Corresponds to NVIC_ClearPendingIRQ in CMSIS. /**@brief Clear Pending Interrupt.
* * @note Corresponds to NVIC_ClearPendingIRQ in CMSIS.
* @pre IRQn is valid and not reserved by the stack. *
* * @pre IRQn is valid and not reserved by the stack.
* @param[in] IRQn See the NVIC_ClearPendingIRQ documentation in CMSIS. *
* * @param[in] IRQn See the NVIC_ClearPendingIRQ documentation in CMSIS.
* @retval ::NRF_SUCCESS The interrupt pending flag is cleared. *
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE IRQn is not available for the application. * @retval ::NRF_SUCCESS The interrupt pending flag is cleared.
*/ * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE IRQn is not available for the application.
__STATIC_INLINE uint32_t sd_nvic_ClearPendingIRQ(IRQn_Type IRQn); */
__STATIC_INLINE uint32_t sd_nvic_ClearPendingIRQ(IRQn_Type IRQn);
/**@brief Set Interrupt Priority.
* @note Corresponds to NVIC_SetPriority in CMSIS. /**@brief Set Interrupt Priority.
* * @note Corresponds to NVIC_SetPriority in CMSIS.
* @pre IRQn is valid and not reserved by the stack. *
* @pre Priority is valid and not reserved by the stack. * @pre IRQn is valid and not reserved by the stack.
* * @pre Priority is valid and not reserved by the stack.
* @param[in] IRQn See the NVIC_SetPriority documentation in CMSIS. *
* @param[in] priority A valid IRQ priority for use by the application. * @param[in] IRQn See the NVIC_SetPriority documentation in CMSIS.
* * @param[in] priority A valid IRQ priority for use by the application.
* @retval ::NRF_SUCCESS The interrupt and priority level is available for the application. *
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE IRQn is not available for the application. * @retval ::NRF_SUCCESS The interrupt and priority level is available for the application.
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED The interrupt priority is not available for the application. * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE IRQn is not available for the application.
*/ * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED The interrupt priority is not available for the application.
__STATIC_INLINE uint32_t sd_nvic_SetPriority(IRQn_Type IRQn, uint32_t priority); */
__STATIC_INLINE uint32_t sd_nvic_SetPriority(IRQn_Type IRQn, uint32_t priority);
/**@brief Get Interrupt Priority.
* @note Corresponds to NVIC_GetPriority in CMSIS. /**@brief Get Interrupt Priority.
* * @note Corresponds to NVIC_GetPriority in CMSIS.
* @pre IRQn is valid and not reserved by the stack. *
* * @pre IRQn is valid and not reserved by the stack.
* @param[in] IRQn See the NVIC_GetPriority documentation in CMSIS. *
* @param[out] p_priority Return value from NVIC_GetPriority. * @param[in] IRQn See the NVIC_GetPriority documentation in CMSIS.
* * @param[out] p_priority Return value from NVIC_GetPriority.
* @retval ::NRF_SUCCESS The interrupt priority is returned in p_priority. *
* @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE - IRQn is not available for the application. * @retval ::NRF_SUCCESS The interrupt priority is returned in p_priority.
*/ * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE - IRQn is not available for the application.
__STATIC_INLINE uint32_t sd_nvic_GetPriority(IRQn_Type IRQn, uint32_t * p_priority); */
__STATIC_INLINE uint32_t sd_nvic_GetPriority(IRQn_Type IRQn, uint32_t * p_priority);
/**@brief System Reset.
* @note Corresponds to NVIC_SystemReset in CMSIS. /**@brief System Reset.
* * @note Corresponds to NVIC_SystemReset in CMSIS.
* @retval ::NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN *
*/ * @retval ::NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN
__STATIC_INLINE uint32_t sd_nvic_SystemReset(void); */
__STATIC_INLINE uint32_t sd_nvic_SystemReset(void);
/**@brief Enter critical region.
* /**@brief Enter critical region.
* @post Application interrupts will be disabled. *
* @note sd_nvic_critical_region_enter() and ::sd_nvic_critical_region_exit() must be called in matching pairs inside each * @post Application interrupts will be disabled.
* execution context * @note sd_nvic_critical_region_enter() and ::sd_nvic_critical_region_exit() must be called in matching pairs inside each
* @sa sd_nvic_critical_region_exit * execution context
* * @sa sd_nvic_critical_region_exit
* @param[out] p_is_nested_critical_region If 1, the application is now in a nested critical region. *
* * @param[out] p_is_nested_critical_region If 1, the application is now in a nested critical region.
* @retval ::NRF_SUCCESS *
*/ * @retval ::NRF_SUCCESS
__STATIC_INLINE uint32_t sd_nvic_critical_region_enter(uint8_t * p_is_nested_critical_region); */
__STATIC_INLINE uint32_t sd_nvic_critical_region_enter(uint8_t * p_is_nested_critical_region);
/**@brief Exit critical region.
* /**@brief Exit critical region.
* @pre Application has entered a critical region using ::sd_nvic_critical_region_enter. *
* @post If not in a nested critical region, the application interrupts will restored to the state before ::sd_nvic_critical_region_enter was called. * @pre Application has entered a critical region using ::sd_nvic_critical_region_enter.
* * @post If not in a nested critical region, the application interrupts will restored to the state before ::sd_nvic_critical_region_enter was called.
* @param[in] is_nested_critical_region If this is set to 1, the critical region won't be exited. @sa sd_nvic_critical_region_enter. *
* * @param[in] is_nested_critical_region If this is set to 1, the critical region won't be exited. @sa sd_nvic_critical_region_enter.
* @retval ::NRF_SUCCESS *
*/ * @retval ::NRF_SUCCESS
__STATIC_INLINE uint32_t sd_nvic_critical_region_exit(uint8_t is_nested_critical_region); */
__STATIC_INLINE uint32_t sd_nvic_critical_region_exit(uint8_t is_nested_critical_region);
/**@} */
/**@} */
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
__STATIC_INLINE int __sd_nvic_irq_disable(void)
{ __STATIC_INLINE int __sd_nvic_irq_disable(void)
int pm = __get_PRIMASK(); {
__disable_irq(); int pm = __get_PRIMASK();
return pm; __disable_irq();
} return pm;
}
__STATIC_INLINE void __sd_nvic_irq_enable(void)
{ __STATIC_INLINE void __sd_nvic_irq_enable(void)
__enable_irq(); {
} __enable_irq();
}
__STATIC_INLINE uint32_t __sd_nvic_app_accessible_irq(IRQn_Type IRQn)
{ __STATIC_INLINE uint32_t __sd_nvic_app_accessible_irq(IRQn_Type IRQn)
if (IRQn < 32) {
{ if (IRQn < 32)
return ((1UL<<IRQn) & __NRF_NVIC_APP_IRQS_0) != 0; {
} return ((1UL<<IRQn) & __NRF_NVIC_APP_IRQS_0) != 0;
else if (IRQn < 64) }
{ else if (IRQn < 64)
return ((1UL<<(IRQn-32)) & __NRF_NVIC_APP_IRQS_1) != 0; {
} return ((1UL<<(IRQn-32)) & __NRF_NVIC_APP_IRQS_1) != 0;
else }
{ else
return 1; {
} return 1;
} }
}
__STATIC_INLINE uint32_t __sd_nvic_is_app_accessible_priority(uint32_t priority)
{ __STATIC_INLINE uint32_t __sd_nvic_is_app_accessible_priority(uint32_t priority)
if(priority >= (1 << __NVIC_PRIO_BITS)) {
{ if(priority >= (1 << __NVIC_PRIO_BITS))
return 0; {
} return 0;
if( priority == 0 }
|| priority == 1 if( priority == 0
|| priority == 4 || priority == 1
) || priority == 4
{ )
return 0; {
} return 0;
return 1; }
} return 1;
}
__STATIC_INLINE uint32_t sd_nvic_EnableIRQ(IRQn_Type IRQn)
{ __STATIC_INLINE uint32_t sd_nvic_EnableIRQ(IRQn_Type IRQn)
if (!__sd_nvic_app_accessible_irq(IRQn)) {
{ if (!__sd_nvic_app_accessible_irq(IRQn))
return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE; {
} return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE;
if (!__sd_nvic_is_app_accessible_priority(NVIC_GetPriority(IRQn))) }
{ if (!__sd_nvic_is_app_accessible_priority(NVIC_GetPriority(IRQn)))
return NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED; {
} return NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED;
}
if (nrf_nvic_state.__cr_flag)
{ if (nrf_nvic_state.__cr_flag)
nrf_nvic_state.__irq_masks[(uint32_t)((int32_t)IRQn) >> 5] |= (uint32_t)(1 << ((uint32_t)((int32_t)IRQn) & (uint32_t)0x1F)); {
} nrf_nvic_state.__irq_masks[(uint32_t)((int32_t)IRQn) >> 5] |= (uint32_t)(1 << ((uint32_t)((int32_t)IRQn) & (uint32_t)0x1F));
else }
{ else
NVIC_EnableIRQ(IRQn); {
} NVIC_EnableIRQ(IRQn);
return NRF_SUCCESS; }
} return NRF_SUCCESS;
}
__STATIC_INLINE uint32_t sd_nvic_DisableIRQ(IRQn_Type IRQn)
{ __STATIC_INLINE uint32_t sd_nvic_DisableIRQ(IRQn_Type IRQn)
if (!__sd_nvic_app_accessible_irq(IRQn)) {
{ if (!__sd_nvic_app_accessible_irq(IRQn))
return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE; {
} return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE;
}
if (nrf_nvic_state.__cr_flag)
{ if (nrf_nvic_state.__cr_flag)
nrf_nvic_state.__irq_masks[(uint32_t)((int32_t)IRQn) >> 5] &= ~(1UL << ((uint32_t)(IRQn) & 0x1F)); {
} nrf_nvic_state.__irq_masks[(uint32_t)((int32_t)IRQn) >> 5] &= ~(1UL << ((uint32_t)(IRQn) & 0x1F));
else }
{ else
NVIC_DisableIRQ(IRQn); {
} NVIC_DisableIRQ(IRQn);
}
return NRF_SUCCESS;
} return NRF_SUCCESS;
}
__STATIC_INLINE uint32_t sd_nvic_GetPendingIRQ(IRQn_Type IRQn, uint32_t * p_pending_irq)
{ __STATIC_INLINE uint32_t sd_nvic_GetPendingIRQ(IRQn_Type IRQn, uint32_t * p_pending_irq)
if (__sd_nvic_app_accessible_irq(IRQn)) {
{ if (__sd_nvic_app_accessible_irq(IRQn))
*p_pending_irq = NVIC_GetPendingIRQ(IRQn); {
return NRF_SUCCESS; *p_pending_irq = NVIC_GetPendingIRQ(IRQn);
} return NRF_SUCCESS;
else }
{ else
return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE; {
} return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE;
} }
}
__STATIC_INLINE uint32_t sd_nvic_SetPendingIRQ(IRQn_Type IRQn)
{ __STATIC_INLINE uint32_t sd_nvic_SetPendingIRQ(IRQn_Type IRQn)
if (__sd_nvic_app_accessible_irq(IRQn)) {
{ if (__sd_nvic_app_accessible_irq(IRQn))
NVIC_SetPendingIRQ(IRQn); {
return NRF_SUCCESS; NVIC_SetPendingIRQ(IRQn);
} return NRF_SUCCESS;
else }
{ else
return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE; {
} return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE;
} }
}
__STATIC_INLINE uint32_t sd_nvic_ClearPendingIRQ(IRQn_Type IRQn)
{ __STATIC_INLINE uint32_t sd_nvic_ClearPendingIRQ(IRQn_Type IRQn)
if (__sd_nvic_app_accessible_irq(IRQn)) {
{ if (__sd_nvic_app_accessible_irq(IRQn))
NVIC_ClearPendingIRQ(IRQn); {
return NRF_SUCCESS; NVIC_ClearPendingIRQ(IRQn);
} return NRF_SUCCESS;
else }
{ else
return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE; {
} return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE;
} }
}
__STATIC_INLINE uint32_t sd_nvic_SetPriority(IRQn_Type IRQn, uint32_t priority)
{ __STATIC_INLINE uint32_t sd_nvic_SetPriority(IRQn_Type IRQn, uint32_t priority)
if (!__sd_nvic_app_accessible_irq(IRQn)) {
{ if (!__sd_nvic_app_accessible_irq(IRQn))
return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE; {
} return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE;
}
if (!__sd_nvic_is_app_accessible_priority(priority))
{ if (!__sd_nvic_is_app_accessible_priority(priority))
return NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED; {
} return NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED;
}
NVIC_SetPriority(IRQn, (uint32_t)priority);
return NRF_SUCCESS; NVIC_SetPriority(IRQn, (uint32_t)priority);
} return NRF_SUCCESS;
}
__STATIC_INLINE uint32_t sd_nvic_GetPriority(IRQn_Type IRQn, uint32_t * p_priority)
{ __STATIC_INLINE uint32_t sd_nvic_GetPriority(IRQn_Type IRQn, uint32_t * p_priority)
if (__sd_nvic_app_accessible_irq(IRQn)) {
{ if (__sd_nvic_app_accessible_irq(IRQn))
*p_priority = (NVIC_GetPriority(IRQn) & 0xFF); {
return NRF_SUCCESS; *p_priority = (NVIC_GetPriority(IRQn) & 0xFF);
} return NRF_SUCCESS;
else }
{ else
return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE; {
} return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE;
} }
}
__STATIC_INLINE uint32_t sd_nvic_SystemReset(void)
{ __STATIC_INLINE uint32_t sd_nvic_SystemReset(void)
NVIC_SystemReset(); {
return NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN; NVIC_SystemReset();
} return NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN;
}
__STATIC_INLINE uint32_t sd_nvic_critical_region_enter(uint8_t * p_is_nested_critical_region)
{ __STATIC_INLINE uint32_t sd_nvic_critical_region_enter(uint8_t * p_is_nested_critical_region)
int was_masked = __sd_nvic_irq_disable(); {
if (!nrf_nvic_state.__cr_flag) int was_masked = __sd_nvic_irq_disable();
{ if (!nrf_nvic_state.__cr_flag)
nrf_nvic_state.__cr_flag = 1; {
nrf_nvic_state.__irq_masks[0] = ( NVIC->ICER[0] & __NRF_NVIC_APP_IRQS_0 ); nrf_nvic_state.__cr_flag = 1;
NVIC->ICER[0] = __NRF_NVIC_APP_IRQS_0; nrf_nvic_state.__irq_masks[0] = ( NVIC->ICER[0] & __NRF_NVIC_APP_IRQS_0 );
nrf_nvic_state.__irq_masks[1] = ( NVIC->ICER[1] & __NRF_NVIC_APP_IRQS_1 ); NVIC->ICER[0] = __NRF_NVIC_APP_IRQS_0;
NVIC->ICER[1] = __NRF_NVIC_APP_IRQS_1; nrf_nvic_state.__irq_masks[1] = ( NVIC->ICER[1] & __NRF_NVIC_APP_IRQS_1 );
*p_is_nested_critical_region = 0; NVIC->ICER[1] = __NRF_NVIC_APP_IRQS_1;
} *p_is_nested_critical_region = 0;
else }
{ else
*p_is_nested_critical_region = 1; {
} *p_is_nested_critical_region = 1;
if (!was_masked) }
{ if (!was_masked)
__sd_nvic_irq_enable(); {
} __sd_nvic_irq_enable();
return NRF_SUCCESS; }
} return NRF_SUCCESS;
}
__STATIC_INLINE uint32_t sd_nvic_critical_region_exit(uint8_t is_nested_critical_region)
{ __STATIC_INLINE uint32_t sd_nvic_critical_region_exit(uint8_t is_nested_critical_region)
if (nrf_nvic_state.__cr_flag && (is_nested_critical_region == 0)) {
{ if (nrf_nvic_state.__cr_flag && (is_nested_critical_region == 0))
int was_masked = __sd_nvic_irq_disable(); {
NVIC->ISER[0] = nrf_nvic_state.__irq_masks[0]; int was_masked = __sd_nvic_irq_disable();
NVIC->ISER[1] = nrf_nvic_state.__irq_masks[1]; NVIC->ISER[0] = nrf_nvic_state.__irq_masks[0];
nrf_nvic_state.__cr_flag = 0; NVIC->ISER[1] = nrf_nvic_state.__irq_masks[1];
if (!was_masked) nrf_nvic_state.__cr_flag = 0;
{ if (!was_masked)
__sd_nvic_irq_enable(); {
} __sd_nvic_irq_enable();
} }
}
return NRF_SUCCESS;
} return NRF_SUCCESS;
}
#endif /* SUPPRESS_INLINE_IMPLEMENTATION */
#endif /* SUPPRESS_INLINE_IMPLEMENTATION */
#ifdef __cplusplus
} #ifdef __cplusplus
#endif }
#endif
#endif // NRF_NVIC_H__
#endif // NRF_NVIC_H__
/**@} */
/**@} */

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

@ -1,355 +1,358 @@
/* /*
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer. * list of conditions and the following disclaimer.
* *
* 2. Redistributions in binary form, except as embedded into a Nordic * 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for * Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of * such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other * conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. * materials provided with the distribution.
* *
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its * 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 * contributors may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* *
* 4. This software, with or without modification, must only be used with a * 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit. * Nordic Semiconductor ASA integrated circuit.
* *
* 5. Any software provided in binary form under this license must not be reverse * 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled. * engineered, decompiled, modified and/or disassembled.
* *
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * 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. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/** /**
@defgroup nrf_sdm_api SoftDevice Manager API @defgroup nrf_sdm_api SoftDevice Manager API
@{ @{
@brief APIs for SoftDevice management. @brief APIs for SoftDevice management.
*/ */
#ifndef NRF_SDM_H__ #ifndef NRF_SDM_H__
#define NRF_SDM_H__ #define NRF_SDM_H__
#include "nrf_svc.h" #include <stdint.h>
#include "nrf.h" #include "nrf.h"
#include "nrf_soc.h" #include "nrf_svc.h"
#include "nrf_error_sdm.h" #include "nrf_error.h"
#include "nrf_error_sdm.h"
#ifdef __cplusplus #include "nrf_soc.h"
extern "C" {
#endif #ifdef __cplusplus
extern "C" {
/** @addtogroup NRF_SDM_DEFINES Defines #endif
* @{ */
#ifdef NRFSOC_DOXYGEN /** @addtogroup NRF_SDM_DEFINES Defines
/// Declared in nrf_mbr.h * @{ */
#define MBR_SIZE 0 #ifdef NRFSOC_DOXYGEN
#warning test /// Declared in nrf_mbr.h
#endif #define MBR_SIZE 0
#warning test
/** @brief The major version for the SoftDevice binary distributed with this header file. */ #endif
#define SD_MAJOR_VERSION (0)
/** @brief The major version for the SoftDevice binary distributed with this header file. */
/** @brief The minor version for the SoftDevice binary distributed with this header file. */ #define SD_MAJOR_VERSION (6)
#define SD_MINOR_VERSION (0)
/** @brief The minor version for the SoftDevice binary distributed with this header file. */
/** @brief The bugfix version for the SoftDevice binary distributed with this header file. */ #define SD_MINOR_VERSION (0)
#define SD_BUGFIX_VERSION (0)
/** @brief The bugfix version for the SoftDevice binary distributed with this header file. */
/** @brief The full version number for the SoftDevice binary this header file was distributed #define SD_BUGFIX_VERSION (0)
* with, as a decimal number in the form Mmmmbbb, where:
* - M is major version (one or more digits) /** @brief The full version number for the SoftDevice binary this header file was distributed
* - mmm is minor version (three digits) * with, as a decimal number in the form Mmmmbbb, where:
* - bbb is bugfix version (three digits). */ * - M is major version (one or more digits)
#define SD_VERSION (SD_MAJOR_VERSION * 1000000 + SD_MINOR_VERSION * 1000 + SD_BUGFIX_VERSION) * - mmm is minor version (three digits)
* - bbb is bugfix version (three digits). */
/** @brief SoftDevice Manager SVC Base number. */ #define SD_VERSION (SD_MAJOR_VERSION * 1000000 + SD_MINOR_VERSION * 1000 + SD_BUGFIX_VERSION)
#define SDM_SVC_BASE 0x10
/** @brief SoftDevice Manager SVC Base number. */
/** @brief SoftDevice unique string size in bytes. */ #define SDM_SVC_BASE 0x10
#define SD_UNIQUE_STR_SIZE 20
/** @brief SoftDevice unique string size in bytes. */
/** @brief Invalid info field. Returned when an info field does not exist. */ #define SD_UNIQUE_STR_SIZE 20
#define SDM_INFO_FIELD_INVALID (0)
/** @brief Invalid info field. Returned when an info field does not exist. */
/** @brief Defines the SoftDevice Information Structure location (address) as an offset from #define SDM_INFO_FIELD_INVALID (0)
the start of the SoftDevice (without MBR)*/
#define SOFTDEVICE_INFO_STRUCT_OFFSET (0x2000) /** @brief Defines the SoftDevice Information Structure location (address) as an offset from
the start of the SoftDevice (without MBR)*/
/** @brief Defines the absolute SoftDevice Information Structure location (address) when the #define SOFTDEVICE_INFO_STRUCT_OFFSET (0x2000)
* SoftDevice is installed just above the MBR (the usual case). */
#define SOFTDEVICE_INFO_STRUCT_ADDRESS (SOFTDEVICE_INFO_STRUCT_OFFSET + MBR_SIZE) /** @brief Defines the absolute SoftDevice Information Structure location (address) when the
* SoftDevice is installed just above the MBR (the usual case). */
/** @brief Defines the offset for the SoftDevice Information Structure size value relative to the #define SOFTDEVICE_INFO_STRUCT_ADDRESS (SOFTDEVICE_INFO_STRUCT_OFFSET + MBR_SIZE)
* SoftDevice base address. The size value is of type uint8_t. */
#define SD_INFO_STRUCT_SIZE_OFFSET (SOFTDEVICE_INFO_STRUCT_OFFSET) /** @brief Defines the offset for the SoftDevice Information Structure size value relative to the
* SoftDevice base address. The size value is of type uint8_t. */
/** @brief Defines the offset for the SoftDevice size value relative to the SoftDevice base address. #define SD_INFO_STRUCT_SIZE_OFFSET (SOFTDEVICE_INFO_STRUCT_OFFSET)
* The size value is of type uint32_t. */
#define SD_SIZE_OFFSET (SOFTDEVICE_INFO_STRUCT_OFFSET + 0x08) /** @brief Defines the offset for the SoftDevice size value relative to the SoftDevice base address.
* The size value is of type uint32_t. */
/** @brief Defines the offset for FWID value relative to the SoftDevice base address. The FWID value #define SD_SIZE_OFFSET (SOFTDEVICE_INFO_STRUCT_OFFSET + 0x08)
* is of type uint16_t. */
#define SD_FWID_OFFSET (SOFTDEVICE_INFO_STRUCT_OFFSET + 0x0C) /** @brief Defines the offset for FWID value relative to the SoftDevice base address. The FWID value
* is of type uint16_t. */
/** @brief Defines the offset for the SoftDevice ID relative to the SoftDevice base address. The ID #define SD_FWID_OFFSET (SOFTDEVICE_INFO_STRUCT_OFFSET + 0x0C)
* is of type uint32_t. */
#define SD_ID_OFFSET (SOFTDEVICE_INFO_STRUCT_OFFSET + 0x10) /** @brief Defines the offset for the SoftDevice ID relative to the SoftDevice base address. The ID
* is of type uint32_t. */
/** @brief Defines the offset for the SoftDevice version relative to the SoftDevice base address in #define SD_ID_OFFSET (SOFTDEVICE_INFO_STRUCT_OFFSET + 0x10)
* the same format as @ref SD_VERSION, stored as an uint32_t. */
#define SD_VERSION_OFFSET (SOFTDEVICE_INFO_STRUCT_OFFSET + 0x14) /** @brief Defines the offset for the SoftDevice version relative to the SoftDevice base address in
* the same format as @ref SD_VERSION, stored as an uint32_t. */
/** @brief Defines the offset for the SoftDevice unique string relative to the SoftDevice base address. #define SD_VERSION_OFFSET (SOFTDEVICE_INFO_STRUCT_OFFSET + 0x14)
* The SD_UNIQUE_STR is stored as an array of uint8_t. The size of array is @ref SD_UNIQUE_STR_SIZE.
*/ /** @brief Defines the offset for the SoftDevice unique string relative to the SoftDevice base address.
#define SD_UNIQUE_STR_OFFSET (SOFTDEVICE_INFO_STRUCT_OFFSET + 0x18) * The SD_UNIQUE_STR is stored as an array of uint8_t. The size of array is @ref SD_UNIQUE_STR_SIZE.
*/
/** @brief Defines a macro for retrieving the actual SoftDevice Information Structure size value #define SD_UNIQUE_STR_OFFSET (SOFTDEVICE_INFO_STRUCT_OFFSET + 0x18)
* from a given base address. Use @ref MBR_SIZE as the argument when the SoftDevice is
* installed just above the MBR (the usual case). */ /** @brief Defines a macro for retrieving the actual SoftDevice Information Structure size value
#define SD_INFO_STRUCT_SIZE_GET(baseaddr) (*((uint8_t *) ((baseaddr) + SD_INFO_STRUCT_SIZE_OFFSET))) * from a given base address. Use @ref MBR_SIZE as the argument when the SoftDevice is
* installed just above the MBR (the usual case). */
/** @brief Defines a macro for retrieving the actual SoftDevice size value from a given base #define SD_INFO_STRUCT_SIZE_GET(baseaddr) (*((uint8_t *) ((baseaddr) + SD_INFO_STRUCT_SIZE_OFFSET)))
* address. Use @ref MBR_SIZE as the argument when the SoftDevice is installed just above
* the MBR (the usual case). */ /** @brief Defines a macro for retrieving the actual SoftDevice size value from a given base
#define SD_SIZE_GET(baseaddr) (*((uint32_t *) ((baseaddr) + SD_SIZE_OFFSET))) * address. Use @ref MBR_SIZE as the argument when the SoftDevice is installed just above
* the MBR (the usual case). */
/** @brief Defines a macro for retrieving the actual FWID value from a given base address. Use #define SD_SIZE_GET(baseaddr) (*((uint32_t *) ((baseaddr) + SD_SIZE_OFFSET)))
* @ref MBR_SIZE as the argument when the SoftDevice is installed just above the MBR (the usual
* case). */ /** @brief Defines a macro for retrieving the actual FWID value from a given base address. Use
#define SD_FWID_GET(baseaddr) (*((uint16_t *) ((baseaddr) + SD_FWID_OFFSET))) * @ref MBR_SIZE as the argument when the SoftDevice is installed just above the MBR (the usual
* case). */
/** @brief Defines a macro for retrieving the actual SoftDevice ID from a given base address. Use #define SD_FWID_GET(baseaddr) (*((uint16_t *) ((baseaddr) + SD_FWID_OFFSET)))
* @ref MBR_SIZE as the argument when the SoftDevice is installed just above the MBR (the
* usual case). */ /** @brief Defines a macro for retrieving the actual SoftDevice ID from a given base address. Use
#define SD_ID_GET(baseaddr) ((SD_INFO_STRUCT_SIZE_GET(baseaddr) > (SD_ID_OFFSET - SOFTDEVICE_INFO_STRUCT_OFFSET)) \ * @ref MBR_SIZE as the argument when the SoftDevice is installed just above the MBR (the
? (*((uint32_t *) ((baseaddr) + SD_ID_OFFSET))) : SDM_INFO_FIELD_INVALID) * usual case). */
#define SD_ID_GET(baseaddr) ((SD_INFO_STRUCT_SIZE_GET(baseaddr) > (SD_ID_OFFSET - SOFTDEVICE_INFO_STRUCT_OFFSET)) \
/** @brief Defines a macro for retrieving the actual SoftDevice version from a given base address. ? (*((uint32_t *) ((baseaddr) + SD_ID_OFFSET))) : SDM_INFO_FIELD_INVALID)
* Use @ref MBR_SIZE as the argument when the SoftDevice is installed just above the MBR
* (the usual case). */ /** @brief Defines a macro for retrieving the actual SoftDevice version from a given base address.
#define SD_VERSION_GET(baseaddr) ((SD_INFO_STRUCT_SIZE_GET(baseaddr) > (SD_VERSION_OFFSET - SOFTDEVICE_INFO_STRUCT_OFFSET)) \ * Use @ref MBR_SIZE as the argument when the SoftDevice is installed just above the MBR
? (*((uint32_t *) ((baseaddr) + SD_VERSION_OFFSET))) : SDM_INFO_FIELD_INVALID) * (the usual case). */
#define SD_VERSION_GET(baseaddr) ((SD_INFO_STRUCT_SIZE_GET(baseaddr) > (SD_VERSION_OFFSET - SOFTDEVICE_INFO_STRUCT_OFFSET)) \
/** @brief Defines a macro for retrieving the address of SoftDevice unique str based on a given base address. ? (*((uint32_t *) ((baseaddr) + SD_VERSION_OFFSET))) : SDM_INFO_FIELD_INVALID)
* Use @ref MBR_SIZE as the argument when the SoftDevice is installed just above the MBR
* (the usual case). */ /** @brief Defines a macro for retrieving the address of SoftDevice unique str based on a given base address.
#define SD_UNIQUE_STR_ADDR_GET(baseaddr) ((SD_INFO_STRUCT_SIZE_GET(baseaddr) > (SD_UNIQUE_STR_OFFSET - SOFTDEVICE_INFO_STRUCT_OFFSET)) \ * Use @ref MBR_SIZE as the argument when the SoftDevice is installed just above the MBR
? (((uint8_t *) ((baseaddr) + SD_UNIQUE_STR_OFFSET))) : SDM_INFO_FIELD_INVALID) * (the usual case). */
#define SD_UNIQUE_STR_ADDR_GET(baseaddr) ((SD_INFO_STRUCT_SIZE_GET(baseaddr) > (SD_UNIQUE_STR_OFFSET - SOFTDEVICE_INFO_STRUCT_OFFSET)) \
/**@defgroup NRF_FAULT_ID_RANGES Fault ID ranges ? (((uint8_t *) ((baseaddr) + SD_UNIQUE_STR_OFFSET))) : SDM_INFO_FIELD_INVALID)
* @{ */
#define NRF_FAULT_ID_SD_RANGE_START 0x00000000 /**< SoftDevice ID range start. */ /**@defgroup NRF_FAULT_ID_RANGES Fault ID ranges
#define NRF_FAULT_ID_APP_RANGE_START 0x00001000 /**< Application ID range start. */ * @{ */
/**@} */ #define NRF_FAULT_ID_SD_RANGE_START 0x00000000 /**< SoftDevice ID range start. */
#define NRF_FAULT_ID_APP_RANGE_START 0x00001000 /**< Application ID range start. */
/**@defgroup NRF_FAULT_IDS Fault ID types /**@} */
* @{ */
#define NRF_FAULT_ID_SD_ASSERT (NRF_FAULT_ID_SD_RANGE_START + 1) /**< SoftDevice assertion. The info parameter is reserved for future used. */ /**@defgroup NRF_FAULT_IDS Fault ID types
#define NRF_FAULT_ID_APP_MEMACC (NRF_FAULT_ID_APP_RANGE_START + 1) /**< Application invalid memory access. The info parameter will contain 0x00000000, * @{ */
in case of SoftDevice RAM access violation. In case of SoftDevice peripheral #define NRF_FAULT_ID_SD_ASSERT (NRF_FAULT_ID_SD_RANGE_START + 1) /**< SoftDevice assertion. The info parameter is reserved for future used. */
register violation the info parameter will contain the sub-region number of #define NRF_FAULT_ID_APP_MEMACC (NRF_FAULT_ID_APP_RANGE_START + 1) /**< Application invalid memory access. The info parameter will contain 0x00000000,
PREGION[0], on whose address range the disallowed write access caused the in case of SoftDevice RAM access violation. In case of SoftDevice peripheral
memory access fault. */ register violation the info parameter will contain the sub-region number of
/**@} */ PREGION[0], on whose address range the disallowed write access caused the
memory access fault. */
/** @} */ /**@} */
/** @addtogroup NRF_SDM_ENUMS Enumerations /** @} */
* @{ */
/** @addtogroup NRF_SDM_ENUMS Enumerations
/**@brief nRF SoftDevice Manager API SVC numbers. */ * @{ */
enum NRF_SD_SVCS
{ /**@brief nRF SoftDevice Manager API SVC numbers. */
SD_SOFTDEVICE_ENABLE = SDM_SVC_BASE, /**< ::sd_softdevice_enable */ enum NRF_SD_SVCS
SD_SOFTDEVICE_DISABLE, /**< ::sd_softdevice_disable */ {
SD_SOFTDEVICE_IS_ENABLED, /**< ::sd_softdevice_is_enabled */ SD_SOFTDEVICE_ENABLE = SDM_SVC_BASE, /**< ::sd_softdevice_enable */
SD_SOFTDEVICE_VECTOR_TABLE_BASE_SET, /**< ::sd_softdevice_vector_table_base_set */ SD_SOFTDEVICE_DISABLE, /**< ::sd_softdevice_disable */
SVC_SDM_LAST /**< Placeholder for last SDM SVC */ SD_SOFTDEVICE_IS_ENABLED, /**< ::sd_softdevice_is_enabled */
}; SD_SOFTDEVICE_VECTOR_TABLE_BASE_SET, /**< ::sd_softdevice_vector_table_base_set */
SVC_SDM_LAST /**< Placeholder for last SDM SVC */
/** @} */ };
/** @addtogroup NRF_SDM_DEFINES Defines /** @} */
* @{ */
/** @addtogroup NRF_SDM_DEFINES Defines
/**@defgroup NRF_CLOCK_LF_ACCURACY Clock accuracy * @{ */
* @{ */
/**@defgroup NRF_CLOCK_LF_ACCURACY Clock accuracy
#define NRF_CLOCK_LF_ACCURACY_250_PPM (0) /**< Default: 250 ppm */ * @{ */
#define NRF_CLOCK_LF_ACCURACY_500_PPM (1) /**< 500 ppm */
#define NRF_CLOCK_LF_ACCURACY_150_PPM (2) /**< 150 ppm */ #define NRF_CLOCK_LF_ACCURACY_250_PPM (0) /**< Default: 250 ppm */
#define NRF_CLOCK_LF_ACCURACY_100_PPM (3) /**< 100 ppm */ #define NRF_CLOCK_LF_ACCURACY_500_PPM (1) /**< 500 ppm */
#define NRF_CLOCK_LF_ACCURACY_75_PPM (4) /**< 75 ppm */ #define NRF_CLOCK_LF_ACCURACY_150_PPM (2) /**< 150 ppm */
#define NRF_CLOCK_LF_ACCURACY_50_PPM (5) /**< 50 ppm */ #define NRF_CLOCK_LF_ACCURACY_100_PPM (3) /**< 100 ppm */
#define NRF_CLOCK_LF_ACCURACY_30_PPM (6) /**< 30 ppm */ #define NRF_CLOCK_LF_ACCURACY_75_PPM (4) /**< 75 ppm */
#define NRF_CLOCK_LF_ACCURACY_20_PPM (7) /**< 20 ppm */ #define NRF_CLOCK_LF_ACCURACY_50_PPM (5) /**< 50 ppm */
#define NRF_CLOCK_LF_ACCURACY_10_PPM (8) /**< 10 ppm */ #define NRF_CLOCK_LF_ACCURACY_30_PPM (6) /**< 30 ppm */
#define NRF_CLOCK_LF_ACCURACY_5_PPM (9) /**< 5 ppm */ #define NRF_CLOCK_LF_ACCURACY_20_PPM (7) /**< 20 ppm */
#define NRF_CLOCK_LF_ACCURACY_2_PPM (10) /**< 2 ppm */ #define NRF_CLOCK_LF_ACCURACY_10_PPM (8) /**< 10 ppm */
#define NRF_CLOCK_LF_ACCURACY_1_PPM (11) /**< 1 ppm */ #define NRF_CLOCK_LF_ACCURACY_5_PPM (9) /**< 5 ppm */
#define NRF_CLOCK_LF_ACCURACY_2_PPM (10) /**< 2 ppm */
/** @} */ #define NRF_CLOCK_LF_ACCURACY_1_PPM (11) /**< 1 ppm */
/**@defgroup NRF_CLOCK_LF_SRC Possible LFCLK oscillator sources /** @} */
* @{ */
/**@defgroup NRF_CLOCK_LF_SRC Possible LFCLK oscillator sources
#define NRF_CLOCK_LF_SRC_RC (0) /**< LFCLK RC oscillator. */ * @{ */
#define NRF_CLOCK_LF_SRC_XTAL (1) /**< LFCLK crystal oscillator. */
#define NRF_CLOCK_LF_SRC_SYNTH (2) /**< LFCLK Synthesized from HFCLK. */ #define NRF_CLOCK_LF_SRC_RC (0) /**< LFCLK RC oscillator. */
#define NRF_CLOCK_LF_SRC_XTAL (1) /**< LFCLK crystal oscillator. */
/** @} */ #define NRF_CLOCK_LF_SRC_SYNTH (2) /**< LFCLK Synthesized from HFCLK. */
/** @} */ /** @} */
/** @addtogroup NRF_SDM_TYPES Types /** @} */
* @{ */
/** @addtogroup NRF_SDM_TYPES Types
/**@brief Type representing LFCLK oscillator source. */ * @{ */
typedef struct
{ /**@brief Type representing LFCLK oscillator source. */
uint8_t source; /**< LF oscillator clock source, see @ref NRF_CLOCK_LF_SRC. */ typedef struct
uint8_t rc_ctiv; /**< Only for ::NRF_CLOCK_LF_SRC_RC: Calibration timer interval in 1/4 second {
units (nRF52: 1-32). uint8_t source; /**< LF oscillator clock source, see @ref NRF_CLOCK_LF_SRC. */
@note To avoid excessive clock drift, 0.5 degrees Celsius is the uint8_t rc_ctiv; /**< Only for ::NRF_CLOCK_LF_SRC_RC: Calibration timer interval in 1/4 second
maximum temperature change allowed in one calibration timer units (nRF52: 1-32).
interval. The interval should be selected to ensure this. @note To avoid excessive clock drift, 0.5 degrees Celsius is the
maximum temperature change allowed in one calibration timer
@note Must be 0 if source is not ::NRF_CLOCK_LF_SRC_RC. */ interval. The interval should be selected to ensure this.
uint8_t rc_temp_ctiv; /**< Only for ::NRF_CLOCK_LF_SRC_RC: How often (in number of calibration
intervals) the RC oscillator shall be calibrated if the temperature @note Must be 0 if source is not ::NRF_CLOCK_LF_SRC_RC. */
hasn't changed. uint8_t rc_temp_ctiv; /**< Only for ::NRF_CLOCK_LF_SRC_RC: How often (in number of calibration
0: Always calibrate even if the temperature hasn't changed. intervals) the RC oscillator shall be calibrated if the temperature
1: Only calibrate if the temperature has changed (legacy - nRF51 only). hasn't changed.
2-33: Check the temperature and only calibrate if it has changed, 0: Always calibrate even if the temperature hasn't changed.
however calibration will take place every rc_temp_ctiv 1: Only calibrate if the temperature has changed (legacy - nRF51 only).
intervals in any case. 2-33: Check the temperature and only calibrate if it has changed,
however calibration will take place every rc_temp_ctiv
@note Must be 0 if source is not ::NRF_CLOCK_LF_SRC_RC. intervals in any case.
@note For nRF52, the application must ensure calibration at least once @note Must be 0 if source is not ::NRF_CLOCK_LF_SRC_RC.
every 8 seconds to ensure +/-500 ppm clock stability. The
recommended configuration for ::NRF_CLOCK_LF_SRC_RC on nRF52 is @note For nRF52, the application must ensure calibration at least once
rc_ctiv=16 and rc_temp_ctiv=2. This will ensure calibration at every 8 seconds to ensure +/-500 ppm clock stability. The
least once every 8 seconds and for temperature changes of 0.5 recommended configuration for ::NRF_CLOCK_LF_SRC_RC on nRF52 is
degrees Celsius every 4 seconds. See the Product Specification rc_ctiv=16 and rc_temp_ctiv=2. This will ensure calibration at
for the nRF52 device being used for more information.*/ least once every 8 seconds and for temperature changes of 0.5
uint8_t accuracy; /**< External clock accuracy used in the LL to compute timing degrees Celsius every 4 seconds. See the Product Specification
windows, see @ref NRF_CLOCK_LF_ACCURACY.*/ for the nRF52 device being used for more information.*/
} nrf_clock_lf_cfg_t; uint8_t accuracy; /**< External clock accuracy used in the LL to compute timing
windows, see @ref NRF_CLOCK_LF_ACCURACY.*/
/**@brief Fault Handler type. } nrf_clock_lf_cfg_t;
*
* When certain unrecoverable errors occur within the application or SoftDevice the fault handler will be called back. /**@brief Fault Handler type.
* The protocol stack will be in an undefined state when this happens and the only way to recover will be to *
* perform a reset, using e.g. CMSIS NVIC_SystemReset(). * When certain unrecoverable errors occur within the application or SoftDevice the fault handler will be called back.
* If the application returns from the fault handler the SoftDevice will call NVIC_SystemReset(). * The protocol stack will be in an undefined state when this happens and the only way to recover will be to
* * perform a reset, using e.g. CMSIS NVIC_SystemReset().
* @note This callback is executed in HardFault context, thus SVC functions cannot be called from the fault callback. * If the application returns from the fault handler the SoftDevice will call NVIC_SystemReset().
* *
* @param[in] id Fault identifier. See @ref NRF_FAULT_IDS. * @note This callback is executed in HardFault context, thus SVC functions cannot be called from the fault callback.
* @param[in] pc The program counter of the instruction that triggered the fault. *
* @param[in] info Optional additional information regarding the fault. Refer to each Fault identifier for details. * @param[in] id Fault identifier. See @ref NRF_FAULT_IDS.
* * @param[in] pc The program counter of the instruction that triggered the fault.
* @note When id is set to @ref NRF_FAULT_ID_APP_MEMACC, pc will contain the address of the instruction being executed at the time when * @param[in] info Optional additional information regarding the fault. Refer to each Fault identifier for details.
* the fault is detected by the CPU. The CPU program counter may have advanced up to 2 instructions (no branching) after the one that triggered the fault. *
*/ * @note When id is set to @ref NRF_FAULT_ID_APP_MEMACC, pc will contain the address of the instruction being executed at the time when
typedef void (*nrf_fault_handler_t)(uint32_t id, uint32_t pc, uint32_t info); * the fault is detected by the CPU. The CPU program counter may have advanced up to 2 instructions (no branching) after the one that triggered the fault.
*/
/** @} */ typedef void (*nrf_fault_handler_t)(uint32_t id, uint32_t pc, uint32_t info);
/** @addtogroup NRF_SDM_FUNCTIONS Functions /** @} */
* @{ */
/** @addtogroup NRF_SDM_FUNCTIONS Functions
/**@brief Enables the SoftDevice and by extension the protocol stack. * @{ */
*
* @note Some care must be taken if a low frequency clock source is already running when calling this function: /**@brief Enables the SoftDevice and by extension the protocol stack.
* If the LF clock has a different source then the one currently running, it will be stopped. Then, the new *
* clock source will be started. * @note Some care must be taken if a low frequency clock source is already running when calling this function:
* * If the LF clock has a different source then the one currently running, it will be stopped. Then, the new
* @note This function has no effect when returning with an error. * clock source will be started.
* *
* @post If return code is ::NRF_SUCCESS * @note This function has no effect when returning with an error.
* - SoC library and protocol stack APIs are made available. *
* - A portion of RAM will be unavailable (see relevant SDS documentation). * @post If return code is ::NRF_SUCCESS
* - Some peripherals will be unavailable or available only through the SoC API (see relevant SDS documentation). * - SoC library and protocol stack APIs are made available.
* - Interrupts will not arrive from protected peripherals or interrupts. * - A portion of RAM will be unavailable (see relevant SDS documentation).
* - nrf_nvic_ functions must be used instead of CMSIS NVIC_ functions for reliable usage of the SoftDevice. * - Some peripherals will be unavailable or available only through the SoC API (see relevant SDS documentation).
* - Interrupt latency may be affected by the SoftDevice (see relevant SDS documentation). * - Interrupts will not arrive from protected peripherals or interrupts.
* - Chosen low frequency clock source will be running. * - nrf_nvic_ functions must be used instead of CMSIS NVIC_ functions for reliable usage of the SoftDevice.
* * - Interrupt latency may be affected by the SoftDevice (see relevant SDS documentation).
* @param p_clock_lf_cfg Low frequency clock source and accuracy. * - Chosen low frequency clock source will be running.
If NULL the clock will be configured as an RC source with rc_ctiv = 16 and .rc_temp_ctiv = 2 *
In the case of XTAL source, the PPM accuracy of the chosen clock source must be greater than or equal to the actual characteristics of your XTAL clock. * @param p_clock_lf_cfg Low frequency clock source and accuracy.
* @param fault_handler Callback to be invoked in case of fault, cannot be NULL. If NULL the clock will be configured as an RC source with rc_ctiv = 16 and .rc_temp_ctiv = 2
* In the case of XTAL source, the PPM accuracy of the chosen clock source must be greater than or equal to the actual characteristics of your XTAL clock.
* @retval ::NRF_SUCCESS * @param fault_handler Callback to be invoked in case of fault, cannot be NULL.
* @retval ::NRF_ERROR_INVALID_ADDR Invalid or NULL pointer supplied. *
* @retval ::NRF_ERROR_INVALID_STATE SoftDevice is already enabled, and the clock source and fault handler cannot be updated. * @retval ::NRF_SUCCESS
* @retval ::NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION SoftDevice interrupt is already enabled, or an enabled interrupt has an illegal priority level. * @retval ::NRF_ERROR_INVALID_ADDR Invalid or NULL pointer supplied.
* @retval ::NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN Unknown low frequency clock source selected. * @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.
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)); * @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.
*/
/**@brief Disables the SoftDevice and by extension the protocol stack. 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));
*
* Idempotent function to disable the SoftDevice.
* /**@brief Disables the SoftDevice and by extension the protocol stack.
* @post SoC library and protocol stack APIs are made unavailable. *
* @post All interrupts that was protected by the SoftDevice will be disabled and initialized to priority 0 (highest). * Idempotent function to disable the SoftDevice.
* @post All peripherals used by the SoftDevice will be reset to default values. *
* @post All of RAM become available. * @post SoC library and protocol stack APIs are made unavailable.
* @post All interrupts are forwarded to the application. * @post All interrupts that was protected by the SoftDevice will be disabled and initialized to priority 0 (highest).
* @post LFCLK source chosen in ::sd_softdevice_enable will be left running. * @post All peripherals used by the SoftDevice will be reset to default values.
* * @post All of RAM become available.
* @retval ::NRF_SUCCESS * @post All interrupts are forwarded to the application.
*/ * @post LFCLK source chosen in ::sd_softdevice_enable will be left running.
SVCALL(SD_SOFTDEVICE_DISABLE, uint32_t, sd_softdevice_disable(void)); *
* @retval ::NRF_SUCCESS
/**@brief Check if the SoftDevice is enabled. */
* SVCALL(SD_SOFTDEVICE_DISABLE, uint32_t, sd_softdevice_disable(void));
* @param[out] p_softdevice_enabled If the SoftDevice is enabled: 1 else 0.
* /**@brief Check if the SoftDevice is enabled.
* @retval ::NRF_SUCCESS *
*/ * @param[out] p_softdevice_enabled If the SoftDevice is enabled: 1 else 0.
SVCALL(SD_SOFTDEVICE_IS_ENABLED, uint32_t, sd_softdevice_is_enabled(uint8_t * p_softdevice_enabled)); *
* @retval ::NRF_SUCCESS
/**@brief Sets the base address of the interrupt vector table for interrupts forwarded from the SoftDevice */
* SVCALL(SD_SOFTDEVICE_IS_ENABLED, uint32_t, sd_softdevice_is_enabled(uint8_t * p_softdevice_enabled));
* This function is only intended to be called when a bootloader is enabled.
* /**@brief Sets the base address of the interrupt vector table for interrupts forwarded from the SoftDevice
* @param[in] address The base address of the interrupt vector table for forwarded interrupts. *
* This function is only intended to be called when a bootloader is enabled.
* @retval ::NRF_SUCCESS *
*/ * @param[in] address The base address of the interrupt vector table for forwarded interrupts.
SVCALL(SD_SOFTDEVICE_VECTOR_TABLE_BASE_SET, uint32_t, sd_softdevice_vector_table_base_set(uint32_t address));
* @retval ::NRF_SUCCESS
/** @} */ */
SVCALL(SD_SOFTDEVICE_VECTOR_TABLE_BASE_SET, uint32_t, sd_softdevice_vector_table_base_set(uint32_t address));
#ifdef __cplusplus
} /** @} */
#endif
#endif // NRF_SDM_H__ #ifdef __cplusplus
}
/** #endif
@} #endif // NRF_SDM_H__
*/
/**
@}
*/

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