A speedtest

Dependencies:   aconno_SEGGER_RTT CustomService

Committer:
jurica238814
Date:
Fri Aug 25 06:53:07 2017 +0000
Branch:
TestBranch
Revision:
2:84d964276266
Parent:
1:8fd903e4bcef
Child:
4:de5cf6b1e96b
New branch (test)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jurica238814 0:796985b808bc 1 /* Copyright (c) 2016 Aconno. All Rights Reserved.
jurica238814 0:796985b808bc 2 *
jurica238814 0:796985b808bc 3 * Licensees are granted free, non-transferable use of the information. NO
jurica238814 0:796985b808bc 4 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
jurica238814 0:796985b808bc 5 * the file.
jurica238814 0:796985b808bc 6 *
jurica238814 0:796985b808bc 7 */
jurica238814 0:796985b808bc 8
jurica238814 0:796985b808bc 9 #include "mbed.h"
jurica238814 0:796985b808bc 10 #include "acd52832_bsp.h"
jurica238814 2:84d964276266 11 #include "ble/BLE.h"
jurica238814 2:84d964276266 12 #include "GapAdvertisingData.h"
jurica238814 0:796985b808bc 13
jurica238814 2:84d964276266 14 #define USE_PWM (0)
jurica238814 2:84d964276266 15 #define USE_BLE (1)
jurica238814 2:84d964276266 16
jurica238814 2:84d964276266 17 #if USE_BLE
jurica238814 2:84d964276266 18 BLE &ble = BLE::Instance();
jurica238814 2:84d964276266 19 #endif
jurica238814 2:84d964276266 20
jurica238814 2:84d964276266 21 Ticker WakeSleepT;
jurica238814 2:84d964276266 22 Ticker turnBuzzOffT;
jurica238814 2:84d964276266 23 Ticker sleepChanger;
jurica238814 2:84d964276266 24 #if USE_PWM
jurica238814 2:84d964276266 25 PwmOut buzzer(p31);
jurica238814 2:84d964276266 26 #endif
jurica238814 0:796985b808bc 27
jurica238814 2:84d964276266 28 #if USE_BLE
jurica238814 2:84d964276266 29 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params){
jurica238814 2:84d964276266 30 BLE& ble = params->ble;
jurica238814 2:84d964276266 31 /* Ensure that it is the default instance of BLE */
jurica238814 2:84d964276266 32 if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
jurica238814 2:84d964276266 33 return;
jurica238814 2:84d964276266 34 }
jurica238814 2:84d964276266 35 uint8_t MSD = 0x23;
jurica238814 2:84d964276266 36 /* setup advertising */
jurica238814 2:84d964276266 37 ble.gap().setAdvertisingInterval(100); // --> Has to be at least 100ms!
jurica238814 2:84d964276266 38 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, &MSD, 1);
jurica238814 2:84d964276266 39 ble.gap().stopAdvertising();
jurica238814 2:84d964276266 40 }
jurica238814 2:84d964276266 41 #endif
jurica238814 2:84d964276266 42
jurica238814 0:796985b808bc 43
jurica238814 0:796985b808bc 44 int main(){
jurica238814 2:84d964276266 45 #if USE_BLE
jurica238814 2:84d964276266 46 ble.init(bleInitComplete);
jurica238814 2:84d964276266 47 /* SpinWait for initialization to complete. This is necessary because the BLE object is used in the main loop below. */
jurica238814 2:84d964276266 48 while (ble.hasInitialized() == false){}
jurica238814 2:84d964276266 49 #endif
jurica238814 2:84d964276266 50
jurica238814 2:84d964276266 51 #if USE_PWM
jurica238814 2:84d964276266 52 buzzer.period(0.0F);
jurica238814 2:84d964276266 53 buzzer.write(0.0F);
jurica238814 2:84d964276266 54 #endif
jurica238814 2:84d964276266 55
jurica238814 2:84d964276266 56 /*
jurica238814 2:84d964276266 57 // Disconnect and stop PWM0
jurica238814 2:84d964276266 58 NRF_PWM0->PSEL.OUT[0] = 0x80000000;
jurica238814 2:84d964276266 59 NRF_PWM0->PSEL.OUT[1] = 0x80000000;
jurica238814 2:84d964276266 60 NRF_PWM0->PSEL.OUT[2] = 0x80000000;
jurica238814 2:84d964276266 61 NRF_PWM0->PSEL.OUT[3] = 0x80000000;
jurica238814 2:84d964276266 62 NRF_PWM0->TASKS_STOP = 1;
jurica238814 2:84d964276266 63 */
jurica238814 2:84d964276266 64
jurica238814 2:84d964276266 65 // Disconnect and stop PWM1
jurica238814 2:84d964276266 66 NRF_PWM1->PSEL.OUT[0] = 0x80000000;
jurica238814 2:84d964276266 67 NRF_PWM1->PSEL.OUT[1] = 0x80000000;
jurica238814 2:84d964276266 68 NRF_PWM1->PSEL.OUT[2] = 0x80000000;
jurica238814 2:84d964276266 69 NRF_PWM1->PSEL.OUT[3] = 0x80000000;
jurica238814 2:84d964276266 70 NRF_PWM1->TASKS_STOP = 1;
jurica238814 2:84d964276266 71
jurica238814 2:84d964276266 72 // Disconnect and stop PWM2
jurica238814 2:84d964276266 73 NRF_PWM2->PSEL.OUT[0] = 0x80000000;
jurica238814 2:84d964276266 74 NRF_PWM2->PSEL.OUT[1] = 0x80000000;
jurica238814 2:84d964276266 75 NRF_PWM2->PSEL.OUT[2] = 0x80000000;
jurica238814 2:84d964276266 76 NRF_PWM2->PSEL.OUT[3] = 0x80000000;
jurica238814 2:84d964276266 77 NRF_PWM2->TASKS_STOP = 1;
jurica238814 2:84d964276266 78
jurica238814 2:84d964276266 79 NRF_CLOCK->TASKS_LFCLKSTART = 1;
jurica238814 2:84d964276266 80 while(!NRF_CLOCK->EVENTS_LFCLKSTARTED);
jurica238814 2:84d964276266 81 NRF_CLOCK->TASKS_HFCLKSTOP;
jurica238814 2:84d964276266 82 NRF_POWER->TASKS_LOWPWR = 0x00000001;
jurica238814 2:84d964276266 83
jurica238814 0:796985b808bc 84 while(1){
jurica238814 2:84d964276266 85 #if USE_BLE
jurica238814 2:84d964276266 86 ble.waitForEvent();
jurica238814 2:84d964276266 87 #endif
jurica238814 2:84d964276266 88 __WFI();
jurica238814 0:796985b808bc 89 }
jurica238814 0:796985b808bc 90 }