Encryp_u

Dependencies:   BLE_API_Encryp CyaSSL-Encryp eMPL_MPU6050 mbed

Fork of Encryptulator2 by Mobius IoT

Committer:
yihui
Date:
Wed Apr 22 07:47:17 2015 +0000
Revision:
1:fc2f9d636751
update libraries; ; delete nRF51822/nordic-sdk/components/gpiote/app_gpiote.c to solve GPIOTE_IRQHandler multiply defined issue. temperarily change nRF51822 library to folder

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 1:fc2f9d636751 1 /* mbed Microcontroller Library
yihui 1:fc2f9d636751 2 * Copyright (c) 2006-2013 ARM Limited
yihui 1:fc2f9d636751 3 *
yihui 1:fc2f9d636751 4 * Licensed under the Apache License, Version 2.0 (the "License");
yihui 1:fc2f9d636751 5 * you may not use this file except in compliance with the License.
yihui 1:fc2f9d636751 6 * You may obtain a copy of the License at
yihui 1:fc2f9d636751 7 *
yihui 1:fc2f9d636751 8 * http://www.apache.org/licenses/LICENSE-2.0
yihui 1:fc2f9d636751 9 *
yihui 1:fc2f9d636751 10 * Unless required by applicable law or agreed to in writing, software
yihui 1:fc2f9d636751 11 * distributed under the License is distributed on an "AS IS" BASIS,
yihui 1:fc2f9d636751 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
yihui 1:fc2f9d636751 13 * See the License for the specific language governing permissions and
yihui 1:fc2f9d636751 14 * limitations under the License.
yihui 1:fc2f9d636751 15 */
yihui 1:fc2f9d636751 16
yihui 1:fc2f9d636751 17 #include "mbed.h"
yihui 1:fc2f9d636751 18 #include "nRF51822n.h"
yihui 1:fc2f9d636751 19 #include "nrf_soc.h"
yihui 1:fc2f9d636751 20
yihui 1:fc2f9d636751 21 #include "btle/btle.h"
yihui 1:fc2f9d636751 22 #include "nrf_delay.h"
yihui 1:fc2f9d636751 23
yihui 1:fc2f9d636751 24 #include "softdevice_handler.h"
yihui 1:fc2f9d636751 25
yihui 1:fc2f9d636751 26 /**
yihui 1:fc2f9d636751 27 * The singleton which represents the nRF51822 transport for the BLEDevice.
yihui 1:fc2f9d636751 28 */
yihui 1:fc2f9d636751 29 static nRF51822n deviceInstance;
yihui 1:fc2f9d636751 30
yihui 1:fc2f9d636751 31 /**
yihui 1:fc2f9d636751 32 * BLE-API requires an implementation of the following function in order to
yihui 1:fc2f9d636751 33 * obtain its transport handle.
yihui 1:fc2f9d636751 34 */
yihui 1:fc2f9d636751 35 BLEDeviceInstanceBase *
yihui 1:fc2f9d636751 36 createBLEDeviceInstance(void)
yihui 1:fc2f9d636751 37 {
yihui 1:fc2f9d636751 38 return (&deviceInstance);
yihui 1:fc2f9d636751 39 }
yihui 1:fc2f9d636751 40
yihui 1:fc2f9d636751 41 nRF51822n::nRF51822n(void)
yihui 1:fc2f9d636751 42 {
yihui 1:fc2f9d636751 43 }
yihui 1:fc2f9d636751 44
yihui 1:fc2f9d636751 45 nRF51822n::~nRF51822n(void)
yihui 1:fc2f9d636751 46 {
yihui 1:fc2f9d636751 47 }
yihui 1:fc2f9d636751 48
yihui 1:fc2f9d636751 49 const char *nRF51822n::getVersion(void)
yihui 1:fc2f9d636751 50 {
yihui 1:fc2f9d636751 51 static char versionString[10];
yihui 1:fc2f9d636751 52 static bool versionFetched = false;
yihui 1:fc2f9d636751 53
yihui 1:fc2f9d636751 54 if (!versionFetched) {
yihui 1:fc2f9d636751 55 ble_version_t version;
yihui 1:fc2f9d636751 56 if (sd_ble_version_get(&version) == NRF_SUCCESS) {
yihui 1:fc2f9d636751 57 snprintf(versionString, sizeof(versionString), "%u.%u", version.version_number, version.subversion_number);
yihui 1:fc2f9d636751 58 versionFetched = true;
yihui 1:fc2f9d636751 59 } else {
yihui 1:fc2f9d636751 60 strncpy(versionString, "unknown", sizeof(versionString));
yihui 1:fc2f9d636751 61 }
yihui 1:fc2f9d636751 62 }
yihui 1:fc2f9d636751 63
yihui 1:fc2f9d636751 64 return versionString;
yihui 1:fc2f9d636751 65 }
yihui 1:fc2f9d636751 66
yihui 1:fc2f9d636751 67 /* (Valid values are -40, -20, -16, -12, -8, -4, 0, 4) */
yihui 1:fc2f9d636751 68 ble_error_t nRF51822n::setTxPower(int8_t txPower)
yihui 1:fc2f9d636751 69 {
yihui 1:fc2f9d636751 70 unsigned rc;
yihui 1:fc2f9d636751 71 if ((rc = sd_ble_gap_tx_power_set(txPower)) != NRF_SUCCESS) {
yihui 1:fc2f9d636751 72 switch (rc) {
yihui 1:fc2f9d636751 73 case NRF_ERROR_BUSY:
yihui 1:fc2f9d636751 74 return BLE_STACK_BUSY;
yihui 1:fc2f9d636751 75 case NRF_ERROR_INVALID_PARAM:
yihui 1:fc2f9d636751 76 default:
yihui 1:fc2f9d636751 77 return BLE_ERROR_PARAM_OUT_OF_RANGE;
yihui 1:fc2f9d636751 78 }
yihui 1:fc2f9d636751 79 }
yihui 1:fc2f9d636751 80
yihui 1:fc2f9d636751 81 return BLE_ERROR_NONE;
yihui 1:fc2f9d636751 82 }
yihui 1:fc2f9d636751 83
yihui 1:fc2f9d636751 84 void nRF51822n::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP)
yihui 1:fc2f9d636751 85 {
yihui 1:fc2f9d636751 86 static const int8_t permittedTxValues[] = {
yihui 1:fc2f9d636751 87 -40, -30, -20, -16, -12, -8, -4, 0, 4
yihui 1:fc2f9d636751 88 };
yihui 1:fc2f9d636751 89
yihui 1:fc2f9d636751 90 *valueArrayPP = permittedTxValues;
yihui 1:fc2f9d636751 91 *countP = sizeof(permittedTxValues) / sizeof(int8_t);
yihui 1:fc2f9d636751 92 }
yihui 1:fc2f9d636751 93
yihui 1:fc2f9d636751 94 ble_error_t nRF51822n::init(void)
yihui 1:fc2f9d636751 95 {
yihui 1:fc2f9d636751 96 /* ToDo: Clear memory contents, reset the SD, etc. */
yihui 1:fc2f9d636751 97 btle_init();
yihui 1:fc2f9d636751 98
yihui 1:fc2f9d636751 99 reset();
yihui 1:fc2f9d636751 100
yihui 1:fc2f9d636751 101 return BLE_ERROR_NONE;
yihui 1:fc2f9d636751 102 }
yihui 1:fc2f9d636751 103
yihui 1:fc2f9d636751 104 ble_error_t nRF51822n::shutdown(void)
yihui 1:fc2f9d636751 105 {
yihui 1:fc2f9d636751 106 return (softdevice_handler_sd_disable() == NRF_SUCCESS) ? BLE_ERROR_NONE : BLE_STACK_BUSY;
yihui 1:fc2f9d636751 107 }
yihui 1:fc2f9d636751 108
yihui 1:fc2f9d636751 109 ble_error_t nRF51822n::reset(void)
yihui 1:fc2f9d636751 110 {
yihui 1:fc2f9d636751 111 nrf_delay_us(500000);
yihui 1:fc2f9d636751 112
yihui 1:fc2f9d636751 113 /* Wait for the radio to come back up */
yihui 1:fc2f9d636751 114 nrf_delay_us(1000000);
yihui 1:fc2f9d636751 115
yihui 1:fc2f9d636751 116 return BLE_ERROR_NONE;
yihui 1:fc2f9d636751 117 }
yihui 1:fc2f9d636751 118
yihui 1:fc2f9d636751 119 void
yihui 1:fc2f9d636751 120 nRF51822n::waitForEvent(void)
yihui 1:fc2f9d636751 121 {
yihui 1:fc2f9d636751 122 sd_app_evt_wait();
yihui 1:fc2f9d636751 123 }