11{-# LANGUAGE FlexibleContexts #-}
22{-# LANGUAGE FlexibleInstances #-}
33{-# LANGUAGE UndecidableInstances #-}
4+ {-# LANGUAGE RecordWildCards #-}
45{-|
56Defines datatypes for all five channels of the AXI4 Lite protocol. For more
67information 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.
910module Protocols.Axi4.Lite.Axi4Lite where
1011
1112import Protocols
13+ import Protocols.Internal
1214import Protocols.Axi4.Common
1315import Clash.Prelude as C
16+ import qualified Prelude as P
17+ import qualified Clash.Explicit.Prelude as CE
1418
1519import 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
2024type instance Width 'Width32 = 32
2125type 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+
133138deriving instance
134139 (C. KnownNat (Width aw ))
135140 => Show (M2S_ReadAddress aw )
@@ -138,7 +143,7 @@ deriving instance
138143data 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
184194deriving 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
203217deriving 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+
0 commit comments