Add firmware support for hard sectors

This commit is contained in:
Eric Anderson
2020-12-24 15:41:51 -08:00
parent 15e6d4959e
commit f1506d0dbd
14 changed files with 143 additions and 31 deletions

View File

@@ -3,6 +3,7 @@
#include "fluxmap.h"
#include "usb/usb.h"
#include "fluxsink/fluxsink.h"
#include "fmt/format.h"
FlagGroup hardwareFluxSinkFlags = {
&usbFlags,
@@ -15,17 +16,34 @@ static IntFlag indexMode(
"index pulse source (0=drive, 1=300 RPM fake source, 2=360 RPM fake source",
0);
static IntFlag hardSectorCount(
{ "--write-hard-sector-count" },
"number of hard sectors on the disk (0=soft sectors)",
0);
void setHardwareFluxSinkDensity(bool high_density)
{
::high_density = high_density;
}
void setHardwareFluxSinkHardSectorCount(int sectorCount)
{
::hardSectorCount.setDefaultValue(sectorCount);
}
class HardwareFluxSink : public FluxSink
{
public:
HardwareFluxSink(unsigned drive):
_drive(drive)
{
if (hardSectorCount.get())
{
std::cerr << "Measuring rotational speed... " << std::flush;
nanoseconds_t oneRevolution = usbGetRotationalPeriod(hardSectorCount);
_hardSectorThreshold = oneRevolution * 3 / (4 * hardSectorCount);
std::cerr << fmt::format("{}ms\n", oneRevolution / 1e6);
}
}
~HardwareFluxSink()
@@ -38,11 +56,12 @@ public:
usbSetDrive(_drive, high_density, indexMode);
usbSeek(track);
return usbWrite(side, fluxmap.rawBytes());
return usbWrite(side, fluxmap.rawBytes(), _hardSectorThreshold);
}
private:
unsigned _drive;
nanoseconds_t _hardSectorThreshold;
};
std::unique_ptr<FluxSink> FluxSink::createHardwareFluxSink(unsigned drive)