config changes

Fork of nRF51822 by Nordic Semiconductor

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

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vincent Coubard 638:c90ae1400bf2 1 /* mbed Microcontroller Library
Vincent Coubard 638:c90ae1400bf2 2 * Copyright (c) 2006-2013 ARM Limited
Vincent Coubard 638:c90ae1400bf2 3 *
Vincent Coubard 638:c90ae1400bf2 4 * Licensed under the Apache License, Version 2.0 (the "License");
Vincent Coubard 638:c90ae1400bf2 5 * you may not use this file except in compliance with the License.
Vincent Coubard 638:c90ae1400bf2 6 * You may obtain a copy of the License at
Vincent Coubard 638:c90ae1400bf2 7 *
Vincent Coubard 638:c90ae1400bf2 8 * http://www.apache.org/licenses/LICENSE-2.0
Vincent Coubard 638:c90ae1400bf2 9 *
Vincent Coubard 638:c90ae1400bf2 10 * Unless required by applicable law or agreed to in writing, software
Vincent Coubard 638:c90ae1400bf2 11 * distributed under the License is distributed on an "AS IS" BASIS,
Vincent Coubard 638:c90ae1400bf2 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Vincent Coubard 638:c90ae1400bf2 13 * See the License for the specific language governing permissions and
Vincent Coubard 638:c90ae1400bf2 14 * limitations under the License.
Vincent Coubard 638:c90ae1400bf2 15 */
Vincent Coubard 638:c90ae1400bf2 16 #include "common/common.h"
Vincent Coubard 638:c90ae1400bf2 17
Vincent Coubard 638:c90ae1400bf2 18 #include "nrf_ble_gap.h"
Vincent Coubard 638:c90ae1400bf2 19 #include "ble_conn_params.h"
Vincent Coubard 638:c90ae1400bf2 20
Vincent Coubard 638:c90ae1400bf2 21 static inline uint32_t msec_to_1_25msec(uint32_t interval_ms) ATTR_ALWAYS_INLINE ATTR_CONST;
Vincent Coubard 638:c90ae1400bf2 22 #if SDK_CONN_PARAMS_MODULE_ENABLE
Vincent Coubard 638:c90ae1400bf2 23 static void error_callback(uint32_t nrf_error);
Vincent Coubard 638:c90ae1400bf2 24 #endif // SDK_CONN_PARAMS_MODULE_ENABLE
Vincent Coubard 638:c90ae1400bf2 25
Vincent Coubard 638:c90ae1400bf2 26 /**************************************************************************/
Vincent Coubard 638:c90ae1400bf2 27 /*!
Vincent Coubard 638:c90ae1400bf2 28 @brief Initialise GAP in the underlying SoftDevice
Vincent Coubard 638:c90ae1400bf2 29
Vincent Coubard 638:c90ae1400bf2 30 @returns
Vincent Coubard 638:c90ae1400bf2 31 */
Vincent Coubard 638:c90ae1400bf2 32 /**************************************************************************/
Vincent Coubard 638:c90ae1400bf2 33 error_t btle_gap_init(void)
Vincent Coubard 638:c90ae1400bf2 34 {
Vincent Coubard 638:c90ae1400bf2 35 ble_gap_conn_params_t gap_conn_params = {0};
Vincent Coubard 638:c90ae1400bf2 36
Vincent Coubard 638:c90ae1400bf2 37 gap_conn_params.min_conn_interval = msec_to_1_25msec(CFG_GAP_CONNECTION_MIN_INTERVAL_MS); // in 1.25ms units
Vincent Coubard 638:c90ae1400bf2 38 gap_conn_params.max_conn_interval = msec_to_1_25msec(CFG_GAP_CONNECTION_MAX_INTERVAL_MS); // in 1.25ms unit
Vincent Coubard 638:c90ae1400bf2 39 gap_conn_params.slave_latency = CFG_GAP_CONNECTION_SLAVE_LATENCY;
Vincent Coubard 638:c90ae1400bf2 40 gap_conn_params.conn_sup_timeout = CFG_GAP_CONNECTION_SUPERVISION_TIMEOUT_MS / 10; // in 10ms unit
Vincent Coubard 638:c90ae1400bf2 41
Vincent Coubard 638:c90ae1400bf2 42 ble_gap_conn_sec_mode_t sec_mode;
Vincent Coubard 638:c90ae1400bf2 43 BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); // no security is needed
Vincent Coubard 638:c90ae1400bf2 44
Vincent Coubard 638:c90ae1400bf2 45 ASSERT_STATUS( sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *) CFG_GAP_LOCAL_NAME, strlen(CFG_GAP_LOCAL_NAME)));
Vincent Coubard 638:c90ae1400bf2 46 ASSERT_STATUS( sd_ble_gap_appearance_set(CFG_GAP_APPEARANCE));
Vincent Coubard 638:c90ae1400bf2 47 ASSERT_STATUS( sd_ble_gap_ppcp_set(&gap_conn_params));
Vincent Coubard 638:c90ae1400bf2 48 ASSERT_STATUS( sd_ble_gap_tx_power_set(CFG_BLE_TX_POWER_LEVEL));
Vincent Coubard 638:c90ae1400bf2 49
Vincent Coubard 638:c90ae1400bf2 50 /**
Vincent Coubard 638:c90ae1400bf2 51 * Call to conn_params_init() is not necessary; and so is disabled by default.
Vincent Coubard 638:c90ae1400bf2 52 * This API should be exposed to the user to be invoked when necessary.
Vincent Coubard 638:c90ae1400bf2 53 */
Vincent Coubard 638:c90ae1400bf2 54 #if SDK_CONN_PARAMS_MODULE_ENABLE
Vincent Coubard 638:c90ae1400bf2 55 /* Connection Parameters */
Vincent Coubard 638:c90ae1400bf2 56 enum {
Vincent Coubard 638:c90ae1400bf2 57 FIRST_UPDATE_DELAY = APP_TIMER_TICKS(5000, CFG_TIMER_PRESCALER),
Vincent Coubard 638:c90ae1400bf2 58 NEXT_UPDATE_DELAY = APP_TIMER_TICKS(5000, CFG_TIMER_PRESCALER),
Vincent Coubard 638:c90ae1400bf2 59 MAX_UPDATE_COUNT = 3
Vincent Coubard 638:c90ae1400bf2 60 };
Vincent Coubard 638:c90ae1400bf2 61
Vincent Coubard 638:c90ae1400bf2 62 ble_conn_params_init_t cp_init = {0};
Vincent Coubard 638:c90ae1400bf2 63
Vincent Coubard 638:c90ae1400bf2 64 cp_init.p_conn_params = NULL;
Vincent Coubard 638:c90ae1400bf2 65 cp_init.first_conn_params_update_delay = FIRST_UPDATE_DELAY;
Vincent Coubard 638:c90ae1400bf2 66 cp_init.next_conn_params_update_delay = NEXT_UPDATE_DELAY;
Vincent Coubard 638:c90ae1400bf2 67 cp_init.max_conn_params_update_count = MAX_UPDATE_COUNT;
Vincent Coubard 638:c90ae1400bf2 68 cp_init.start_on_notify_cccd_handle = BLE_GATT_HANDLE_INVALID;
Vincent Coubard 638:c90ae1400bf2 69 cp_init.disconnect_on_fail = true;
Vincent Coubard 638:c90ae1400bf2 70 cp_init.evt_handler = NULL;
Vincent Coubard 638:c90ae1400bf2 71 cp_init.error_handler = error_callback;
Vincent Coubard 638:c90ae1400bf2 72
Vincent Coubard 638:c90ae1400bf2 73 ASSERT_STATUS ( ble_conn_params_init(&cp_init));
Vincent Coubard 638:c90ae1400bf2 74 #endif // SDK_CONN_PARAMS_MODULE_ENABLE
Vincent Coubard 638:c90ae1400bf2 75
Vincent Coubard 638:c90ae1400bf2 76 return ERROR_NONE;
Vincent Coubard 638:c90ae1400bf2 77 }
Vincent Coubard 638:c90ae1400bf2 78
Vincent Coubard 638:c90ae1400bf2 79 /**************************************************************************/
Vincent Coubard 638:c90ae1400bf2 80 /*!
Vincent Coubard 638:c90ae1400bf2 81 @brief Converts msecs to an integer representing 1.25ms units
Vincent Coubard 638:c90ae1400bf2 82
Vincent Coubard 638:c90ae1400bf2 83 @param[in] ms
Vincent Coubard 638:c90ae1400bf2 84 The number of milliseconds to conver to 1.25ms units
Vincent Coubard 638:c90ae1400bf2 85
Vincent Coubard 638:c90ae1400bf2 86 @returns The number of 1.25ms units in the supplied number of ms
Vincent Coubard 638:c90ae1400bf2 87 */
Vincent Coubard 638:c90ae1400bf2 88 /**************************************************************************/
Vincent Coubard 638:c90ae1400bf2 89 static inline uint32_t msec_to_1_25msec(uint32_t interval_ms)
Vincent Coubard 638:c90ae1400bf2 90 {
Vincent Coubard 638:c90ae1400bf2 91 return (interval_ms * 4) / 5;
Vincent Coubard 638:c90ae1400bf2 92 }
Vincent Coubard 638:c90ae1400bf2 93
Vincent Coubard 638:c90ae1400bf2 94 #if SDK_CONN_PARAMS_MODULE_ENABLE
Vincent Coubard 638:c90ae1400bf2 95 static void error_callback(uint32_t nrf_error)
Vincent Coubard 638:c90ae1400bf2 96 {
Vincent Coubard 638:c90ae1400bf2 97 ASSERT_STATUS_RET_VOID( nrf_error );
Vincent Coubard 638:c90ae1400bf2 98 }
Vincent Coubard 638:c90ae1400bf2 99 #endif // SDK_CONN_PARAMS_MODULE_ENABLE