From 546493a6c9fd8c09f9420953a4ff79eeb6636dd3 Mon Sep 17 00:00:00 2001 From: Ryan Slawson Date: Mon, 3 Mar 2025 19:20:25 +0100 Subject: [PATCH] Fixups for chain configuration and delaying until devices are done testing. --- .../src/Bittide/Instances/Hitl/Driver/Demo.hs | 84 +++++++++++++++---- 1 file changed, 66 insertions(+), 18 deletions(-) diff --git a/bittide-instances/src/Bittide/Instances/Hitl/Driver/Demo.hs b/bittide-instances/src/Bittide/Instances/Hitl/Driver/Demo.hs index 91f3dc6a3..96d743556 100644 --- a/bittide-instances/src/Bittide/Instances/Hitl/Driver/Demo.hs +++ b/bittide-instances/src/Bittide/Instances/Hitl/Driver/Demo.hs @@ -55,7 +55,7 @@ data OcdInitData = OcdInitData data TestStatus = TestRunning | TestDone Bool | TestTimeout deriving (Eq) -type StartDelay = 20 -- seconds +type StartDelay = 5 -- seconds driverFunc :: (HasCallStack) => @@ -74,16 +74,6 @@ driverFunc testName targets = do let hitlDir = projectDir "_build/hitl/" <> testName - -- 500ms after start of R/W test - delayUntil = startTime + snatToNum (SNat @StartDelay) + fromIntegral (500_000_000 :: Int) - waitUntilDelay :: IO () - waitUntilDelay = do - now <- getTime Monotonic - let delayAmt = toNanoSecs (delayUntil - now) `quot` 1000 - if now >= delayUntil - then return () - else threadDelay (fromIntegral delayAmt) - calcTimeSpentMs = (`div` 1_000_000) . toNanoSecs . diffTimeSpec startTime <$> getTime Monotonic getTargetIndex :: HwTarget -> Int @@ -382,6 +372,63 @@ driverFunc testName targets = do tryWithTimeout "PE buffer readout" 15_000_000 $ readUntil gdb.stdoutHandle endString putStrLn $ "PE buffer readout:\n" <> bufInit + muGetCurrentTime :: + (HasCallStack) => + (HwTarget, DeviceInfo) -> + ProcessStdIoHandles -> + IO (Unsigned 64) + muGetCurrentTime (_, d) gdb = do + putStrLn $ "Getting current time from device " <> d.deviceId + -- Write capture command to `timeWb` component + Gdb.runCommands gdb.stdinHandle ["set {char[4]}(0xD0000000) = 0x0"] + let + currentStringLsbs = "START OF STARTTIME LSBS" + endStringLsbs = "END OF STARTTIME LSBS" + Gdb.runCommands + gdb.stdinHandle + [ "printf \"" <> currentStringLsbs <> "\\n\"" + , "x/1xw 0xD0000008" + , "printf \"" <> endStringLsbs <> "\\n\"" + ] + _ <- + tryWithTimeout "Waiting for GDB to be ready for curtime lsbs readout" 15_000_000 + $ readUntil gdb.stdoutHandle currentStringLsbs + currentStringLsbs0 <- + tryWithTimeout "Current time lsbs readout" 15_000_000 + $ readUntil gdb.stdoutHandle endStringLsbs + let + currentStringLsbs1 = trim $ L.drop 2 $ L.dropWhile (/= ':') currentStringLsbs0 + currentTimeLsbsI :: Integer + currentTimeLsbsI = read currentStringLsbs1 + currentTimeLsbs :: Unsigned 32 + currentTimeLsbs = fromIntegral currentTimeLsbsI + putStrLn $ "GDB said: " <> currentStringLsbs1 + putStrLn $ "I read: " <> show currentTimeLsbs + let + currentStringMsbs = "START OF CURTIME MSBS" + endStringMsbs = "END OF CURTIME MSBS" + Gdb.runCommands + gdb.stdinHandle + [ "printf \"" <> currentStringMsbs <> "\\n\"" + , "x/1xw 0xD000000C" + , "printf \"" <> endStringMsbs <> "\\n\"" + ] + _ <- + tryWithTimeout "Waiting for GDB to be ready for curtime msbs readout" 15_000_000 + $ readUntil gdb.stdoutHandle currentStringMsbs + currentStringMsbs0 <- + tryWithTimeout "Current time msbs readout" 15_000_000 + $ readUntil gdb.stdoutHandle endStringMsbs + let + currentStringMsbs1 = trim $ L.drop 2 $ L.dropWhile (/= ':') currentStringMsbs0 + currentTimeMsbsI :: Integer + currentTimeMsbsI = read currentStringMsbs1 + currentTimeMsbs :: Unsigned 32 + currentTimeMsbs = fromIntegral currentTimeMsbsI + putStrLn $ "GDB said: " <> currentStringMsbs1 + putStrLn $ "I read: " <> show currentTimeMsbs + return $ bitCoerce (currentTimeMsbs, currentTimeLsbs) + muWriteCfg :: (HasCallStack) => (HwTarget, DeviceInfo) -> @@ -467,24 +514,25 @@ driverFunc testName targets = do ugnPairsTable <- zipWithM muGetUgns targets muGdbs let ugnPairsTableV = fromJust . V.fromList $ fromJust . V.fromList <$> ugnPairsTable - liftIO $ putStrLn "Calculating IGNs for all targets" - liftIO $ printAllIgns ugnPairsTableV fpgaSetup - liftIO $ mapM_ print ugnPairsTableV + liftIO $ do + putStrLn "Calculating IGNs for all targets" + printAllIgns ugnPairsTableV fpgaSetup + mapM_ print ugnPairsTableV + currentTime <- liftIO $ muGetCurrentTime (L.head targets) (L.head muGdbs) let - startOffset :: SNat (PeriodToCycles GthTx (Seconds StartDelay)) - startOffset = SNat + startOffset = currentTime + natToNum @(PeriodToCycles GthTx (Seconds StartDelay)) chainConfig :: Vec FpgaCount (Ugns.PeConfig (Unsigned 64) (Index 9)) chainConfig = fullChainConfiguration (SNat @FpgaCount) fpgaSetup ugnPairsTableV - (snatToNum startOffset) + startOffset liftIO $ do putStrLn "Calculated the following configs for the switch processing elements:" forM_ chainConfig print _ <- sequenceA $ L.zipWith3 muWriteCfg targets muGdbs (toList chainConfig) - liftIO waitUntilDelay + liftIO $ threadDelay (natToNum @StartDelay * 1_250_000) _ <- liftIO $ sequenceA $ L.zipWith muReadPeBuffer targets muGdbs let