Skip to content

Commit 41247c0

Browse files
committed
Add Simulate instance for AXI4Lite
1 parent cc790e6 commit 41247c0

File tree

3 files changed

+31
-32
lines changed

3 files changed

+31
-32
lines changed

src/Protocols/Axi4/Lite/Axi4Lite.hs

Lines changed: 31 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,17 @@ 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 (NFDataX (S2M_Axi4Lite aw bw)) => 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+
simToSigFwd Proxy = C.fromList_lazy
246+
simToSigBwd Proxy = C.fromList_lazy
247+
sigToSimFwd Proxy = C.sample_lazy
248+
sigToSimBwd Proxy = C.sample_lazy
249+

src/Protocols/Df.hs

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

186186

187187

188-
simulateManager SimulationConfig{..} acks circ =
189-
P.take timeoutAfter $
190-
CE.sample_lazy $
191-
P.snd $
192-
toSignals circ ((), resetAndAcks)
193-
where
194-
resetAndAcks = C.fromList $ (P.map Ack (replicate resetCycles False) <> acks)
195-
196-
-- TODO: apply simulation config
197-
simulateSubordinate SimulationConfig{..} fwds circ = CE.sample_lazy ackSig
198-
where
199-
(ackSig, ()) = toSignals circ (dataSig, ())
200-
dataSig = C.fromList_lazy (ackedData resetCycles fwds (C.sample ackSig))
201-
202-
ackedData resetN _ (_:acks) | resetN > 0 =
203-
NoData : ackedData (resetN - 1) fwds acks
204-
ackedData _ [] (_:acks) = NoData : ackedData 0 [] acks
205-
ackedData _ (dat:datas) (ack:acks) = case ack of
206-
Ack True -> dat : ackedData 0 (datas) acks
207-
Ack False -> dat : ackedData 0 (dat:datas) acks
208-
209-
210188

211189
instance DfLike dom (Df dom) a where
212190
type Data (Df dom) a = Data a

src/Protocols/Internal.hs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@ newtype Circuit a b =
145145
-- | Protocol-agnostic acknowledgement
146146
newtype Ack = Ack Bool
147147
deriving (Generic, C.NFDataX, Show)
148-
<<<<<<< HEAD
149-
=======
150-
151-
>>>>>>> 744b99a... Add AXI4 Lite types
152148

153149
-- | Acknowledge. Used in circuit-notation plugin to drive ignore components.
154150
instance Default Ack where
@@ -514,9 +510,6 @@ instance Drivable () where
514510
simulateRight _ _ _ = ()
515511
simulateLeft _ _ _ = ()
516512

517-
simulateManager _ _ _ = ()
518-
simulateSubordinate _ _ _ = ()
519-
520513

521514
instance (Simulate a, Simulate b) => Simulate (a, b) where
522515
type SimulateFwdType (a, b) = (SimulateFwdType a, SimulateFwdType b)

0 commit comments

Comments
 (0)