ghz 2000 / nRF51822_BLE_UART_HRM1017

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 
00023 /**
00024  * The singleton which represents the nRF51822 transport for the BLEDevice.
00025  */
00026 static nRF51822n deviceInstance;
00027 
00028 /**
00029  * BLE-API requires an implementation of the following function in order to
00030  * obtain its transport handle.
00031  */
00032 BLEDeviceInstanceBase *
00033 createBLEDeviceInstance(void)
00034 {
00035     return (&deviceInstance);
00036 }
00037 
00038 /**************************************************************************/
00039 /*!
00040     @brief  Constructor
00041 */
00042 /**************************************************************************/
00043 nRF51822n::nRF51822n(void)
00044 {
00045 }
00046 
00047 /**************************************************************************/
00048 /*!
00049     @brief  Destructor
00050 */
00051 /**************************************************************************/
00052 nRF51822n::~nRF51822n(void)
00053 {
00054 }
00055 
00056 /**************************************************************************/
00057 /*!
00058     @brief  Initialises anything required to start using BLE
00059 
00060     @returns    ble_error_t
00061 
00062     @retval     BLE_ERROR_NONE
00063                 Everything executed properly
00064 
00065     @section EXAMPLE
00066 
00067     @code
00068 
00069     @endcode
00070 */
00071 /**************************************************************************/
00072 ble_error_t nRF51822n::init(void)
00073 {
00074     /* ToDo: Clear memory contents, reset the SD, etc. */
00075     btle_init();
00076 
00077     reset();
00078 
00079     return BLE_ERROR_NONE;
00080 }
00081 
00082 /**************************************************************************/
00083 /*!
00084     @brief  Resets the BLE HW, removing any existing services and
00085             characteristics
00086 
00087     @returns    ble_error_t
00088 
00089     @retval     BLE_ERROR_NONE
00090                 Everything executed properly
00091 
00092     @section EXAMPLE
00093 
00094     @code
00095 
00096     @endcode
00097 */
00098 /**************************************************************************/
00099 ble_error_t nRF51822n::reset(void)
00100 {
00101     wait(0.5);
00102 
00103     /* Wait for the radio to come back up */
00104     wait(1);
00105 
00106     return BLE_ERROR_NONE;
00107 }
00108 
00109 void
00110 nRF51822n::waitForEvent(void)
00111 {
00112     sd_app_evt_wait();
00113 }