diff --git a/src/Harp.Toolkit/Verify/Suites/CoreRegisters/R_TIMESTAMP_SECOND.cs b/src/Harp.Toolkit/Verify/Suites/CoreRegisters/R_TIMESTAMP_SECOND.cs index 4a6472f..ff55486 100644 --- a/src/Harp.Toolkit/Verify/Suites/CoreRegisters/R_TIMESTAMP_SECOND.cs +++ b/src/Harp.Toolkit/Verify/Suites/CoreRegisters/R_TIMESTAMP_SECOND.cs @@ -6,9 +6,14 @@ internal class R_TIMESTAMP_SECOND : Suite { public override string Description => "Timestamp Seconds Register Tests"; + const string ClockLockedMessage = "The timestamp register is locked (CLK_LOCK), so the device correctly refuses writes."; + [HarpTest(Description = "Validates that the Timestamp Seconds register is writable.")] public async Task IsWritable(VerifyConnection device) { + if (await IsClockLockedAsync(device)) + return new Result(false, Status.Skipped, ClockLockedMessage); + const uint setSeconds = 42; const double maximumElapsedSeconds = 2.0; await device.WriteTimestampSecondsAsync(setSeconds); @@ -54,6 +59,9 @@ public async Task IsMonotonic(VerifyConnection device) [HarpTest(Description = "Validates that writing a past timestamp value takes effect and can be read back.")] public async Task WritePastValueRoundTrip(VerifyConnection device) { + if (await IsClockLockedAsync(device)) + return new Result(false, Status.Skipped, ClockLockedMessage); + const long maximumElapsedSeconds = 1; var current = await device.ReadTimestampSecondsAsync(); var tPast = current >= 10 ? current - 10 : 0u; @@ -71,4 +79,17 @@ public async Task WritePastValueRoundTrip(VerifyConnection device) : $"Wrote {tPast} to TimestampSeconds and read it back as {readBack}, " + $"outside the expected range of {tPast} to {tPast + maximumElapsedSeconds}."); } + + static async Task IsClockLockedAsync(VerifyConnection device) + { + try + { + var configuration = (ClockConfigurationFlags)await device.ReadByteAsync(ClockConfiguration.Address); + return configuration.HasFlag(ClockConfigurationFlags.ClockLock); + } + catch (Exception) + { + return false; + } + } }