Fix race conditions on SPI and integrate the SPI NOR Flash driver into DFUService (WIP)
This commit is contained in:
@@ -15,9 +15,10 @@ int DfuServiceCallback(uint16_t conn_handle, uint16_t attr_handle,
|
||||
return dfuService->OnServiceData(conn_handle, attr_handle, ctxt);
|
||||
}
|
||||
|
||||
DfuService::DfuService(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::Ble& bleController) :
|
||||
DfuService::DfuService(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::Ble& bleController, Pinetime::Drivers::SpiNorFlash& spiNorFlash) :
|
||||
systemTask{systemTask},
|
||||
bleController{bleController},
|
||||
spiNorFlash{spiNorFlash},
|
||||
characteristicDefinition{
|
||||
{
|
||||
.uuid = (ble_uuid_t *) &packetCharacteristicUuid,
|
||||
@@ -104,6 +105,15 @@ int DfuService::WritePacketHandler(uint16_t connectionHandle, os_mbuf *om) {
|
||||
applicationSize = om->om_data[8] + (om->om_data[9] << 8) + (om->om_data[10] << 16) + (om->om_data[11] << 24);
|
||||
NRF_LOG_INFO("[DFU] -> Start data received : SD size : %d, BT size : %d, app size : %d", softdeviceSize, bootloaderSize, applicationSize);
|
||||
|
||||
for(int erased = 0; erased < applicationSize; erased += 0x1000) {
|
||||
spiNorFlash.SectorErase(erased);
|
||||
|
||||
auto p = spiNorFlash.ProgramFailed();
|
||||
auto e = spiNorFlash.EraseFailed();
|
||||
NRF_LOG_INFO("[DFU] Erasing sector %d - %d-%d", erased, p, e);
|
||||
|
||||
}
|
||||
|
||||
uint8_t data[] {16, 1, 1};
|
||||
SendNotification(connectionHandle, data, 3);
|
||||
state = States::Init;
|
||||
@@ -128,10 +138,15 @@ int DfuService::WritePacketHandler(uint16_t connectionHandle, os_mbuf *om) {
|
||||
|
||||
case States::Data: {
|
||||
nbPacketReceived++;
|
||||
|
||||
spiNorFlash.Write(bytesReceived, om->om_data, om->om_len);
|
||||
|
||||
bytesReceived += om->om_len;
|
||||
bleController.FirmwareUpdateCurrentBytes(bytesReceived);
|
||||
NRF_LOG_INFO("[DFU] -> Bytes received : %d in %d packets", bytesReceived, nbPacketReceived);
|
||||
|
||||
|
||||
|
||||
if((nbPacketReceived % nbPacketsToNotify) == 0) {
|
||||
uint8_t data[5]{static_cast<uint8_t>(Opcodes::PacketReceiptNotification),
|
||||
(uint8_t)(bytesReceived&0x000000FFu),(uint8_t)(bytesReceived>>8u), (uint8_t)(bytesReceived>>16u),(uint8_t)(bytesReceived>>24u) };
|
||||
|
||||
@@ -8,17 +8,22 @@ namespace Pinetime {
|
||||
namespace System {
|
||||
class SystemTask;
|
||||
}
|
||||
namespace Drivers {
|
||||
class SpiNorFlash;
|
||||
}
|
||||
namespace Controllers {
|
||||
class Ble;
|
||||
class DfuService {
|
||||
public:
|
||||
DfuService(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::Ble& bleController);
|
||||
DfuService(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::Ble& bleController,
|
||||
Pinetime::Drivers::SpiNorFlash& spiNorFlash);
|
||||
void Init();
|
||||
|
||||
int OnServiceData(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt *context);
|
||||
private:
|
||||
Pinetime::System::SystemTask& systemTask;
|
||||
Pinetime::Controllers::Ble& bleController;
|
||||
Pinetime::Drivers::SpiNorFlash& spiNorFlash;
|
||||
|
||||
static constexpr uint16_t dfuServiceId {0x1530};
|
||||
static constexpr uint16_t packetCharacteristicId {0x1532};
|
||||
|
||||
@@ -24,12 +24,14 @@ using namespace Pinetime::Controllers;
|
||||
NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
|
||||
Pinetime::Controllers::Ble& bleController,
|
||||
DateTime& dateTimeController,
|
||||
Pinetime::Controllers::NotificationManager& notificationManager) :
|
||||
Pinetime::Controllers::NotificationManager& notificationManager,
|
||||
Pinetime::Drivers::SpiNorFlash& spiNorFlash) :
|
||||
systemTask{systemTask},
|
||||
bleController{bleController},
|
||||
dateTimeController{dateTimeController},
|
||||
notificationManager{notificationManager},
|
||||
dfuService{systemTask, bleController},
|
||||
spiNorFlash{spiNorFlash},
|
||||
dfuService{systemTask, bleController, spiNorFlash},
|
||||
currentTimeClient{dateTimeController},
|
||||
alertNotificationClient{systemTask, notificationManager} {
|
||||
|
||||
|
||||
@@ -8,12 +8,17 @@
|
||||
#include <host/ble_gap.h>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Drivers {
|
||||
class SpiNorFlash;
|
||||
}
|
||||
namespace Controllers {
|
||||
class DateTime;
|
||||
class NimbleController {
|
||||
|
||||
public:
|
||||
NimbleController(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::Ble& bleController, DateTime& dateTimeController, Pinetime::Controllers::NotificationManager& notificationManager);
|
||||
NimbleController(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::Ble& bleController,
|
||||
DateTime& dateTimeController, Pinetime::Controllers::NotificationManager& notificationManager,
|
||||
Pinetime::Drivers::SpiNorFlash& spiNorFlash);
|
||||
void Init();
|
||||
void StartAdvertising();
|
||||
int OnGAPEvent(ble_gap_event *event);
|
||||
@@ -34,6 +39,7 @@ namespace Pinetime {
|
||||
Pinetime::Controllers::Ble& bleController;
|
||||
DateTime& dateTimeController;
|
||||
Pinetime::Controllers::NotificationManager& notificationManager;
|
||||
Pinetime::Drivers::SpiNorFlash& spiNorFlash;
|
||||
Pinetime::Controllers::DfuService dfuService;
|
||||
|
||||
DeviceInformationService deviceInformationService;
|
||||
|
||||
Reference in New Issue
Block a user