Merge pull request #4 from ARMmbed/migrate-changes-from-ble-nrf51822

Migrate changes from ble nrf51822
This commit is contained in:
LIYOU ZHOU 2015-12-01 12:25:37 +00:00
commit 545566992e
14 changed files with 382 additions and 1184 deletions

View File

@ -42,7 +42,6 @@
"source/nordic_sdk/components/libraries/util", "source/nordic_sdk/components/libraries/util",
"source/nordic_sdk/components/softdevice/common/softdevice_handler", "source/nordic_sdk/components/softdevice/common/softdevice_handler",
"source/nordic_sdk/components/softdevice/s130/headers", "source/nordic_sdk/components/softdevice/s130/headers",
"source/nordic_sdk/components/toolchain", "source/nordic_sdk/components/toolchain"
"source/nordic_sdk/components/toolchain/gcc"
] ]
} }

View File

@ -110,8 +110,3 @@
# included from ble_conn_params.c # included from ble_conn_params.c
app_timer.h app_timer.h
# included from device_manager_peripheral.c
app_trace.h
# included from nrf51.h
core_cm0.h

View File

@ -28,316 +28,354 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
#include "ble_conn_params.h" #include "ble_conn_params.h"
#include <stdlib.h> #include <stdlib.h>
#include "nordic_common.h" #include "nordic_common.h"
#include "ble_hci.h" #include "ble_hci.h"
#include "app_timer.h" #include "ble_srv_common.h"
#include "ble_srv_common.h" #include "app_util.h"
#include "app_util.h"
#ifdef USE_APP_TIMER
#include "app_timer.h"
static ble_conn_params_init_t m_conn_params_config; /**< Configuration as specified by the application. */ #else
static ble_gap_conn_params_t m_preferred_conn_params; /**< Connection parameters preferred by the application. */ #include "mbed.h"
static uint8_t m_update_count; /**< Number of Connection Parameter Update messages that has currently been sent. */ #endif
static uint16_t m_conn_handle; /**< Current connection handle. */
static ble_gap_conn_params_t m_current_conn_params; /**< Connection parameters received in the most recent Connect event. */ static ble_conn_params_init_t m_conn_params_config; /**< Configuration as specified by the application. */
static app_timer_id_t m_conn_params_timer_id; /**< Connection parameters timer. */ static ble_gap_conn_params_t m_preferred_conn_params; /**< Connection parameters preferred by the application. */
static uint8_t m_update_count; /**< Number of Connection Parameter Update messages that has currently been sent. */
static bool m_change_param = false; static uint16_t m_conn_handle; /**< Current connection handle. */
static ble_gap_conn_params_t m_current_conn_params; /**< Connection parameters received in the most recent Connect event. */
static bool is_conn_params_ok(ble_gap_conn_params_t * p_conn_params) #ifdef USE_APP_TIMER
{ static app_timer_id_t m_conn_params_timer_id; /**< Connection parameters timer. */
// Check if interval is within the acceptable range. #else
// NOTE: Using max_conn_interval in the received event data because this contains static Ticker m_conn_params_timer;
// the client's connection interval. #endif
if (
(p_conn_params->max_conn_interval >= m_preferred_conn_params.min_conn_interval) static bool m_change_param = false;
&&
(p_conn_params->max_conn_interval <= m_preferred_conn_params.max_conn_interval) static bool is_conn_params_ok(ble_gap_conn_params_t * p_conn_params)
) {
{ // Check if interval is within the acceptable range.
return true; // NOTE: Using max_conn_interval in the received event data because this contains
} // the client's connection interval.
else if (
{ (p_conn_params->max_conn_interval >= m_preferred_conn_params.min_conn_interval)
return false; &&
} (p_conn_params->max_conn_interval <= m_preferred_conn_params.max_conn_interval)
} )
{
return true;
static void update_timeout_handler(void * p_context) }
{ else
UNUSED_PARAMETER(p_context); {
return false;
if (m_conn_handle != BLE_CONN_HANDLE_INVALID) }
{ }
// Check if we have reached the maximum number of attempts
m_update_count++;
if (m_update_count <= m_conn_params_config.max_conn_params_update_count) #ifdef USE_APP_TIMER
{ static void update_timeout_handler(void * p_context)
uint32_t err_code; {
UNUSED_PARAMETER(p_context);
// Parameters are not ok, send connection parameters update request.
err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params); #else /* #if !USE_APP_TIMER */
if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) static void update_timeout_handler(void)
{ {
m_conn_params_config.error_handler(err_code); m_conn_params_timer.detach(); /* this is supposed to be a single-shot timer callback */
} #endif /* #if !USE_APP_TIMER */
} if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
else {
{ // Check if we have reached the maximum number of attempts
m_update_count = 0; m_update_count++;
if (m_update_count <= m_conn_params_config.max_conn_params_update_count)
// Negotiation failed, disconnect automatically if this has been configured {
if (m_conn_params_config.disconnect_on_fail) uint32_t err_code;
{
uint32_t err_code; // Parameters are not ok, send connection parameters update request.
err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params);
err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE); if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) {
{ m_conn_params_config.error_handler(err_code);
m_conn_params_config.error_handler(err_code); }
} }
} else
{
// Notify the application that the procedure has failed m_update_count = 0;
if (m_conn_params_config.evt_handler != NULL)
{ // Negotiation failed, disconnect automatically if this has been configured
ble_conn_params_evt_t evt; if (m_conn_params_config.disconnect_on_fail)
{
evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED; uint32_t err_code;
m_conn_params_config.evt_handler(&evt);
} err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
} if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
} {
} m_conn_params_config.error_handler(err_code);
}
}
uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init)
{ // Notify the application that the procedure has failed
uint32_t err_code; if (m_conn_params_config.evt_handler != NULL)
{
m_conn_params_config = *p_init; ble_conn_params_evt_t evt;
m_change_param = false;
if (p_init->p_conn_params != NULL) evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED;
{ m_conn_params_config.evt_handler(&evt);
m_preferred_conn_params = *p_init->p_conn_params; }
}
// Set the connection params in stack }
err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params); }
if (err_code != NRF_SUCCESS)
{
return err_code; uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init)
} {
} uint32_t err_code;
else
{ m_conn_params_config = *p_init;
// Fetch the connection params from stack m_change_param = false;
err_code = sd_ble_gap_ppcp_get(&m_preferred_conn_params); if (p_init->p_conn_params != NULL)
if (err_code != NRF_SUCCESS) {
{ m_preferred_conn_params = *p_init->p_conn_params;
return err_code;
} // Set the connection params in stack
} err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params);
if (err_code != NRF_SUCCESS)
m_conn_handle = BLE_CONN_HANDLE_INVALID; {
m_update_count = 0; return err_code;
}
return app_timer_create(&m_conn_params_timer_id, }
APP_TIMER_MODE_SINGLE_SHOT, else
update_timeout_handler); {
} // Fetch the connection params from stack
err_code = sd_ble_gap_ppcp_get(&m_preferred_conn_params);
if (err_code != NRF_SUCCESS)
uint32_t ble_conn_params_stop(void) {
{ return err_code;
return app_timer_stop(m_conn_params_timer_id); }
} }
m_conn_handle = BLE_CONN_HANDLE_INVALID;
static void conn_params_negotiation(void) m_update_count = 0;
{
// Start negotiation if the received connection parameters are not acceptable #ifdef USE_APP_TIMER
if (!is_conn_params_ok(&m_current_conn_params)) return app_timer_create(&m_conn_params_timer_id,
{ APP_TIMER_MODE_SINGLE_SHOT,
uint32_t err_code; update_timeout_handler);
uint32_t timeout_ticks; #else
return NRF_SUCCESS;
if (m_change_param) #endif
{ }
// Notify the application that the procedure has failed
if (m_conn_params_config.evt_handler != NULL)
{ uint32_t ble_conn_params_stop(void)
ble_conn_params_evt_t evt; {
#ifdef USE_APP_TIMER
evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED; return app_timer_stop(m_conn_params_timer_id);
m_conn_params_config.evt_handler(&evt); #else /* #if !USE_APP_TIMER */
} m_conn_params_timer.detach();
} return NRF_SUCCESS;
else #endif /* #if !USE_APP_TIMER */
{ }
if (m_update_count == 0)
{
// First connection parameter update static void conn_params_negotiation(void)
timeout_ticks = m_conn_params_config.first_conn_params_update_delay; {
} // Start negotiation if the received connection parameters are not acceptable
else if (!is_conn_params_ok(&m_current_conn_params))
{ {
timeout_ticks = m_conn_params_config.next_conn_params_update_delay; #ifdef USE_APP_TIMER
} uint32_t err_code;
#endif
err_code = app_timer_start(m_conn_params_timer_id, timeout_ticks, NULL); uint32_t timeout_ticks;
if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
{ if (m_change_param)
m_conn_params_config.error_handler(err_code); {
} // Notify the application that the procedure has failed
} if (m_conn_params_config.evt_handler != NULL)
} {
else ble_conn_params_evt_t evt;
{
// Notify the application that the procedure has succeded evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED;
if (m_conn_params_config.evt_handler != NULL) m_conn_params_config.evt_handler(&evt);
{ }
ble_conn_params_evt_t evt; }
else
evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED; {
m_conn_params_config.evt_handler(&evt); if (m_update_count == 0)
} {
} // First connection parameter update
m_change_param = false; timeout_ticks = m_conn_params_config.first_conn_params_update_delay;
} }
else
{
static void on_connect(ble_evt_t * p_ble_evt) timeout_ticks = m_conn_params_config.next_conn_params_update_delay;
{ }
// Save connection parameters
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; #ifdef USE_APP_TIMER
m_current_conn_params = p_ble_evt->evt.gap_evt.params.connected.conn_params; err_code = app_timer_start(m_conn_params_timer_id, timeout_ticks, NULL);
m_update_count = 0; // Connection parameter negotiation should re-start every connection if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
{
// Check if we shall handle negotiation on connect m_conn_params_config.error_handler(err_code);
if (m_conn_params_config.start_on_notify_cccd_handle == BLE_GATT_HANDLE_INVALID) }
{ #else
conn_params_negotiation(); m_conn_params_timer.attach(update_timeout_handler, timeout_ticks / 32768);
} #endif
} }
}
else
static void on_disconnect(ble_evt_t * p_ble_evt) {
{ // Notify the application that the procedure has succeded
uint32_t err_code; if (m_conn_params_config.evt_handler != NULL)
{
m_conn_handle = BLE_CONN_HANDLE_INVALID; ble_conn_params_evt_t evt;
// Stop timer if running evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED;
m_update_count = 0; // Connection parameters updates should happen during every connection m_conn_params_config.evt_handler(&evt);
}
err_code = app_timer_stop(m_conn_params_timer_id); }
if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) m_change_param = false;
{ }
m_conn_params_config.error_handler(err_code);
}
} static void on_connect(ble_evt_t * p_ble_evt)
{
// Save connection parameters
static void on_write(ble_evt_t * p_ble_evt) m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
{ m_current_conn_params = p_ble_evt->evt.gap_evt.params.connected.conn_params;
ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; m_update_count = 0; // Connection parameter negotiation should re-start every connection
// Check if this the correct CCCD // Check if we shall handle negotiation on connect
if ( if (m_conn_params_config.start_on_notify_cccd_handle == BLE_GATT_HANDLE_INVALID)
(p_evt_write->handle == m_conn_params_config.start_on_notify_cccd_handle) {
&& conn_params_negotiation();
(p_evt_write->len == 2) }
) }
{
// Check if this is a 'start notification'
if (ble_srv_is_notification_enabled(p_evt_write->data)) static void on_disconnect(ble_evt_t * p_ble_evt)
{ {
// Do connection parameter negotiation if necessary #ifdef USE_APP_TIMER
conn_params_negotiation(); uint32_t err_code;
} #endif
else
{ m_conn_handle = BLE_CONN_HANDLE_INVALID;
uint32_t err_code;
// Stop timer if running
// Stop timer if running m_update_count = 0; // Connection parameters updates should happen during every connection
err_code = app_timer_stop(m_conn_params_timer_id);
if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) #ifdef USE_APP_TIMER
{ err_code = app_timer_stop(m_conn_params_timer_id);
m_conn_params_config.error_handler(err_code); if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
} {
} m_conn_params_config.error_handler(err_code);
} }
} #else
m_conn_params_timer.detach();
#endif
static void on_conn_params_update(ble_evt_t * p_ble_evt) }
{
// Copy the parameters
m_current_conn_params = p_ble_evt->evt.gap_evt.params.conn_param_update.conn_params; static void on_write(ble_evt_t * p_ble_evt)
{
conn_params_negotiation(); ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
}
// Check if this the correct CCCD
if (
void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt) (p_evt_write->handle == m_conn_params_config.start_on_notify_cccd_handle)
{ &&
switch (p_ble_evt->header.evt_id) (p_evt_write->len == 2)
{ )
case BLE_GAP_EVT_CONNECTED: {
on_connect(p_ble_evt); // Check if this is a 'start notification'
break; if (ble_srv_is_notification_enabled(p_evt_write->data))
{
case BLE_GAP_EVT_DISCONNECTED: // Do connection parameter negotiation if necessary
on_disconnect(p_ble_evt); conn_params_negotiation();
break; }
else
case BLE_GATTS_EVT_WRITE: {
on_write(p_ble_evt); #ifdef USE_APP_TIMER
break; uint32_t err_code;
case BLE_GAP_EVT_CONN_PARAM_UPDATE: // Stop timer if running
on_conn_params_update(p_ble_evt); err_code = app_timer_stop(m_conn_params_timer_id);
break; if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL))
{
default: m_conn_params_config.error_handler(err_code);
// No implementation needed. }
break; #else /* #if !USE_APP_TIMER */
} m_conn_params_timer.detach();
} #endif /* #if !USE_APP_TIMER */
}
}
uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t * new_params) }
{
uint32_t err_code;
static void on_conn_params_update(ble_evt_t * p_ble_evt)
m_preferred_conn_params = *new_params; {
// Set the connection params in stack // Copy the parameters
err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params); m_current_conn_params = p_ble_evt->evt.gap_evt.params.conn_param_update.conn_params;
if (err_code == NRF_SUCCESS)
{ conn_params_negotiation();
if (!is_conn_params_ok(&m_current_conn_params)) }
{
m_change_param = true;
err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params); void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt)
m_update_count = 1; {
} switch (p_ble_evt->header.evt_id)
else {
{ case BLE_GAP_EVT_CONNECTED:
// Notify the application that the procedure has succeded on_connect(p_ble_evt);
if (m_conn_params_config.evt_handler != NULL) break;
{
ble_conn_params_evt_t evt; case BLE_GAP_EVT_DISCONNECTED:
on_disconnect(p_ble_evt);
evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED; break;
m_conn_params_config.evt_handler(&evt);
} case BLE_GATTS_EVT_WRITE:
err_code = NRF_SUCCESS; on_write(p_ble_evt);
} break;
}
return err_code; case BLE_GAP_EVT_CONN_PARAM_UPDATE:
} on_conn_params_update(p_ble_evt);
break;
default:
// No implementation needed.
break;
}
}
uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t * new_params)
{
uint32_t err_code;
m_preferred_conn_params = *new_params;
// Set the connection params in stack
err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params);
if (err_code == NRF_SUCCESS)
{
if (!is_conn_params_ok(&m_current_conn_params))
{
m_change_param = true;
err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params);
m_update_count = 1;
}
else
{
// Notify the application that the procedure has succeded
if (m_conn_params_config.evt_handler != NULL)
{
ble_conn_params_evt_t evt;
evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED;
m_conn_params_config.evt_handler(&evt);
}
err_code = NRF_SUCCESS;
}
}
return err_code;
}

