Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of nRF51822 by
btle_gap.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "common/common.h " 00017 00018 #include "app_timer.h " 00019 #include "ble_gap.h" 00020 #include "ble_conn_params.h " 00021 00022 static inline uint32_t msec_to_1_25msec(uint32_t interval_ms) ATTR_ALWAYS_INLINE ATTR_CONST; 00023 static void error_callback(uint32_t nrf_error); 00024 00025 /**************************************************************************/ 00026 /*! 00027 @brief Initialise GAP in the underlying SoftDevice 00028 00029 @returns 00030 */ 00031 /**************************************************************************/ 00032 error_t btle_gap_init(void) 00033 { 00034 ble_gap_conn_params_t gap_conn_params = {0}; 00035 00036 gap_conn_params.min_conn_interval = msec_to_1_25msec( 00037 CFG_GAP_CONNECTION_MIN_INTERVAL_MS); // in 1.25ms units 00038 gap_conn_params.max_conn_interval = msec_to_1_25msec( 00039 CFG_GAP_CONNECTION_MAX_INTERVAL_MS); // in 1.25ms unit 00040 gap_conn_params.slave_latency = CFG_GAP_CONNECTION_SLAVE_LATENCY; 00041 gap_conn_params.conn_sup_timeout = 00042 CFG_GAP_CONNECTION_SUPERVISION_TIMEOUT_MS / 10; // in 10ms unit 00043 00044 ble_gap_conn_sec_mode_t sec_mode; 00045 BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); // no security is needed 00046 00047 ASSERT_STATUS( sd_ble_gap_device_name_set(&sec_mode, 00048 (const uint8_t *) 00049 CFG_GAP_LOCAL_NAME, 00050 strlen(CFG_GAP_LOCAL_NAME))); 00051 ASSERT_STATUS( sd_ble_gap_appearance_set(CFG_GAP_APPEARANCE)); 00052 ASSERT_STATUS( sd_ble_gap_ppcp_set(&gap_conn_params)); 00053 ASSERT_STATUS( sd_ble_gap_tx_power_set(CFG_BLE_TX_POWER_LEVEL)); 00054 00055 /* Connection Parameters */ 00056 enum { 00057 FIRST_UPDATE_DELAY = APP_TIMER_TICKS(5000, CFG_TIMER_PRESCALER), 00058 NEXT_UPDATE_DELAY = APP_TIMER_TICKS(5000, CFG_TIMER_PRESCALER), 00059 MAX_UPDATE_COUNT = 3 00060 }; 00061 00062 ble_conn_params_init_t cp_init = {0}; 00063 00064 cp_init.p_conn_params = NULL; 00065 cp_init.first_conn_params_update_delay = FIRST_UPDATE_DELAY; 00066 cp_init.next_conn_params_update_delay = NEXT_UPDATE_DELAY; 00067 cp_init.max_conn_params_update_count = MAX_UPDATE_COUNT; 00068 cp_init.start_on_notify_cccd_handle = BLE_GATT_HANDLE_INVALID; 00069 cp_init.disconnect_on_fail = true; 00070 cp_init.evt_handler = NULL; 00071 cp_init.error_handler = error_callback; 00072 00073 ASSERT_STATUS ( ble_conn_params_init(&cp_init)); 00074 00075 return ERROR_NONE; 00076 } 00077 00078 /**************************************************************************/ 00079 /*! 00080 @brief Converts msecs to an integer representing 1.25ms units 00081 00082 @param[in] ms 00083 The number of milliseconds to conver to 1.25ms units 00084 00085 @returns The number of 1.25ms units in the supplied number of ms 00086 */ 00087 /**************************************************************************/ 00088 static inline uint32_t msec_to_1_25msec(uint32_t interval_ms) 00089 { 00090 return (interval_ms * 4) / 5; 00091 } 00092 00093 static void error_callback(uint32_t nrf_error) 00094 { 00095 ASSERT_STATUS_RET_VOID( nrf_error ); 00096 }
Generated on Tue Jul 12 2022 19:00:52 by
