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

@@ -144,9 +144,12 @@ public:
await_reply<struct any_frame>(F_FRAME_RECALIBRATE_REPLY);
}
nanoseconds_t getRotationalPeriod(void)
nanoseconds_t getRotationalPeriod(int hardSectorCount)
{
struct any_frame f = { .f = {.type = F_FRAME_MEASURE_SPEED_CMD, .size = sizeof(f)} };
struct measurespeed_frame f = {
.f = {.type = F_FRAME_MEASURE_SPEED_CMD, .size = sizeof(f)},
.hard_sector_count = (uint8_t) hardSectorCount,
};
usb_cmd_send(&f, f.f.size);
auto r = await_reply<struct speed_frame>(F_FRAME_MEASURE_SPEED_REPLY);
@@ -227,12 +230,15 @@ public:
await_reply<struct any_frame>(F_FRAME_BULK_READ_TEST_REPLY);
}
Bytes read(int side, bool synced, nanoseconds_t readTime)
Bytes read(int side, bool synced, nanoseconds_t readTime,
nanoseconds_t hardSectorThreshold)
{
hardSectorThreshold += 5e5; /* Round to nearest ms. */
struct read_frame f = {
.f = { .type = F_FRAME_READ_CMD, .size = sizeof(f) },
.side = (uint8_t) side,
.synced = (uint8_t) synced
.synced = (uint8_t) synced,
.hardsec_threshold_ms = (uint8_t) (hardSectorThreshold / 1e6),
};
uint16_t milliseconds = readTime / 1e6;
((uint8_t*)&f.milliseconds)[0] = milliseconds;
@@ -249,14 +255,16 @@ public:
return buffer;
}
void write(int side, const Bytes& bytes)
void write(int side, const Bytes& bytes, nanoseconds_t hardSectorThreshold)
{
unsigned safelen = bytes.size() & ~(FRAME_SIZE-1);
Bytes safeBytes = bytes.slice(0, safelen);
hardSectorThreshold += 5e5; /* Round to nearest ms. */
struct write_frame f = {
.f = { .type = F_FRAME_WRITE_CMD, .size = sizeof(f) },
.side = (uint8_t) side,
.hardsec_threshold_ms = (uint8_t) (hardSectorThreshold / 1e6),
};
((uint8_t*)&f.bytes_to_write)[0] = safelen;
((uint8_t*)&f.bytes_to_write)[1] = safelen >> 8;
@@ -269,11 +277,13 @@ public:
await_reply<struct any_frame>(F_FRAME_WRITE_REPLY);
}
void erase(int side)
void erase(int side, nanoseconds_t hardSectorThreshold)
{
hardSectorThreshold += 5e5; /* Round to nearest ms. */
struct erase_frame f = {
.f = { .type = F_FRAME_ERASE_CMD, .size = sizeof(f) },
.side = (uint8_t) side,
.hardsec_threshold_ms = (uint8_t) (hardSectorThreshold / 1e6),
};
usb_cmd_send(&f, f.f.size);