View File

@ -85,7 +85,7 @@
* be stored. In such cases, application will be notified with DM_DEVICE_CONTEXT_FULL * be stored. In such cases, application will be notified with DM_DEVICE_CONTEXT_FULL
* as event result at the completion of the security procedure. * as event result at the completion of the security procedure.
*/ */
#define DEVICE_MANAGER_MAX_BONDS 7 #define DEVICE_MANAGER_MAX_BONDS 2
/** /**

View File

@ -31,7 +31,6 @@
*/ */
#include "device_manager.h" #include "device_manager.h"
#include "app_trace.h"
#include "pstorage.h" #include "pstorage.h"
#include "ble_hci.h" #include "ble_hci.h"
#include "app_error.h" #include "app_error.h"
@ -162,7 +161,7 @@ typedef enum
* @note That if ENABLE_DEBUG_LOG_SUPPORT is disabled, having DM_DISABLE_LOGS has no effect. * @note That if ENABLE_DEBUG_LOG_SUPPORT is disabled, having DM_DISABLE_LOGS has no effect.
* @{ * @{
*/ */
#define nDM_DISABLE_LOGS /**< Enable this macro to disable any logs from this module. */ #define DM_DISABLE_LOGS /**< Enable this macro to disable any logs from this module. */
#ifndef DM_DISABLE_LOGS #ifndef DM_DISABLE_LOGS
#define DM_LOG app_trace_log /**< Used for logging details. */ #define DM_LOG app_trace_log /**< Used for logging details. */

View File

@ -28,61 +28,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
/****************************************************************************************************//**
* @file nrf51.h
*
* @brief CMSIS Cortex-M0 Peripheral Access Layer Header File for
* nrf51 from Nordic Semiconductor.
*
* @version V522
* @date 29. April 2015
*
* @note Generated with SVDConv V2.81d
* from CMSIS SVD File 'nrf51.xml' Version 522,
*
* @par Copyright (c) 2013, Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*******************************************************************************************************/
/** @addtogroup Nordic Semiconductor
* @{
*/
/** @addtogroup nrf51
* @{
*/
#ifndef NRF51_H #ifndef NRF51_H
#define NRF51_H #define NRF51_H

View File

@ -69,7 +69,7 @@ static __INLINE uint32_t pstorage_flash_page_end()
#define PSTORAGE_SWAP_ADDR PSTORAGE_DATA_END_ADDR /**< Top-most page is used as swap area for clear and update. */ #define PSTORAGE_SWAP_ADDR PSTORAGE_DATA_END_ADDR /**< Top-most page is used as swap area for clear and update. */
#define PSTORAGE_MAX_BLOCK_SIZE PSTORAGE_FLASH_PAGE_SIZE /**< Maximum size of block that can be registered with the module. Should be configured based on system requirements. And should be greater than or equal to the minimum size. */ #define PSTORAGE_MAX_BLOCK_SIZE PSTORAGE_FLASH_PAGE_SIZE /**< Maximum size of block that can be registered with the module. Should be configured based on system requirements. And should be greater than or equal to the minimum size. */
#define PSTORAGE_CMD_QUEUE_SIZE 10 /**< Maximum number of flash access commands that can be maintained by the module for all applications. Configurable. */ #define PSTORAGE_CMD_QUEUE_SIZE 2 /**< Maximum number of flash access commands that can be maintained by the module for all applications. Configurable. */
/** Abstracts persistently memory block identifier. */ /** Abstracts persistently memory block identifier. */

View File

@ -151,6 +151,7 @@ uint32_t dfu_init_prevalidate(uint8_t * p_init_data, uint32_t init_data_len)
uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len) uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len)
{ {
#if NEED_CRC_CHECK /* disabled for now */
uint16_t image_crc; uint16_t image_crc;
uint16_t received_crc; uint16_t received_crc;
@ -169,6 +170,7 @@ uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len)
{ {
return NRF_ERROR_INVALID_DATA; return NRF_ERROR_INVALID_DATA;
} }
#endif /* NEED_CRC_CHECK */
return NRF_SUCCESS; return NRF_SUCCESS;
} }

