Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822
main.cpp@0:3bbe1a2f1b66, 2015-10-05 (annotated)
- Committer:
- jbru
- Date:
- Mon Oct 05 12:45:18 2015 +0000
- Revision:
- 0:3bbe1a2f1b66
- Child:
- 1:2e7bb567b396
- Child:
- 2:fb1f4bd366dc
initial commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jbru | 0:3bbe1a2f1b66 | 1 | /* |
| jbru | 0:3bbe1a2f1b66 | 2 | * Simple testcase that attempts to collect infos about the SoftDevice, and |
| jbru | 0:3bbe1a2f1b66 | 3 | * signal when there is an error. On success, should blink slowly (2s period). |
| jbru | 0:3bbe1a2f1b66 | 4 | * On failure, blink every 200ms. |
| jbru | 0:3bbe1a2f1b66 | 5 | * |
| jbru | 0:3bbe1a2f1b66 | 6 | * In addition, if VERBOSE is defined, show the following messages: |
| jbru | 0:3bbe1a2f1b66 | 7 | * |
| jbru | 0:3bbe1a2f1b66 | 8 | * For an S130 (1.0.0) Image: |
| jbru | 0:3bbe1a2f1b66 | 9 | * Firmware ID = 67 |
| jbru | 0:3bbe1a2f1b66 | 10 | * Firmware version = s130 (guessed) |
| jbru | 0:3bbe1a2f1b66 | 11 | * S110 flag = 0 |
| jbru | 0:3bbe1a2f1b66 | 12 | * (GattClient scan = success (0)) |
| jbru | 0:3bbe1a2f1b66 | 13 | * |
| jbru | 0:3bbe1a2f1b66 | 14 | * For an S110 (8.0.0) Image: |
| jbru | 0:3bbe1a2f1b66 | 15 | * Firmware ID = 64 |
| jbru | 0:3bbe1a2f1b66 | 16 | * Firmware version = s110 (guessed) |
| jbru | 0:3bbe1a2f1b66 | 17 | * S110 flag = 1 |
| jbru | 0:3bbe1a2f1b66 | 18 | * (GattClient scan = not implemented (2)) |
| jbru | 0:3bbe1a2f1b66 | 19 | * |
| jbru | 0:3bbe1a2f1b66 | 20 | * If TEST_BLE is defined, also test GattClient support. With S110, should |
| jbru | 0:3bbe1a2f1b66 | 21 | * return BLE_ERROR_NOT_IMPLEMENTED. Otherwise BLE_ERROR_NONE. |
| jbru | 0:3bbe1a2f1b66 | 22 | * |
| jbru | 0:3bbe1a2f1b66 | 23 | * A PARAM_OUT_OF_RANGE (3) error with S110 most likely means that Central |
| jbru | 0:3bbe1a2f1b66 | 24 | * features where not properly disabled. |
| jbru | 0:3bbe1a2f1b66 | 25 | * In that case, if S110 flag is 1, it means that the nRF51822 is an old version |
| jbru | 0:3bbe1a2f1b66 | 26 | * and does not recognize that flag. |
| jbru | 0:3bbe1a2f1b66 | 27 | */ |
| jbru | 0:3bbe1a2f1b66 | 28 | #define VERBOSE |
| jbru | 0:3bbe1a2f1b66 | 29 | #define TEST_BLE |
| jbru | 0:3bbe1a2f1b66 | 30 | |
| jbru | 0:3bbe1a2f1b66 | 31 | #include "mbed.h" |
| jbru | 0:3bbe1a2f1b66 | 32 | |
| jbru | 0:3bbe1a2f1b66 | 33 | #undef LED1 |
| jbru | 0:3bbe1a2f1b66 | 34 | #define LED1 p18 |
| jbru | 0:3bbe1a2f1b66 | 35 | Serial pc(p9, p11); |
| jbru | 0:3bbe1a2f1b66 | 36 | DigitalOut led1(LED1); |
| jbru | 0:3bbe1a2f1b66 | 37 | |
| jbru | 0:3bbe1a2f1b66 | 38 | /* introspection macros */ |
| jbru | 0:3bbe1a2f1b66 | 39 | #include "nrf_sdm.h" |
| jbru | 0:3bbe1a2f1b66 | 40 | |
| jbru | 0:3bbe1a2f1b66 | 41 | /* An S110 application is supposed to be built with one of those flags */ |
| jbru | 0:3bbe1a2f1b66 | 42 | #if defined(TARGET_MCU_NRF51_16K_S110) || defined(TARGET_MCU_NRF51_32K_S110) |
| jbru | 0:3bbe1a2f1b66 | 43 | # define S110_MACRO 1 |
| jbru | 0:3bbe1a2f1b66 | 44 | #else |
| jbru | 0:3bbe1a2f1b66 | 45 | # define S110_MACRO 0 |
| jbru | 0:3bbe1a2f1b66 | 46 | #endif |
| jbru | 0:3bbe1a2f1b66 | 47 | |
| jbru | 0:3bbe1a2f1b66 | 48 | #ifdef VERBOSE |
| jbru | 0:3bbe1a2f1b66 | 49 | # define PRINTF printf |
| jbru | 0:3bbe1a2f1b66 | 50 | #else |
| jbru | 0:3bbe1a2f1b66 | 51 | # define PRINTF(...) |
| jbru | 0:3bbe1a2f1b66 | 52 | #endif |
| jbru | 0:3bbe1a2f1b66 | 53 | |
| jbru | 0:3bbe1a2f1b66 | 54 | #ifdef TEST_BLE |
| jbru | 0:3bbe1a2f1b66 | 55 | # include "ble/BLE.h" |
| jbru | 0:3bbe1a2f1b66 | 56 | BLE ble; |
| jbru | 0:3bbe1a2f1b66 | 57 | |
| jbru | 0:3bbe1a2f1b66 | 58 | void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params) |
| jbru | 0:3bbe1a2f1b66 | 59 | { |
| jbru | 0:3bbe1a2f1b66 | 60 | } |
| jbru | 0:3bbe1a2f1b66 | 61 | #endif |
| jbru | 0:3bbe1a2f1b66 | 62 | |
| jbru | 0:3bbe1a2f1b66 | 63 | int main(void) |
| jbru | 0:3bbe1a2f1b66 | 64 | { |
| jbru | 0:3bbe1a2f1b66 | 65 | bool error = false; |
| jbru | 0:3bbe1a2f1b66 | 66 | uint32_t fwid = SD_FWID_GET(MBR_SIZE); |
| jbru | 0:3bbe1a2f1b66 | 67 | /* TODO: find details about the specific version (0x67 is S130 v1.0.0) */ |
| jbru | 0:3bbe1a2f1b66 | 68 | bool is_s110 = (fwid != 0x67); |
| jbru | 0:3bbe1a2f1b66 | 69 | |
| jbru | 0:3bbe1a2f1b66 | 70 | PRINTF("Firmware ID = %x\r\n", fwid); |
| jbru | 0:3bbe1a2f1b66 | 71 | PRINTF("Firmware version = %s (guessed)\r\n", (is_s110 ? "s110" : "s130")); |
| jbru | 0:3bbe1a2f1b66 | 72 | PRINTF("S110 flag = %d\r\n", S110_MACRO); |
| jbru | 0:3bbe1a2f1b66 | 73 | |
| jbru | 0:3bbe1a2f1b66 | 74 | #ifdef TEST_BLE |
| jbru | 0:3bbe1a2f1b66 | 75 | { |
| jbru | 0:3bbe1a2f1b66 | 76 | ble.init(); |
| jbru | 0:3bbe1a2f1b66 | 77 | |
| jbru | 0:3bbe1a2f1b66 | 78 | if (ble.gap().setScanParams(1000, 50) != BLE_ERROR_NONE) { |
| jbru | 0:3bbe1a2f1b66 | 79 | PRINTF("Failed to set scan parameters!\r\n"); |
| jbru | 0:3bbe1a2f1b66 | 80 | return 1; |
| jbru | 0:3bbe1a2f1b66 | 81 | } |
| jbru | 0:3bbe1a2f1b66 | 82 | |
| jbru | 0:3bbe1a2f1b66 | 83 | /* We expect startScan to return an error when we're using S110 */ |
| jbru | 0:3bbe1a2f1b66 | 84 | int ret = ble.gap().startScan(advertisementCallback); |
| jbru | 0:3bbe1a2f1b66 | 85 | PRINTF("GattClient scan = %s (%d)\r\n", |
| jbru | 0:3bbe1a2f1b66 | 86 | (ret == BLE_ERROR_NONE ? "success" : |
| jbru | 0:3bbe1a2f1b66 | 87 | (ret == BLE_ERROR_NOT_IMPLEMENTED ? "not implemented" : |
| jbru | 0:3bbe1a2f1b66 | 88 | "unexpected error")), |
| jbru | 0:3bbe1a2f1b66 | 89 | ret); |
| jbru | 0:3bbe1a2f1b66 | 90 | |
| jbru | 0:3bbe1a2f1b66 | 91 | if (is_s110 && ret != BLE_ERROR_NOT_IMPLEMENTED) |
| jbru | 0:3bbe1a2f1b66 | 92 | error = true; |
| jbru | 0:3bbe1a2f1b66 | 93 | if (!is_s110 && ret != BLE_ERROR_NONE) |
| jbru | 0:3bbe1a2f1b66 | 94 | error = true; |
| jbru | 0:3bbe1a2f1b66 | 95 | } |
| jbru | 0:3bbe1a2f1b66 | 96 | #endif |
| jbru | 0:3bbe1a2f1b66 | 97 | |
| jbru | 0:3bbe1a2f1b66 | 98 | if (S110_MACRO ^ is_s110) /* Check if SD and flags are in sync */ |
| jbru | 0:3bbe1a2f1b66 | 99 | error = true; |
| jbru | 0:3bbe1a2f1b66 | 100 | |
| jbru | 0:3bbe1a2f1b66 | 101 | while (true) { |
| jbru | 0:3bbe1a2f1b66 | 102 | /* Blink fast when there is an obvious issue */ |
| jbru | 0:3bbe1a2f1b66 | 103 | wait_ms(error ? 50 : 1000); |
| jbru | 0:3bbe1a2f1b66 | 104 | led1 = !led1; |
| jbru | 0:3bbe1a2f1b66 | 105 | } |
| jbru | 0:3bbe1a2f1b66 | 106 | } |