Jean-Philippe Brucker / Mbed 2 deprecated NRF51_SoftDevice_test_case

Dependencies:   BLE_API mbed nRF51822

Committer:
jbru
Date:
Mon Oct 05 14:31:08 2015 +0000
Revision:
1:2e7bb567b396
Parent:
0:3bbe1a2f1b66
Remove hack to force use of the mkit pins

Who changed what in which revision?

UserRevisionLine numberNew 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 /* introspection macros */
jbru 0:3bbe1a2f1b66 34 #include "nrf_sdm.h"
jbru 0:3bbe1a2f1b66 35
jbru 0:3bbe1a2f1b66 36 /* An S110 application is supposed to be built with one of those flags */
jbru 0:3bbe1a2f1b66 37 #if defined(TARGET_MCU_NRF51_16K_S110) || defined(TARGET_MCU_NRF51_32K_S110)
jbru 0:3bbe1a2f1b66 38 # define S110_MACRO 1
jbru 0:3bbe1a2f1b66 39 #else
jbru 0:3bbe1a2f1b66 40 # define S110_MACRO 0
jbru 0:3bbe1a2f1b66 41 #endif
jbru 0:3bbe1a2f1b66 42
jbru 0:3bbe1a2f1b66 43 #ifdef VERBOSE
jbru 0:3bbe1a2f1b66 44 # define PRINTF printf
jbru 0:3bbe1a2f1b66 45 #else
jbru 0:3bbe1a2f1b66 46 # define PRINTF(...)
jbru 0:3bbe1a2f1b66 47 #endif
jbru 0:3bbe1a2f1b66 48
jbru 0:3bbe1a2f1b66 49 #ifdef TEST_BLE
jbru 0:3bbe1a2f1b66 50 # include "ble/BLE.h"
jbru 0:3bbe1a2f1b66 51 BLE ble;
jbru 0:3bbe1a2f1b66 52
jbru 0:3bbe1a2f1b66 53 void advertisementCallback(const Gap::AdvertisementCallbackParams_t *params)
jbru 0:3bbe1a2f1b66 54 {
jbru 0:3bbe1a2f1b66 55 }
jbru 0:3bbe1a2f1b66 56 #endif
jbru 0:3bbe1a2f1b66 57
jbru 0:3bbe1a2f1b66 58 int main(void)
jbru 0:3bbe1a2f1b66 59 {
jbru 0:3bbe1a2f1b66 60 bool error = false;
jbru 0:3bbe1a2f1b66 61 uint32_t fwid = SD_FWID_GET(MBR_SIZE);
jbru 0:3bbe1a2f1b66 62 /* TODO: find details about the specific version (0x67 is S130 v1.0.0) */
jbru 0:3bbe1a2f1b66 63 bool is_s110 = (fwid != 0x67);
jbru 0:3bbe1a2f1b66 64
jbru 0:3bbe1a2f1b66 65 PRINTF("Firmware ID = %x\r\n", fwid);
jbru 0:3bbe1a2f1b66 66 PRINTF("Firmware version = %s (guessed)\r\n", (is_s110 ? "s110" : "s130"));
jbru 0:3bbe1a2f1b66 67 PRINTF("S110 flag = %d\r\n", S110_MACRO);
jbru 0:3bbe1a2f1b66 68
jbru 0:3bbe1a2f1b66 69 #ifdef TEST_BLE
jbru 0:3bbe1a2f1b66 70 {
jbru 0:3bbe1a2f1b66 71 ble.init();
jbru 0:3bbe1a2f1b66 72
jbru 0:3bbe1a2f1b66 73 if (ble.gap().setScanParams(1000, 50) != BLE_ERROR_NONE) {
jbru 0:3bbe1a2f1b66 74 PRINTF("Failed to set scan parameters!\r\n");
jbru 0:3bbe1a2f1b66 75 return 1;
jbru 0:3bbe1a2f1b66 76 }
jbru 0:3bbe1a2f1b66 77
jbru 0:3bbe1a2f1b66 78 /* We expect startScan to return an error when we're using S110 */
jbru 0:3bbe1a2f1b66 79 int ret = ble.gap().startScan(advertisementCallback);
jbru 0:3bbe1a2f1b66 80 PRINTF("GattClient scan = %s (%d)\r\n",
jbru 0:3bbe1a2f1b66 81 (ret == BLE_ERROR_NONE ? "success" :
jbru 0:3bbe1a2f1b66 82 (ret == BLE_ERROR_NOT_IMPLEMENTED ? "not implemented" :
jbru 0:3bbe1a2f1b66 83 "unexpected error")),
jbru 0:3bbe1a2f1b66 84 ret);
jbru 0:3bbe1a2f1b66 85
jbru 0:3bbe1a2f1b66 86 if (is_s110 && ret != BLE_ERROR_NOT_IMPLEMENTED)
jbru 0:3bbe1a2f1b66 87 error = true;
jbru 0:3bbe1a2f1b66 88 if (!is_s110 && ret != BLE_ERROR_NONE)
jbru 0:3bbe1a2f1b66 89 error = true;
jbru 0:3bbe1a2f1b66 90 }
jbru 0:3bbe1a2f1b66 91 #endif
jbru 0:3bbe1a2f1b66 92
jbru 0:3bbe1a2f1b66 93 if (S110_MACRO ^ is_s110) /* Check if SD and flags are in sync */
jbru 0:3bbe1a2f1b66 94 error = true;
jbru 0:3bbe1a2f1b66 95
jbru 0:3bbe1a2f1b66 96 while (true) {
jbru 0:3bbe1a2f1b66 97 /* Blink fast when there is an obvious issue */
jbru 0:3bbe1a2f1b66 98 wait_ms(error ? 50 : 1000);
jbru 0:3bbe1a2f1b66 99 led1 = !led1;
jbru 0:3bbe1a2f1b66 100 }
jbru 0:3bbe1a2f1b66 101 }