summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2020-06-01 16:30:24 +0200
committerJF <jf@codingfield.com>2020-06-01 16:30:24 +0200
commit07f74cee63d77882191c8ce53c598f91e6159ba8 (patch)
treef7490e5ace467a881a2e863e9af0163842bb94db /src
parentb41a856b9dced4d8acf249e8c63e0c95c1b3e2e5 (diff)
DFU : add timeout detection : abort dfu procedure after 10s without any data from the host.
Diffstat (limited to 'src')
-rw-r--r--src/Components/Ble/DfuService.cpp46
-rw-r--r--src/Components/Ble/DfuService.h7
-rw-r--r--src/DisplayApp/DisplayApp.cpp6
-rw-r--r--src/DisplayApp/Screens/FirmwareUpdate.cpp12
-rw-r--r--src/DisplayApp/Screens/FirmwareUpdate.h2
-rw-r--r--src/FreeRTOSConfig.h2
-rw-r--r--src/SystemTask/SystemTask.cpp3
7 files changed, 45 insertions, 33 deletions
diff --git a/src/Components/Ble/DfuService.cpp b/src/Components/Ble/DfuService.cpp
index 0d67d848..38a550f0 100644
--- a/src/Components/Ble/DfuService.cpp
+++ b/src/Components/Ble/DfuService.cpp
@@ -16,11 +16,16 @@ int DfuServiceCallback(uint16_t conn_handle, uint16_t attr_handle,
return dfuService->OnServiceData(conn_handle, attr_handle, ctxt);
}
-void NotificationTimerCallback( TimerHandle_t xTimer ) {
- auto dfuService = static_cast<DfuService *>(pvTimerGetTimerID( xTimer ));
+void NotificationTimerCallback(TimerHandle_t xTimer) {
+ auto dfuService = static_cast<DfuService *>(pvTimerGetTimerID(xTimer));
dfuService->OnNotificationTimer();
}
+void TimeoutTimerCallback(TimerHandle_t xTimer) {
+ auto dfuService = static_cast<DfuService *>(pvTimerGetTimerID(xTimer));
+ dfuService->OnTimeout();
+}
+
DfuService::DfuService(Pinetime::System::SystemTask &systemTask, Pinetime::Controllers::Ble &bleController,
Pinetime::Drivers::SpiNorFlash &spiNorFlash) :
systemTask{systemTask},
@@ -66,6 +71,7 @@ DfuService::DfuService(Pinetime::System::SystemTask &systemTask, Pinetime::Contr
},
} {
notificationTimer = xTimerCreate ("notificationTimer", 1000, pdFALSE, this, NotificationTimerCallback);
+ timeoutTimer = xTimerCreate ("notificationTimer", 10000, pdFALSE, this, TimeoutTimerCallback);
}
void DfuService::Init() {
@@ -74,6 +80,10 @@ void DfuService::Init() {
}
int DfuService::OnServiceData(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt *context) {
+ if(bleController.IsFirmwareUpdating()){
+ xTimerStart(timeoutTimer, 0);
+ }
+
ble_gatts_find_chr((ble_uuid_t *) &serviceUuid, (ble_uuid_t *) &packetCharacteristicUuid, nullptr,
&packetCharacteristicHandle);
@@ -150,11 +160,6 @@ int DfuService::WritePacketHandler(uint16_t connectionHandle, os_mbuf *om) {
nbPacketReceived++;
auto offset = ((nbPacketReceived - 1) % nbPacketsToNotify) * 20;
std::memcpy(tempBuffer + offset, om->om_data, om->om_len);
- if (firstCrc) {
- tempCrc = ComputeCrc(om->om_data, om->om_len, NULL);
- firstCrc = false;
- } else
- tempCrc = ComputeCrc(om->om_data, om->om_len, &tempCrc);
if (nbPacketReceived > 0 && (nbPacketReceived % nbPacketsToNotify) == 0) {
#if 1
@@ -190,7 +195,7 @@ int DfuService::WritePacketHandler(uint16_t connectionHandle, os_mbuf *om) {
uint8_t data[3]{static_cast<uint8_t>(Opcodes::Response),
static_cast<uint8_t>(Opcodes::ReceiveFirmwareImage),
static_cast<uint8_t>(ErrorCodes::NoError)};
- NRF_LOG_INFO("[DFU] -> Send packet notification : all bytes received! CRC = %u -- %d", tempCrc, connectionHandle);
+ NRF_LOG_INFO("[DFU] -> Send packet notification : all bytes received!");
SendNotification(connectionHandle, data, 3);
state = States::Validate;
}
@@ -266,7 +271,7 @@ int DfuService::ControlPointHandler(uint16_t connectionHandle, os_mbuf *om) {
return 0;
case Opcodes::ValidateFirmware: {
if (state != States::Validate) {
- NRF_LOG_INFO("[DFU] -> Validate firmware image requested, but we are not in Data state");
+ NRF_LOG_INFO("[DFU] -> Validate firmware image requested, but we are not in Data state %d", state);
return 0;
}
@@ -301,6 +306,8 @@ int DfuService::ControlPointHandler(uint16_t connectionHandle, os_mbuf *om) {
NRF_LOG_INFO("[DFU] -> Activate image and reset!");
bleController.StopFirmwareUpdate();
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::BleFirmwareUpdateFinished);
+ Reset();
+ bleController.State(Pinetime::Controllers::Ble::FirmwareUpdateStates::Validated);
return 0;
default:
return 0;
@@ -375,3 +382,24 @@ void DfuService::OnNotificationTimer() {
notificationSize = 0;
}
}
+
+void DfuService::OnTimeout() {
+ Reset();
+}
+
+void DfuService::Reset() {
+ state = States::Idle;
+ nbPacketsToNotify = 0;
+ nbPacketReceived = 0;
+ bytesReceived = 0;
+ softdeviceSize = 0;
+ bootloaderSize = 0;
+ applicationSize = 0;
+ expectedCrc = 0;
+ notificatonConnectionHandle = 0;
+ notificationSize = 0;
+ xTimerStop(notificationTimer, 0);
+ bleController.State(Pinetime::Controllers::Ble::FirmwareUpdateStates::Error);
+ bleController.StopFirmwareUpdate();
+ systemTask.PushMessage(Pinetime::System::SystemTask::Messages::BleFirmwareUpdateFinished);
+}
diff --git a/src/Components/Ble/DfuService.h b/src/Components/Ble/DfuService.h
index 3de17f9f..73846c86 100644
--- a/src/Components/Ble/DfuService.h
+++ b/src/Components/Ble/DfuService.h
@@ -26,6 +26,9 @@ namespace Pinetime {
int OnServiceData(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt *context);
void OnNotificationTimer();
+ void OnTimeout();
+
+ void Reset();
private:
Pinetime::System::SystemTask &systemTask;
@@ -125,11 +128,9 @@ namespace Pinetime {
uint16_t ComputeCrc(uint8_t const *p_data, uint32_t size, uint16_t const *p_crc);
- bool firstCrc = true;
- uint16_t tempCrc = 0;
-
void WriteMagicNumber();
TimerHandle_t notificationTimer;
+ TimerHandle_t timeoutTimer;
uint16_t notificatonConnectionHandle = 0;
size_t notificationSize = 0;
diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp
index c42639c7..01c3aa96 100644
--- a/src/DisplayApp/DisplayApp.cpp
+++ b/src/DisplayApp/DisplayApp.cpp
@@ -163,13 +163,9 @@ void DisplayApp::Refresh() {
lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Down);
currentScreen.reset(nullptr);
currentScreen.reset(new Screens::FirmwareUpdate(this, bleController));
+ onClockApp = false;
break;
- case Messages::BleFirmwareUpdateFinished:
- lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Down);
- currentScreen.reset(nullptr);
- currentScreen.reset(new Screens::Clock(this, dateTimeController, batteryController, bleController));
- break;
}
}
}
diff --git a/src/DisplayApp/Screens/FirmwareUpdate.cpp b/src/DisplayApp/Screens/FirmwareUpdate.cpp
index 138211c4..e831114d 100644
--- a/src/DisplayApp/Screens/FirmwareUpdate.cpp
+++ b/src/DisplayApp/Screens/FirmwareUpdate.cpp
@@ -26,15 +26,6 @@ FirmwareUpdate::FirmwareUpdate(Pinetime::Applications::DisplayApp *app, Pinetime
lv_label_set_text(percentLabel, "");
lv_obj_set_auto_realign(percentLabel, true);
lv_obj_align(percentLabel, bar1, LV_ALIGN_OUT_TOP_MID, 0, 60);
-
- button = lv_btn_create(lv_scr_act(), NULL);
- //lv_obj_set_event_cb(button, event_handler);
- lv_obj_align(button, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
- lv_obj_set_hidden(button, true);
-
- labelBtn = lv_label_create(button, NULL);
- lv_label_set_text(labelBtn, "Back");
- lv_obj_set_hidden(labelBtn, true);
}
FirmwareUpdate::~FirmwareUpdate() {
@@ -88,7 +79,4 @@ void FirmwareUpdate::UpdateValidated() {
void FirmwareUpdate::UpdateError() {
lv_label_set_recolor(percentLabel, true);
lv_label_set_text(percentLabel, "#ff0000 Error!#");
-
- lv_obj_set_hidden(labelBtn, false);
- lv_obj_set_hidden(button, false);
}
diff --git a/src/DisplayApp/Screens/FirmwareUpdate.h b/src/DisplayApp/Screens/FirmwareUpdate.h
index 87e93959..a571d667 100644
--- a/src/DisplayApp/Screens/FirmwareUpdate.h
+++ b/src/DisplayApp/Screens/FirmwareUpdate.h
@@ -31,8 +31,6 @@ namespace Pinetime {
lv_obj_t* bar1;
lv_obj_t* percentLabel;
lv_obj_t* titleLabel;
- lv_obj_t* labelBtn;
- lv_obj_t* button;
mutable char percentStr[10];
bool running = true;
States state;
diff --git a/src/FreeRTOSConfig.h b/src/FreeRTOSConfig.h
index 557e5edf..93289e1a 100644
--- a/src/FreeRTOSConfig.h
+++ b/src/FreeRTOSConfig.h
@@ -96,7 +96,7 @@
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( 0 )
#define configTIMER_QUEUE_LENGTH 32
-#define configTIMER_TASK_STACK_DEPTH ( 120 )
+#define configTIMER_TASK_STACK_DEPTH ( 240 )
/* Tickless Idle configuration. */
#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 2
diff --git a/src/SystemTask/SystemTask.cpp b/src/SystemTask/SystemTask.cpp
index 7bba3c3e..eb36c7b8 100644
--- a/src/SystemTask/SystemTask.cpp
+++ b/src/SystemTask/SystemTask.cpp
@@ -118,7 +118,8 @@ void SystemTask::Work() {
break;
case Messages::BleFirmwareUpdateFinished:
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::BleFirmwareUpdateFinished);
- NVIC_SystemReset();
+ if(bleController.State() == Pinetime::Controllers::Ble::FirmwareUpdateStates::Validated)
+ NVIC_SystemReset();
break;
default: break;
}