porting to v8.0 of the SDK

This commit is contained in:
Rohit Grover 2015-03-30 15:24:28 +01:00
parent 2783e0289c
commit 4ae92f89c1
48 changed files with 5164 additions and 1789 deletions

View file

@ -58,11 +58,10 @@ static void sys_evt_dispatch(uint32_t sys_evt)
error_t btle_init(void)
{
const bool useScheduler = false;
#if defined(TARGET_DELTA_DFCM_NNN40) || defined(TARGET_HRM1017)
SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION, useScheduler);
SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION, NULL);
#else
SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, useScheduler);
SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL);
#endif
// Enable BLE stack
@ -125,7 +124,11 @@ static void btle_handler(ble_evt_t *p_ble_evt)
nRF51Gap::getInstance().setConnectionHandle(handle);
const Gap::ConnectionParams_t *params = reinterpret_cast<Gap::ConnectionParams_t *>(&(p_ble_evt->evt.gap_evt.params.connected.conn_params));
const ble_gap_addr_t *peer = &p_ble_evt->evt.gap_evt.params.connected.peer_addr;
nRF51Gap::getInstance().processConnectionEvent(handle, static_cast<Gap::addr_type_t>(peer->addr_type), peer->addr, params);
const ble_gap_addr_t *own = &p_ble_evt->evt.gap_evt.params.connected.own_addr;
nRF51Gap::getInstance().processConnectionEvent(handle,
static_cast<Gap::addr_type_t>(peer->addr_type), peer->addr,
static_cast<Gap::addr_type_t>(own->addr_type), own->addr,
params);
break;
}
@ -162,22 +165,21 @@ static void btle_handler(ble_evt_t *p_ble_evt)
case BLE_GAP_EVT_SEC_PARAMS_REQUEST: {
ble_gap_sec_params_t sec_params = {0};
sec_params.timeout = 30; /*< Timeout for Pairing Request or
* Security Request (in seconds). */
sec_params.bond = 1; /**< Perform bonding. */
sec_params.mitm = CFG_BLE_SEC_PARAM_MITM;
sec_params.io_caps = CFG_BLE_SEC_PARAM_IO_CAPABILITIES;
sec_params.oob = CFG_BLE_SEC_PARAM_OOB;
sec_params.min_key_size = CFG_BLE_SEC_PARAM_MIN_KEY_SIZE;
sec_params.max_key_size = CFG_BLE_SEC_PARAM_MAX_KEY_SIZE;
sec_params.bond = 1; /**< Perform bonding. */
sec_params.mitm = CFG_BLE_SEC_PARAM_MITM;
sec_params.io_caps = CFG_BLE_SEC_PARAM_IO_CAPABILITIES;
sec_params.oob = CFG_BLE_SEC_PARAM_OOB;
sec_params.min_key_size = CFG_BLE_SEC_PARAM_MIN_KEY_SIZE;
sec_params.max_key_size = CFG_BLE_SEC_PARAM_MAX_KEY_SIZE;
ASSERT_STATUS_RET_VOID(sd_ble_gap_sec_params_reply(nRF51Gap::getInstance().getConnectionHandle(),
BLE_GAP_SEC_STATUS_SUCCESS, &sec_params));
ble_gap_sec_keyset_t sec_keyset = {0};
ASSERT_STATUS_RET_VOID(sd_ble_gap_sec_params_reply(nRF51Gap::getInstance().getConnectionHandle(), BLE_GAP_SEC_STATUS_SUCCESS, &sec_params, &sec_keyset));
}
break;
case BLE_GAP_EVT_TIMEOUT:
if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT) {
if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISING) {
nRF51Gap::getInstance().processEvent(GapEvents::GAP_EVENT_TIMEOUT);
}
break;

View file

