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.
Dependents: BLE_iBeacon_Exercise
Fork of BLE_API_Native by
hw/nRF51822n/btle/btle_gap.cpp@3:cb37056dbcc6, 2014-02-06 (annotated)
- Committer:
- ktownsend
- Date:
- Thu Feb 06 13:05:36 2014 +0000
- Revision:
- 3:cb37056dbcc6
- Parent:
- hw/nRF51822n/btle/btle_gap.c@0:4c3097c65247
Renamed files to cpp and removed extra IRQ handlers
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ktownsend | 0:4c3097c65247 | 1 | /* mbed Microcontroller Library |
ktownsend | 0:4c3097c65247 | 2 | * Copyright (c) 2006-2013 ARM Limited |
ktownsend | 0:4c3097c65247 | 3 | * |
ktownsend | 0:4c3097c65247 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ktownsend | 0:4c3097c65247 | 5 | * you may not use this file except in compliance with the License. |
ktownsend | 0:4c3097c65247 | 6 | * You may obtain a copy of the License at |
ktownsend | 0:4c3097c65247 | 7 | * |
ktownsend | 0:4c3097c65247 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
ktownsend | 0:4c3097c65247 | 9 | * |
ktownsend | 0:4c3097c65247 | 10 | * Unless required by applicable law or agreed to in writing, software |
ktownsend | 0:4c3097c65247 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
ktownsend | 0:4c3097c65247 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ktownsend | 0:4c3097c65247 | 13 | * See the License for the specific language governing permissions and |
ktownsend | 0:4c3097c65247 | 14 | * limitations under the License. |
ktownsend | 0:4c3097c65247 | 15 | */ |
ktownsend | 0:4c3097c65247 | 16 | #include "common/common.h" |
ktownsend | 0:4c3097c65247 | 17 | |
ktownsend | 0:4c3097c65247 | 18 | #include "app_timer.h" |
ktownsend | 0:4c3097c65247 | 19 | #include "ble_gap.h" |
ktownsend | 0:4c3097c65247 | 20 | #include "ble_conn_params.h" |
ktownsend | 0:4c3097c65247 | 21 | |
ktownsend | 0:4c3097c65247 | 22 | static inline uint32_t msec_to_1_25msec(uint32_t interval_ms) ATTR_ALWAYS_INLINE ATTR_CONST; |
ktownsend | 0:4c3097c65247 | 23 | static void error_callback(uint32_t nrf_error); |
ktownsend | 0:4c3097c65247 | 24 | |
ktownsend | 0:4c3097c65247 | 25 | /**************************************************************************/ |
ktownsend | 0:4c3097c65247 | 26 | /*! |
ktownsend | 0:4c3097c65247 | 27 | @brief Initialise GAP in the underlying SoftDevice |
ktownsend | 0:4c3097c65247 | 28 | |
ktownsend | 0:4c3097c65247 | 29 | @returns |
ktownsend | 0:4c3097c65247 | 30 | */ |
ktownsend | 0:4c3097c65247 | 31 | /**************************************************************************/ |
ktownsend | 0:4c3097c65247 | 32 | error_t btle_gap_init(void) |
ktownsend | 0:4c3097c65247 | 33 | { |
ktownsend | 0:4c3097c65247 | 34 | ble_gap_conn_params_t gap_conn_params = { 0 }; |
ktownsend | 0:4c3097c65247 | 35 | |
ktownsend | 0:4c3097c65247 | 36 | gap_conn_params.min_conn_interval = msec_to_1_25msec(CFG_GAP_CONNECTION_MIN_INTERVAL_MS) ; // in 1.25ms unit |
ktownsend | 0:4c3097c65247 | 37 | gap_conn_params.max_conn_interval = msec_to_1_25msec(CFG_GAP_CONNECTION_MAX_INTERVAL_MS) ; // in 1.25ms unit |
ktownsend | 0:4c3097c65247 | 38 | gap_conn_params.slave_latency = CFG_GAP_CONNECTION_SLAVE_LATENCY ; |
ktownsend | 0:4c3097c65247 | 39 | gap_conn_params.conn_sup_timeout = CFG_GAP_CONNECTION_SUPERVISION_TIMEOUT_MS / 10 ; // in 10ms unit |
ktownsend | 0:4c3097c65247 | 40 | |
ktownsend | 0:4c3097c65247 | 41 | ble_gap_conn_sec_mode_t sec_mode; |
ktownsend | 0:4c3097c65247 | 42 | BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); // no security is needed |
ktownsend | 0:4c3097c65247 | 43 | |
ktownsend | 0:4c3097c65247 | 44 | ASSERT_STATUS( sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *) CFG_GAP_LOCAL_NAME, strlen(CFG_GAP_LOCAL_NAME)) ); |
ktownsend | 0:4c3097c65247 | 45 | ASSERT_STATUS( sd_ble_gap_appearance_set(CFG_GAP_APPEARANCE) ); |
ktownsend | 0:4c3097c65247 | 46 | ASSERT_STATUS( sd_ble_gap_ppcp_set(&gap_conn_params) ); |
ktownsend | 0:4c3097c65247 | 47 | ASSERT_STATUS( sd_ble_gap_tx_power_set(CFG_BLE_TX_POWER_LEVEL) ); |
ktownsend | 0:4c3097c65247 | 48 | |
ktownsend | 0:4c3097c65247 | 49 | /* Connection Parameters */ |
ktownsend | 0:4c3097c65247 | 50 | enum { |
ktownsend | 0:4c3097c65247 | 51 | FIRST_UPDATE_DELAY = APP_TIMER_TICKS(5000, CFG_TIMER_PRESCALER), |
ktownsend | 0:4c3097c65247 | 52 | NEXT_UPDATE_DELAY = APP_TIMER_TICKS(5000, CFG_TIMER_PRESCALER), |
ktownsend | 0:4c3097c65247 | 53 | MAX_UPDATE_COUNT = 3 |
ktownsend | 0:4c3097c65247 | 54 | }; |
ktownsend | 0:4c3097c65247 | 55 | |
ktownsend | 0:4c3097c65247 | 56 | ble_conn_params_init_t cp_init = { 0 }; |
ktownsend | 0:4c3097c65247 | 57 | |
ktownsend | 0:4c3097c65247 | 58 | cp_init.p_conn_params = NULL ; |
ktownsend | 0:4c3097c65247 | 59 | cp_init.first_conn_params_update_delay = FIRST_UPDATE_DELAY ; |
ktownsend | 0:4c3097c65247 | 60 | cp_init.next_conn_params_update_delay = NEXT_UPDATE_DELAY ; |
ktownsend | 0:4c3097c65247 | 61 | cp_init.max_conn_params_update_count = MAX_UPDATE_COUNT ; |
ktownsend | 0:4c3097c65247 | 62 | cp_init.start_on_notify_cccd_handle = BLE_GATT_HANDLE_INVALID ; |
ktownsend | 0:4c3097c65247 | 63 | cp_init.disconnect_on_fail = true ; |
ktownsend | 0:4c3097c65247 | 64 | cp_init.evt_handler = NULL ; |
ktownsend | 0:4c3097c65247 | 65 | cp_init.error_handler = error_callback; |
ktownsend | 0:4c3097c65247 | 66 | |
ktownsend | 0:4c3097c65247 | 67 | ASSERT_STATUS ( ble_conn_params_init(&cp_init) ); |
ktownsend | 0:4c3097c65247 | 68 | |
ktownsend | 0:4c3097c65247 | 69 | return ERROR_NONE; |
ktownsend | 0:4c3097c65247 | 70 | } |
ktownsend | 0:4c3097c65247 | 71 | |
ktownsend | 0:4c3097c65247 | 72 | /**************************************************************************/ |
ktownsend | 0:4c3097c65247 | 73 | /*! |
ktownsend | 0:4c3097c65247 | 74 | @brief Converts msecs to an integer representing 1.25ms units |
ktownsend | 0:4c3097c65247 | 75 | |
ktownsend | 0:4c3097c65247 | 76 | @param[in] ms |
ktownsend | 0:4c3097c65247 | 77 | The number of milliseconds to conver to 1.25ms units |
ktownsend | 0:4c3097c65247 | 78 | |
ktownsend | 0:4c3097c65247 | 79 | @returns The number of 1.25ms units in the supplied number of ms |
ktownsend | 0:4c3097c65247 | 80 | */ |
ktownsend | 0:4c3097c65247 | 81 | /**************************************************************************/ |
ktownsend | 0:4c3097c65247 | 82 | static inline uint32_t msec_to_1_25msec(uint32_t interval_ms) |
ktownsend | 0:4c3097c65247 | 83 | { |
ktownsend | 0:4c3097c65247 | 84 | return (interval_ms * 4) / 5 ; |
ktownsend | 0:4c3097c65247 | 85 | } |
ktownsend | 0:4c3097c65247 | 86 | |
ktownsend | 0:4c3097c65247 | 87 | static void error_callback(uint32_t nrf_error) |
ktownsend | 0:4c3097c65247 | 88 | { |
ktownsend | 0:4c3097c65247 | 89 | ASSERT_STATUS_RET_VOID( nrf_error ); |
ktownsend | 0:4c3097c65247 | 90 | } |