Patched version of nrf51822 FOTA compatible driver, with GPTIO disabled, as it clashed with the mbed definitions...

Fork of nRF51822 by Nordic Semiconductor

Committer:
rgrover1
Date:
Wed Dec 03 14:33:28 2014 +0000
Revision:
80:cdcc094ab166
Parent:
79:540d11f2764f
Child:
96:f98c65780f4a
Synchronized with git rev 5c80717d
Author: Rohit Grover
add support for shutdown().
This API allows for the GATT/GAP state to be purged.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rohit Grover 22:c6ee8136847e 1 /* mbed Microcontroller Library
Rohit Grover 22:c6ee8136847e 2 * Copyright (c) 2006-2013 ARM Limited
Rohit Grover 22:c6ee8136847e 3 *
Rohit Grover 22:c6ee8136847e 4 * Licensed under the Apache License, Version 2.0 (the "License");
Rohit Grover 22:c6ee8136847e 5 * you may not use this file except in compliance with the License.
Rohit Grover 22:c6ee8136847e 6 * You may obtain a copy of the License at
Rohit Grover 22:c6ee8136847e 7 *
Rohit Grover 22:c6ee8136847e 8 * http://www.apache.org/licenses/LICENSE-2.0
Rohit Grover 22:c6ee8136847e 9 *
Rohit Grover 22:c6ee8136847e 10 * Unless required by applicable law or agreed to in writing, software
Rohit Grover 22:c6ee8136847e 11 * distributed under the License is distributed on an "AS IS" BASIS,
Rohit Grover 22:c6ee8136847e 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Rohit Grover 22:c6ee8136847e 13 * See the License for the specific language governing permissions and
Rohit Grover 22:c6ee8136847e 14 * limitations under the License.
Rohit Grover 22:c6ee8136847e 15 */
Rohit Grover 22:c6ee8136847e 16
Rohit Grover 22:c6ee8136847e 17 #include "mbed.h"
Rohit Grover 22:c6ee8136847e 18 #include "nRF51822n.h"
Rohit Grover 23:cdab28442479 19 #include "nrf_soc.h"
Rohit Grover 22:c6ee8136847e 20
Rohit Grover 22:c6ee8136847e 21 #include "btle/btle.h"
Rohit Grover 56:a1071b629aa3 22 #include "nrf_delay.h"
Rohit Grover 22:c6ee8136847e 23
rgrover1 80:cdcc094ab166 24 #include "softdevice_handler.h"
rgrover1 80:cdcc094ab166 25
Rohit Grover 22:c6ee8136847e 26 /**
Rohit Grover 22:c6ee8136847e 27 * The singleton which represents the nRF51822 transport for the BLEDevice.
Rohit Grover 22:c6ee8136847e 28 */
Rohit Grover 25:a1c356620131 29 static nRF51822n deviceInstance;
Rohit Grover 22:c6ee8136847e 30
Rohit Grover 22:c6ee8136847e 31 /**
Rohit Grover 22:c6ee8136847e 32 * BLE-API requires an implementation of the following function in order to
Rohit Grover 22:c6ee8136847e 33 * obtain its transport handle.
Rohit Grover 22:c6ee8136847e 34 */
Rohit Grover 25:a1c356620131 35 BLEDeviceInstanceBase *
Rohit Grover 25:a1c356620131 36 createBLEDeviceInstance(void)
Rohit Grover 22:c6ee8136847e 37 {
Rohit Grover 25:a1c356620131 38 return (&deviceInstance);
Rohit Grover 22:c6ee8136847e 39 }
Rohit Grover 22:c6ee8136847e 40
Rohit Grover 22:c6ee8136847e 41 nRF51822n::nRF51822n(void)
Rohit Grover 22:c6ee8136847e 42 {
Rohit Grover 22:c6ee8136847e 43 }
Rohit Grover 22:c6ee8136847e 44
Rohit Grover 22:c6ee8136847e 45 nRF51822n::~nRF51822n(void)
Rohit Grover 22:c6ee8136847e 46 {
Rohit Grover 22:c6ee8136847e 47 }
Rohit Grover 22:c6ee8136847e 48
Rohit Grover 52:120bd37b9d0d 49 const char *nRF51822n::getVersion(void)
Rohit Grover 52:120bd37b9d0d 50 {
Rohit Grover 52:120bd37b9d0d 51 static char versionString[10];
Rohit Grover 52:120bd37b9d0d 52 static bool versionFetched = false;
Rohit Grover 52:120bd37b9d0d 53
Rohit Grover 52:120bd37b9d0d 54 if (!versionFetched) {
Rohit Grover 52:120bd37b9d0d 55 ble_version_t version;
Rohit Grover 52:120bd37b9d0d 56 if (sd_ble_version_get(&version) == NRF_SUCCESS) {
Rohit Grover 52:120bd37b9d0d 57 snprintf(versionString, sizeof(versionString), "%u.%u", version.version_number, version.subversion_number);
Rohit Grover 52:120bd37b9d0d 58 versionFetched = true;
Rohit Grover 52:120bd37b9d0d 59 } else {
Rohit Grover 52:120bd37b9d0d 60 strncpy(versionString, "unknown", sizeof(versionString));
Rohit Grover 52:120bd37b9d0d 61 }
Rohit Grover 52:120bd37b9d0d 62 }
Rohit Grover 52:120bd37b9d0d 63
Rohit Grover 52:120bd37b9d0d 64 return versionString;
Rohit Grover 52:120bd37b9d0d 65 }
Rohit Grover 52:120bd37b9d0d 66
Rohit Grover 52:120bd37b9d0d 67 /* (Valid values are -40, -20, -16, -12, -8, -4, 0, 4) */
Rohit Grover 52:120bd37b9d0d 68 ble_error_t nRF51822n::setTxPower(int8_t txPower)
Rohit Grover 52:120bd37b9d0d 69 {
Rohit Grover 52:120bd37b9d0d 70 unsigned rc;
Rohit Grover 52:120bd37b9d0d 71 if ((rc = sd_ble_gap_tx_power_set(txPower)) != NRF_SUCCESS) {
Rohit Grover 52:120bd37b9d0d 72 switch (rc) {
Rohit Grover 52:120bd37b9d0d 73 case NRF_ERROR_BUSY:
Rohit Grover 52:120bd37b9d0d 74 return BLE_STACK_BUSY;
Rohit Grover 52:120bd37b9d0d 75 case NRF_ERROR_INVALID_PARAM:
Rohit Grover 52:120bd37b9d0d 76 default:
Rohit Grover 52:120bd37b9d0d 77 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Rohit Grover 52:120bd37b9d0d 78 }
Rohit Grover 52:120bd37b9d0d 79 }
Rohit Grover 52:120bd37b9d0d 80
Rohit Grover 52:120bd37b9d0d 81 return BLE_ERROR_NONE;
Rohit Grover 52:120bd37b9d0d 82 }
Rohit Grover 52:120bd37b9d0d 83
Rohit Grover 22:c6ee8136847e 84 ble_error_t nRF51822n::init(void)
Rohit Grover 22:c6ee8136847e 85 {
Rohit Grover 22:c6ee8136847e 86 /* ToDo: Clear memory contents, reset the SD, etc. */
Rohit Grover 22:c6ee8136847e 87 btle_init();
Rohit Grover 22:c6ee8136847e 88
Rohit Grover 22:c6ee8136847e 89 reset();
Rohit Grover 22:c6ee8136847e 90
Rohit Grover 22:c6ee8136847e 91 return BLE_ERROR_NONE;
Rohit Grover 22:c6ee8136847e 92 }
Rohit Grover 22:c6ee8136847e 93
rgrover1 80:cdcc094ab166 94 ble_error_t nRF51822n::shutdown(void)
rgrover1 80:cdcc094ab166 95 {
rgrover1 80:cdcc094ab166 96 return (softdevice_handler_sd_disable() == NRF_SUCCESS) ? BLE_ERROR_NONE : BLE_STACK_BUSY;
rgrover1 80:cdcc094ab166 97 }
rgrover1 80:cdcc094ab166 98
Rohit Grover 22:c6ee8136847e 99 ble_error_t nRF51822n::reset(void)
Rohit Grover 22:c6ee8136847e 100 {
Rohit Grover 56:a1071b629aa3 101 nrf_delay_us(500000);
Rohit Grover 22:c6ee8136847e 102
Rohit Grover 22:c6ee8136847e 103 /* Wait for the radio to come back up */
Rohit Grover 56:a1071b629aa3 104 nrf_delay_us(1000000);
Rohit Grover 22:c6ee8136847e 105
Rohit Grover 22:c6ee8136847e 106 return BLE_ERROR_NONE;
Rohit Grover 22:c6ee8136847e 107 }
Rohit Grover 23:cdab28442479 108
Rohit Grover 23:cdab28442479 109 void
Rohit Grover 23:cdab28442479 110 nRF51822n::waitForEvent(void)
Rohit Grover 23:cdab28442479 111 {
Rohit Grover 23:cdab28442479 112 sd_app_evt_wait();
rgrover1 79:540d11f2764f 113 }