@ -119,31 +119,38 @@ ble_error_t nRF51GattServer::addService(GattService &service)
@brief Reads the value of a characteristic, based on the service
and characteristic index fields
@param[in] charHandle
@param[in] attributeHandle
The handle of the GattCharacteristic to read from
@param[in] buffer
Buffer to hold the the characteristic's value
(raw byte array in LSB format)
@param[in] len
The number of bytes read into the buffer
@param[in/out] len
input: Length in bytes to be read.
output: Total length of attribute value upon successful return.
@returns ble_error_t
@retval BLE_ERROR_NONE
Everything executed properly
@section EXAMPLE
@code
@endcode
*/
/**************************************************************************/
ble_error_t nRF51GattServer::readValue(GattAttribute::Handle_t charHandle, uint8_t buffer[], uint16_t *const lengthP)
ble_error_t nRF51GattServer::readValue(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
{
return readValue(BLE_CONN_HANDLE_INVALID, attributeHandle, buffer, lengthP);
}
ble_error_t nRF51GattServer::readValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
{
ble_gatts_value_t value = {
.len = *lengthP,
.offset = 0,
.p_value = buffer,
};
ASSERT( ERROR_NONE ==
sd_ble_gatts_value_get(nrfCharacteristicHandles[charHandle].value_handle, 0, lengthP, buffer),
sd_ble_gatts_value_get(connectionHandle, nrfCharacteristicHandles[attributeHandle].value_handle, &value),
BLE_ERROR_PARAM_OUT_OF_RANGE);
*lengthP = value.len;
return BLE_ERROR_NONE;
}
@ -165,52 +172,50 @@ ble_error_t nRF51GattServer::readValue(GattAttribute::Handle_t charHandle, uint8
@retval BLE_ERROR_NONE
Everything executed properly
@section EXAMPLE
@code
@endcode
*/
/**************************************************************************/
ble_error_t nRF51GattServer::updateValue(GattAttribute::Handle_t charHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
ble_error_t nRF51GattServer::updateValue(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
{
return updateValue(BLE_CONN_HANDLE_INVALID, attributeHandle, buffer, len, localOnly);
}
ble_error_t nRF51GattServer::updateValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
{
uint16_t gapConnectionHandle = nRF51Gap::getInstance().getConnectionHandle();
ble_error_t returnValue = BLE_ERROR_NONE;
ble_gatts_value_t value = {
.len = len,
.offset = 0,
.p_value = const_cast<uint8_t *>(buffer),
};
if (localOnly) {
/* Only update locally regardless of notify/indicate */
ASSERT_INT( ERROR_NONE,
sd_ble_gatts_value_set(nrfCharacteristicHandles[charHandle].value_handle, 0, &len, buffer),
sd_ble_gatts_value_set(connectionHandle, nrfCharacteristicHandles[attributeHandle].value_handle, &value),
BLE_ERROR_PARAM_OUT_OF_RANGE );
return BLE_ERROR_NONE;
return BLE_ERROR_NONE;
}
if ((p_characteristics[charHandle]->getProperties() &
(GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE |
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)) &&
(gapConnectionHandle != BLE_CONN_HANDLE_INVALID)) {
if ((p_characteristics[attributeHandle]->getProperties() & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)) &&
(gapConnectionHandle != connectionHandle)) {
/* HVX update for the characteristic value */
ble_gatts_hvx_params_t hvx_params;
hvx_params.handle = nrfCharacteristicHandles[charHandle].value_handle;
hvx_params.handle = nrfCharacteristicHandles[attributeHandle].value_handle;
hvx_params.type =
(p_characteristics[charHandle]->getProperties() &
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) ?
BLE_GATT_HVX_NOTIFICATION : BLE_GATT_HVX_INDICATION;
(p_characteristics[attributeHandle]->getProperties() & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) ? BLE_GATT_HVX_NOTIFICATION : BLE_GATT_HVX_INDICATION;
hvx_params.offset = 0;
hvx_params.p_data = const_cast<uint8_t *>(buffer);
hvx_params.p_len = &len;
error_t error = (error_t) sd_ble_gatts_hvx(gapConnectionHandle, &hvx_params);
/* ERROR_INVALID_STATE, ERROR_BUSY, ERROR_GATTS_SYS_ATTR_MISSING and
*ERROR_NO_TX_BUFFERS the ATT table has been updated. */
if ((error != ERROR_NONE) && (error != ERROR_INVALID_STATE) &&
(error != ERROR_BLE_NO_TX_BUFFERS) && (error != ERROR_BUSY) &&
(error != ERROR_BLEGATTS_SYS_ATTR_MISSING)) {
/* ERROR_INVALID_STATE, ERROR_BUSY, ERROR_GATTS_SYS_ATTR_MISSING and ERROR_NO_TX_BUFFERS the ATT table has been updated. */
if ((error != ERROR_NONE) && (error != ERROR_INVALID_STATE) && (error != ERROR_BLE_NO_TX_BUFFERS) && (error != ERROR_BUSY) && (error != ERROR_BLEGATTS_SYS_ATTR_MISSING)) {
ASSERT_INT( ERROR_NONE,
sd_ble_gatts_value_set(nrfCharacteristicHandles[charHandle].value_handle, 0, &len, buffer),
sd_ble_gatts_value_set(connectionHandle, nrfCharacteristicHandles[attributeHandle].value_handle, &value),
BLE_ERROR_PARAM_OUT_OF_RANGE );
}
@ -222,7 +227,7 @@ ble_error_t nRF51GattServer::updateValue(GattAttribute::Handle_t charHandle, con
}
} else {
ASSERT_INT( ERROR_NONE,
sd_ble_gatts_value_set(nrfCharacteristicHandles[charHandle].value_handle, 0, &len, buffer),
sd_ble_gatts_value_set(connectionHandle, nrfCharacteristicHandles[attributeHandle].value_handle, &value),
BLE_ERROR_PARAM_OUT_OF_RANGE );
}
@ -281,7 +286,7 @@ void nRF51GattServer::hwCallback(ble_evt_t *p_ble_evt)
}
case BLE_GATTS_EVT_SYS_ATTR_MISSING:
sd_ble_gatts_sys_attr_set(gattsEventP->conn_handle, NULL, 0);
sd_ble_gatts_sys_attr_set(gattsEventP->conn_handle, NULL, 0, 0);
return;
case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:

View file

@ -21,6 +21,7 @@
#include "blecommon.h"
#include "ble.h" /* nordic ble */
#include "Gap.h"
#include "GattServer.h"
class nRF51GattServer : public GattServer
@ -33,8 +34,10 @@ public:
/* Functions that must be implemented from GattServer */
virtual ble_error_t addService(GattService &);
virtual ble_error_t readValue(GattAttribute::Handle_t handle, uint8_t buffer[], uint16_t *const lengthP);
virtual ble_error_t readValue(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
virtual ble_error_t readValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
virtual ble_error_t updateValue(GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
virtual ble_error_t updateValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
virtual ble_error_t initializeGATTDatabase(void);
/* nRF51 Functions */

View file

@ -224,14 +224,20 @@ static void on_connect(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt)
static bool is_cccd_configured(ble_dfu_t * p_dfu)
{
// Check if the CCCDs are configured.
uint16_t cccd_len = BLE_CCCD_VALUE_LEN;
uint8_t cccd_val_buf[BLE_CCCD_VALUE_LEN];
ble_gatts_value_t gatts_value;
// Initialize value struct.
memset(&gatts_value, 0, sizeof(gatts_value));
gatts_value.len = BLE_CCCD_VALUE_LEN;
gatts_value.offset = 0;
gatts_value.p_value = cccd_val_buf;
// Check the CCCD Value of DFU Control Point.
uint32_t err_code = sd_ble_gatts_value_get(p_dfu->dfu_ctrl_pt_handles.cccd_handle,
0,
&cccd_len,
cccd_val_buf);
uint32_t err_code = sd_ble_gatts_value_get(p_dfu->conn_handle,
p_dfu->dfu_ctrl_pt_handles.cccd_handle,
&gatts_value);
if (err_code != NRF_SUCCESS)
{
if (p_dfu->error_handler != NULL)
@ -387,7 +393,7 @@ static uint32_t on_ctrl_pt_write(ble_dfu_t * p_dfu, ble_gatts_evt_write_t * p_bl
* @param[in] p_dfu DFU Service Structure.
* @param[in] p_ble_evt Pointer to the event received from BLE stack.
*/
static void on_rw_auth_req(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt)
static void on_rw_authorize_req(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt)
{
ble_gatts_evt_rw_authorize_request_t * p_authorize_request;
@ -397,6 +403,12 @@ static void on_rw_auth_req(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt)
(p_authorize_request->type == BLE_GATTS_AUTHORIZE_TYPE_WRITE)
&&
(p_authorize_request->request.write.handle == p_dfu->dfu_ctrl_pt_handles.value_handle)
&&
(p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.op != BLE_GATTS_OP_PREP_WRITE_REQ)
&&
(p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.op != BLE_GATTS_OP_EXEC_WRITE_REQ_NOW)
&&
(p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.op != BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL)
)
{
uint32_t err_code;
@ -537,7 +549,7 @@ void ble_dfu_on_ble_evt(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt)
break;
case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
on_rw_auth_req(p_dfu, p_ble_evt);
on_rw_authorize_req(p_dfu, p_ble_evt);
break;
default:

View file

@ -130,7 +130,7 @@ typedef void (*ble_dfu_evt_handler_t) (ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt)
*
* @details This structure contains status information related to the service.
*/
typedef struct ble_dfu_s
struct ble_dfu_s
{
uint16_t conn_handle; /**< Handle of the current connection (as provided by the S110 SoftDevice). This will be BLE_CONN_HANDLE_INVALID when not in a connection. */
uint16_t revision; /**< Handle of DFU Service (as provided by the S110 SoftDevice). */
@ -142,7 +142,7 @@ typedef struct ble_dfu_s
ble_gatts_char_handles_t dfu_rev_handles; /**< Handles related to the DFU Revision characteristic. */
ble_dfu_evt_handler_t evt_handler; /**< The event handler to be called when an event is to be sent to the application.*/
ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */
} ble_dfu_t;
};
/**@brief DFU service initialization structure.
*

View file

@ -122,35 +122,6 @@ static uint32_t appearance_encode(uint8_t * p_encoded_data, uint8_t * p_len)
}
static uint32_t uint8_array_encode(const uint8_array_t * p_uint8_array,
uint8_t adv_type,
uint8_t * p_encoded_data,
uint8_t * p_len)
{
// Check parameter consistency.
if (p_uint8_array->p_data == NULL)
{
return NRF_ERROR_INVALID_PARAM;
}
// Check for buffer overflow.
if ((*p_len) + ADV_DATA_OFFSET + p_uint8_array->size > BLE_GAP_ADV_MAX_SIZE)
{
return NRF_ERROR_DATA_SIZE;
}
// Encode Length and AD Type.
p_encoded_data[(*p_len)++] = 1 + p_uint8_array->size;
p_encoded_data[(*p_len)++] = adv_type;
// Encode array.
memcpy(&p_encoded_data[*p_len], p_uint8_array->p_data, p_uint8_array->size);
(*p_len) += p_uint8_array->size;
return NRF_SUCCESS;
}
static uint32_t tx_power_level_encode(int8_t tx_power_level,
uint8_t * p_encoded_data,
uint8_t * p_len)
@ -439,18 +410,13 @@ static uint32_t adv_data_encode(const ble_advdata_t * p_advdata,
}
}
// Encode flags.
if (p_advdata->flags.size > 0)
if(p_advdata->flags != 0 )
{
err_code = uint8_array_encode(&p_advdata->flags,
BLE_GAP_AD_TYPE_FLAGS,
p_encoded_data,
p_len);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
}
// Encode flags.
p_encoded_data[(*p_len)++] = 1 + sizeof(uint8_t);
p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_FLAGS;
p_encoded_data[(*p_len)++] = p_advdata->flags;
}
// Encode TX power level.
if (p_advdata->p_tx_power_level != NULL)
@ -543,9 +509,8 @@ static uint32_t adv_data_encode(const ble_advdata_t * p_advdata,
static uint32_t advdata_check(const ble_advdata_t * p_advdata)
{
// Flags must be included in advertising data, and the BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED flag must be set.
if ((p_advdata->flags.size == 0) ||
(p_advdata->flags.p_data == NULL) ||
((p_advdata->flags.p_data[0] & BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED) == 0)
if (
((p_advdata->flags & BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED) == 0)
)
{
return NRF_ERROR_INVALID_PARAM;
@ -558,7 +523,7 @@ static uint32_t advdata_check(const ble_advdata_t * p_advdata)
static uint32_t srdata_check(const ble_advdata_t * p_srdata)
{
// Flags shall not be included in the scan response data.
if (p_srdata->flags.size > 0)
if (p_srdata->flags)
{
return NRF_ERROR_INVALID_PARAM;
}

View file

@ -72,7 +72,7 @@ typedef struct
ble_advdata_name_type_t name_type; /**< Type of device name. */
uint8_t short_name_len; /**< Length of short device name (if short type is specified). */
bool include_appearance; /**< Determines if Appearance shall be included. */
uint8_array_t flags; /**< Advertising data Flags field. */
uint8_t flags; /**< Advertising data Flags field. */
int8_t * p_tx_power_level; /**< TX Power Level field. */
ble_advdata_uuid_list_t uuids_more_available; /**< List of UUIDs in the 'More Available' list. */
ble_advdata_uuid_list_t uuids_complete; /**< List of UUIDs in the 'Complete' list. */

View file

@ -30,7 +30,7 @@
* all contextual information is flushed. For example, SMP Information Exchanged during
* pairing and GATT Configuration is not retained on disconnection.
*
* Note that this module allows management of contextual information but
* Note that this module allows management of contextual information but
* does not provide an interface for connection management. Therefore, entering connectible
* mode, connection establishment, or disconnection of a link with peer is not in scope
* of this module.
@ -79,7 +79,7 @@
* @details Possible Service/Protocol context per peer device. The Device Manager provides the
* functionality of persistently storing the Service/Protocol context and can automatically
* load them when needed.
* For example system attributes for a GATT Server. Based on the nature of the application,
* For example system attributes for a GATT Server. Based on the nature of the application,
* not all service types may be needed. The application can specify
* only the service/protocol context it wants to use at the time of registration.
* @{
@ -193,7 +193,7 @@ typedef uint8_t dm_application_instance_t;
/**
* @brief Connection Instance.
*
* @details Identifies connection instance for an active device. This instance is allocated by the
* @details Identifies connection instance for an active device. This instance is allocated by the
* device manager when a connection is established and is notified with DM_EVT_CONNECTION
* with the event result NRF_SUCCESS.
*/
@ -254,10 +254,9 @@ typedef struct dm_sign_key
/** @brief Security keys. */
typedef struct dm_sec_keyset
{
union
union
{
dm_enc_key_t * p_enc_key; /**< Pointer to Device Manager encryption information structure. */
ble_gap_enc_info_t * p_enc_info; /**< Pointer to GAP encryption information. */
} enc_key;
dm_id_key_t * p_id_key; /**< Identity key, or NULL. */
dm_sign_key_t * p_sign_key; /**< Signing key, or NULL. */
@ -294,7 +293,8 @@ typedef struct device_handle
*/
typedef struct
{
uint32_t len; /**< Length of data . */
uint32_t flags; /**< Additional flags identifying data. */
uint32_t len; /**< Length of data. */
uint8_t * p_data; /**< Pointer to contextual data, a copy is made of the data. */
} dm_context_t;
@ -364,16 +364,16 @@ typedef struct
* @param[in] p_handle Identifies the peer for which the event is being notified.
* @param[in] p_event Identifies the event, any associated parameters and parameter length.
* See \ref dm_events for details on event types and their significance.
* @param[in,out] event_result Provide additional information on the event.
* @param[in,out] event_result Provide additional information on the event.
* In addition to SDK error codes there is also a return value
* indicating if maximum number of connections has been reached when connecting or bonding.
*
* @retval NRF_SUCCESS on success, or a failure to indicate if it could handle the event
* successfully. There is no action taken in case application returns a failure.
*/
typedef api_result_t (*dm_event_cb_t)(dm_handle_t const * p_handle,
dm_event_t const * p_event,
api_result_t event_result);
typedef ret_code_t (*dm_event_cb_t)(dm_handle_t const * p_handle,
dm_event_t const * p_event,
ret_code_t event_result);
/**
* @brief Initialization Parameters.
@ -406,9 +406,9 @@ typedef struct
*/
typedef enum
{
NOT_ENCRYPTED, /**< The link does not security. */
ENCRYPTION_IN_PROGRESS, /**< Security is in progress of being established.*/
ENCRYPTED /**< The link is secure.*/
NOT_ENCRYPTED, /**< The link is not secured. */
ENCRYPTION_IN_PROGRESS, /**< Link security is being established.*/
ENCRYPTED /**< The link is secure.*/
} dm_security_status_t;
/** @} */
@ -423,7 +423,7 @@ typedef enum
* - Context Management APIs.
* - Utility APIs.
*
* MSCs describe usage of these APIs.
* MSCs describe usage of these APIs.
* See @ref dm_msc.
* @{
*/
@ -449,7 +449,7 @@ typedef enum
*
* @note It is mandatory that pstorage is initialized before initializing this module.
*/
api_result_t dm_init(dm_init_param_t const * p_init_param);
ret_code_t dm_init(dm_init_param_t const * p_init_param);
/**
* @brief Function for registering the application.
@ -462,7 +462,7 @@ api_result_t dm_init(dm_init_param_t const * p_init_param);
* Maximum number of application instances device manager can support is determined
* by DM_MAX_APPLICATIONS.
*
* All applications must be registered before initiating or accepting connections from the peer.
* All applications must be registered before initiating or accepting connections from the peer.
*
* @param[in] p_appl_param Application parameters.
* @param[out] p_appl_instance Application Instance Identifier in case registration is successful.
@ -473,8 +473,8 @@ api_result_t dm_init(dm_init_param_t const * p_init_param);
*
* @note Currently only one application instance is supported by the module.
*/
api_result_t dm_register(dm_application_instance_t * p_appl_instance,
dm_application_param_t const * p_appl_param);
ret_code_t dm_register(dm_application_instance_t * p_appl_instance,
dm_application_param_t const * p_appl_param);
/**
* @brief Function for handling BLE events.
@ -521,7 +521,7 @@ void dm_ble_evt_handler(ble_evt_t * p_ble_evt);
* @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application
* or if the peer is not connected when this procedure is requested.
*/
api_result_t dm_security_setup_req(dm_handle_t * p_handle);
ret_code_t dm_security_setup_req(dm_handle_t * p_handle);
/**
* @brief Function for reading the status of the security on a link.
@ -539,7 +539,7 @@ api_result_t dm_security_setup_req(dm_handle_t * p_handle);
* @retval NRF_ERROR_INVALID_ADDR If peer is not identified by the handle provided by the application
* or if peer is not connected when this procedure is requested.
*/
api_result_t dm_security_status_req(dm_handle_t const * p_handle, dm_security_status_t * p_status);
ret_code_t dm_security_status_req(dm_handle_t const * p_handle, dm_security_status_t * p_status);
/**
* @brief Function for creating the whitelist.
@ -551,7 +551,7 @@ api_result_t dm_security_status_req(dm_handle_t const * p_handle, dm_security_st
* @param[in,out] p_whitelist Pointer where created whitelist is provided to the application.
*
* @note 'addr_count' and 'irk_count' fields of the structure should be populated with the maximum
* number of devices that the application wishes to request in the whitelist.
* number of devices that the application wishes to request in the whitelist.
* If the number of bonded devices is less than requested, the fields are updated with that number of devices.
* If the number of devices are more than requested, the module will populate the list
* with devices in the order the bond was established with the peer devices. Also, if this routine is
@ -563,8 +563,8 @@ api_result_t dm_security_status_req(dm_handle_t const * p_handle, dm_security_st
* application registration.
* @retval NRF_ERROR_NULL If p_handle or p_whitelist is NULL.
*/
api_result_t dm_whitelist_create(dm_application_instance_t const * p_handle,
ble_gap_whitelist_t * p_whitelist);
ret_code_t dm_whitelist_create(dm_application_instance_t const * p_handle,
ble_gap_whitelist_t * p_whitelist);
/** @} */
@ -582,8 +582,8 @@ api_result_t dm_whitelist_create(dm_application_instance_t const * p_handle,
* @{
*/
api_result_t dm_device_add(dm_handle_t * p_handle,
dm_device_context_t const * p_context);
ret_code_t dm_device_add(dm_handle_t * p_handle,
dm_device_context_t const * p_context);
/**
* @brief Function for deleting a peer device context and all related information from the database.
@ -605,7 +605,7 @@ api_result_t dm_device_add(dm_handle_t * p_handle,
* bonded device. The respective events DM_EVT_SERVICE_CONTEXT_DELETED and
* DM_EVT_APPL_CONTEXT_DELETED are not notified to the application.
*/
api_result_t dm_device_delete(dm_handle_t const * p_handle);
ret_code_t dm_device_delete(dm_handle_t const * p_handle);
/**
* @brief Function for deleting all peer device context and all related information from the database.
@ -628,7 +628,7 @@ api_result_t dm_device_delete(dm_handle_t const * p_handle);
* bonded device. The respective events DM_EVT_SERVICE_CONTEXT_DELETED and
* DM_EVT_APPL_CONTEXT_DELETED are not notified to the application.
*/
api_result_t dm_device_delete_all(dm_application_instance_t const * p_handle);
ret_code_t dm_device_delete_all(dm_application_instance_t const * p_handle);
/**
* @brief Function for setting Service Context for a peer device identified by 'p_handle' parameter.
@ -655,8 +655,8 @@ api_result_t dm_device_delete_all(dm_application_instance_t const * p_handle);
* @retval NRF_ERROR_NULL If p_handle is NULL.
* @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application.
*/
api_result_t dm_service_context_set(dm_handle_t const * p_handle,
dm_service_context_t const * p_context);
ret_code_t dm_service_context_set(dm_handle_t const * p_handle,
dm_service_context_t const * p_context);
/**
* @brief Function for getting Service Context for a peer device identified by 'p_handle' parameter.
@ -678,15 +678,15 @@ api_result_t dm_service_context_set(dm_handle_t const * p_handle,
* @retval NRF_ERROR_NULL If p_handle is NULL.
* @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application.
*/
api_result_t dm_service_context_get(dm_handle_t const * p_handle,
dm_service_context_t * p_context);
ret_code_t dm_service_context_get(dm_handle_t const * p_handle,
dm_service_context_t * p_context);
/**
* @brief Function for deleting a Service Context for a peer device identified by the 'p_handle' parameter.
*
* @details This API allows application to delete a Service Context identified for a peer device
* identified by the 'p_handle' parameter. If this API returns NRF_SUCCESS,
* DM_EVT_SERVICE_CONTEXT_DELETED event is notified to the application.
* DM_EVT_SERVICE_CONTEXT_DELETED event is notified to the application.
* Event result is notified along with the event and indicates success or failure of this
* procedure.
*
@ -698,7 +698,7 @@ api_result_t dm_service_context_get(dm_handle_t const * p_handle,
* @retval NRF_ERROR_NULL If p_handle is NULL.
* @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application.
*/
api_result_t dm_service_context_delete(dm_handle_t const * p_handle);
ret_code_t dm_service_context_delete(dm_handle_t const * p_handle);
/**
* @brief Function for setting Application Context for a peer device identified by the 'p_handle' parameter.
@ -728,8 +728,8 @@ api_result_t dm_service_context_delete(dm_handle_t const * p_handle);
*
* @note The API returns FEATURE_NOT_ENABLED in case DEVICE_MANAGER_APP_CONTEXT_SIZE is set to zero.
*/
api_result_t dm_application_context_set(dm_handle_t const * p_handle,
dm_application_context_t const * p_context);
ret_code_t dm_application_context_set(dm_handle_t const * p_handle,
dm_application_context_t const * p_context);
/**
* @brief Function for getting Application Context for a peer device identified by the 'p_handle' parameter.
@ -753,8 +753,8 @@ api_result_t dm_application_context_set(dm_handle_t const * p_handl
* @note The API returns FEATURE_NOT_ENABLED in case DEVICE_MANAGER_APP_CONTEXT_SIZE is set to
* zero.
*/
api_result_t dm_application_context_get(dm_handle_t const * p_handle,
dm_application_context_t * p_context);
ret_code_t dm_application_context_get(dm_handle_t const * p_handle,
dm_application_context_t * p_context);
/**
* @brief Function for deleting Application Context for a peer device identified by the 'p_handle' parameter.
@ -775,7 +775,7 @@ api_result_t dm_application_context_get(dm_handle_t const * p_handle,
*
* @note The API returns FEATURE_NOT_ENABLED if the DEVICE_MANAGER_APP_CONTEXT_SIZE is set to zero.
*/
api_result_t dm_application_context_delete(dm_handle_t const * p_handle);
ret_code_t dm_application_context_delete(dm_handle_t const * p_handle);
/** @} */
@ -798,8 +798,8 @@ api_result_t dm_application_context_delete(dm_handle_t const * p_handle);
* application registration.
* @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL.
*/
api_result_t dm_application_instance_set(dm_application_instance_t const * p_appl_instance,
dm_handle_t * p_handle);
ret_code_t dm_application_instance_set(dm_application_instance_t const * p_appl_instance,
dm_handle_t * p_handle);
/**
* @brief Function for getting a peer's device address.
@ -813,8 +813,8 @@ api_result_t dm_application_instance_set(dm_application_instance_t const * p_app
* @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL.
* @retval NRF_ERROR_NOT_FOUND If the peer could not be identified.
*/
api_result_t dm_peer_addr_get(dm_handle_t const * p_handle,
ble_gap_addr_t * p_addr);
ret_code_t dm_peer_addr_get(dm_handle_t const * p_handle,
ble_gap_addr_t * p_addr);
/**
* @brief Function for setting/updating a peer's device address.
@ -830,15 +830,15 @@ api_result_t dm_peer_addr_get(dm_handle_t const * p_handle,
* @retval NRF_ERROR_INVALID_PARAM If this procedure is requested while connected to the peer or if the address
* type was set to BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE.
*
* @note Setting or updating a peer's device address is permitted
* @note Setting or updating a peer's device address is permitted
* only for a peer that is bonded and disconnected.
* @note Updated address is reflected only after DM_EVT_DEVICE_CONTEXT_STORED is notified to the
* application for this bonded device instance. In order to avoid abnormal behaviour, it is
* recommended to not invite/initiate connections on the updated address unless this event
* has been notified.
*/
api_result_t dm_peer_addr_set(dm_handle_t const * p_handle,
ble_gap_addr_t const * p_addr);
ret_code_t dm_peer_addr_set(dm_handle_t const * p_handle,
ble_gap_addr_t const * p_addr);
/**
* @brief Function for initializing Device Manager handle.
@ -850,16 +850,12 @@ api_result_t dm_peer_addr_set(dm_handle_t const * p_handle,
*
* @note This routine is permitted before initialization of the module.
*/
api_result_t dm_handle_initialize(dm_handle_t * p_handle);
ret_code_t dm_handle_initialize(dm_handle_t * p_handle);
/**
* @brief Function for getting distributed keys for a device.
*
* @details This routine is used to get distributed keys with a bonded device. This API is currently
* only available on S120 (GAP Central role).
*
* @param[in] p_handle Device Manager handle identifying the peer.
*
* @param[in] p_handle Device Manager handle identifying the peer.
* @param[out] p_key_dist Pointer to distributed keys.
*
* @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
@ -868,8 +864,22 @@ api_result_t dm_handle_initialize(dm_handle_t * p_handle);
* @retval NRF_ERROR_NULL If the p_handle and/or p_key_dist pointer is NULL.
* @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application.
*/
api_result_t dm_distributed_keys_get(dm_handle_t const * p_handle,
dm_sec_keyset_t * p_key_dist);
ret_code_t dm_distributed_keys_get(dm_handle_t const * p_handle,
dm_sec_keyset_t * p_key_dist);
/**
* @brief Function for getting the corresponding dm_handle_t based on the connection handle.
*
* @param[in] conn_handle Connection handle as provided by the SoftDevice.
* @param[in,out] p_handle Pointer to the p_handle containg the application instance for the
* registered application. If the application instance is valid then
* the p_handle will be filled with requested data.
*
* @retval NRF_SUCCESS On success, else an error code indicating reason for failure.
* @retval NRF_ERROR_NULL If the p_handle pointer is NULL.
* @retval NRF_ERROR_NOT_FOUND If no p_handle is found for the provided connection handle.
*/
ret_code_t dm_handle_get(uint16_t conn_handle, dm_handle_t * p_handle);
/** @} */
/** @} */

File diff suppressed because it is too large Load diff

View file

@ -46,10 +46,12 @@ typedef enum
#define IS_UPDATING_SD(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_SD) /**< Macro for determining if a SoftDevice update is ongoing. */
#define IS_UPDATING_BL(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_BL) /**< Macro for determining if a Bootloader update is ongoing. */
#define IS_UPDATING_APP(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_APP) /**< Macro for determining if a Application update is ongoing. */
#define IMAGE_WRITE_IN_PROGRESS() (m_data_received > 0) /**< Macro for determining is image write in progress. */
#define IMAGE_WRITE_IN_PROGRESS() (m_data_received > 0) /**< Macro for determining if an image write is in progress. */
#define IS_WORD_SIZED(SIZE) ((SIZE & (sizeof(uint32_t) - 1)) == 0) /**< Macro for checking that the provided is word sized. */
/**@cond NO_DOXYGEN */
static uint32_t m_data_received; /**< Amount of received data. */
/**@endcond */
/**@brief Type definition of function used for preparing of the bank before receiving of a
* software image.

View file

@ -26,8 +26,8 @@
*
* @note The application must make sure that all SuperVisor Calls (SVC) are forwarded to the
* bootloader to ensure correct behavior. Forwarding of SVCs to the bootloader is
* done using the SoftDevice SVC \ref sd_softdevice_vector_table_base_set with the value
* present in \c NRF_UICR->BOOTLOADERADDR.
* done using the SoftDevice SVC @ref sd_softdevice_vector_table_base_set with the value
* present in @c NRF_UICR->BOOTLOADERADDR.
*/
#ifndef DFU_BLE_SVC_H__
@ -40,12 +40,13 @@
#include "nrf_soc.h"
#include "nrf_error_sdm.h"
#define BOOTLOADER_SVC_BASE 0x0 /**< The number of the lowest SVC number reserved for the bootloader. */
#define BOOTLOADER_SVC_BASE 0x0 /**< The number of the lowest SVC number reserved for the bootloader. */
#define SYSTEM_SERVICE_ATT_SIZE 8 /**< Size of the system service attribute length including CRC-16 at the end. */
/**@brief The SVC numbers used by the SVC functions in the SoC library. */
enum BOOTLOADER_SVCS
{
DFU_BLE_SVC_SET_PEER_DATA = BOOTLOADER_SVC_BASE,
DFU_BLE_SVC_SET_PEER_DATA = BOOTLOADER_SVC_BASE, /**< SVC number for the setting of peer data call. */
BOOTLOADER_SVC_LAST
};
@ -58,9 +59,10 @@ enum BOOTLOADER_SVCS
*/
typedef struct
{
ble_gap_enc_info_t enc_info;
ble_gap_irk_t irk;
ble_gap_addr_t addr;
ble_gap_addr_t addr; /**< BLE GAP address of the device that initiated the DFU process. */
ble_gap_irk_t irk; /**< IRK of the device that initiated the DFU process if this device uses Private Resolvable Addresses. */
ble_gap_enc_key_t enc_key; /**< Encryption key structure containing encrypted diversifier and LTK for re-establishing the bond. */
uint8_t sys_serv_attr[SYSTEM_SERVICE_ATT_SIZE]; /**< System service attributes for restoring of Service Changed Indication setting in DFU mode. */
} dfu_ble_peer_data_t;
/**@brief SVC Function for setting peer data containing address, IRK, and LTK to establish bonded
@ -69,7 +71,7 @@ typedef struct
* @param[in] p_peer_data Pointer to the peer data containing keys for the connection.
*
* @retval NRF_ERROR_NULL If a NULL pointer was provided as argument.
* @retval NRF_SUCCESS If the function completed successfully.
* @retval NRF_SUCCESS If the function completed successfully.
*/
SVCALL(DFU_BLE_SVC_SET_PEER_DATA, uint32_t, dfu_ble_svc_set_peer_data(dfu_ble_peer_data_t * p_peer_data));

View file

@ -88,10 +88,12 @@ uint32_t dfu_init_prevalidate(uint8_t * p_init_data, uint32_t init_data_len)
m_extended_packet_length);
/** [DFU init application version] */
// In order to support application versioning this check should be updated.
// This template allows for any application to be installed however customer could place a
// revision number at bottom of application to be verified by bootloader. This could be done at
// a relative location to this papplication for example Application start address + 0x0100.
// To support application versioning, this check should be updated.
// This template allows for any application to be installed. However,
// customers can place a revision number at the bottom of the application
// to be verified by the bootloader. This can be done at a location
// relative to the application, for example the application start
// address + 0x0100.
/** [DFU init application version] */
// First check to verify the image to be transfered matches the device type.

View file

@ -45,11 +45,7 @@ typedef struct
#define NRF_UICR_BOOT_START_ADDRESS (NRF_UICR_BASE + 0x14) /**< Register where the bootloader start address is stored in the UICR register. */
#ifdef S310_STACK
#define CODE_REGION_1_START 0x00020000 /**< This field should correspond to the size of Code Region 0, (which is identical to Start of Code Region 1), found in UICR.CLEN0 register. This value is used for compile safety, as the linker will fail if application expands into bootloader. Runtime, the bootloader will use the value found in UICR.CLEN0. */
#else
#define CODE_REGION_1_START SOFTDEVICE_INFORMATION->softdevice_size /**< This field should correspond to the size of Code Region 0, (which is identical to Start of Code Region 1), found in UICR.CLEN0 register. This value is used for compile safety, as the linker will fail if application expands into bootloader. Runtime, the bootloader will use the value found in UICR.CLEN0. */
#endif
#define CODE_REGION_1_START SOFTDEVICE_INFORMATION->softdevice_size /**< This field should correspond to the size of Code Region 0, (which is identical to Start of Code Region 1), found in UICR.CLEN0 register. This value is used for compile safety, as the linker will fail if application expands into bootloader. Runtime, the bootloader will use the value found in UICR.CLEN0. */
#define SOFTDEVICE_REGION_START 0x00001000 /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
#define BOOTLOADER_REGION_START 0x0003C000 /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
@ -58,8 +54,12 @@ typedef struct
#define DFU_REGION_TOTAL_SIZE (BOOTLOADER_REGION_START - CODE_REGION_1_START) /**< Total size of the region between SD and Bootloader. */
#define DFU_APP_DATA_RESERVED 0x0000 /**< Size of Application Data that must be preserved between application updates. This value must be a multiple of page size. Page size is 0x400 (1024d) bytes, thus this value must be 0x0000, 0x0400, 0x0800, 0x0C00, 0x1000, etc. */
#define DFU_IMAGE_MAX_SIZE_FULL (DFU_REGION_TOTAL_SIZE - DFU_APP_DATA_RESERVED) /**< Maximum size of a application, excluding save data from the application. */
#define DFU_IMAGE_MAX_SIZE_BANKED (((DFU_REGION_TOTAL_SIZE)/2) - DFU_APP_DATA_RESERVED) /**< Maximum size of a application, excluding save data from the application. */
#define DFU_BANK_PADDING (DFU_APP_DATA_RESERVED % (2 * CODE_PAGE_SIZE)) /**< Padding to ensure that image size banked is always page sized. */
#define DFU_IMAGE_MAX_SIZE_FULL (DFU_REGION_TOTAL_SIZE - DFU_APP_DATA_RESERVED) /**< Maximum size of an application, excluding save data from the application. */
#define DFU_IMAGE_MAX_SIZE_BANKED ((DFU_REGION_TOTAL_SIZE - \
DFU_APP_DATA_RESERVED - \
DFU_BANK_PADDING) / 2) /**< Maximum size of an application, excluding save data from the application. */
#define DFU_BL_IMAGE_MAX_SIZE (BOOTLOADER_SETTINGS_ADDRESS - BOOTLOADER_REGION_START) /**< Maximum size of a bootloader, excluding save data from the current bootloader. */
#define DFU_BANK_0_REGION_START CODE_REGION_1_START /**< Bank 0 region start. */

View file

@ -73,9 +73,9 @@ static void dfu_app_set_peer_data(void)
err_code = dm_distributed_keys_get(&m_dm_handle, &key_set);
APP_ERROR_CHECK(err_code);
m_peer_data.addr = key_set.keys_central.p_id_key->id_addr_info;
m_peer_data.enc_info = *key_set.keys_central.enc_key.p_enc_info;
m_peer_data.irk = key_set.keys_central.p_id_key->id_info;
m_peer_data.addr = key_set.keys_central.p_id_key->id_addr_info;
m_peer_data.enc_key = *((ble_gap_enc_key_t *)(key_set.keys_central.enc_key.p_enc_key));
m_peer_data.irk = key_set.keys_central.p_id_key->id_info;
err_code = dfu_ble_svc_set_peer_data(&m_peer_data);
APP_ERROR_CHECK(err_code);

View file

@ -1,52 +0,0 @@
/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*
*/
/** @file
*
* @defgroup crc_compute CRC compute
* @{
* @ingroup hci_transport
*
* @brief This module implements the CRC-16 calculation in the blocks.
*/
#ifndef CRC16_H__
#define CRC16_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Function for calculating CRC-16 in blocks.
*
* Feed each consecutive data block into this function, along with the current value of p_crc as
* returned by the previous call of this function. The first call of this function should pass NULL
* as the initial value of the crc in p_crc.
*
* @param[in] p_data The input data block for computation.
* @param[in] size The size of the input data block in bytes.
* @param[in] p_crc The previous calculated CRC-16 value or NULL if first call.
*
* @return The updated CRC-16 value, based on the input supplied.
*/
uint16_t crc16_compute(const uint8_t * p_data, uint32_t size, const uint16_t * p_crc);
#ifdef __cplusplus
}
#endif
#endif // CRC16_H__
/** @} */

View file

@ -94,8 +94,8 @@ void GPIOTE_IRQHandler(void)
if (((1 << i) & m_enabled_users_mask) != 0)
{
uint32_t transition_pins;
uint32_t event_low_to_high;
uint32_t event_high_to_low;
uint32_t event_low_to_high = 0;
uint32_t event_high_to_low = 0;
// Find set of pins on which there has been a transition.
transition_pins = (pins_state ^ ~p_user->sense_high_pins) & p_user->pins_mask;
@ -103,29 +103,33 @@ void GPIOTE_IRQHandler(void)
// Toggle SENSE level for all pins that have changed state.
sense_level_toggle(p_user, transition_pins);
// Second read after setting sense.
// Second read for this user after setting sense.
// Level changes for previous processed users would trigger a pending interrupt.
// Check if any pins have changed while serving this interrupt.
pins_changed = NRF_GPIO->IN ^ pins_state;
pins_changed = (NRF_GPIO->IN ^ pins_state) & p_user->pins_mask;
if (pins_changed)
{
// Transition pins detected in late stage.
uint32_t late_transition_pins;
uint32_t late_pins_state;
pins_state |= pins_changed;
late_pins_state = pins_state ^ pins_changed;
// Find set of pins on which there has been a transition.
late_transition_pins = (pins_state ^ ~p_user->sense_high_pins) & p_user->pins_mask;
late_transition_pins = (late_pins_state ^ ~p_user->sense_high_pins) & p_user->pins_mask;
// Toggle SENSE level for all pins that have changed state in last phase.
sense_level_toggle(p_user, late_transition_pins);
// Update pins that has changed state since the interrupt occurred.
transition_pins |= late_transition_pins;
//transition_pins |= late_transition_pins;
event_high_to_low = (~late_pins_state & p_user->pins_high_to_low_mask) & late_transition_pins;
event_low_to_high = (late_pins_state & p_user->pins_low_to_high_mask) & late_transition_pins;
}
// Call user event handler if an event has occurred.
event_high_to_low = (~pins_state & p_user->pins_high_to_low_mask) & transition_pins;
event_low_to_high = (pins_state & p_user->pins_low_to_high_mask) & transition_pins;
event_high_to_low |= (~pins_state & p_user->pins_high_to_low_mask) & transition_pins;
event_low_to_high |= (pins_state & p_user->pins_low_to_high_mask) & transition_pins;
if ((event_low_to_high | event_high_to_low) != 0)
{
@ -133,6 +137,27 @@ void GPIOTE_IRQHandler(void)
}
}
}
// Second read after setting sense.
// Check if any pins have changed while serving this interrupt.
// pins_changed = NRF_GPIO->IN ^ pins_state;
// if (pins_changed)
// {
// // Transition pins detected in late stage.
// uint32_t late_transition_pins;
// pins_state ^= pins_changed;
// // Find set of pins on which there has been a transition.
// late_transition_pins = (pins_state ^ ~p_user->sense_high_pins) & p_user->pins_mask;
// // Toggle SENSE level for all pins that have changed state in last phase.
// sense_level_toggle(p_user, late_transition_pins);
// // Update pins that has changed state since the interrupt occurred.
// transition_pins |= late_transition_pins;
// }
}

View file

@ -53,7 +53,7 @@
*
* @param[in] MAX_USERS Maximum number of GPIOTE users.
*
* @return Required buffer size (in bytes).
* @retval Required buffer size (in bytes).
*/
#define APP_GPIOTE_BUF_SIZE(MAX_USERS) ((MAX_USERS) * GPIOTE_USER_NODE_SIZE)
@ -139,7 +139,7 @@ uint32_t app_gpiote_user_enable(app_gpiote_user_id_t user_id);
*
* @param[in] user_id Id of user to enable.
*
* @return NRF_SUCCESS On success.
* @retval NRF_SUCCESS On success.
* @retval NRF_ERROR_INVALID_PARAM Invalid user_id provided, No a valid user.
* @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE
* module.
@ -153,7 +153,7 @@ uint32_t app_gpiote_user_disable(app_gpiote_user_id_t user_id);
* the specified user. All bits corresponding to pins in the state
* 'high' will have value '1', all others will have value '0'.
*
* @return NRF_SUCCESS On success.
* @retval NRF_SUCCESS On success.
* @retval NRF_ERROR_INVALID_PARAM Invalid user_id provided, No a valid user.
* @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE
* module.
@ -167,7 +167,7 @@ uint32_t app_gpiote_pins_state_get(app_gpiote_user_id_t user_id, uint32_t * p_pi
* @param[in] polarity Specify operation on input that shall trigger IN event.
* @param[in] event_handler Event handler invoked on the IN event in the GPIOTE interrupt.
*
* @return NRF_SUCCESS On success.
* @retval NRF_SUCCESS On success.
* @retval NRF_ERROR_INVALID_PARAM Invalid channel or pin number.
* @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support IN events.
*/
@ -178,7 +178,7 @@ uint32_t app_gpiote_input_event_handler_register(const uint8_t channel,
/**@brief Function for unregistering event handlers for GPIOTE IN events.
*
* @return NRF_SUCCESS On success.
* @retval NRF_SUCCESS On success.
* @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support IN events.
*/
uint32_t app_gpiote_input_event_handler_unregister(const uint8_t channel);
@ -187,28 +187,28 @@ uint32_t app_gpiote_input_event_handler_unregister(const uint8_t channel);
*
* @param[in] event_handler Event handler invoked at the end of the GPIOTE interrupt.
*
* @return NRF_SUCCESS On success.
* @retval NRF_SUCCESS On success.
* @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support IN events.
*/
uint32_t app_gpiote_end_irq_event_handler_register(app_gpiote_input_event_handler_t event_handler);
/**@brief Function for unregistering event handler invoked at the end of a GPIOTE interrupt.
*
* @return NRF_SUCCESS On success.
* @retval NRF_SUCCESS On success.
* @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support IN events.
*/
uint32_t app_gpiote_end_irq_event_handler_unregister(void);
/**@brief Function for enabling interrupts in the GPIOTE driver.
*
* @return NRF_SUCCESS On success.
* @retval NRF_SUCCESS On success.
* @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support.
*/
uint32_t app_gpiote_enable_interrupts(void);
/**@brief Function for disabling interrupts in the GPIOTE driver.
*
* @return NRF_SUCCESS On success.
* @retval NRF_SUCCESS On success.
* @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support.
*/
uint32_t app_gpiote_disable_interrupts(void);

View file

@ -35,13 +35,6 @@ static volatile uint8_t m_queue_end_index; /**< Index of queue entry at the
static uint16_t m_queue_event_size; /**< Maximum event size in queue. */
static uint16_t m_queue_size; /**< Number of queue entries. */
/**@brief Macro for checking if a queue is full. */
#define APP_SCHED_QUEUE_FULL() (next_index(m_queue_end_index) == m_queue_start_index)
/**@brief Macro for checking if a queue is empty. */
#define APP_SCHED_QUEUE_EMPTY() (m_queue_end_index == m_queue_start_index)
/**@brief Function for incrementing a queue index, and handle wrap-around.
*
* @param[in] index Old index.
@ -54,6 +47,26 @@ static __INLINE uint8_t next_index(uint8_t index)
}
static __INLINE uint8_t app_sched_queue_full()
{
uint8_t tmp = m_queue_start_index;
return next_index(m_queue_end_index) == tmp;
}
/**@brief Macro for checking if a queue is full. */
#define APP_SCHED_QUEUE_FULL() app_sched_queue_full()
static __INLINE uint8_t app_sched_queue_empty()
{
uint8_t tmp = m_queue_start_index;
return m_queue_end_index == tmp;
}
/**@brief Macro for checking if a queue is empty. */
#define APP_SCHED_QUEUE_EMPTY() app_sched_queue_empty()
uint32_t app_sched_init(uint16_t event_size, uint16_t queue_size, void * p_event_buffer)
{
uint16_t data_start_index = (queue_size + 1) * sizeof(event_header_t);

View file

@ -1,152 +0,0 @@
/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*
*/
/** @file
*
* @defgroup app_scheduler Scheduler
* @{
* @ingroup app_common
*
* @brief The scheduler is used for transferring execution from the interrupt context to the main
* context.
*
* @details See @ref seq_diagrams_sched for sequence diagrams illustrating the flow of events
* when using the Scheduler.
*
* @section app_scheduler_req Requirements:
*
* @subsection main_context_logic Logic in main context:
*
* - Define an event handler for each type of event expected.
* - Initialize the scheduler by calling the APP_SCHED_INIT() macro before entering the
* application main loop.
* - Call app_sched_execute() from the main loop each time the application wakes up because of an
* event (typically when sd_app_evt_wait() returns).
*
* @subsection int_context_logic Logic in interrupt context:
*
* - In the interrupt handler, call app_sched_event_put()
* with the appropriate data and event handler. This will insert an event into the
* scheduler's queue. The app_sched_execute() function will pull this event and call its
* handler in the main context.
*
* @if (SD_S110 && !SD_S310)
* For an example usage of the scheduler, see the implementations of
* @ref ble_sdk_app_hids_mouse and @ref ble_sdk_app_hids_keyboard.
* @endif
*
* @image html scheduler_working.jpg The high level design of the scheduler
*/
#ifndef APP_SCHEDULER_H__
#define APP_SCHEDULER_H__
#include <stdint.h>
#include "app_error.h"
#define APP_SCHED_EVENT_HEADER_SIZE 8 /**< Size of app_scheduler.event_header_t (only for use inside APP_SCHED_BUF_SIZE()). */
/**@brief Compute number of bytes required to hold the scheduler buffer.
*
* @param[in] EVENT_SIZE Maximum size of events to be passed through the scheduler.
* @param[in] QUEUE_SIZE Number of entries in scheduler queue (i.e. the maximum number of events
* that can be scheduled for execution).
*
* @return Required scheduler buffer size (in bytes).
*/
#define APP_SCHED_BUF_SIZE(EVENT_SIZE, QUEUE_SIZE) \
(((EVENT_SIZE) + APP_SCHED_EVENT_HEADER_SIZE) * ((QUEUE_SIZE) + 1))
/**@brief Scheduler event handler type. */
typedef void (*app_sched_event_handler_t)(void * p_event_data, uint16_t event_size);
/**@brief Macro for initializing the event scheduler.
*
* @details It will also handle dimensioning and allocation of the memory buffer required