@@ -8,7 +8,7 @@ Types modelling the Wishbone bus protocol.
88-}
99module Protocols.Wishbone where
1010
11- import Clash.Prelude (DivRU , Nat , Type , (:::) )
11+ import Clash.Prelude (Nat , (:::) )
1212import Prelude hiding (head , not , (&&) )
1313
1414import Clash.Signal.Internal (Signal (.. ))
@@ -19,17 +19,17 @@ import Protocols.Idle
1919import Clash.Prelude qualified as C
2020
2121-- | Data communicated from a Wishbone Master to a Wishbone Slave
22- data WishboneM2S addressWidth selWidth dat = WishboneM2S
23- { addr :: " ADR" ::: C. BitVector addressWidth
22+ data WishboneM2S addressBits dataBytes = WishboneM2S
23+ { addr :: " ADR" ::: C. BitVector addressBits
2424 -- ^ The address output array [ADR_O()] is used to pass a binary address. The higher array
2525 -- boundary is specific to the address width of the core, and the lower array boundary is
2626 -- determined by the data port size and granularity. For example the array size on a 32-bit
2727 -- data port with BYTE granularity is [ADR_O(n..2)]. In some cases (such as FIFO
2828 -- interfaces) the array may not be present on the interface.
29- , writeData :: " DAT_MOSI" ::: dat
29+ , writeData :: " DAT_MOSI" ::: C. BitVector ( dataBytes C. * 8 )
3030 -- ^ The data output array [DAT_O()] is used to pass binary data. The array boundaries are
3131 -- determined by the port size, with a maximum port size of 64-bits (e.g. [DAT_I(63..0)]).
32- , busSelect :: " SEL" ::: C. BitVector selWidth
32+ , busSelect :: " SEL" ::: C. BitVector dataBytes
3333 -- ^ The select output array [SEL_O()] indicates where valid data is expected on the [DAT_I()]
3434 -- signal array during READ cycles, and where it is placed on the [DAT_O()] signal array
3535 -- during WRITE cycles. The array boundaries are determined by the granularity of a port.
@@ -69,16 +69,16 @@ data WishboneM2S addressWidth selWidth dat = WishboneM2S
6969 deriving (NFData , C.Generic , C.NFDataX , Eq , C.BitPack )
7070
7171instance
72- (C. ShowX dat , C. KnownNat addressWidth , C. KnownNat selWidth ) =>
73- C. ShowX (WishboneM2S addressWidth selWidth dat )
72+ (C. KnownNat addressBits , C. KnownNat dataBytes ) =>
73+ C. ShowX (WishboneM2S addressBits dataBytes )
7474 where
7575 showX = show
7676
7777-- Compact printing for M2S values. This handles undefined values in the
7878-- structure too.
7979instance
80- (C. ShowX dat , C. KnownNat addressWidth , C. KnownNat selWidth ) =>
81- Show (WishboneM2S addressWidth selWidth dat )
80+ (C. KnownNat addressBits , C. KnownNat dataBytes ) =>
81+ Show (WishboneM2S addressBits dataBytes )
8282 where
8383 show WishboneM2S {.. } =
8484 " WishboneM2S [ "
@@ -121,8 +121,8 @@ instance
121121 CycleTypeIdentifier val -> " reserved (" <> C. showX val <> " )"
122122
123123-- | Data communicated from a Wishbone Slave to a Wishbone Master
124- data WishboneS2M dat = WishboneS2M
125- { readData :: " DAT_MISO" ::: dat
124+ data WishboneS2M dataBytes = WishboneS2M
125+ { readData :: " DAT_MISO" ::: C. BitVector ( dataBytes C. * 8 )
126126 -- ^ The data output array [DAT_O()] is used to pass binary data. The array boundaries are
127127 -- determined by the port size, with a maximum port size of 64-bits (e.g. [DAT_I(63..0)]).
128128 , acknowledge :: " ACK" ::: Bool
@@ -143,12 +143,12 @@ data WishboneS2M dat = WishboneS2M
143143 }
144144 deriving (NFData , C.Generic , C.NFDataX , Eq , C.BitPack )
145145
146- instance (C. ShowX dat ) => C. ShowX (WishboneS2M dat ) where
146+ instance (C. KnownNat dataBytes ) => C. ShowX (WishboneS2M dataBytes ) where
147147 showX = show
148148
149149-- Compact printing for S2M values. This handles undefined values in the
150150-- structure too.
151- instance (C. ShowX dat ) => Show (WishboneS2M dat ) where
151+ instance (C. KnownNat dataBytes ) => Show (WishboneS2M dataBytes ) where
152152 show WishboneS2M {.. } =
153153 " WishboneS2M [ "
154154 <> prefix acknowledge
@@ -217,27 +217,27 @@ data
217217 Wishbone
218218 (dom :: C. Domain )
219219 (mode :: WishboneMode )
220- (addressWidth :: Nat )
221- (userType :: Type )
220+ (addressBits :: Nat )
221+ (dataBytes :: Nat )
222222
223- instance Protocol (Wishbone dom mode addressWidth dat ) where
223+ instance Protocol (Wishbone dom mode addressBits dataBytes ) where
224224 type
225- Fwd (Wishbone dom mode addressWidth dat ) =
226- Signal dom (WishboneM2S addressWidth ( C. BitSize dat ` DivRU ` 8 ) dat )
225+ Fwd (Wishbone dom mode addressBits dataBytes ) =
226+ Signal dom (WishboneM2S addressBits dataBytes )
227227
228- type Bwd (Wishbone dom mode addressWidth dat ) = Signal dom (WishboneS2M dat )
228+ type Bwd (Wishbone dom mode addressBits dataBytes ) = Signal dom (WishboneS2M dataBytes )
229229
230230instance
231- (C. KnownNat aw , C. KnownNat ( C. BitSize dat ), C. NFDataX dat ) =>
232- IdleCircuit (Wishbone dom mode aw dat )
231+ (C. KnownNat aw , C. KnownNat dw ) =>
232+ IdleCircuit (Wishbone dom mode aw dw )
233233 where
234234 idleFwd _ = C. pure emptyWishboneM2S
235235 idleBwd _ = C. pure emptyWishboneS2M
236236
237237-- | Construct "default" Wishbone M2S signals
238238emptyWishboneM2S ::
239- (C. KnownNat addressWidth , C. KnownNat ( C. BitSize dat ), C. NFDataX dat ) =>
240- WishboneM2S addressWidth ( C. BitSize dat ` DivRU ` 8 ) dat
239+ (C. KnownNat addressBits , C. KnownNat dataBytes ) =>
240+ WishboneM2S addressBits dataBytes
241241emptyWishboneM2S =
242242 WishboneM2S
243243 { addr = C. deepErrorX " M2S address not defined"
@@ -252,7 +252,7 @@ emptyWishboneM2S =
252252 }
253253
254254-- | Construct "default" Wishbone S2M signals
255- emptyWishboneS2M :: (C. NFDataX dat ) => WishboneS2M dat
255+ emptyWishboneS2M :: (C. KnownNat dataBytes ) => WishboneS2M dataBytes
256256emptyWishboneS2M =
257257 WishboneS2M
258258 { readData = C. deepErrorX " S2M readData not defined"
@@ -267,56 +267,55 @@ whether transactions are in progress(returns true for any 'hasTerminateFlag').
267267This is useful to determine whether a Wishbone bus is active.
268268
269269>>> :{
270- let m2s = (emptyWishboneM2S @32 @() ){busCycle = True, strobe = True}
270+ let m2s = (emptyWishboneM2S @32 @4 ){busCycle = True, strobe = True}
271271 s2m = emptyWishboneS2M{acknowledge = True}
272272 in hasBusActivity (m2s, s2m)
273273:}
274274True
275275
276276>>> :{
277- let m2s = (emptyWishboneM2S @32 @() ){busCycle = True, strobe = True}
277+ let m2s = (emptyWishboneM2S @32 @4 ){busCycle = True, strobe = True}
278278 s2m = emptyWishboneS2M{retry = True}
279279 in hasBusActivity (m2s, s2m)
280280:}
281281True
282282
283283>>> :{
284- let m2s = (emptyWishboneM2S @32 @() ){busCycle = True}
284+ let m2s = (emptyWishboneM2S @32 @4 ){busCycle = True}
285285 s2m = emptyWishboneS2M{acknowledge = True}
286286 in hasBusActivity (m2s, s2m)
287287:}
288288False
289289
290290>>> :{
291- let m2s = (emptyWishboneM2S @32 @() ){busCycle = True, strobe = True}
291+ let m2s = (emptyWishboneM2S @32 @4 ){busCycle = True, strobe = True}
292292 s2m = emptyWishboneS2M
293293 in hasBusActivity (m2s, s2m)
294294:}
295295False
296296
297297>>> :{
298- let m2s = emptyWishboneM2S @32 @()
298+ let m2s = emptyWishboneM2S @32 @4
299299 s2m = emptyWishboneS2M{acknowledge = True}
300300 in hasBusActivity (m2s, s2m)
301301:}
302302False
303303-}
304- hasBusActivity :: (WishboneM2S addressWidth sel dat , WishboneS2M dat ) -> Bool
304+ hasBusActivity :: (WishboneM2S addressBits dataBytes , WishboneS2M dataBytes ) -> Bool
305305hasBusActivity (m2s, s2m) = busCycle m2s C. && strobe m2s C. && hasTerminateFlag s2m
306306
307307-- | Helper function to determine whether a Slave signals the termination of a cycle.
308- hasTerminateFlag :: WishboneS2M dat -> Bool
308+ hasTerminateFlag :: WishboneS2M dataBytes -> Bool
309309hasTerminateFlag s2m = acknowledge s2m || err s2m || retry s2m
310310
311311{- | Force a /nack/ on the backward channel and /no data/ on the forward
312312channel if reset is asserted.
313313-}
314314forceResetSanity ::
315- forall dom mode aw a .
315+ forall dom mode aw dw .
316316 ( C. HiddenClockResetEnable dom
317317 , C. KnownNat aw
318- , C. KnownNat (C. BitSize a )
319- , C. NFDataX a
318+ , C. KnownNat dw
320319 ) =>
321- Circuit (Wishbone dom mode aw a ) (Wishbone dom mode aw a )
320+ Circuit (Wishbone dom mode aw dw ) (Wishbone dom mode aw dw )
322321forceResetSanity = forceResetSanityGeneric
0 commit comments