Skip to content

Commit

Permalink
Fixups for chain configuration and delaying until devices are done te…
Browse files Browse the repository at this point in the history
…sting.
  • Loading branch information
rslawson committed Mar 3, 2025
1 parent 3de3ed2 commit 546493a
Showing 1 changed file with 66 additions and 18 deletions.
84 changes: 66 additions & 18 deletions bittide-instances/src/Bittide/Instances/Hitl/Driver/Demo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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
Expand Down Expand Up @@ -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) ->
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 546493a

Please sign in to comment.