SG RFID nRF51822 fork
Fork of nRF51822 by
Embed:
(wiki syntax)
Show/hide line numbers
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[10]; 00052 static bool versionFetched = false; 00053 00054 if (!versionFetched) { 00055 ble_version_t version; 00056 if (sd_ble_version_get(&version) == NRF_SUCCESS) { 00057 snprintf(versionString, sizeof(versionString), "%u.%u", version.version_number, version.subversion_number); 00058 versionFetched = true; 00059 } else { 00060 strncpy(versionString, "unknown", sizeof(versionString)); 00061 } 00062 } 00063 00064 return versionString; 00065 } 00066 00067 /* (Valid values are -40, -20, -16, -12, -8, -4, 0, 4) */ 00068 ble_error_t nRF51822n::setTxPower(int8_t txPower) 00069 { 00070 unsigned rc; 00071 if ((rc = sd_ble_gap_tx_power_set(txPower)) != NRF_SUCCESS) { 00072 switch (rc) { 00073 case NRF_ERROR_BUSY: 00074 return BLE_STACK_BUSY; 00075 case NRF_ERROR_INVALID_PARAM: 00076 default: 00077 return BLE_ERROR_PARAM_OUT_OF_RANGE; 00078 } 00079 } 00080 00081 return BLE_ERROR_NONE; 00082 } 00083 00084 void nRF51822n::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP) 00085 { 00086 static const int8_t permittedTxValues[] = { 00087 -40, -30, -20, -16, -12, -8, -4, 0, 4 00088 }; 00089 00090 *valueArrayPP = permittedTxValues; 00091 *countP = sizeof(permittedTxValues) / sizeof(int8_t); 00092 } 00093 00094 ble_error_t nRF51822n::init(void) 00095 { 00096 /* ToDo: Clear memory contents, reset the SD, etc. */ 00097 btle_init(); 00098 00099 reset(); 00100 00101 return BLE_ERROR_NONE; 00102 } 00103 00104 ble_error_t nRF51822n::shutdown(void) 00105 { 00106 return (softdevice_handler_sd_disable() == NRF_SUCCESS) ? BLE_ERROR_NONE : BLE_STACK_BUSY; 00107 } 00108 00109 ble_error_t nRF51822n::reset(void) 00110 { 00111 nrf_delay_us(500000); 00112 00113 /* Wait for the radio to come back up */ 00114 nrf_delay_us(1000000); 00115 00116 return BLE_ERROR_NONE; 00117 } 00118 00119 void 00120 nRF51822n::waitForEvent(void) 00121 { 00122 sd_app_evt_wait(); 00123 }
Generated on Tue Jul 12 2022 15:07:44 by 1.7.2