From 462a58d75740f20811d40afcd50d4b3cf7838b12 Mon Sep 17 00:00:00 2001 From: Michael Gurevich Date: Tue, 7 Jul 2020 10:13:57 +0300 Subject: [PATCH 1/7] example for fus --- BLE_LEDBlinker/mbed-os.lib | 2 +- BLE_LEDBlinker/source/main.cpp | 112 ++++++++++++++++++++++++++++++--- 2 files changed, 106 insertions(+), 8 deletions(-) diff --git a/BLE_LEDBlinker/mbed-os.lib b/BLE_LEDBlinker/mbed-os.lib index 426d1dd0..afbd5b42 100644 --- a/BLE_LEDBlinker/mbed-os.lib +++ b/BLE_LEDBlinker/mbed-os.lib @@ -1 +1 @@ -https://github.com/ARMmbed/mbed-os/#a6207cadad0acd1876f436dc6baeddf46c42af06 +https://github.com/ARMmbed/mbed-os/#5008a954b7b47f68bb4d93db946138d7978fd10d diff --git a/BLE_LEDBlinker/source/main.cpp b/BLE_LEDBlinker/source/main.cpp index 1d43da22..17d9f646 100644 --- a/BLE_LEDBlinker/source/main.cpp +++ b/BLE_LEDBlinker/source/main.cpp @@ -22,6 +22,24 @@ #include "ble/gap/Gap.h" #include "ble/gap/AdvertisingDataParser.h" #include "pretty_printer.h" +#include "shci.h" + +/** + * Define list of reboot reason + */ +#define CFG_REBOOT_ON_FW_APP (0x00) +#define CFG_REBOOT_FUS_FW_UPGRADE (0x01) +#define CFG_REBOOT_ON_CPU2_UPGRADE (0x02) + +/** + * Define mapping of OTA messages in SRAM + */ +#define CFG_OTA_REBOOT_VAL_MSG (*(uint8_t*)(SRAM1_BASE+0)) +#define CFG_OTA_START_SECTOR_IDX_VAL_MSG (*(uint8_t*)(SRAM1_BASE+1)) +#define CFG_OTA_NBR_OF_SECTOR_VAL_MSG (*(uint8_t*)(SRAM1_BASE+2)) + +InterruptIn button2(BUTTON2); +InterruptIn button3(BUTTON3); const static char PEER_NAME[] = "LED"; @@ -84,6 +102,9 @@ void trigger_read(const GattWriteCallbackParams *response) { } } +volatile int _fus_option = 0; + + class LEDBlinkerDemo : ble::Gap::EventHandler { public: LEDBlinkerDemo(BLE &ble, events::EventQueue &event_queue) : @@ -91,7 +112,7 @@ class LEDBlinkerDemo : ble::Gap::EventHandler { _event_queue(event_queue), _alive_led(LED1, 1), _actuated_led(LED2, 0), - _is_connecting(false) { } + _is_connecting(false){ } ~LEDBlinkerDemo() { } @@ -99,20 +120,67 @@ class LEDBlinkerDemo : ble::Gap::EventHandler { _ble.gap().setEventHandler(this); _ble.init(this, &LEDBlinkerDemo::on_init_complete); + + //SHCI_C2_FUS_StartWs(); _event_queue.call_every(500, this, &LEDBlinkerDemo::blink); - - _event_queue.dispatch_forever(); + + _event_queue.dispatch_forever(); } private: + + int run_fus_install() + { + uint8_t fus_state_value; + + if(CFG_OTA_REBOOT_VAL_MSG == CFG_REBOOT_ON_FW_APP) { + printf("wireless FW is running\n"); + return 0; + } + + printf("FUS FW is running\n"); + if(CFG_OTA_REBOOT_VAL_MSG == CFG_REBOOT_FUS_FW_UPGRADE) { + printf("Call SHCI_C2_FUS_FwUpgrade\n"); + CFG_OTA_REBOOT_VAL_MSG = CFG_REBOOT_ON_CPU2_UPGRADE; + SHCI_C2_FUS_FwUpgrade(0, 0); + while(1); + } + + if(CFG_OTA_REBOOT_VAL_MSG == CFG_REBOOT_ON_CPU2_UPGRADE) { + fus_state_value = SHCI_C2_FUS_GetState(NULL); + printf("fus_state_value %d\n", fus_state_value); + if(fus_state_value == 0xFF) + { + printf("Error FUS, should not get here\n"); + while(1); + } + + if(fus_state_value != 0) + { + printf("FUS is upgrading\n"); + while(1); + } + + if( fus_state_value == 0) + { + printf("FUS is done installation, start BLE FW\n"); + CFG_OTA_REBOOT_VAL_MSG = CFG_REBOOT_ON_FW_APP; + SHCI_C2_FUS_StartWs(); + while(1); + } + } + + return 0; + } + /** Callback triggered when the ble initialization process has finished */ void on_init_complete(BLE::InitializationCompleteCallbackContext *params) { if (params->error != BLE_ERROR_NONE) { - printf("Ble initialization failed."); + printf("Ble initialization failed.\n"); return; } - + print_mac_address(); _ble.gattClient().onDataRead(trigger_toggled_write); @@ -121,10 +189,26 @@ class LEDBlinkerDemo : ble::Gap::EventHandler { ble::ScanParameters scan_params; _ble.gap().setScanParameters(scan_params); _ble.gap().startScan(); + } void blink() { - _alive_led = !_alive_led; + _alive_led = !_alive_led; + + if( _fus_option == 3) { + printf("start FUS %d\n", _fus_option); + _fus_option = 0; + CFG_OTA_REBOOT_VAL_MSG = CFG_REBOOT_FUS_FW_UPGRADE; + SHCI_C2_FUS_GetState(NULL); + SHCI_C2_FUS_GetState(NULL); + while(1); + } + + if( _fus_option == 2) { + printf("start upgrade%d\n", _fus_option); + _fus_option = 0; + run_fus_install(); + } } private: @@ -216,13 +300,27 @@ void schedule_ble_events(BLE::OnEventsToProcessCallbackContext *context) { event_queue.call(Callback(&context->ble, &BLE::processEvents)); } +void flip2() +{ + // _fus_option = 2; +} + +void flip3() +{ + _fus_option = 3; +} + int main() { + button2.fall(&flip2); // attach the address of the flip function to the rising edge + button3.fall(&flip3); + + BLE &ble = BLE::Instance(); ble.onEventsToProcess(schedule_ble_events); LEDBlinkerDemo demo(ble, event_queue); demo.start(); - + return 0; } From 04d44f29f616b8efce016628bf479e22919cdbba Mon Sep 17 00:00:00 2001 From: Michael Gurevich Date: Tue, 7 Jul 2020 10:45:05 +0300 Subject: [PATCH 2/7] bump mbedos --- BLE_LEDBlinker/mbed-os.lib | 2 +- BLE_LEDBlinker/source/main.cpp | 37 ++++++++++++++-------------------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/BLE_LEDBlinker/mbed-os.lib b/BLE_LEDBlinker/mbed-os.lib index afbd5b42..0b7204db 100644 --- a/BLE_LEDBlinker/mbed-os.lib +++ b/BLE_LEDBlinker/mbed-os.lib @@ -1 +1 @@ -https://github.com/ARMmbed/mbed-os/#5008a954b7b47f68bb4d93db946138d7978fd10d +https://github.com/ARMmbed/mbed-os/#06e82ef22755ea3df377394cf82d684793c1d5fe diff --git a/BLE_LEDBlinker/source/main.cpp b/BLE_LEDBlinker/source/main.cpp index 17d9f646..2f62a196 100644 --- a/BLE_LEDBlinker/source/main.cpp +++ b/BLE_LEDBlinker/source/main.cpp @@ -23,22 +23,9 @@ #include "ble/gap/AdvertisingDataParser.h" #include "pretty_printer.h" #include "shci.h" +#include "app_conf.h" -/** - * Define list of reboot reason - */ -#define CFG_REBOOT_ON_FW_APP (0x00) -#define CFG_REBOOT_FUS_FW_UPGRADE (0x01) -#define CFG_REBOOT_ON_CPU2_UPGRADE (0x02) - -/** - * Define mapping of OTA messages in SRAM - */ -#define CFG_OTA_REBOOT_VAL_MSG (*(uint8_t*)(SRAM1_BASE+0)) -#define CFG_OTA_START_SECTOR_IDX_VAL_MSG (*(uint8_t*)(SRAM1_BASE+1)) -#define CFG_OTA_NBR_OF_SECTOR_VAL_MSG (*(uint8_t*)(SRAM1_BASE+2)) - -InterruptIn button2(BUTTON2); +//InterruptIn button2(BUTTON2); InterruptIn button3(BUTTON3); const static char PEER_NAME[] = "LED"; @@ -130,7 +117,7 @@ class LEDBlinkerDemo : ble::Gap::EventHandler { private: - int run_fus_install() +/* int run_fus_install() { uint8_t fus_state_value; @@ -173,6 +160,7 @@ class LEDBlinkerDemo : ble::Gap::EventHandler { return 0; } +*/ /** Callback triggered when the ble initialization process has finished */ void on_init_complete(BLE::InitializationCompleteCallbackContext *params) { @@ -182,6 +170,7 @@ class LEDBlinkerDemo : ble::Gap::EventHandler { } print_mac_address(); + printf("prees button near bkinking led to start FUS\n"); _ble.gattClient().onDataRead(trigger_toggled_write); _ble.gattClient().onDataWritten(trigger_read); @@ -196,19 +185,19 @@ class LEDBlinkerDemo : ble::Gap::EventHandler { _alive_led = !_alive_led; if( _fus_option == 3) { - printf("start FUS %d\n", _fus_option); + printf("starting FUS\n"); _fus_option = 0; - CFG_OTA_REBOOT_VAL_MSG = CFG_REBOOT_FUS_FW_UPGRADE; SHCI_C2_FUS_GetState(NULL); SHCI_C2_FUS_GetState(NULL); while(1); } - if( _fus_option == 2) { +/* if( _fus_option == 2) { printf("start upgrade%d\n", _fus_option); _fus_option = 0; run_fus_install(); } +*/ } private: @@ -300,10 +289,11 @@ void schedule_ble_events(BLE::OnEventsToProcessCallbackContext *context) { event_queue.call(Callback(&context->ble, &BLE::processEvents)); } +/* void flip2() { - // _fus_option = 2; -} + _fus_option = 2; +}*/ void flip3() { @@ -312,9 +302,12 @@ void flip3() int main() { - button2.fall(&flip2); // attach the address of the flip function to the rising edge + //button2.fall(&flip2); // attach the address of the flip function to the rising edge button3.fall(&flip3); + //printf("CFG_OTA_REBOOT_VAL_MSG %d\n", CFG_OTA_REBOOT_VAL_MSG); + //CFG_OTA_REBOOT_VAL_MSG = CFG_REBOOT_ON_CPU2_UPGRADE; + //printf("CFG_OTA_REBOOT_VAL_MSG again %d\n", CFG_OTA_REBOOT_VAL_MSG); BLE &ble = BLE::Instance(); ble.onEventsToProcess(schedule_ble_events); From 097bb074812229c87980e4866ee5a5feea3d902e Mon Sep 17 00:00:00 2001 From: Michael Gurevich Date: Tue, 7 Jul 2020 12:23:04 +0300 Subject: [PATCH 3/7] bump mbedos --- BLE_LEDBlinker/mbed-os.lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BLE_LEDBlinker/mbed-os.lib b/BLE_LEDBlinker/mbed-os.lib index 0b7204db..030adcf4 100644 --- a/BLE_LEDBlinker/mbed-os.lib +++ b/BLE_LEDBlinker/mbed-os.lib @@ -1 +1 @@ -https://github.com/ARMmbed/mbed-os/#06e82ef22755ea3df377394cf82d684793c1d5fe +https://github.com/micgur01/mbed-os/#06e82ef22755ea3df377394cf82d684793c1d5fe From 14bf73e2823cd2cd77fecacad1eacaff2fd7d16b Mon Sep 17 00:00:00 2001 From: Michael Gurevich Date: Tue, 7 Jul 2020 15:51:01 +0300 Subject: [PATCH 4/7] fix grammar --- BLE_LEDBlinker/source/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BLE_LEDBlinker/source/main.cpp b/BLE_LEDBlinker/source/main.cpp index 2f62a196..d8d4767c 100644 --- a/BLE_LEDBlinker/source/main.cpp +++ b/BLE_LEDBlinker/source/main.cpp @@ -170,7 +170,7 @@ class LEDBlinkerDemo : ble::Gap::EventHandler { } print_mac_address(); - printf("prees button near bkinking led to start FUS\n"); + printf("press button near blinking led to start FUS\n"); _ble.gattClient().onDataRead(trigger_toggled_write); _ble.gattClient().onDataWritten(trigger_read); From 105496a6e500e5a4a309c9557bc7a52dccfc11df Mon Sep 17 00:00:00 2001 From: Michael Gurevich Date: Wed, 8 Jul 2020 17:34:17 +0300 Subject: [PATCH 5/7] add baud rate and bump mbed-os --- BLE_LEDBlinker/mbed-os.lib | 2 +- BLE_LEDBlinker/mbed_app.json | 4 +++ BLE_LEDBlinker/source/main.cpp | 51 +++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/BLE_LEDBlinker/mbed-os.lib b/BLE_LEDBlinker/mbed-os.lib index 030adcf4..1ebd7067 100644 --- a/BLE_LEDBlinker/mbed-os.lib +++ b/BLE_LEDBlinker/mbed-os.lib @@ -1 +1 @@ -https://github.com/micgur01/mbed-os/#06e82ef22755ea3df377394cf82d684793c1d5fe +https://github.com/micgur01/mbed-os/#aba6511d03fd0ec5172c4ce3151ebc332a516b0e diff --git a/BLE_LEDBlinker/mbed_app.json b/BLE_LEDBlinker/mbed_app.json index 205b8cd4..0ed12142 100644 --- a/BLE_LEDBlinker/mbed_app.json +++ b/BLE_LEDBlinker/mbed_app.json @@ -1,5 +1,9 @@ { "target_overrides": { + + "*": { + "platform.stdio-baud-rate" : 115200 + }, "K64F": { "target.components_add": ["BlueNRG_MS"], "target.features_add": ["BLE"], diff --git a/BLE_LEDBlinker/source/main.cpp b/BLE_LEDBlinker/source/main.cpp index d8d4767c..af49bfc7 100644 --- a/BLE_LEDBlinker/source/main.cpp +++ b/BLE_LEDBlinker/source/main.cpp @@ -35,6 +35,48 @@ static EventQueue event_queue(/* event count */ 10 * EVENTS_EVENT_SIZE); static DiscoveredCharacteristic led_characteristic; static bool trigger_led_characteristic = false; +void printpad(uint8_t num) +{ + if(num < 16) { + printf("0"); + printf("%X", num); + } else + { + printf("%02X", num); + } + +} + +#define print_array(_arr, _size, big_end) print_array___(_arr, _size, big_end, #_arr) +void print_array___(uint8_t* arr, size_t size, bool big_end, const char *name) { + printf("vvvvvvvvvv %s vvvvvvvvvv\n\t", name); + for (size_t i=0; i < size; i+=4) + { + if (i && ((i % 16) == 0)){ + printf("\n\t"); + } + else if (i && ((i % 4) == 0)){ + printf(" "); + } + printf("0x"); + if( big_end ) { + printpad(arr[i]); + printpad(arr[i+1]); + printpad(arr[i+2]); + printpad(arr[i+3]); + } else { + printpad(arr[i+3]); + printpad(arr[i+2]); + printpad(arr[i+1]); + printpad(arr[i]); + } + } + if(big_end) + printf("\n big endian presentation--------%s----\n", name); + else + printf("\n little endian presentation-----%s-------\n", name); +} + void service_discovery(const DiscoveredService *service) { if (service->getUUID().shortOrLong() == UUID::UUID_TYPE_SHORT) { printf("S UUID-%x attrs[%u %u]\r\n", service->getUUID().getShortUUID(), service->getStartHandle(), service->getEndHandle()); @@ -184,12 +226,19 @@ class LEDBlinkerDemo : ble::Gap::EventHandler { void blink() { _alive_led = !_alive_led; + //print_array((uint8_t*)CFG_OTA_REBOOT_VAL_MSG, 0x200, false); + if( _fus_option == 3) { printf("starting FUS\n"); _fus_option = 0; + printf("one\n"); SHCI_C2_FUS_GetState(NULL); + printf("two\n"); SHCI_C2_FUS_GetState(NULL); - while(1); + printf("while\n"); + while(1) { + //printf("restart\n"); + }; } /* if( _fus_option == 2) { From 37620d4fc93ff09f9bd13d0e0d97dd9513dc5cd6 Mon Sep 17 00:00:00 2001 From: Michael Gurevich Date: Wed, 8 Jul 2020 20:54:14 +0300 Subject: [PATCH 6/7] add printouts --- BLE_LEDBlinker/source/main.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/BLE_LEDBlinker/source/main.cpp b/BLE_LEDBlinker/source/main.cpp index af49bfc7..49af1139 100644 --- a/BLE_LEDBlinker/source/main.cpp +++ b/BLE_LEDBlinker/source/main.cpp @@ -210,7 +210,6 @@ class LEDBlinkerDemo : ble::Gap::EventHandler { printf("Ble initialization failed.\n"); return; } - print_mac_address(); printf("press button near blinking led to start FUS\n"); @@ -225,19 +224,19 @@ class LEDBlinkerDemo : ble::Gap::EventHandler { void blink() { _alive_led = !_alive_led; - + //print_array((uint8_t*)CFG_OTA_REBOOT_VAL_MSG, 0x200, false); if( _fus_option == 3) { printf("starting FUS\n"); _fus_option = 0; - printf("one\n"); - SHCI_C2_FUS_GetState(NULL); - printf("two\n"); - SHCI_C2_FUS_GetState(NULL); - printf("while\n"); + printf("first call SHCI_C2_FUS_GetState\n"); + SHCI_C2_FUS_GetState( NULL ); + printf("second call SHCI_C2_FUS_GetState\n"); + SHCI_C2_FUS_GetState( NULL ); + printf("restart?\n"); while(1) { - //printf("restart\n"); + printf("restart?\n"); }; } @@ -351,6 +350,7 @@ void flip3() int main() { + //button2.fall(&flip2); // attach the address of the flip function to the rising edge button3.fall(&flip3); From cbea3f6d3427c619a51866c22f381562c88d9696 Mon Sep 17 00:00:00 2001 From: Michael Gurevich Date: Mon, 13 Jul 2020 17:48:20 +0300 Subject: [PATCH 7/7] add flags to ready event --- BLE_LEDBlinker/mbed-os.lib | 4 +- BLE_LEDBlinker/source/main.cpp | 184 ++++++++------------------------- 2 files changed, 45 insertions(+), 143 deletions(-) diff --git a/BLE_LEDBlinker/mbed-os.lib b/BLE_LEDBlinker/mbed-os.lib index 1ebd7067..0ea5e6ea 100644 --- a/BLE_LEDBlinker/mbed-os.lib +++ b/BLE_LEDBlinker/mbed-os.lib @@ -1 +1,3 @@ -https://github.com/micgur01/mbed-os/#aba6511d03fd0ec5172c4ce3151ebc332a516b0e +https://github.com/micgur01/mbed-os/#56c3b98a25da17bc9d5d594575297d7297dc7896 + + diff --git a/BLE_LEDBlinker/source/main.cpp b/BLE_LEDBlinker/source/main.cpp index 49af1139..6394f37a 100644 --- a/BLE_LEDBlinker/source/main.cpp +++ b/BLE_LEDBlinker/source/main.cpp @@ -25,8 +25,6 @@ #include "shci.h" #include "app_conf.h" -//InterruptIn button2(BUTTON2); -InterruptIn button3(BUTTON3); const static char PEER_NAME[] = "LED"; @@ -35,47 +33,10 @@ static EventQueue event_queue(/* event count */ 10 * EVENTS_EVENT_SIZE); static DiscoveredCharacteristic led_characteristic; static bool trigger_led_characteristic = false; -void printpad(uint8_t num) -{ - if(num < 16) { - printf("0"); - printf("%X", num); - } else - { - printf("%02X", num); - } - -} -#define print_array(_arr, _size, big_end) print_array___(_arr, _size, big_end, #_arr) -void print_array___(uint8_t* arr, size_t size, bool big_end, const char *name) { - printf("vvvvvvvvvv %s vvvvvvvvvv\n\t", name); - for (size_t i=0; i < size; i+=4) - { - if (i && ((i % 16) == 0)){ - printf("\n\t"); - } - else if (i && ((i % 4) == 0)){ - printf(" "); - } - printf("0x"); - if( big_end ) { - printpad(arr[i]); - printpad(arr[i+1]); - printpad(arr[i+2]); - printpad(arr[i+3]); - } else { - printpad(arr[i+3]); - printpad(arr[i+2]); - printpad(arr[i+1]); - printpad(arr[i]); - } - } - if(big_end) - printf("\n big endian presentation--------%s----\n", name); - else - printf("\n little endian presentation-----%s-------\n", name); -} +extern "C" int handle_ready_event; +static bool startBLEbyExample = false; +static bool startFUSbyExample = false; void service_discovery(const DiscoveredService *service) { if (service->getUUID().shortOrLong() == UUID::UUID_TYPE_SHORT) { @@ -146,106 +107,58 @@ class LEDBlinkerDemo : ble::Gap::EventHandler { ~LEDBlinkerDemo() { } void start() { - _ble.gap().setEventHandler(this); + _ble.gap().setEventHandler(this); + printf("ble.init\n"); _ble.init(this, &LEDBlinkerDemo::on_init_complete); + printf("ble.init done\n"); - //SHCI_C2_FUS_StartWs(); - - _event_queue.call_every(500, this, &LEDBlinkerDemo::blink); - - _event_queue.dispatch_forever(); - } + if( startBLEbyExample && startFUSbyExample) + printf("startBLEbyExample && startFUSbyExample are true, please choose one\n"); -private: -/* int run_fus_install() - { - uint8_t fus_state_value; - - if(CFG_OTA_REBOOT_VAL_MSG == CFG_REBOOT_ON_FW_APP) { - printf("wireless FW is running\n"); - return 0; - } - - printf("FUS FW is running\n"); - if(CFG_OTA_REBOOT_VAL_MSG == CFG_REBOOT_FUS_FW_UPGRADE) { - printf("Call SHCI_C2_FUS_FwUpgrade\n"); - CFG_OTA_REBOOT_VAL_MSG = CFG_REBOOT_ON_CPU2_UPGRADE; - SHCI_C2_FUS_FwUpgrade(0, 0); - while(1); + if ( startBLEbyExample ) { + printf("start BLE\n"); + SHCI_C2_FUS_StartWs(); } - if(CFG_OTA_REBOOT_VAL_MSG == CFG_REBOOT_ON_CPU2_UPGRADE) { - fus_state_value = SHCI_C2_FUS_GetState(NULL); - printf("fus_state_value %d\n", fus_state_value); - if(fus_state_value == 0xFF) - { - printf("Error FUS, should not get here\n"); - while(1); - } + if ( startFUSbyExample ) { + printf("start FUS\n"); + SHCI_C2_FUS_GetState( NULL ); + SHCI_C2_FUS_GetState( NULL ); + } - if(fus_state_value != 0) - { - printf("FUS is upgrading\n"); - while(1); - } - - if( fus_state_value == 0) - { - printf("FUS is done installation, start BLE FW\n"); - CFG_OTA_REBOOT_VAL_MSG = CFG_REBOOT_ON_FW_APP; - SHCI_C2_FUS_StartWs(); - while(1); - } - } - - return 0; + printf("handle_ready_event @start %d\n", handle_ready_event); + //_event_queue.call_every(5000, this, &LEDBlinkerDemo::blink); + + _event_queue.dispatch_forever(); } -*/ + +private: /** Callback triggered when the ble initialization process has finished */ void on_init_complete(BLE::InitializationCompleteCallbackContext *params) { - if (params->error != BLE_ERROR_NONE) { - printf("Ble initialization failed.\n"); - return; - } - print_mac_address(); - printf("press button near blinking led to start FUS\n"); - _ble.gattClient().onDataRead(trigger_toggled_write); - _ble.gattClient().onDataWritten(trigger_read); + printf("handle_ready_event @on_init_complete %d\n", handle_ready_event); - ble::ScanParameters scan_params; - _ble.gap().setScanParameters(scan_params); - _ble.gap().startScan(); - + if( handle_ready_event == 1) { + if (params->error != BLE_ERROR_NONE) { + printf("Ble initialization failed.\n"); + return; + } + + print_mac_address(); + _ble.gattClient().onDataRead(trigger_toggled_write); + _ble.gattClient().onDataWritten(trigger_read); + + ble::ScanParameters scan_params; + _ble.gap().setScanParameters(scan_params); + _ble.gap().startScan(); + } } void blink() { - _alive_led = !_alive_led; - - //print_array((uint8_t*)CFG_OTA_REBOOT_VAL_MSG, 0x200, false); - - if( _fus_option == 3) { - printf("starting FUS\n"); - _fus_option = 0; - printf("first call SHCI_C2_FUS_GetState\n"); - SHCI_C2_FUS_GetState( NULL ); - printf("second call SHCI_C2_FUS_GetState\n"); - SHCI_C2_FUS_GetState( NULL ); - printf("restart?\n"); - while(1) { - printf("restart?\n"); - }; - } - -/* if( _fus_option == 2) { - printf("start upgrade%d\n", _fus_option); - _fus_option = 0; - run_fus_install(); - } -*/ + _alive_led = !_alive_led; } private: @@ -337,29 +250,16 @@ void schedule_ble_events(BLE::OnEventsToProcessCallbackContext *context) { event_queue.call(Callback(&context->ble, &BLE::processEvents)); } -/* -void flip2() -{ - _fus_option = 2; -}*/ - -void flip3() -{ - _fus_option = 3; -} int main() { + printf("Start Example\n"); - //button2.fall(&flip2); // attach the address of the flip function to the rising edge - button3.fall(&flip3); + printf("CFG_OTA_REBOOT_VAL_MSG %d\n", CFG_OTA_REBOOT_VAL_MSG); + CFG_OTA_REBOOT_VAL_MSG = CFG_REBOOT_ON_FW_APP; - //printf("CFG_OTA_REBOOT_VAL_MSG %d\n", CFG_OTA_REBOOT_VAL_MSG); - //CFG_OTA_REBOOT_VAL_MSG = CFG_REBOOT_ON_CPU2_UPGRADE; - //printf("CFG_OTA_REBOOT_VAL_MSG again %d\n", CFG_OTA_REBOOT_VAL_MSG); - BLE &ble = BLE::Instance(); - ble.onEventsToProcess(schedule_ble_events); + //ble.onEventsToProcess(schedule_ble_events); LEDBlinkerDemo demo(ble, event_queue); demo.start();