Skip to content

Commit

Permalink
Make GDB init wait until target device is connected.
Browse files Browse the repository at this point in the history
  • Loading branch information
rslawson committed Feb 19, 2025
1 parent 1ea20fe commit 7999628
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
13 changes: 3 additions & 10 deletions bittide-instances/src/Bittide/Instances/Hitl/Driver/Demo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import Bittide.Instances.Hitl.Setup (demoRigInfo)
import Bittide.Instances.Hitl.Utils.Program
import Bittide.Instances.Hitl.Utils.Vivado

import Control.Exception (SomeException, catch)
import Control.Monad (forM_, zipWithM)
import Control.Monad.IO.Class
import Data.Maybe (fromMaybe)
Expand Down Expand Up @@ -182,6 +181,9 @@ driverFunc testName targets = do
</> "gdb-" <> binName <> "-" <> show (getTargetIndex hwT) <> ".log"
Gdb.setFile gdb $ firmwareBinariesDir "riscv32imc" Release </> binName
Gdb.setTarget gdb gdbPort
Gdb.runCommands gdb.stdinHandle ["echo connected to target device"]
tryWithTimeout "Waiting for GDB to be ready to proceed" 15_000_000
$ expectLine gdb.stdoutHandle gdbWaitForConnect

let
gdbProcName = "GDB (" <> binName <> ", " <> show d.deviceId <> ")"
Expand Down Expand Up @@ -246,16 +248,8 @@ driverFunc testName targets = do
then (count + 1, acc)
else (count, code)

dumpBuffer :: Handle -> (Handle -> IO a) -> IO ()
dumpBuffer hdl f = do
ready <- catch (hReady hdl) $ \(_ :: SomeException) -> return False
if ready
then f hdl >> dumpBuffer hdl f
else return ()

muGdbCheck :: (HwTarget, DeviceInfo) -> ProcessStdIoHandles -> VivadoM ExitCode
muGdbCheck (_, _) gdb = do
liftIO $ dumpBuffer gdb.stdoutHandle hGetLine
liftIO $ Gdb.runCommands gdb.stdinHandle ["x/4sb 0x60000000", "echo END OF WHOAMI\\n"]
gdbRead <-
liftIO
Expand All @@ -266,7 +260,6 @@ driverFunc testName targets = do

ccGdbCheck :: (HwTarget, DeviceInfo) -> ProcessStdIoHandles -> VivadoM ExitCode
ccGdbCheck (_, _) gdb = do
liftIO $ dumpBuffer gdb.stdoutHandle hGetLine
liftIO $ Gdb.runCommands gdb.stdinHandle ["x/4sb 0x60000000", "echo END OF WHOAMI\\n"]
gdbRead <-
liftIO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Paths_bittide_instances

import Control.Monad.Catch
import Control.Monad.IO.Class
import Data.List (isPrefixOf)
import Data.List (isInfixOf, isPrefixOf)
import Data.Maybe (fromJust)
import System.IO
import System.Posix.Env (getEnvironment)
Expand Down Expand Up @@ -239,6 +239,11 @@ openOcdWaitForHalt s
| "Halting processor" `isPrefixOf` s = Stop Ok
| otherwise = Continue

gdbWaitForConnect :: String -> Filter
gdbWaitForConnect s
| "connected to target device" `isInfixOf` s = Stop Ok
| otherwise = Continue

gdbWaitForLoad :: String -> Filter
gdbWaitForLoad s
| "Remote communication error." `isPrefixOf` s =
Expand Down

0 comments on commit 7999628

Please sign in to comment.