Skip to content

Commit d8e80f9

Browse files
committed
Add Simulate instance for AXI4Lite
1 parent 6eaaa8e commit d8e80f9

File tree

3 files changed

+64
-28
lines changed

3 files changed

+64
-28
lines changed

src/Protocols/Axi4/Lite/Axi4Lite.hs

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE FlexibleContexts #-}
22
{-# LANGUAGE FlexibleInstances #-}
33
{-# LANGUAGE UndecidableInstances #-}
4+
{-# LANGUAGE RecordWildCards #-}
45
{-|
56
Defines datatypes for all five channels of the AXI4 Lite protocol. For more
67
information on AXI4 Lite, see chapter B of the AMBA AXI specification.
@@ -9,13 +10,16 @@ information on AXI4 Lite, see chapter B of the AMBA AXI specification.
910
module Protocols.Axi4.Lite.Axi4Lite where
1011

1112
import Protocols
13+
import Protocols.Internal
1214
import Protocols.Axi4.Common
1315
import Clash.Prelude as C
16+
import qualified Prelude as P
17+
import qualified Clash.Explicit.Prelude as CE
1418

1519
import Control.DeepSeq
1620

1721
-- | AXI4 Lite busses are always either 32 bit or 64 bit.
18-
data BusWidth = Width32 | Width64 deriving (Show, Eq)
22+
data BusWidth = Width32 | Width64 deriving (Show, Eq, Generic, NFDataX)
1923

2024
type instance Width 'Width32 = 32
2125
type instance Width 'Width64 = 64
@@ -32,7 +36,6 @@ type family ReadBusWidthType (bw :: BusWidth) where
3236
ReadBusWidthType 'Width32 = C.Vec 4 (C.BitVector 8)
3337
ReadBusWidthType 'Width64 = C.Vec 8 (C.BitVector 8)
3438

35-
3639
---------------------------
3740
--- Write address types ---
3841
---------------------------
@@ -130,6 +133,8 @@ data M2S_ReadAddress
130133
_arprot :: PermissionsType 'KeepPermissions
131134
} deriving (Generic)
132135

136+
deriving instance (KnownNat (Width aw)) => NFDataX (M2S_ReadAddress aw)
137+
133138
deriving instance
134139
(C.KnownNat (Width aw))
135140
=> Show (M2S_ReadAddress aw)
@@ -138,7 +143,7 @@ deriving instance
138143
data S2M_ReadAddress
139144
= S2M_ReadAddress {
140145
_arready :: Bool
141-
} deriving (Show, Generic)
146+
} deriving (Show, Generic, NFDataX)
142147

143148

144149
-----------------------
@@ -180,6 +185,11 @@ data M2S_Axi4Lite
180185
m2s_ra :: M2S_ReadAddress aw,
181186
m2s_rd :: M2S_ReadData bw
182187
}
188+
deriving (Generic)
189+
190+
deriving instance
191+
(NFDataX (ReadBusWidthType bw), NFDataX (WriteBusWidthType bw), KnownNat (Width aw))
192+
=> NFDataX (M2S_Axi4Lite aw bw)
183193

184194
deriving instance
185195
( Show (ReadBusWidthType bw)
@@ -199,6 +209,10 @@ data S2M_Axi4Lite
199209
s2m_ra :: S2M_ReadAddress,
200210
s2m_rd :: S2M_ReadData bw
201211
}
212+
deriving (Generic)
213+
214+
-- this breaks when e.g. fromList is used on an unconstrained value :: S2MAxi4Lite aw bw.
215+
deriving instance (NFDataX (ReadBusWidthType bw)) => NFDataX (S2M_Axi4Lite aw bw)
202216

203217
deriving instance
204218
( Show (ReadBusWidthType bw)
@@ -219,3 +233,50 @@ instance Protocol (Axi4Lite dom aw bw) where
219233
type Fwd (Axi4Lite dom aw bw) = C.Signal dom (M2S_Axi4Lite aw bw)
220234
type Bwd (Axi4Lite dom aw bw) = C.Signal dom (S2M_Axi4Lite aw bw)
221235

236+
237+
instance Backpressure (Axi4Lite dom aw bw) where
238+
boolsToBwd = error "Cannot construct arbitrary S2M AXI type from boolean."
239+
240+
instance Simulate (Axi4Lite dom aw bw) where
241+
type SimulateFwdType (Axi4Lite dom aw bw) = [M2S_Axi4Lite aw bw]
242+
type SimulateBwdType (Axi4Lite dom aw bw) = [S2M_Axi4Lite aw bw]
243+
type SimulateChannels (Axi4Lite dom aw bw) = 1
244+
245+
simulateRight :: SimulationConfig
246+
-> [S2M_Axi4Lite aw bw]
247+
-> Circuit () (Axi4Lite dom aw bw)
248+
-> [M2S_Axi4Lite aw bw]
249+
simulateRight SimulationConfig{..} bwds circ =
250+
P.take timeoutAfter $
251+
CE.sample_lazy $
252+
P.snd $
253+
toSignals circ ((), resetAndBwds)
254+
where
255+
resetAndBwds = C.fromList_lazy $ P.replicate resetCycles idleS2MChannels <> bwds
256+
idleS2MChannels = S2M_Axi4Lite {
257+
s2m_wa = S2M_WriteAddress False,
258+
s2m_wd = S2M_WriteData False,
259+
s2m_wr = S2M_NoWriteResponse,
260+
s2m_ra = S2M_ReadAddress False,
261+
s2m_rd = S2M_NoReadData
262+
}
263+
264+
simulateLeft :: SimulationConfig
265+
-> [M2S_Axi4Lite aw bw]
266+
-> Circuit (Axi4Lite dom aw bw) ()
267+
-> [S2M_Axi4Lite aw bw]
268+
simulateLeft SimulationConfig{..} fwds circ =
269+
P.take timeoutAfter $
270+
CE.sample_lazy $
271+
P.fst $
272+
toSignals circ (resetAndFwds, ())
273+
where
274+
resetAndFwds = C.fromList_lazy $ P.replicate resetCycles idleM2SChannels <> fwds
275+
idleM2SChannels = M2S_Axi4Lite {
276+
m2s_wa = M2S_NoWriteAddress,
277+
m2s_wd = M2S_NoWriteData,
278+
m2s_wr = M2S_WriteResponse False,
279+
m2s_ra = M2S_NoReadAddress,
280+
m2s_rd = M2S_ReadData False
281+
}
282+

src/Protocols/Df.hs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -177,28 +177,6 @@ instance (C.KnownDomain dom, C.NFDataX a, C.ShowX a, Show a) => Simulate (Df dom
177177

178178

179179

180-
simulateManager SimulationConfig{..} acks circ =
181-
P.take timeoutAfter $
182-
CE.sample_lazy $
183-
P.snd $
184-
toSignals circ ((), resetAndAcks)
185-
where
186-
resetAndAcks = C.fromList $ (P.map Ack (replicate resetCycles False) <> acks)
187-
188-
-- TODO: apply simulation config
189-
simulateSubordinate SimulationConfig{..} fwds circ = CE.sample_lazy ackSig
190-
where
191-
(ackSig, ()) = toSignals circ (dataSig, ())
192-
dataSig = C.fromList_lazy (ackedData resetCycles fwds (C.sample ackSig))
193-
194-
ackedData resetN _ (_:acks) | resetN > 0 =
195-
NoData : ackedData (resetN - 1) fwds acks
196-
ackedData _ [] (_:acks) = NoData : ackedData 0 [] acks
197-
ackedData _ (dat:datas) (ack:acks) = case ack of
198-
Ack True -> dat : ackedData 0 (datas) acks
199-
Ack False -> dat : ackedData 0 (dat:datas) acks
200-
201-
202180

203181
instance DfLike dom (Df dom) a where
204182
type Data (Df dom) a = Data a

src/Protocols/Internal.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,6 @@ instance Simulate () where
491491
simulateRight _ _ _ = ()
492492
simulateLeft _ _ _ = ()
493493

494-
simulateManager _ _ _ = ()
495-
simulateSubordinate _ _ _ = ()
496-
497494

498495
instance (Simulate a, Simulate b) => Simulate (a, b) where
499496
type SimulateType (a, b) = (SimulateType a, SimulateType b)

0 commit comments

Comments
 (0)