Nordic stack and drivers for the mbed BLE API

Fork of nRF51822 by Nordic Semiconductor

Committer:
Vincent Coubard
Date:
Wed Sep 14 14:39:43 2016 +0100
Revision:
640:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vincent Coubard 640:c90ae1400bf2 1 /*
Vincent Coubard 640:c90ae1400bf2 2 * Copyright (c) Nordic Semiconductor ASA
Vincent Coubard 640:c90ae1400bf2 3 * All rights reserved.
Vincent Coubard 640:c90ae1400bf2 4 *
Vincent Coubard 640:c90ae1400bf2 5 * Redistribution and use in source and binary forms, with or without modification,
Vincent Coubard 640:c90ae1400bf2 6 * are permitted provided that the following conditions are met:
Vincent Coubard 640:c90ae1400bf2 7 *
Vincent Coubard 640:c90ae1400bf2 8 * 1. Redistributions of source code must retain the above copyright notice, this
Vincent Coubard 640:c90ae1400bf2 9 * list of conditions and the following disclaimer.
Vincent Coubard 640:c90ae1400bf2 10 *
Vincent Coubard 640:c90ae1400bf2 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this
Vincent Coubard 640:c90ae1400bf2 12 * list of conditions and the following disclaimer in the documentation and/or
Vincent Coubard 640:c90ae1400bf2 13 * other materials provided with the distribution.
Vincent Coubard 640:c90ae1400bf2 14 *
Vincent Coubard 640:c90ae1400bf2 15 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
Vincent Coubard 640:c90ae1400bf2 16 * contributors to this software may be used to endorse or promote products
Vincent Coubard 640:c90ae1400bf2 17 * derived from this software without specific prior written permission.
Vincent Coubard 640:c90ae1400bf2 18 *
Vincent Coubard 640:c90ae1400bf2 19 *
Vincent Coubard 640:c90ae1400bf2 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Vincent Coubard 640:c90ae1400bf2 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Vincent Coubard 640:c90ae1400bf2 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Vincent Coubard 640:c90ae1400bf2 23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Vincent Coubard 640:c90ae1400bf2 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Vincent Coubard 640:c90ae1400bf2 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Vincent Coubard 640:c90ae1400bf2 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Vincent Coubard 640:c90ae1400bf2 27 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Vincent Coubard 640:c90ae1400bf2 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Vincent Coubard 640:c90ae1400bf2 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Vincent Coubard 640:c90ae1400bf2 30 *
Vincent Coubard 640:c90ae1400bf2 31 */
Vincent Coubard 640:c90ae1400bf2 32
Vincent Coubard 640:c90ae1400bf2 33 /** @file
Vincent Coubard 640:c90ae1400bf2 34 *
Vincent Coubard 640:c90ae1400bf2 35 * @defgroup ble_sdk_lib_conn_params Connection Parameters Negotiation
Vincent Coubard 640:c90ae1400bf2 36 * @{
Vincent Coubard 640:c90ae1400bf2 37 * @ingroup ble_sdk_lib
Vincent Coubard 640:c90ae1400bf2 38 * @brief Module for initiating and executing a connection parameters negotiation procedure.
Vincent Coubard 640:c90ae1400bf2 39 */
Vincent Coubard 640:c90ae1400bf2 40
Vincent Coubard 640:c90ae1400bf2 41 #ifndef BLE_CONN_PARAMS_H__
Vincent Coubard 640:c90ae1400bf2 42 #define BLE_CONN_PARAMS_H__
Vincent Coubard 640:c90ae1400bf2 43
Vincent Coubard 640:c90ae1400bf2 44 #include <stdint.h>
Vincent Coubard 640:c90ae1400bf2 45 #include "nrf_ble.h"
Vincent Coubard 640:c90ae1400bf2 46 #include "ble_srv_common.h"
Vincent Coubard 640:c90ae1400bf2 47
Vincent Coubard 640:c90ae1400bf2 48 /**@brief Connection Parameters Module event type. */
Vincent Coubard 640:c90ae1400bf2 49 typedef enum
Vincent Coubard 640:c90ae1400bf2 50 {
Vincent Coubard 640:c90ae1400bf2 51 BLE_CONN_PARAMS_EVT_FAILED , /**< Negotiation procedure failed. */
Vincent Coubard 640:c90ae1400bf2 52 BLE_CONN_PARAMS_EVT_SUCCEEDED /**< Negotiation procedure succeeded. */
Vincent Coubard 640:c90ae1400bf2 53 } ble_conn_params_evt_type_t;
Vincent Coubard 640:c90ae1400bf2 54
Vincent Coubard 640:c90ae1400bf2 55 /**@brief Connection Parameters Module event. */
Vincent Coubard 640:c90ae1400bf2 56 typedef struct
Vincent Coubard 640:c90ae1400bf2 57 {
Vincent Coubard 640:c90ae1400bf2 58 ble_conn_params_evt_type_t evt_type; /**< Type of event. */
Vincent Coubard 640:c90ae1400bf2 59 } ble_conn_params_evt_t;
Vincent Coubard 640:c90ae1400bf2 60
Vincent Coubard 640:c90ae1400bf2 61 /**@brief Connection Parameters Module event handler type. */
Vincent Coubard 640:c90ae1400bf2 62 typedef void (*ble_conn_params_evt_handler_t) (ble_conn_params_evt_t * p_evt);
Vincent Coubard 640:c90ae1400bf2 63
Vincent Coubard 640:c90ae1400bf2 64 /**@brief Connection Parameters Module init structure. This contains all options and data needed for
Vincent Coubard 640:c90ae1400bf2 65 * initialization of the connection parameters negotiation module. */
Vincent Coubard 640:c90ae1400bf2 66 typedef struct
Vincent Coubard 640:c90ae1400bf2 67 {
Vincent Coubard 640:c90ae1400bf2 68 ble_gap_conn_params_t * p_conn_params; /**< Pointer to the connection parameters desired by the application. When calling ble_conn_params_init, if this parameter is set to NULL, the connection parameters will be fetched from host. */
Vincent Coubard 640:c90ae1400bf2 69 uint32_t first_conn_params_update_delay; /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (in number of timer ticks). */
Vincent Coubard 640:c90ae1400bf2 70 uint32_t next_conn_params_update_delay; /**< Time between each call to sd_ble_gap_conn_param_update after the first (in number of timer ticks). Recommended value 30 seconds as per BLUETOOTH SPECIFICATION Version 4.0. */
Vincent Coubard 640:c90ae1400bf2 71 uint8_t max_conn_params_update_count; /**< Number of attempts before giving up the negotiation. */
Vincent Coubard 640:c90ae1400bf2 72 uint16_t start_on_notify_cccd_handle; /**< If procedure is to be started when notification is started, set this to the handle of the corresponding CCCD. Set to BLE_GATT_HANDLE_INVALID if procedure is to be started on connect event. */
Vincent Coubard 640:c90ae1400bf2 73 bool disconnect_on_fail; /**< Set to TRUE if a failed connection parameters update shall cause an automatic disconnection, set to FALSE otherwise. */
Vincent Coubard 640:c90ae1400bf2 74 ble_conn_params_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Connection Parameters. */
Vincent Coubard 640:c90ae1400bf2 75 ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */
Vincent Coubard 640:c90ae1400bf2 76 } ble_conn_params_init_t;
Vincent Coubard 640:c90ae1400bf2 77
Vincent Coubard 640:c90ae1400bf2 78
Vincent Coubard 640:c90ae1400bf2 79 /**@brief Function for initializing the Connection Parameters module.
Vincent Coubard 640:c90ae1400bf2 80 *
Vincent Coubard 640:c90ae1400bf2 81 * @note If the negotiation procedure should be triggered when notification/indication of
Vincent Coubard 640:c90ae1400bf2 82 * any characteristic is enabled by the peer, then this function must be called after
Vincent Coubard 640:c90ae1400bf2 83 * having initialized the services.
Vincent Coubard 640:c90ae1400bf2 84 *
Vincent Coubard 640:c90ae1400bf2 85 * @param[in] p_init This contains information needed to initialize this module.
Vincent Coubard 640:c90ae1400bf2 86 *
Vincent Coubard 640:c90ae1400bf2 87 * @return NRF_SUCCESS on successful initialization, otherwise an error code.
Vincent Coubard 640:c90ae1400bf2 88 */
Vincent Coubard 640:c90ae1400bf2 89 uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init);
Vincent Coubard 640:c90ae1400bf2 90
Vincent Coubard 640:c90ae1400bf2 91 /**@brief Function for stopping the Connection Parameters module.
Vincent Coubard 640:c90ae1400bf2 92 *
Vincent Coubard 640:c90ae1400bf2 93 * @details This function is intended to be used by the application to clean up the connection
Vincent Coubard 640:c90ae1400bf2 94 * parameters update module. This will stop the connection parameters update timer if
Vincent Coubard 640:c90ae1400bf2 95 * running, thereby preventing any impending connection parameters update procedure. This
Vincent Coubard 640:c90ae1400bf2 96 * function must be called by the application when it needs to clean itself up (for
Vincent Coubard 640:c90ae1400bf2 97 * example, before disabling the bluetooth SoftDevice) so that an unwanted timer expiry
Vincent Coubard 640:c90ae1400bf2 98 * event can be avoided.
Vincent Coubard 640:c90ae1400bf2 99 *
Vincent Coubard 640:c90ae1400bf2 100 * @return NRF_SUCCESS on successful initialization, otherwise an error code.
Vincent Coubard 640:c90ae1400bf2 101 */
Vincent Coubard 640:c90ae1400bf2 102 uint32_t ble_conn_params_stop(void);
Vincent Coubard 640:c90ae1400bf2 103
Vincent Coubard 640:c90ae1400bf2 104 /**@brief Function for changing the current connection parameters to a new set.
Vincent Coubard 640:c90ae1400bf2 105 *
Vincent Coubard 640:c90ae1400bf2 106 * @details Use this function to change the connection parameters to a new set of parameter
Vincent Coubard 640:c90ae1400bf2 107 * (ie different from the ones given at init of the module).
Vincent Coubard 640:c90ae1400bf2 108 * This function is usefull for scenario where most of the time the application
Vincent Coubard 640:c90ae1400bf2 109 * needs a relatively big connection interval, and just sometimes, for a temporary
Vincent Coubard 640:c90ae1400bf2 110 * period requires shorter connection interval, for example to transfer a higher
Vincent Coubard 640:c90ae1400bf2 111 * amount of data.
Vincent Coubard 640:c90ae1400bf2 112 * If the given parameters does not match the current connection's parameters
Vincent Coubard 640:c90ae1400bf2 113 * this function initiates a new negotiation.
Vincent Coubard 640:c90ae1400bf2 114 *
Vincent Coubard 640:c90ae1400bf2 115 * @param[in] new_params This contains the new connections parameters to setup.
Vincent Coubard 640:c90ae1400bf2 116 *
Vincent Coubard 640:c90ae1400bf2 117 * @return NRF_SUCCESS on successful initialization, otherwise an error code.
Vincent Coubard 640:c90ae1400bf2 118 */
Vincent Coubard 640:c90ae1400bf2 119 uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t *new_params);
Vincent Coubard 640:c90ae1400bf2 120
Vincent Coubard 640:c90ae1400bf2 121 /**@brief Function for handling the Application's BLE Stack events.
Vincent Coubard 640:c90ae1400bf2 122 *
Vincent Coubard 640:c90ae1400bf2 123 * @details Handles all events from the BLE stack that are of interest to this module.
Vincent Coubard 640:c90ae1400bf2 124 *
Vincent Coubard 640:c90ae1400bf2 125 * @param[in] p_ble_evt The event received from the BLE stack.
Vincent Coubard 640:c90ae1400bf2 126 */
Vincent Coubard 640:c90ae1400bf2 127 void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt);
Vincent Coubard 640:c90ae1400bf2 128
Vincent Coubard 640:c90ae1400bf2 129 #endif // BLE_CONN_PARAMS_H__
Vincent Coubard 640:c90ae1400bf2 130
Vincent Coubard 640:c90ae1400bf2 131 /** @} */