View File

@ -42,10 +42,10 @@
#ifndef MEM_POOL_INTERNAL_H__ #ifndef MEM_POOL_INTERNAL_H__
#define MEM_POOL_INTERNAL_H__ #define MEM_POOL_INTERNAL_H__
#define TX_BUF_SIZE 32u /**< TX buffer size in bytes. */ #define TX_BUF_SIZE 4u /**< TX buffer size in bytes. */
#define RX_BUF_SIZE 600u /**< RX buffer size in bytes. */ #define RX_BUF_SIZE 32u /**< RX buffer size in bytes. */
#define RX_BUF_QUEUE_SIZE 2u /**< RX buffer element size. */ #define RX_BUF_QUEUE_SIZE 8u /**< RX buffer element size. */
#endif // MEM_POOL_INTERNAL_H__ #endif // MEM_POOL_INTERNAL_H__

View File

@ -1,87 +0,0 @@
/*
* Copyright (c) Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __DEBUG_H_
#define __DEBUG_H_
#include <stdint.h>
#include <stdio.h>
/**
* @defgroup app_trace Debug Logger
* @ingroup app_common
* @{
* @brief Enables debug logs/ trace over UART.
* @details Enables debug logs/ trace over UART. Tracing is enabled only if
* ENABLE_DEBUG_LOG_SUPPORT is defined in the project.
*/
#ifdef ENABLE_DEBUG_LOG_SUPPORT
/**
* @brief Module Initialization.
*
* @details Initializes the module to use UART as trace output.
*
* @warning This function will configure UART using default board configuration.
* Do not call this function if UART is configured from a higher level in the application.
*/
void app_trace_init(void);
/**
* @brief Log debug messages.
*
* @details This API logs messages over UART. The module must be initialized before using this API.
*
* @note Though this is currently a macro, it should be used used and treated as function.
*/
#define app_trace_log printf
/**
* @brief Dump auxiliary byte buffer to the debug trace.
*
* @details This API logs messages over UART. The module must be initialized before using this API.
*
* @param[in] p_buffer Buffer to be dumped on the debug trace.
* @param[in] len Size of the buffer.
*/
void app_trace_dump(uint8_t * p_buffer, uint32_t len);
#else // ENABLE_DEBUG_LOG_SUPPORT
#define app_trace_init(...)
#define app_trace_log(...)
#define app_trace_dump(...)
#endif // ENABLE_DEBUG_LOG_SUPPORT
/** @} */
#endif //__DEBUG_H_

