Compare commits

..

2 Commits

Author SHA1 Message Date
Yasser Yassine 1b00c6a05b Gigastar(2): Fix bootloaders steps 2025-10-30 14:37:12 -04:00
Kyle Schwarz ebf9409c18 Device: Guard mutex usage 2025-10-30 11:18:12 -04:00
4 changed files with 57 additions and 18 deletions

View File

@ -554,26 +554,28 @@ bool Device::goOnline() {
return false;
}
assignedClientId = com->getClientIDSync();
if(assignedClientId) {
// firmware supports clientid/mutex
networkMutexCallbackHandle = lockAllNetworks(std::numeric_limits<uint32_t>::max(), std::numeric_limits<uint32_t>::max(), NetworkMutexType::Shared, [this](std::shared_ptr<Message> message) {
auto netMutexMsg = std::static_pointer_cast<NetworkMutexMessage>(message);
if(netMutexMsg->networks.size() && netMutexMsg->event.has_value()) {
switch(*netMutexMsg->event) {
case NetworkMutexEvent::Acquired:
lockedNetworks.emplace(*netMutexMsg->networks.begin());
break;
case NetworkMutexEvent::Released: {
auto it = lockedNetworks.find(*netMutexMsg->networks.begin());
if (it != lockedNetworks.end())
lockedNetworks.erase(it);
break;
if(supportsNetworkMutex()) {
assignedClientId = com->getClientIDSync();
if(assignedClientId) {
// firmware supports clientid/mutex
networkMutexCallbackHandle = lockAllNetworks(std::numeric_limits<uint32_t>::max(), std::numeric_limits<uint32_t>::max(), NetworkMutexType::Shared, [this](std::shared_ptr<Message> message) {
auto netMutexMsg = std::static_pointer_cast<NetworkMutexMessage>(message);
if(netMutexMsg->networks.size() && netMutexMsg->event.has_value()) {
switch(*netMutexMsg->event) {
case NetworkMutexEvent::Acquired:
lockedNetworks.emplace(*netMutexMsg->networks.begin());
break;
case NetworkMutexEvent::Released: {
auto it = lockedNetworks.find(*netMutexMsg->networks.begin());
if (it != lockedNetworks.end())
lockedNetworks.erase(it);
break;
}
}
}
}
}
);
);
}
}
// (re)start the keeponline

View File

@ -28,7 +28,8 @@ struct BootloaderPhase {
Finalize,
Reconnect,
EnterBootloader,
Wait
Wait,
EnterApplication
};
virtual Type getType() const = 0;
@ -70,6 +71,16 @@ struct EnterBootloaderPhase : public BootloaderPhase {
}
};
struct EnterApplicationPhase : public BootloaderPhase {
Type getType() const override {
return Type::EnterApplication;
}
ChipID chip;
EnterApplicationPhase(ChipID chip) : chip(chip) {}
};
struct FlashPhase : public BootloaderPhase {
Type getType() const override {
return Type::Flash;

View File

@ -67,10 +67,23 @@ public:
}
}
if(useNewBootloader) {
auto mainChip = std::find_if(chipVersions.begin(), chipVersions.end(), [](const auto& chip) { return chip.name == "ZCHIP"; });
auto usbChip = std::find_if(chipVersions.begin(), chipVersions.end(), [](const auto& chip) { return chip.name == "USB ZCHIP"; });
ChipID mainChipID;
if(mainChip != chipVersions.end()) {
mainChipID = mainChip->id;
} else if(usbChip != chipVersions.end()) {
mainChipID = usbChip->id;
} else {
return {};
}
BootloaderPipeline pipeline;
for(const auto& version : chipVersions) {
pipeline.add<FlashPhase>(version.id, BootloaderCommunication::RADMultiChip);
}
pipeline.add<EnterApplicationPhase>(mainChipID);
pipeline.add<ReconnectPhase>();
pipeline.add<WaitPhase>(std::chrono::milliseconds(3000));
return pipeline;

View File

@ -146,10 +146,23 @@ public:
BootloaderPipeline getBootloader() override {
auto chipVersions = getChipVersions();
auto mainChip = std::find_if(chipVersions.begin(), chipVersions.end(), [](const auto& chip) { return chip.name == "ZCHIP"; });
auto usbChip = std::find_if(chipVersions.begin(), chipVersions.end(), [](const auto& chip) { return chip.name == "USB ZCHIP"; });
ChipID mainChipID;
if(mainChip != chipVersions.end()) {
mainChipID = mainChip->id;
} else if(usbChip != chipVersions.end()) {
mainChipID = usbChip->id;
} else {
return {};
}
BootloaderPipeline pipeline;
for(const auto& version : chipVersions) {
pipeline.add<FlashPhase>(version.id, BootloaderCommunication::RADMultiChip);
}
pipeline.add<EnterApplicationPhase>(mainChipID);
pipeline.add<ReconnectPhase>();
pipeline.add<WaitPhase>(std::chrono::milliseconds(3000));
return pipeline;