/ 11111

Fork of nRF51822 by Nordic Semiconductor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers nRF51822n.cpp Source File

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 BLE.
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 BLEInstanceBase *
00036 createBLEInstance(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 ble_error_t nRF51822n::init(void)
00075 {
00076     /* ToDo: Clear memory contents, reset the SD, etc. */
00077     btle_init();
00078 
00079     return BLE_ERROR_NONE;
00080 }
00081 
00082 ble_error_t nRF51822n::shutdown(void)
00083 {
00084     return (softdevice_handler_sd_disable() == NRF_SUCCESS) ? BLE_ERROR_NONE : BLE_STACK_BUSY;
00085 }
00086 
00087 void
00088 nRF51822n::waitForEvent(void)
00089 {
00090     sd_app_evt_wait();
00091 }