View File

@ -547,7 +547,9 @@ typedef struct
{ {
ble_gap_addr_t peer_addr; /**< Bluetooth address of the peer device. */ ble_gap_addr_t peer_addr; /**< Bluetooth address of the peer device. */
ble_gap_addr_t own_addr; /**< Bluetooth address of the local device used during connection setup. */ ble_gap_addr_t own_addr; /**< Bluetooth address of the local device used during connection setup. */
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
uint8_t role; /**< BLE role for this connection, see @ref BLE_GAP_ROLES */ uint8_t role; /**< BLE role for this connection, see @ref BLE_GAP_ROLES */
#endif
uint8_t irk_match :1; /**< If 1, peer device's address resolved using an IRK. */ uint8_t irk_match :1; /**< If 1, peer device's address resolved using an IRK. */
uint8_t irk_match_idx :7; /**< Index in IRK list where the address was matched. */ uint8_t irk_match_idx :7; /**< Index in IRK list where the address was matched. */
ble_gap_conn_params_t conn_params; /**< GAP Connection Parameters. */ ble_gap_conn_params_t conn_params; /**< GAP Connection Parameters. */

View File

@ -54,6 +54,7 @@
/** @} */ /** @} */
#if 0 /* The following have been duplicated in blecommon.h */
/** @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 */
@ -79,6 +80,7 @@
#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. */
/** @} */ /** @} */
#endif /* The following have been duplicated in blecommon.h */
/** @defgroup BLE_UUID_TYPES Types of UUID /** @defgroup BLE_UUID_TYPES Types of UUID
@ -89,6 +91,7 @@
/** @} */ /** @} */
#if 0 /* The following have been duplicated in blecommon.h */
/** @defgroup BLE_APPEARANCES Bluetooth Appearance values /** @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
* @{ */ * @{ */
@ -142,6 +145,7 @@
#define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_POD 5187 /**< Location Pod (Outdoor Sports Activity subtype). */ #define BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_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). */
/** @} */ /** @} */
#endif /* The following have been duplicated in blecommon.h */
/** @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 {\

View File

@ -1,714 +0,0 @@
/*
* Copyright (c) Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/**************************************************************************//**
* @file core_cm0.h
* @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File
* @version V3.20
* @date 25. February 2013
*
* @note
*
******************************************************************************/
/* Copyright (c) 2009 - 2013 ARM LIMITED
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of ARM nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
*
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND 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.
---------------------------------------------------------------------------*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __CORE_CM0_H_GENERIC
#define __CORE_CM0_H_GENERIC
/** \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
CMSIS violates the following MISRA-C:2004 rules:
\li Required Rule 8.5, object/function definition in header file.<br>
Function definitions in header files are used to allow 'inlining'.
\li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
Unions are used for effective representation of core registers.
\li Advisory Rule 19.7, Function-like macro defined.<br>
Function-like macros are used to allow more efficient code.
*/
/*******************************************************************************
* CMSIS definitions
******************************************************************************/
/** \ingroup Cortex_M0
@{
*/
/* CMSIS CM0 definitions */
#define __CM0_CMSIS_VERSION_MAIN (0x03) /*!< [31:16] CMSIS HAL main version */
#define __CM0_CMSIS_VERSION_SUB (0x20) /*!< [15:0] CMSIS HAL sub version */
#define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16) | \
__CM0_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */
#define __CORTEX_M (0x00) /*!< Cortex-M Core */
#if defined ( __CC_ARM )
#define __ASM __asm /*!< asm keyword for ARM Compiler */
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
#define __STATIC_INLINE static __inline
#elif defined ( __ICCARM__ )
#define __ASM __asm /*!< asm keyword for IAR Compiler */
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
#define __STATIC_INLINE static inline
#elif defined ( __GNUC__ )
#define __ASM __asm /*!< asm keyword for GNU Compiler */
#define __INLINE inline /*!< inline keyword for GNU Compiler */
#define __STATIC_INLINE static inline
#elif defined ( __TASKING__ )
#define __ASM __asm /*!< asm keyword for TASKING Compiler */
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
#define __STATIC_INLINE static inline
#endif
/** __FPU_USED indicates whether an FPU is used or not. This core does not support an FPU at all
*/
#define __FPU_USED 0
#if defined ( __CC_ARM )
#if defined __TARGET_FPU_VFP
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __ICCARM__ )
#if defined __ARMVFP__
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __GNUC__ )
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __TASKING__ )
#if defined __FPU_VFP__
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#endif
#include <stdint.h> /* standard types definitions */
#include <core_cmInstr.h> /* Core Instruction Access */
#include <core_cmFunc.h> /* Core Function Access */
#endif /* __CORE_CM0_H_GENERIC */
#ifndef __CMSIS_GENERIC
#ifndef __CORE_CM0_H_DEPENDANT
#define __CORE_CM0_H_DEPENDANT
/* check device defines and use defaults */
#if defined __CHECK_DEVICE_DEFINES
#ifndef __CM0_REV
#define __CM0_REV 0x0000
#warning "__CM0_REV not defined in device header file; using default!"
#endif
#ifndef __NVIC_PRIO_BITS
#define __NVIC_PRIO_BITS 2
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
#endif
#ifndef __Vendor_SysTickConfig
#define __Vendor_SysTickConfig 0
#warning "__Vendor_SysTickConfig not defined in device header file; using default!"
#endif
#endif
/* IO definitions (access restrictions to peripheral registers) */
/**
\defgroup CMSIS_glob_defs CMSIS Global Defines
<strong>IO Type Qualifiers</strong> are used
\li to specify the access to peripheral variables.
\li for automatic generation of peripheral register debug information.
*/
#ifdef __cplusplus
#define __I volatile /*!< Defines 'read only' permissions */
#else
#define __I volatile const /*!< Defines 'read only' permissions */
#endif
#define __O volatile /*!< Defines 'write only' permissions */
#define __IO volatile /*!< Defines 'read / write' permissions */
/*@} end of group Cortex_M0 */
/*******************************************************************************
* Register Abstraction
Core Register contain:
- Core Register
- Core NVIC Register
- Core SCB Register
- Core SysTick Register
******************************************************************************/
/** \defgroup CMSIS_core_register Defines and Type Definitions
\brief Type definitions and defines for Cortex-M processor based devices.
*/
/** \ingroup CMSIS_core_register
\defgroup CMSIS_CORE Status and Control Registers
\brief Core Register type definitions.
@{
*/
/** \brief Union type to access the Application Program Status Register (APSR).
*/
typedef union
{
struct
{
#if (__CORTEX_M != 0x04)
uint32_t _reserved0:27; /*!< bit: 0..26 Reserved */
#else
uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */
uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */
#endif
uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} APSR_Type;
/** \brief Union type to access the Interrupt Program Status Register (IPSR).
*/
typedef union
{
struct
{
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} IPSR_Type;
/** \brief Union type to access the Special-Purpose Program Status Registers (xPSR).
*/
typedef union
{
struct
{
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
#if (__CORTEX_M != 0x04)
uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
#else
uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */
uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */
#endif
uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */
uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} xPSR_Type;
/** \brief Union type to access the Control Registers (CONTROL).
*/
typedef union
{
struct
{
uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */
uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */
uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} CONTROL_Type;
/*@} end of group CMSIS_CORE */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
\brief Type definitions for the NVIC Registers
@{
*/
/** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
*/
typedef struct
{
__IO uint32_t ISER[1]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
uint32_t RESERVED0[31];
__IO uint32_t ICER[1]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
uint32_t RSERVED1[31];
__IO uint32_t ISPR[1]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
uint32_t RESERVED2[31];
__IO uint32_t ICPR[1]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
uint32_t RESERVED3[31];
uint32_t RESERVED4[64];
__IO uint32_t IP[8]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */
} NVIC_Type;
/*@} end of group CMSIS_NVIC */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_SCB System Control Block (SCB)
\brief Type definitions for the System Control Block Registers
@{
*/
/** \brief Structure type to access the System Control Block (SCB).
*/
typedef struct
{
__I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
__IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
uint32_t RESERVED0;
__IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
__IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
__IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
uint32_t RESERVED1;
__IO uint32_t SHP[2]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */
__IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
} SCB_Type;
/* SCB CPUID Register Definitions */
#define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */
#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
#define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */
#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
#define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */
#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
#define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */
#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
#define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */
#define SCB_CPUID_REVISION_Msk (0xFUL << SCB_CPUID_REVISION_Pos) /*!< SCB CPUID: REVISION Mask */
/* SCB Interrupt Control State Register Definitions */
#define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */
#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
#define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */
#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
#define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */
#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
#define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */
#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
#define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */
#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
#define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */
#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
#define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */
#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
#define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */
#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
#define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */
#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos) /*!< SCB ICSR: VECTACTIVE Mask */
/* SCB Application Interrupt and Reset Control Register Definitions */
#define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */
#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
#define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */
#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
#define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */
#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
#define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */
#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
#define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */
#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
/* SCB System Control Register Definitions */
#define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */
#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
#define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */
#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
#define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */
#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
/* SCB Configuration Control Register Definitions */
#define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */
#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
#define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */
#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
/* SCB System Handler Control and State Register Definitions */
#define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */
#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
/*@} end of group CMSIS_SCB */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_SysTick System Tick Timer (SysTick)
\brief Type definitions for the System Timer Registers.
@{
*/
/** \brief Structure type to access the System Timer (SysTick).
*/
typedef struct
{
__IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
__IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
__IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
__I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
} SysTick_Type;
/* SysTick Control / Status Register Definitions */
#define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */
#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
#define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */
#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
#define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */
#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
#define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */
#define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos) /*!< SysTick CTRL: ENABLE Mask */
/* SysTick Reload Register Definitions */
#define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */
#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos) /*!< SysTick LOAD: RELOAD Mask */
/* SysTick Current Register Definitions */
#define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */
#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick VAL: CURRENT Mask */
/* SysTick Calibration Register Definitions */
#define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */
#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
#define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */
#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
#define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */
#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick CALIB: TENMS Mask */
/*@} end of group CMSIS_SysTick */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
\brief Cortex-M0 Core Debug Registers (DCB registers, SHCSR, and DFSR)
are only accessible over DAP and not via processor. Therefore
they are not covered by the Cortex-M0 header file.
@{
*/
/*@} end of group CMSIS_CoreDebug */
/** \ingroup CMSIS_core_register
\defgroup CMSIS_core_base Core Definitions
\brief Definitions for base addresses, unions, and structures.
@{
*/
/* Memory mapping of Cortex-M0 Hardware */
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
/*@} */
/*******************************************************************************
* Hardware Abstraction Layer
Core Function Interface contains:
- Core NVIC Functions
- Core SysTick Functions
- Core Register Access Functions
******************************************************************************/
/** \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
*/
/* ########################## NVIC functions #################################### */
/** \ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_NVICFunctions NVIC Functions
\brief Functions that manage interrupts and exceptions via the NVIC.
@{
*/
/* Interrupt Priorities are WORD accessible only under ARMv6M */
/* The following MACROS handle generation of the register offset and byte masks */
#define _BIT_SHIFT(IRQn) ( (((uint32_t)(IRQn) ) & 0x03) * 8 )
#define _SHP_IDX(IRQn) ( ((((uint32_t)(IRQn) & 0x0F)-8) >> 2) )
#define _IP_IDX(IRQn) ( ((uint32_t)(IRQn) >> 2) )
/** \brief Function for enabling External Interrupt.
The function enables a device-specific interrupt in the NVIC interrupt controller.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
{
NVIC->ISER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
/** \brief Function for disabling External Interrupt.
The function disables a device-specific interrupt in the NVIC interrupt controller.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
{
NVIC->ICER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
/** \brief Function for getting Pending Interrupt.
The function reads the pending register in the NVIC and returns the pending bit
for the specified interrupt.
\param [in] IRQn Interrupt number.
\return 0 Interrupt status is not pending.
\return 1 Interrupt status is pending.
*/
__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
{
return((uint32_t) ((NVIC->ISPR[0] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0));
}
/** \brief Function for setting Pending Interrupt.
The function sets the pending bit of an external interrupt.
\param [in] IRQn Interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
{
NVIC->ISPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
/** \brief Function for clearing Pending Interrupt.
The function clears the pending bit of an external interrupt.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
{
NVIC->ICPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */
}
/** \brief Function for setting Interrupt Priority.
The function sets the priority of an interrupt.
\note The priority cannot be set for every core interrupt.
\param [in] IRQn Interrupt number.
\param [in] priority Priority to set.
*/
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
{
if(IRQn < 0) {
SCB->SHP[_SHP_IDX(IRQn)] = (SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
(((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
else {
NVIC->IP[_IP_IDX(IRQn)] = (NVIC->IP[_IP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
(((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
}
/** \brief Function for getting Interrupt Priority.
The function reads the priority of an interrupt. The interrupt
number can be positive to specify an external (device specific)
interrupt, or negative to specify an internal (core) interrupt.
\param [in] IRQn Interrupt number.
\return Interrupt Priority. Value is aligned automatically to the implemented
priority bits of the microcontroller.
*/
__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
{
if(IRQn < 0) {
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & 0xFF) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M0 system interrupts */
else {
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & 0xFF) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */
}
/** \brief Function for System Reset.
The function initiates a system reset request to reset the MCU.
*/
__STATIC_INLINE void NVIC_SystemReset(void)
{
__DSB(); /* Ensure all outstanding memory accesses included
buffered write are completed before reset */
SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) |
SCB_AIRCR_SYSRESETREQ_Msk);
__DSB(); /* Ensure completion of memory access */
while(1); /* wait until reset */
}
/*@} end of CMSIS_Core_NVICFunctions */
/* ################################## SysTick function ############################################ */
/** \ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_SysTickFunctions SysTick Functions
\brief Functions that configure the System.
@{
*/
#if (__Vendor_SysTickConfig == 0)
/** \brief Function for system Tick Configuration.
The function initializes the System Timer and its interrupt, and starts the System Tick Timer.
Counter is in free running mode to generate periodic interrupts.
\param [in] ticks Number of ticks between two interrupts.
\return 0 Function succeeded.
\return 1 Function failed.
\note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
must contain a vendor-specific implementation of this function.
*/
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if ((ticks - 1) > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
SysTick->LOAD = ticks - 1; /* set reload register */
NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Systick Interrupt */
SysTick->VAL = 0; /* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
return (0); /* Function successful */
}
#endif
/*@} end of CMSIS_Core_SysTickFunctions */
#endif /* __CORE_CM0_H_DEPENDANT */
#endif /* __CMSIS_GENERIC */
#ifdef __cplusplus
}
#endif

View File

@ -55,6 +55,10 @@ static bool is_disabled_in_debug_needed(void);
uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK; uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
#endif #endif
#ifndef YOTTA_CFG_HARDWARE_CLOCKS_NRF_LFCLK_SRC
# define YOTTA_CFG_HARDWARE_CLOCKS_NRF_LFCLK_SRC 1UL /* The default is to wait for LFLCK to start */
#endif
void SystemCoreClockUpdate(void) void SystemCoreClockUpdate(void)
{ {
SystemCoreClock = __SYSTEM_CLOCK; SystemCoreClock = __SYSTEM_CLOCK;
@ -82,7 +86,17 @@ void SystemInit(void)
if (is_disabled_in_debug_needed()) if (is_disabled_in_debug_needed())
{ {
NRF_MPU->DISABLEINDEBUG = MPU_DISABLEINDEBUG_DISABLEINDEBUG_Disabled << MPU_DISABLEINDEBUG_DISABLEINDEBUG_Pos; NRF_MPU->DISABLEINDEBUG = MPU_DISABLEINDEBUG_DISABLEINDEBUG_Disabled << MPU_DISABLEINDEBUG_DISABLEINDEBUG_Pos;
} }
// Start the external 32khz crystal oscillator.
NRF_CLOCK->LFCLKSRC = (YOTTA_CFG_HARDWARE_CLOCKS_NRF_LFCLK_SRC << CLOCK_LFCLKSRC_SRC_Pos);
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK->TASKS_LFCLKSTART = 1;
// Wait for the external oscillator to start up.
while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {
// Do nothing.
}
} }