Compare commits
3 commits
fix-compat
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
89664a01f6 | ||
|
2d9bc945c5 | ||
|
f2a464b090 |
|
@ -1,7 +1,6 @@
|
||||||
package TagEngine(
|
package TagEngine(
|
||||||
MkTagType,
|
MkTagType(..),
|
||||||
TagEngine(..),
|
TagEngine(..),
|
||||||
Util.BasicResult(..),
|
|
||||||
mkTagEngine) where
|
mkTagEngine) where
|
||||||
|
|
||||||
import Vector
|
import Vector
|
||||||
|
@ -41,18 +40,18 @@ mkTagEngine = do
|
||||||
requestSignal <- mkRWire -- Signals a tag request
|
requestSignal <- mkRWire -- Signals a tag request
|
||||||
|
|
||||||
-- Debug
|
-- Debug
|
||||||
debugOnce <- mkReg True
|
debugOnce <- mkReg False
|
||||||
|
|
||||||
-- Rules
|
-- Rules
|
||||||
addRules |>
|
addRules |>
|
||||||
rules
|
rules
|
||||||
"debug_initial_state": when debugOnce ==> do
|
"debug_initial_state": when debugOnce ==> do
|
||||||
$display "tagUsage: " (fshow (readVReg tagUsage))
|
-- $display "tagUsage: " (fshow (readVReg tagUsage))
|
||||||
debugOnce := False
|
debugOnce := False
|
||||||
|
|
||||||
"retire_tag": when True ==> do
|
"retire_tag": when True ==> do
|
||||||
let tag = retireQueue.first
|
let tag = retireQueue.first
|
||||||
$display "Retiring tag: " (fshow tag)
|
-- $display "Retiring tag: " (fshow tag)
|
||||||
retireQueue.deq
|
retireQueue.deq
|
||||||
freeTagQueue.enq tag
|
freeTagQueue.enq tag
|
||||||
retireSignal.wset tag
|
retireSignal.wset tag
|
||||||
|
@ -67,13 +66,13 @@ mkTagEngine = do
|
||||||
usage' = update usage requestTag True
|
usage' = update usage requestTag True
|
||||||
usage'' = update usage' retireTag False
|
usage'' = update usage' retireTag False
|
||||||
writeVReg tagUsage usage''
|
writeVReg tagUsage usage''
|
||||||
$display $time " Updated usage (request + retire): " (fshow |> readVReg tagUsage)
|
-- $display $time " Updated usage (request + retire): " (fshow |> readVReg tagUsage)
|
||||||
(Just retireTag, Nothing) -> do
|
(Just retireTag, Nothing) -> do
|
||||||
(select tagUsage retireTag) := False
|
(select tagUsage retireTag) := False
|
||||||
$display $time " Updated usage (retire): " (fshow (readVReg tagUsage))
|
-- $display $time " Updated usage (retire): " (fshow (readVReg tagUsage))
|
||||||
(Nothing, Just requestTag) -> do
|
(Nothing, Just requestTag) -> do
|
||||||
(select tagUsage requestTag) := True
|
(select tagUsage requestTag) := True
|
||||||
$display $time " Updated usage (request): " (fshow (readVReg tagUsage))
|
-- $display $time " Updated usage (request): " (fshow (readVReg tagUsage))
|
||||||
(Nothing, Nothing) -> action {}
|
(Nothing, Nothing) -> action {}
|
||||||
|
|
||||||
-- Interface
|
-- Interface
|
||||||
|
|
67
bs/Tests/BusTester.bs
Normal file
67
bs/Tests/BusTester.bs
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
package TagEngineTester(mkTagEngineTester) where
|
||||||
|
|
||||||
|
import TagEngine
|
||||||
|
import ActionSeq
|
||||||
|
import Assert
|
||||||
|
|
||||||
|
mkTagEngineTester :: Module Empty
|
||||||
|
mkTagEngineTester = do
|
||||||
|
tagEngine :: TagEngine 5 <- mkTagEngine
|
||||||
|
runOnce :: Reg Bool <- mkReg False
|
||||||
|
|
||||||
|
s :: ActionSeq
|
||||||
|
s <-
|
||||||
|
let
|
||||||
|
requestTagAction :: Action
|
||||||
|
requestTagAction =
|
||||||
|
do
|
||||||
|
tag <- tagEngine.requestTag
|
||||||
|
$display $time " got tag : " (fshow tag)
|
||||||
|
|
||||||
|
retireTagAction :: UInt 3 -> Action
|
||||||
|
retireTagAction tag =
|
||||||
|
do
|
||||||
|
res <- tagEngine.retireTag tag
|
||||||
|
$display $time " retiring tag : " (fshow tag) " " (fshow res)
|
||||||
|
action {}
|
||||||
|
|
||||||
|
in
|
||||||
|
actionSeq $
|
||||||
|
do requestTagAction
|
||||||
|
|> do
|
||||||
|
requestTagAction
|
||||||
|
-- tag <- tagEngine.requestTag
|
||||||
|
|> do requestTagAction
|
||||||
|
|> do requestTagAction
|
||||||
|
|> do requestTagAction
|
||||||
|
|> do retireTagAction 2
|
||||||
|
-- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST"
|
||||||
|
|> do
|
||||||
|
retireTagAction 4
|
||||||
|
requestTagAction
|
||||||
|
-- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST"
|
||||||
|
-- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST"
|
||||||
|
|> do
|
||||||
|
retireTagAction 4
|
||||||
|
requestTagAction
|
||||||
|
-- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST"
|
||||||
|
|> do $finish
|
||||||
|
-- |> do retireTagAction 4
|
||||||
|
-- |> do retireTagAction 4
|
||||||
|
-- |> do retireTagAction 0
|
||||||
|
-- |> do requestTagAction
|
||||||
|
-- |> do requestTagAction
|
||||||
|
-- |> do retireTagAction 1
|
||||||
|
-- |> do requestTagAction
|
||||||
|
-- |> do $finish
|
||||||
|
|
||||||
|
addRules $
|
||||||
|
rules
|
||||||
|
-- "counter": when True ==>
|
||||||
|
-- do
|
||||||
|
-- count := count + 1
|
||||||
|
-- $display "count : " (fshow count)
|
||||||
|
"testIncrement": when (runOnce == False) ==>
|
||||||
|
do
|
||||||
|
s.start
|
||||||
|
runOnce := True
|
|
@ -2,6 +2,10 @@ package TagEngineTester(mkTagEngineTester) where
|
||||||
|
|
||||||
import TagEngine
|
import TagEngine
|
||||||
import ActionSeq
|
import ActionSeq
|
||||||
|
import Printf
|
||||||
|
import Util
|
||||||
|
|
||||||
|
type NumTags = 5
|
||||||
|
|
||||||
mkTagEngineTester :: Module Empty
|
mkTagEngineTester :: Module Empty
|
||||||
mkTagEngineTester = do
|
mkTagEngineTester = do
|
||||||
|
@ -15,50 +19,58 @@ mkTagEngineTester = do
|
||||||
requestTagAction =
|
requestTagAction =
|
||||||
do
|
do
|
||||||
tag <- tagEngine.requestTag
|
tag <- tagEngine.requestTag
|
||||||
$display $time " got tag : " (fshow tag)
|
-- $display $time " got tag : " (fshow tag)
|
||||||
|
action {}
|
||||||
|
|
||||||
retireTagAction :: UInt 3 -> Action
|
retireTagAction :: UInt 3 -> Action
|
||||||
retireTagAction tag =
|
retireTagAction tag =
|
||||||
do
|
do
|
||||||
res <- tagEngine.retireTag tag
|
res <- tagEngine.retireTag tag
|
||||||
$display $time " retiring tag : " (fshow tag) " " (fshow res)
|
-- $display $time " retiring tag : " (fshow tag) " " (fshow res)
|
||||||
action {}
|
action {}
|
||||||
|
|
||||||
in
|
in
|
||||||
actionSeq $
|
actionSeq $
|
||||||
do requestTagAction
|
do
|
||||||
|> do requestTagAction
|
$display "=== TESTING TagEngine ==="
|
||||||
|> do requestTagAction
|
let expectedTag = 4
|
||||||
|> do requestTagAction
|
tag <- tagEngine.requestTag
|
||||||
|> do requestTagAction
|
dynamicAssert (tag == expectedTag) ""
|
||||||
|
|> do
|
||||||
|
let expectedTag = 3
|
||||||
|
tag <- tagEngine.requestTag
|
||||||
|
dynamicAssert (tag == expectedTag) ""
|
||||||
|
|> do
|
||||||
|
let expectedTag = 2
|
||||||
|
tag <- tagEngine.requestTag
|
||||||
|
dynamicAssert (tag == expectedTag) ""
|
||||||
|
|> do
|
||||||
|
let expectedTag = 1
|
||||||
|
tag <- tagEngine.requestTag
|
||||||
|
dynamicAssert (tag == expectedTag) ""
|
||||||
|
|> do
|
||||||
|
let expectedTag = 0
|
||||||
|
tag <- tagEngine.requestTag
|
||||||
|
dynamicAssert (tag == expectedTag) ""
|
||||||
|> do retireTagAction 2
|
|> do retireTagAction 2
|
||||||
-- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST"
|
|
||||||
|> do
|
|> do
|
||||||
retireTagAction 4
|
retireTagAction 4
|
||||||
requestTagAction
|
let expectedTag :: MkTagType NumTags
|
||||||
-- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST"
|
expectedTag = 2
|
||||||
-- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST"
|
tag <- tagEngine.requestTag
|
||||||
|
dynamicAssert (tag == expectedTag) ""
|
||||||
|> do
|
|> do
|
||||||
retireTagAction 4
|
retireTagAction 2
|
||||||
requestTagAction
|
let expectedTag = 4
|
||||||
-- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST"
|
tag <- tagEngine.requestTag
|
||||||
|> do $finish
|
dynamicAssert (tag == expectedTag) ""
|
||||||
-- |> do retireTagAction 4
|
|> do
|
||||||
-- |> do retireTagAction 4
|
$display "=== PASSED ==="
|
||||||
-- |> do retireTagAction 0
|
terminateSimNoError
|
||||||
-- |> do requestTagAction
|
|
||||||
-- |> do requestTagAction
|
|
||||||
-- |> do retireTagAction 1
|
|
||||||
-- |> do requestTagAction
|
|
||||||
-- |> do $finish
|
|
||||||
|
|
||||||
addRules $
|
addRules $
|
||||||
rules
|
rules
|
||||||
-- "counter": when True ==>
|
"start unit test": when (runOnce == False) ==>
|
||||||
-- do
|
|
||||||
-- count := count + 1
|
|
||||||
-- $display "count : " (fshow count)
|
|
||||||
"testIncrement": when (runOnce == False) ==>
|
|
||||||
do
|
do
|
||||||
s.start
|
s.start
|
||||||
runOnce := True
|
runOnce := True
|
||||||
|
|
|
@ -7,9 +7,9 @@ import BRAM
|
||||||
import CBindings
|
import CBindings
|
||||||
import Bus
|
import Bus
|
||||||
import TagEngine
|
import TagEngine
|
||||||
|
|
||||||
import List
|
import List
|
||||||
import ActionSeq
|
import ActionSeq
|
||||||
|
|
||||||
import Vector
|
import Vector
|
||||||
import BusTypes
|
import BusTypes
|
||||||
|
|
||||||
|
|
45
bs/Util.bs
45
bs/Util.bs
|
@ -1,24 +1,37 @@
|
||||||
package Util(
|
package Util(
|
||||||
(|>),
|
(|>),
|
||||||
BasicResult(..),
|
terminateSimNoError,
|
||||||
simulate_for) where
|
terminateSimWithError,
|
||||||
|
dynamicAssert
|
||||||
|
) where
|
||||||
|
|
||||||
|
import CBindings
|
||||||
|
|
||||||
infixr 0 |>
|
infixr 0 |>
|
||||||
|
|
||||||
data BasicResult = Success
|
|
||||||
| Failure
|
|
||||||
deriving (Bits, Eq, FShow)
|
|
||||||
|
|
||||||
(|>) :: (a -> b) -> a -> b
|
(|>) :: (a -> b) -> a -> b
|
||||||
f |> x = f x;
|
f |> x = f x;
|
||||||
|
|
||||||
simulate_for :: (Bits a n, Arith a, Eq a) => Reg a -> Reg a -> Rules
|
assertMessage :: String -> String -> String
|
||||||
simulate_for curr_cycle end_cycle =
|
assertMessage which mess =
|
||||||
rules
|
letseq pos = getStringPosition mess -- get position of original message literal
|
||||||
"count_cycle_rule": when True ==> action
|
in (which +++" assertion failed: " +++ printPosition pos +++ mess)
|
||||||
curr_cycle := curr_cycle + 1
|
|
||||||
if curr_cycle == end_cycle
|
dynamicAssert :: Bool -> String -> Action
|
||||||
then
|
dynamicAssert = if not testAssert then (\ _ _ -> noAction)
|
||||||
$finish
|
else (\ b s -> if b then noAction else
|
||||||
else
|
action
|
||||||
$display "cycle = " curr_cycle
|
$display (assertMessage "Dynamic" s)
|
||||||
|
restoreTerminal
|
||||||
|
$finish 1
|
||||||
|
)
|
||||||
|
|
||||||
|
terminateSimNoError :: Action
|
||||||
|
terminateSimNoError = do
|
||||||
|
restoreTerminal
|
||||||
|
$finish 0
|
||||||
|
|
||||||
|
terminateSimWithError :: Action
|
||||||
|
terminateSimWithError = do
|
||||||
|
restoreTerminal
|
||||||
|
$finish 1
|
||||||
|
|
Loading…
Reference in a new issue