Skip to content

Commit

Permalink
Replace system timer by C++ standard time for timeout of 3 s (#1361)
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Nov 16, 2023
1 parent b46d564 commit 06726a8
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions cpp/piscsi/piscsi_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "devices/host_services.h"
#include "hal/gpiobus_factory.h"
#include "hal/gpiobus.h"
#include "hal/systimer.h"
#include "piscsi/piscsi_core.h"
#include <spdlog/spdlog.h>
#include <netinet/in.h>
Expand All @@ -30,6 +29,7 @@
#include <iostream>
#include <fstream>
#include <vector>
#include <chrono>

using namespace std;
using namespace filesystem;
Expand Down Expand Up @@ -456,21 +456,19 @@ bool Piscsi::ExecuteCommand(CommandContext& context) const
bool Piscsi::IsNotBusy() const
{
// Wait until BSY is released as there is a possibility for the
// initiator to assert it while setting the ID (for up to 3 seconds)
if (bus->GetBSY()) {
const uint32_t now = SysTimer::GetTimerLow();

// Wait for 3s
while ((SysTimer::GetTimerLow() - now) < 3'000'000) {
bus->Acquire();

if (!bus->GetBSY()) {
return true;
}
}

return false;
}
// initiator to assert it while setting the ID (for up to 3 seconds)
if (bus->GetBSY()) {
const auto now = chrono::steady_clock::now();
while ((chrono::duration_cast<chrono::seconds>(chrono::steady_clock::now() - now).count()) < 3) {
bus->Acquire();

if (!bus->GetBSY()) {
return true;
}
}

return false;
}

return true;
return true;
}

0 comments on commit 06726a8

Please sign in to comment.