Nordic stack and drivers for the mbed BLE API

Dependents:   idd_hw5_bleFanProto

Fork of nRF51822 by Nordic Semiconductor

Committer:
Rohit Grover
Date:
Mon Jun 09 09:12:10 2014 +0100
Revision:
22:c6ee8136847e
Parent:
16:d8161e2af6c6
Child:
23:cdab28442479
slowly switching to astyle code formatting as recommended by the team

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 22:c6ee8136847e 19
Rohit Grover 22:c6ee8136847e 20 #include "btle/btle.h"
Rohit Grover 22:c6ee8136847e 21
Rohit Grover 22:c6ee8136847e 22 /**
Rohit Grover 22:c6ee8136847e 23 * The singleton which represents the nRF51822 transport for the BLEDevice.
Rohit Grover 22:c6ee8136847e 24 */
Rohit Grover 22:c6ee8136847e 25 static nRF51822n deviceInstance;
Rohit Grover 22:c6ee8136847e 26
Rohit Grover 22:c6ee8136847e 27 /**
Rohit Grover 22:c6ee8136847e 28 * BLE-API requires an implementation of the following function in order to
Rohit Grover 22:c6ee8136847e 29 * obtain its transport handle.
Rohit Grover 22:c6ee8136847e 30 */
Rohit Grover 22:c6ee8136847e 31 BLEDeviceInstanceBase *
Rohit Grover 22:c6ee8136847e 32 createBLEDeviceInstance(void)
Rohit Grover 22:c6ee8136847e 33 {
Rohit Grover 22:c6ee8136847e 34 return (&deviceInstance);
Rohit Grover 22:c6ee8136847e 35 }
Rohit Grover 22:c6ee8136847e 36
Rohit Grover 22:c6ee8136847e 37 /**************************************************************************/
Rohit Grover 22:c6ee8136847e 38 /*!
Rohit Grover 22:c6ee8136847e 39 @brief Constructor
Rohit Grover 22:c6ee8136847e 40 */
Rohit Grover 22:c6ee8136847e 41 /**************************************************************************/
Rohit Grover 22:c6ee8136847e 42 nRF51822n::nRF51822n(void)
Rohit Grover 22:c6ee8136847e 43 {
Rohit Grover 22:c6ee8136847e 44 }
Rohit Grover 22:c6ee8136847e 45
Rohit Grover 22:c6ee8136847e 46 /**************************************************************************/
Rohit Grover 22:c6ee8136847e 47 /*!
Rohit Grover 22:c6ee8136847e 48 @brief Destructor
Rohit Grover 22:c6ee8136847e 49 */
Rohit Grover 22:c6ee8136847e 50 /**************************************************************************/
Rohit Grover 22:c6ee8136847e 51 nRF51822n::~nRF51822n(void)
Rohit Grover 22:c6ee8136847e 52 {
Rohit Grover 22:c6ee8136847e 53 }
Rohit Grover 22:c6ee8136847e 54
Rohit Grover 22:c6ee8136847e 55 /**************************************************************************/
Rohit Grover 22:c6ee8136847e 56 /*!
Rohit Grover 22:c6ee8136847e 57 @brief Initialises anything required to start using BLE
Rohit Grover 22:c6ee8136847e 58
Rohit Grover 22:c6ee8136847e 59 @returns ble_error_t
Rohit Grover 22:c6ee8136847e 60
Rohit Grover 22:c6ee8136847e 61 @retval BLE_ERROR_NONE
Rohit Grover 22:c6ee8136847e 62 Everything executed properly
Rohit Grover 22:c6ee8136847e 63
Rohit Grover 22:c6ee8136847e 64 @section EXAMPLE
Rohit Grover 22:c6ee8136847e 65
Rohit Grover 22:c6ee8136847e 66 @code
Rohit Grover 22:c6ee8136847e 67
Rohit Grover 22:c6ee8136847e 68 @endcode
Rohit Grover 22:c6ee8136847e 69 */
Rohit Grover 22:c6ee8136847e 70 /**************************************************************************/
Rohit Grover 22:c6ee8136847e 71 ble_error_t nRF51822n::init(void)
Rohit Grover 22:c6ee8136847e 72 {
Rohit Grover 22:c6ee8136847e 73 /* ToDo: Clear memory contents, reset the SD, etc. */
Rohit Grover 22:c6ee8136847e 74 btle_init();
Rohit Grover 22:c6ee8136847e 75
Rohit Grover 22:c6ee8136847e 76 reset();
Rohit Grover 22:c6ee8136847e 77
Rohit Grover 22:c6ee8136847e 78 return BLE_ERROR_NONE;
Rohit Grover 22:c6ee8136847e 79 }
Rohit Grover 22:c6ee8136847e 80
Rohit Grover 22:c6ee8136847e 81 /**************************************************************************/
Rohit Grover 22:c6ee8136847e 82 /*!
Rohit Grover 22:c6ee8136847e 83 @brief Resets the BLE HW, removing any existing services and
Rohit Grover 22:c6ee8136847e 84 characteristics
Rohit Grover 22:c6ee8136847e 85
Rohit Grover 22:c6ee8136847e 86 @returns ble_error_t
Rohit Grover 22:c6ee8136847e 87
Rohit Grover 22:c6ee8136847e 88 @retval BLE_ERROR_NONE
Rohit Grover 22:c6ee8136847e 89 Everything executed properly
Rohit Grover 22:c6ee8136847e 90
Rohit Grover 22:c6ee8136847e 91 @section EXAMPLE
Rohit Grover 22:c6ee8136847e 92
Rohit Grover 22:c6ee8136847e 93 @code
Rohit Grover 22:c6ee8136847e 94
Rohit Grover 22:c6ee8136847e 95 @endcode
Rohit Grover 22:c6ee8136847e 96 */
Rohit Grover 22:c6ee8136847e 97 /**************************************************************************/
Rohit Grover 22:c6ee8136847e 98 ble_error_t nRF51822n::reset(void)
Rohit Grover 22:c6ee8136847e 99 {
Rohit Grover 22:c6ee8136847e 100 wait(0.5);
Rohit Grover 22:c6ee8136847e 101
Rohit Grover 22:c6ee8136847e 102 /* Wait for the radio to come back up */
Rohit Grover 22:c6ee8136847e 103 wait(1);
Rohit Grover 22:c6ee8136847e 104
Rohit Grover 22:c6ee8136847e 105 return BLE_ERROR_NONE;
Rohit Grover 22:c6ee8136847e 106 }