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
nRF51822n.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 00017 #include "mbed.h" 00018 #include "nRF51822n.h" 00019 #include "nrf_soc.h" 00020 00021 #include "btle/btle.h" 00022 #include "nrf_delay.h" 00023 00024 #include "softdevice_handler.h " 00025 00026 /** 00027 * The singleton which represents the nRF51822 transport for the BLEDevice. 00028 */ 00029 static nRF51822n deviceInstance; 00030 00031 /** 00032 * BLE-API requires an implementation of the following function in order to 00033 * obtain its transport handle. 00034 */ 00035 BLEDeviceInstanceBase * 00036 createBLEDeviceInstance(void) 00037 { 00038 return (&deviceInstance); 00039 } 00040 00041 nRF51822n::nRF51822n(void) 00042 { 00043 } 00044 00045 nRF51822n::~nRF51822n(void) 00046 { 00047 } 00048 00049 const char *nRF51822n::getVersion(void) 00050 { 00051 static char versionString[32]; 00052 static bool versionFetched = false; 00053 00054 if (!versionFetched) { 00055 ble_version_t version; 00056 if ((sd_ble_version_get(&version) == NRF_SUCCESS) && (version.company_id == 0x0059)) { 00057 switch (version.version_number) { 00058 case 0x07: 00059 snprintf(versionString, sizeof(versionString), "Nordic BLE4.1 fw:%04x", version.subversion_number); 00060 break; 00061 default: 00062 snprintf(versionString, sizeof(versionString), "Nordic (spec unknown) fw:%04x", version.subversion_number); 00063 break; 00064 } 00065 versionFetched = true; 00066 } else { 00067 strncpy(versionString, "unknown", sizeof(versionString)); 00068 } 00069 } 00070 00071 return versionString; 00072 } 00073 00074 /* (Valid values are -40, -20, -16, -12, -8, -4, 0, 4) */ 00075 ble_error_t nRF51822n::setTxPower(int8_t txPower) 00076 { 00077 unsigned rc; 00078 if ((rc = sd_ble_gap_tx_power_set(txPower)) != NRF_SUCCESS) { 00079 switch (rc) { 00080 case NRF_ERROR_BUSY: 00081 return BLE_STACK_BUSY; 00082 case NRF_ERROR_INVALID_PARAM: 00083 default: 00084 return BLE_ERROR_PARAM_OUT_OF_RANGE; 00085 } 00086 } 00087 00088 return BLE_ERROR_NONE; 00089 } 00090 00091 void nRF51822n::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP) 00092 { 00093 static const int8_t permittedTxValues[] = { 00094 -40, -30, -20, -16, -12, -8, -4, 0, 4 00095 }; 00096 00097 *valueArrayPP = permittedTxValues; 00098 *countP = sizeof(permittedTxValues) / sizeof(int8_t); 00099 } 00100 00101 ble_error_t nRF51822n::init(void) 00102 { 00103 /* ToDo: Clear memory contents, reset the SD, etc. */ 00104 btle_init(); 00105 00106 reset(); 00107 00108 return BLE_ERROR_NONE; 00109 } 00110 00111 ble_error_t nRF51822n::shutdown(void) 00112 { 00113 return (softdevice_handler_sd_disable() == NRF_SUCCESS) ? BLE_ERROR_NONE : BLE_STACK_BUSY; 00114 } 00115 00116 ble_error_t nRF51822n::reset(void) 00117 { 00118 nrf_delay_us(500000); 00119 00120 /* Wait for the radio to come back up */ 00121 nrf_delay_us(1000000); 00122 00123 return BLE_ERROR_NONE; 00124 } 00125 00126 void 00127 nRF51822n::waitForEvent(void) 00128 { 00129 sd_app_evt_wait(); 00130 }
Generated on Tue Jul 12 2022 19:22:46 by
1.7.2
