clash-protocols
Copyright(C) 2024 QBayLogic B.V.
LicenseBSD2 (see the file LICENSE)
MaintainerQBayLogic B.V. <devops@qbaylogic.com>
Safe HaskellNone
LanguageGHC2021

Protocols.PacketStream

Description

Provides the PacketStream protocol, a simple streaming protocol for transferring packets of data between components.

Apart from the protocol definition, some components, all of which are generic in dataWidth, are also provided:

  1. Several small utilities such as filtering a stream based on its metadata.
  2. FIFOs
  3. Components which upsize or downsize dataWidth
  4. Components which read from the stream (depacketizers)
  5. Components which write to the stream (packetizers)
  6. Components which split and merge a stream based on its metadata
Synopsis

Documentation

bimapMeta :: forall p a b c d (dom :: Domain) (dataWidth :: Nat). Bifunctor p => (a -> b) -> (c -> d) -> Circuit (PacketStream dom dataWidth (p a c)) (PacketStream dom dataWidth (p b d)) Source #

Like bimap, but over the metadata of a PacketStream.

bimapMetaS :: forall p (dom :: Domain) a b c d (dataWidth :: Nat). Bifunctor p => Signal dom (a -> b) -> Signal dom (c -> d) -> Circuit (PacketStream dom dataWidth (p a c)) (PacketStream dom dataWidth (p b d)) Source #

Like bimapMeta but can reason over signals, this circuit combinator is akin to <*>.

consume :: forall (dom :: Domain) (dataWidth :: Nat) meta. HiddenReset dom => Circuit (PacketStream dom dataWidth meta) () Source #

Always acknowledges incoming data.

eitherMeta :: forall a c b (dom :: Domain) (dataWidth :: Nat). (a -> c) -> (b -> c) -> Circuit (PacketStream dom dataWidth (Either a b)) (PacketStream dom dataWidth c) Source #

Like either, but over the metadata of a PacketStream.

eitherMetaS :: forall (dom :: Domain) a c b (dataWidth :: Nat). Signal dom (a -> c) -> Signal dom (b -> c) -> Circuit (PacketStream dom dataWidth (Either a b)) (PacketStream dom dataWidth c) Source #

Like eitherMeta but can reason over signals, this circuit combinator is akin to <*>.

empty :: forall (dom :: Domain) (dataWidth :: Nat) meta. Circuit () (PacketStream dom dataWidth meta) Source #

Never produces a value.

fanout :: forall (n :: Nat) (dataWidth :: Nat) meta (dom :: Domain). (HiddenClockResetEnable dom, KnownNat n, KnownNat dataWidth, 1 <= n, NFDataX meta) => Circuit (PacketStream dom dataWidth meta) (Vec n (PacketStream dom dataWidth meta)) Source #

Copy data of a single PacketStream to multiple. LHS will only receive an acknowledgement when all RHS receivers have acknowledged data.

filterMeta Source #

Arguments

:: forall meta (dom :: Domain) (dataWidth :: Nat). (meta -> Bool)

Predicate which specifies whether to keep a fragment based on its metadata

-> Circuit (PacketStream dom dataWidth meta) (PacketStream dom dataWidth meta) 

Like filter, but over the metadata of a PacketStream.

filterMetaS Source #

Arguments

:: forall (dom :: Domain) meta (dataWidth :: Nat). Signal dom (meta -> Bool)

Predicate which specifies whether to keep a fragment based on its metadata, wrapped in a Signal

-> Circuit (PacketStream dom dataWidth meta) (PacketStream dom dataWidth meta) 

Like filterMeta but can reason over signals, this circuit combinator is akin to <*>.

firstMeta :: forall p a b (dom :: Domain) (dataWidth :: Nat) c. Bifunctor p => (a -> b) -> Circuit (PacketStream dom dataWidth (p a c)) (PacketStream dom dataWidth (p b c)) Source #

Like first, but over the metadata of a PacketStream.

firstMetaS :: forall p (dom :: Domain) a b (dataWidth :: Nat) c. Bifunctor p => Signal dom (a -> b) -> Circuit (PacketStream dom dataWidth (p a c)) (PacketStream dom dataWidth (p b c)) Source #

Like firstMeta but can reason over signals, this circuit combinator is akin to <*>.

forceResetSanity :: forall (dom :: Domain) (dataWidth :: Nat) meta. (KnownDomain dom, HiddenReset dom) => Circuit (PacketStream dom dataWidth meta) (PacketStream dom dataWidth meta) Source #

Force a nack on the backward channel and Nothing on the forward channel if reset is asserted.

fstMeta :: forall (dom :: Domain) (dataWidth :: Nat) a b. Circuit (PacketStream dom dataWidth (a, b)) (PacketStream dom dataWidth a) Source #

Like fst, but over the metadata of a PacketStream.

mapMeta Source #

Arguments

:: forall metaIn metaOut (dom :: Domain) (dataWidth :: Nat). (metaIn -> metaOut)

Function to apply on the metadata

-> Circuit (PacketStream dom dataWidth metaIn) (PacketStream dom dataWidth metaOut) 

Like map, but over the metadata of a PacketStream.

mapMetaS Source #

Arguments

:: forall (dom :: Domain) metaIn metaOut (dataWidth :: Nat). Signal dom (metaIn -> metaOut)

Function to apply on the metadata, wrapped in a Signal

-> Circuit (PacketStream dom dataWidth metaIn) (PacketStream dom dataWidth metaOut) 

Like mapMeta but can reason over signals, this circuit combinator is akin to <*>.

nullByte Source #

Arguments

:: String

Component which caused the error

-> BitVector 8 

Undefined PacketStream null byte. Will throw an error if evaluated. The source of the error should be supplied for a more informative error message; otherwise it is unclear which component threw the error.

registerBoth :: forall (dataWidth :: Nat) meta (dom :: Domain). (HiddenClockResetEnable dom, KnownNat dataWidth, NFDataX meta) => Circuit (PacketStream dom dataWidth meta) (PacketStream dom dataWidth meta) Source #

A pipeline skid buffer: places registers on both the backward and forward part of a circuit. This completely breaks up the combinatorial path between the left and right side of this component. In order to achieve this, it has to buffer Fwd twice.

Another benefit of this component is that the circuit on the left hand side may now use Bwd in order to compute its Fwd, because this cannot introduce combinatorial loops anymore.

Runs at full throughput, but causes 2 clock cycles of latency.

registerBwd :: forall (dataWidth :: Nat) meta (dom :: Domain). (HiddenClockResetEnable dom, KnownNat dataWidth, NFDataX meta) => Circuit (PacketStream dom dataWidth meta) (PacketStream dom dataWidth meta) Source #

Place a register on the backward part of a circuit. This adds combinational delay on the forward path.

registerFwd :: forall (dataWidth :: Nat) meta (dom :: Domain). (HiddenClockResetEnable dom, KnownNat dataWidth, NFDataX meta) => Circuit (PacketStream dom dataWidth meta) (PacketStream dom dataWidth meta) Source #

Place a register on the forward part of a circuit. This adds combinational delay on the backward path.

secondMeta :: forall p b c (dom :: Domain) (dataWidth :: Nat) a. Bifunctor p => (b -> c) -> Circuit (PacketStream dom dataWidth (p a b)) (PacketStream dom dataWidth (p a c)) Source #

Like second, but over the metadata of a PacketStream.

secondMetaS :: forall p (dom :: Domain) b c (dataWidth :: Nat) a. Bifunctor p => Signal dom (b -> c) -> Circuit (PacketStream dom dataWidth (p a b)) (PacketStream dom dataWidth (p a c)) Source #

Like secondMeta but can reason over signals, this circuit combinator is akin to <*>.

sndMeta :: forall (dom :: Domain) (dataWidth :: Nat) a b. Circuit (PacketStream dom dataWidth (a, b)) (PacketStream dom dataWidth b) Source #

Like snd, but over the metadata of a PacketStream.

stripTrailingEmptyC :: forall (dataWidth :: Nat) meta (dom :: Domain). (HiddenClockResetEnable dom, KnownNat dataWidth, NFDataX meta) => Circuit (PacketStream dom dataWidth meta) (PacketStream dom dataWidth meta) Source #

Strips trailing zero-byte transfers from packets in the stream. That is, if a packet consists of more than one transfer and _last of the last transfer in that packet is Just 0, the last transfer of that packet will be dropped and _last of the transfer before that will be set to maxBound. If such a trailing zero-byte transfer had _abort asserted, it will be preserved.

Has one clock cycle latency, but runs at full throughput.

toCSignal :: forall (dom :: Domain) (dataWidth :: Nat) meta. HiddenClockResetEnable dom => Circuit (PacketStream dom dataWidth meta) (CSignal dom (Maybe (PacketStreamM2S dataWidth meta))) Source #

Converts a PacketStream into a CSignal: always acknowledges.

truncateAbortedPackets :: forall (dom :: Domain) (dataWidth :: Nat) meta. (HiddenClockResetEnable dom, KnownNat dataWidth, ShowX meta, 1 <= dataWidth) => Circuit (PacketStream dom dataWidth meta) (PacketStream dom dataWidth meta) Source #

When a packet is aborted, this circuit will truncate the current packet by setting the _last field of the transaction to Just 0 and the _abort field to True. All subsequent transactions will be consumed without being forwarded.

unsafeAbortOnBackpressureC :: forall (dataWidth :: Nat) meta (dom :: Domain). HiddenClockResetEnable dom => Circuit (CSignal dom (Maybe (PacketStreamM2S dataWidth meta))) (PacketStream dom dataWidth meta) Source #

Sets _abort upon receiving backpressure from the subordinate.

UNSAFE: because fwdOut depends on bwdIn, this may introduce combinatorial loops. You need to make sure that a sequential element is inserted along this path. It is possible to use one of the skid buffers to ensure this. For example:

>>> safeAbortOnBackpressureC1 = unsafeAbortOnBackpressureC |> registerFwd
>>> safeAbortOnBackpressureC2 = unsafeAbortOnBackpressureC |> registerBwd

Note that registerFwd utilizes less resources than registerBwd.

unsafeDropBackpressure :: forall (dom :: Domain) (dwIn :: Nat) meta (dwOut :: Nat). HiddenClockResetEnable dom => Circuit (PacketStream dom dwIn meta) (PacketStream dom dwOut meta) -> Circuit (CSignal dom (Maybe (PacketStreamM2S dwIn meta))) (CSignal dom (Maybe (PacketStreamM2S dwOut meta))) Source #

Drop all backpressure signals.

unsafeFromCSignal :: forall (dom :: Domain) (dataWidth :: Nat) meta. Circuit (CSignal dom (Maybe (PacketStreamM2S dataWidth meta))) (PacketStream dom dataWidth meta) Source #

Circuit to convert a CSignal into a PacketStream. This is unsafe, because it ignores all incoming backpressure.

void :: forall (dom :: Domain) (dataWidth :: Nat) meta. HiddenClockResetEnable dom => Circuit (PacketStream dom dataWidth meta) () Source #

Never acknowledges incoming data.

zeroOutInvalidBytesC :: forall (dom :: Domain) (dataWidth :: Nat) meta. (KnownNat dataWidth, 1 <= dataWidth) => Circuit (PacketStream dom dataWidth meta) (PacketStream dom dataWidth meta) Source #

Sets data bytes that are not enabled in a PacketStream to 0x00.

data PacketStream (dom :: Domain) (dataWidth :: Nat) meta Source #

Simple valid-ready streaming protocol for transferring packets between components.

Invariants:

  1. A manager must not check the Bwd channel when it is sending Nothing over the Fwd channel.
  2. A manager must keep sending the same data until the subordinate has acknowledged it, i.e. upon observing _ready as True.
  3. A manager must keep the metadata (_meta) of an entire packet it sends constant.
  4. A subordinate which receives a transfer with _abort asserted must either forward this _abort or drop the packet.
  5. A packet may not be interrupted by another packet.

This protocol allows the last transfer of a packet to have zero valid bytes in _data, so it also allows 0-byte packets. Note that concrete implementations of the protocol are free to disallow 0-byte packets or packets with a trailing zero-byte transfer for whatever reason.

The value of data bytes which are not enabled is undefined.

Instances

Instances details
DfConv (PacketStream dom dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

Associated Types

type Dom (PacketStream dom dataWidth meta) 
Instance details

Defined in Protocols.PacketStream.Base

type Dom (PacketStream dom dataWidth meta) = dom
type BwdPayload (PacketStream dom dataWidth meta) 
Instance details

Defined in Protocols.PacketStream.Base

type BwdPayload (PacketStream dom dataWidth meta) = ()
type FwdPayload (PacketStream dom dataWidth meta) 
Instance details

Defined in Protocols.PacketStream.Base

type FwdPayload (PacketStream dom dataWidth meta) = PacketStreamM2S dataWidth meta

Methods

toDfCircuit :: Proxy (PacketStream dom dataWidth meta) -> Circuit (Df (Dom (PacketStream dom dataWidth meta)) (FwdPayload (PacketStream dom dataWidth meta)), Reverse (Df (Dom (PacketStream dom dataWidth meta)) (BwdPayload (PacketStream dom dataWidth meta)))) (PacketStream dom dataWidth meta) Source #

fromDfCircuit :: Proxy (PacketStream dom dataWidth meta) -> Circuit (PacketStream dom dataWidth meta) (Df (Dom (PacketStream dom dataWidth meta)) (FwdPayload (PacketStream dom dataWidth meta)), Reverse (Df (Dom (PacketStream dom dataWidth meta)) (BwdPayload (PacketStream dom dataWidth meta)))) Source #

(KnownNat dataWidth, NFDataX meta, NFData meta, ShowX meta, Show meta, Eq meta, KnownDomain dom) => Test (PacketStream dom dataWidth meta) Source # 
Instance details

Defined in Protocols.Experimental.PacketStream

Methods

expectN :: (HasCallStack, MonadTest m) => Proxy (PacketStream dom dataWidth meta) -> ExpectOptions -> SimulateFwdType (PacketStream dom dataWidth meta) -> m (ExpectType (PacketStream dom dataWidth meta)) Source #

Backpressure (PacketStream dom dataWidth meta) Source # 
Instance details

Defined in Protocols.Experimental.PacketStream

Methods

boolsToBwd :: Proxy (PacketStream dom dataWidth meta) -> [Bool] -> Bwd (PacketStream dom dataWidth meta) Source #

KnownDomain dom => Drivable (PacketStream dom dataWidth meta) Source # 
Instance details

Defined in Protocols.Experimental.PacketStream

Associated Types

type ExpectType (PacketStream dom dataWidth meta) 
Instance details

Defined in Protocols.Experimental.PacketStream

type ExpectType (PacketStream dom dataWidth meta) = [PacketStreamM2S dataWidth meta]

Methods

toSimulateType :: Proxy (PacketStream dom dataWidth meta) -> ExpectType (PacketStream dom dataWidth meta) -> SimulateFwdType (PacketStream dom dataWidth meta) Source #

fromSimulateType :: Proxy (PacketStream dom dataWidth meta) -> SimulateFwdType (PacketStream dom dataWidth meta) -> ExpectType (PacketStream dom dataWidth meta) Source #

driveC :: SimulationConfig -> SimulateFwdType (PacketStream dom dataWidth meta) -> Circuit () (PacketStream dom dataWidth meta) Source #

sampleC :: SimulationConfig -> Circuit () (PacketStream dom dataWidth meta) -> SimulateFwdType (PacketStream dom dataWidth meta) Source #

KnownDomain dom => Simulate (PacketStream dom dataWidth meta) Source # 
Instance details

Defined in Protocols.Experimental.PacketStream

Associated Types

type SimulateFwdType (PacketStream dom dataWidth meta) 
Instance details

Defined in Protocols.Experimental.PacketStream

type SimulateFwdType (PacketStream dom dataWidth meta) = [Maybe (PacketStreamM2S dataWidth meta)]
type SimulateBwdType (PacketStream dom dataWidth meta) 
Instance details

Defined in Protocols.Experimental.PacketStream

type SimulateBwdType (PacketStream dom dataWidth meta) = [PacketStreamS2M]
type SimulateChannels (PacketStream dom dataWidth meta) 
Instance details

Defined in Protocols.Experimental.PacketStream

type SimulateChannels (PacketStream dom dataWidth meta) = 1

Methods

simToSigFwd :: Proxy (PacketStream dom dataWidth meta) -> SimulateFwdType (PacketStream dom dataWidth meta) -> Fwd (PacketStream dom dataWidth meta) Source #

simToSigBwd :: Proxy (PacketStream dom dataWidth meta) -> SimulateBwdType (PacketStream dom dataWidth meta) -> Bwd (PacketStream dom dataWidth meta) Source #

sigToSimFwd :: Proxy (PacketStream dom dataWidth meta) -> Fwd (PacketStream dom dataWidth meta) -> SimulateFwdType (PacketStream dom dataWidth meta) Source #

sigToSimBwd :: Proxy (PacketStream dom dataWidth meta) -> Bwd (PacketStream dom dataWidth meta) -> SimulateBwdType (PacketStream dom dataWidth meta) Source #

stallC :: SimulationConfig -> Vec (SimulateChannels (PacketStream dom dataWidth meta)) (StallAck, [Int]) -> Circuit (PacketStream dom dataWidth meta) (PacketStream dom dataWidth meta) Source #

IdleCircuit (PacketStream dom dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

Methods

idleFwd :: Proxy (PacketStream dom dataWidth meta) -> Fwd (PacketStream dom dataWidth meta) Source #

idleBwd :: Proxy (PacketStream dom dataWidth meta) -> Bwd (PacketStream dom dataWidth meta) Source #

Protocol (PacketStream dom dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

Associated Types

type Fwd (PacketStream dom dataWidth meta) 
Instance details

Defined in Protocols.PacketStream.Base

type Fwd (PacketStream dom dataWidth meta) = Signal dom (Maybe (PacketStreamM2S dataWidth meta))
type Bwd (PacketStream dom dataWidth meta) 
Instance details

Defined in Protocols.PacketStream.Base

type Bwd (PacketStream dom dataWidth meta) = Signal dom PacketStreamS2M
type BwdPayload (PacketStream dom dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

type BwdPayload (PacketStream dom dataWidth meta) = ()
type Dom (PacketStream dom dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

type Dom (PacketStream dom dataWidth meta) = dom
type FwdPayload (PacketStream dom dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

type FwdPayload (PacketStream dom dataWidth meta) = PacketStreamM2S dataWidth meta
type ExpectType (PacketStream dom dataWidth meta) Source # 
Instance details

Defined in Protocols.Experimental.PacketStream

type ExpectType (PacketStream dom dataWidth meta) = [PacketStreamM2S dataWidth meta]
type SimulateBwdType (PacketStream dom dataWidth meta) Source # 
Instance details

Defined in Protocols.Experimental.PacketStream

type SimulateBwdType (PacketStream dom dataWidth meta) = [PacketStreamS2M]
type SimulateChannels (PacketStream dom dataWidth meta) Source # 
Instance details

Defined in Protocols.Experimental.PacketStream

type SimulateChannels (PacketStream dom dataWidth meta) = 1
type SimulateFwdType (PacketStream dom dataWidth meta) Source # 
Instance details

Defined in Protocols.Experimental.PacketStream

type SimulateFwdType (PacketStream dom dataWidth meta) = [Maybe (PacketStreamM2S dataWidth meta)]
type Bwd (PacketStream dom dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

type Bwd (PacketStream dom dataWidth meta) = Signal dom PacketStreamS2M
type Fwd (PacketStream dom dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

type Fwd (PacketStream dom dataWidth meta) = Signal dom (Maybe (PacketStreamM2S dataWidth meta))

data PacketStreamM2S (dataWidth :: Nat) meta Source #

Data sent from manager to subordinate.

Heavily inspired by the M2S data of AMBA AXI4-Stream, but simplified:

  • _tdata is moved into _data, which serves the exact same purpose: the actual data of the transfer.
  • _tkeep is changed to _last.
  • _tstrb is removed as there are no position bytes.
  • _tid is removed, because packets may not be interrupted by other packets.
  • _tdest is moved into _meta.
  • _tuser is moved into _meta.
  • _tvalid is modeled by wrapping this type into a Maybe.

Constructors

PacketStreamM2S 

Fields

  • _data :: Vec dataWidth (BitVector 8)

    The bytes to be transmitted.

  • _last :: Maybe (Index (dataWidth + 1))

    If this is Just then it signals that this transfer is the end of a packet and contains the number of valid bytes in _data, starting from index 0.

    If it is Nothing then this transfer is not yet the end of a packet and all bytes are valid. This implies that no null bytes are allowed in the middle of a packet, only after a packet.

  • _meta :: meta

    Metadata of a packet. Must be constant during a packet.

  • _abort :: Bool

    Iff true, the packet corresponding to this transfer is invalid. The subordinate must either drop the packet or forward the _abort.

Instances

Instances details
Default (Maybe (PacketStreamM2S dataWidth meta)) Source #

Used by circuit-notation to create an empty stream

Instance details

Defined in Protocols.PacketStream.Base

Methods

def :: Maybe (PacketStreamM2S dataWidth meta) #

Functor (PacketStreamM2S dataWidth) Source # 
Instance details

Defined in Protocols.PacketStream.Base

Methods

fmap :: (a -> b) -> PacketStreamM2S dataWidth a -> PacketStreamM2S dataWidth b #

(<$) :: a -> PacketStreamM2S dataWidth b -> PacketStreamM2S dataWidth a #

(KnownNat dataWidth, AutoReg meta) => AutoReg (PacketStreamM2S dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> PacketStreamM2S dataWidth meta -> Signal dom (PacketStreamM2S dataWidth meta) -> Signal dom (PacketStreamM2S dataWidth meta) #

Bundle (PacketStreamM2S dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

Methods

bundle :: forall (dom :: Domain). Unbundled dom (PacketStreamM2S dataWidth meta) -> Signal dom (PacketStreamM2S dataWidth meta) #

unbundle :: forall (dom :: Domain). Signal dom (PacketStreamM2S dataWidth meta) -> Unbundled dom (PacketStreamM2S dataWidth meta) #

(KnownNat dataWidth, NFDataX meta) => NFDataX (PacketStreamM2S dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

Methods

deepErrorX :: String -> PacketStreamM2S dataWidth meta #

hasUndefined :: PacketStreamM2S dataWidth meta -> Bool #

ensureSpine :: PacketStreamM2S dataWidth meta -> PacketStreamM2S dataWidth meta #

rnfX :: PacketStreamM2S dataWidth meta -> () #

ShowX meta => ShowX (PacketStreamM2S dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

Methods

showsPrecX :: Int -> PacketStreamM2S dataWidth meta -> ShowS #

showX :: PacketStreamM2S dataWidth meta -> String #

showListX :: [PacketStreamM2S dataWidth meta] -> ShowS #

NFData meta => NFData (PacketStreamM2S dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

Methods

rnf :: PacketStreamM2S dataWidth meta -> () #

Generic (PacketStreamM2S dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

Associated Types

type Rep (PacketStreamM2S dataWidth meta) 
Instance details

Defined in Protocols.PacketStream.Base

type Rep (PacketStreamM2S dataWidth meta) = D1 ('MetaData "PacketStreamM2S" "Protocols.PacketStream.Base" "clash-protocols-0.1-inplace" 'False) (C1 ('MetaCons "PacketStreamM2S" 'PrefixI 'True) ((S1 ('MetaSel ('Just "_data") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Vec dataWidth (BitVector 8))) :*: S1 ('MetaSel ('Just "_last") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe (Index (dataWidth + 1))))) :*: (S1 ('MetaSel ('Just "_meta") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 meta) :*: S1 ('MetaSel ('Just "_abort") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool))))

Methods

from :: PacketStreamM2S dataWidth meta -> Rep (PacketStreamM2S dataWidth meta) x #

to :: Rep (PacketStreamM2S dataWidth meta) x -> PacketStreamM2S dataWidth meta #

Show meta => Show (PacketStreamM2S dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

Methods

showsPrec :: Int -> PacketStreamM2S dataWidth meta -> ShowS #

show :: PacketStreamM2S dataWidth meta -> String #

showList :: [PacketStreamM2S dataWidth meta] -> ShowS #

(KnownNat dataWidth, Eq meta) => Eq (PacketStreamM2S dataWidth meta) Source #

Two PacketStream transfers are equal if and only if:

  1. They have the same _last
  2. They have the same _meta.
  3. They have the same _abort.
  4. All bytes in _data which are enabled by _last are equal.

Data bytes that are not enabled are not considered in the equality check, because the protocol allows them to be undefined.

Examples

>>> t1 = PacketStreamM2S (0x11 :> 0x22 :> 0x33 :> Nil) Nothing () False
>>> t2 = PacketStreamM2S (0x11 :> 0x22 :> 0x33 :> Nil) (Just 2) () False
>>> t3 = PacketStreamM2S (0x11 :> 0x22 :> 0xFF :> Nil) (Just 2) () False
>>> t4 = PacketStreamM2S (0x11 :> 0x22 :> undefined :> Nil) (Just 2) () False
>>> t1 == t1
True
>>> t2 == t3
True
>>> t1 /= t2
True
>>> t3 == t4
True
Instance details

Defined in Protocols.PacketStream.Base

Methods

(==) :: PacketStreamM2S dataWidth meta -> PacketStreamM2S dataWidth meta -> Bool #

(/=) :: PacketStreamM2S dataWidth meta -> PacketStreamM2S dataWidth meta -> Bool #

type Unbundled dom (PacketStreamM2S dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

type Unbundled dom (PacketStreamM2S dataWidth meta) = Signal dom (PacketStreamM2S dataWidth meta)
type Rep (PacketStreamM2S dataWidth meta) Source # 
Instance details

Defined in Protocols.PacketStream.Base

type Rep (PacketStreamM2S dataWidth meta) = D1 ('MetaData "PacketStreamM2S" "Protocols.PacketStream.Base" "clash-protocols-0.1-inplace" 'False) (C1 ('MetaCons "PacketStreamM2S" 'PrefixI 'True) ((S1 ('MetaSel ('Just "_data") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Vec dataWidth (BitVector 8))) :*: S1 ('MetaSel ('Just "_last") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe (Index (dataWidth + 1))))) :*: (S1 ('MetaSel ('Just "_meta") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 meta) :*: S1 ('MetaSel ('Just "_abort") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool))))

newtype PacketStreamS2M Source #

Data sent from the subordinate to manager.

The only information transmitted is whether the subordinate is ready to receive data.

Constructors

PacketStreamS2M 

Fields

  • _ready :: Bool

    Iff True, the subordinate is ready to receive data.

Instances

Instances details
AutoReg PacketStreamS2M Source # 
Instance details

Defined in Protocols.PacketStream.Base

Methods

autoReg :: forall (dom :: Domain). (HasCallStack, KnownDomain dom) => Clock dom -> Reset dom -> Enable dom -> PacketStreamS2M -> Signal dom PacketStreamS2M -> Signal dom PacketStreamS2M #

Bundle PacketStreamS2M Source # 
Instance details

Defined in Protocols.PacketStream.Base

Associated Types

type Unbundled dom PacketStreamS2M 
Instance details

Defined in Protocols.PacketStream.Base

Methods

bundle :: forall (dom :: Domain). Unbundled dom PacketStreamS2M -> Signal dom PacketStreamS2M #

unbundle :: forall (dom :: Domain). Signal dom PacketStreamS2M -> Unbundled dom PacketStreamS2M #

NFDataX PacketStreamS2M Source # 
Instance details

Defined in Protocols.PacketStream.Base

ShowX PacketStreamS2M Source # 
Instance details

Defined in Protocols.PacketStream.Base

Default PacketStreamS2M Source #

Used by circuit-notation to create a sink that always acknowledges

Instance details

Defined in Protocols.PacketStream.Base

Generic PacketStreamS2M Source # 
Instance details

Defined in Protocols.PacketStream.Base

Associated Types

type Rep PacketStreamS2M 
Instance details

Defined in Protocols.PacketStream.Base

type Rep PacketStreamS2M = D1 ('MetaData "PacketStreamS2M" "Protocols.PacketStream.Base" "clash-protocols-0.1-inplace" 'True) (C1 ('MetaCons "PacketStreamS2M" 'PrefixI 'True) (S1 ('MetaSel ('Just "_ready") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)))
Show PacketStreamS2M Source # 
Instance details

Defined in Protocols.PacketStream.Base

Eq PacketStreamS2M Source # 
Instance details

Defined in Protocols.PacketStream.Base

type Rep PacketStreamS2M Source # 
Instance details

Defined in Protocols.PacketStream.Base

type Rep PacketStreamS2M = D1 ('MetaData "PacketStreamS2M" "Protocols.PacketStream.Base" "clash-protocols-0.1-inplace" 'True) (C1 ('MetaCons "PacketStreamS2M" 'PrefixI 'True) (S1 ('MetaSel ('Just "_ready") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)))
type Unbundled dom PacketStreamS2M Source # 
Instance details

Defined in Protocols.PacketStream.Base

FIFOs

packetFifoC Source #

Arguments

:: forall (dom :: Domain) (dataWidth :: Nat) meta (contentDepth :: Nat) (metaDepth :: Nat). (HiddenClockResetEnable dom, KnownNat dataWidth, 1 <= contentDepth, 1 <= metaDepth, NFDataX meta) 
=> SNat contentDepth

The content FIFO will contain 2^contentDepth entries.

-> SNat metaDepth

The metadata FIFO will contain 2^metaDepth entries.

-> FullMode

The backpressure behaviour of the FIFO when it is full.

-> Circuit (PacketStream dom dataWidth meta) (PacketStream dom dataWidth meta) 

FIFO circuit optimized for the PacketStream protocol. Contains two FIFOs, one for packet data (_data, _last) and one for packet metadata (_meta). Because metadata is constant per packet, the metadata FIFO can be significantly shallower, saving resources.

Moreover, the output of the FIFO has some other properties:

  • All packets which contain a transfer with _abort set are dropped.
  • All packets that are bigger than or equal to 2^contentDepth - 1 transfers are dropped.
  • There are no gaps in output packets, i.e. Nothing in between valid transfers of a packet.

The circuit is able to satisfy these properties because it first loads an entire packet before it may transmit it. That is also why packets bigger than the content FIFO need to be dropped.

Two modes can be selected:

  • Backpressure: assert backpressure like normal when the FIFO is full.
  • Drop: never give backpressure, instead drop the current packet we are loading.

data FullMode Source #

Specifies the behaviour of packetFifoC when it is full.

Constructors

Backpressure

Assert backpressure when the FIFO is full.

Drop

Drop new packets when the FIFO is full. The FIFO never asserts backpressure.

asyncFifoC Source #

Arguments

:: forall (wDom :: Domain) (rDom :: Domain) (depth :: Nat) (dataWidth :: Nat) meta. (KnownDomain wDom, KnownDomain rDom, KnownNat depth, KnownNat dataWidth, 2 <= depth, 1 <= dataWidth, NFDataX meta) 
=> SNat depth

2^depth is the number of elements this component can store

-> Clock wDom

Clock signal in the write domain

-> Reset wDom

Reset signal in the write domain

-> Enable wDom

Enable signal in the write domain

-> Clock rDom

Clock signal in the read domain

-> Reset rDom

Reset signal in the read domain

-> Enable rDom

Enable signal in the read domain

-> Circuit (PacketStream wDom dataWidth meta) (PacketStream rDom dataWidth meta) 

Asynchronous FIFO circuit that can be used to safely cross clock domains. Uses asyncFIFOSynchronizer internally.

Converters

downConverterC Source #

Arguments

:: forall (dwOut :: Nat) (n :: Nat) meta (dom :: Domain). (HiddenClockResetEnable dom, KnownNat dwOut, KnownNat n, 1 <= dwOut, 1 <= n, NFDataX meta) 
=> Circuit (PacketStream dom (dwOut * n) meta) (PacketStream dom dwOut meta)

Downconverter circuit

Converts packet streams of a data width which is a multiple of n, i.e. dwOut * n, to packet streams of a smaller (or equal) data width dwOut, where n > 0. When n ~ 1, this component is just the identity circuit, idC.

If _abort is asserted on an input transfer, it will be asserted on all corresponding output sub-transfers as well. All zero-byte transfers are preserved.

Has one clock cycle of latency, all M2S outputs are registered. Throughput is optimal, a transfer of k valid bytes is transmitted in k clock cycles. To be precise, throughput is at least (1 / n)%, so at least 50% if n = 2 for example. We specify at least, because the throughput may be on the last transfer of a packet, when not all bytes have to be valid. If there is only one valid byte in the last transfer, then the throughput will always be 100% for that particular transfer.

unsafeUpConverterC Source #

Arguments

:: forall (dwIn :: Nat) meta (dom :: Domain) (n :: Nat). (HiddenClockResetEnable dom, 1 <= dwIn, 1 <= n, KnownNat dwIn, KnownNat n, NFDataX meta) 
=> Circuit (CSignal dom (Maybe (PacketStreamM2S dwIn meta))) (CSignal dom (Maybe (PacketStreamM2S (dwIn * n) meta)))

Unsafe upconverter circuit

Unsafe version of upConverterC.

Because upConverterC runs at full throughput, i.e. it only asserts backpressure if the subordinate asserts backpressure, we supply this variant which drops all backpressure signals. This can be used when the source circuit does not support backpressure. Using this variant in that case will improve timing and probably reduce resource usage.

upConverterC Source #

Arguments

:: forall (dwIn :: Nat) (n :: Nat) meta (dom :: Domain). (HiddenClockResetEnable dom, 1 <= dwIn, 1 <= n, KnownNat dwIn, KnownNat n, NFDataX meta) 
=> Circuit (PacketStream dom dwIn meta) (PacketStream dom (dwIn * n) meta)

Upconverter circuit

Converts packet streams of arbitrary data width dwIn to packet streams of a bigger (or equal) data width dwIn * n, where n > 0. When n ~ 1, this component is just the identity circuit, idC.

If _abort is asserted on any of the input sub-transfers, it will be asserted on the corresponding output transfer as well. All zero-byte transfers are preserved.

Has one cycle of latency, all M2S outputs are registered. Provides full throughput.

Depacketizers

depacketizeToDfC Source #

Arguments

:: forall (headerBytes :: Nat) header meta a (dataWidth :: Nat) (dom :: Domain). (HiddenClockResetEnable dom, NFDataX meta, NFDataX a, BitPack header, KnownNat headerBytes, KnownNat dataWidth, 1 <= headerBytes, 1 <= dataWidth, BitSize header ~ (headerBytes * 8)) 
=> (header -> meta -> a)

Mapping from the parsed header and input _meta to the Df output

-> Circuit (PacketStream dom dataWidth meta) (Df dom a) 

Reads bytes at the start of each packet into a header structure, and transforms this header structure along with the input metadata to an output structure a, which is transmitted over a Df channel. Such a structure is sent once per packet over the Df channel, but only if the packet was big enough (contained at least headerBytes valid data bytes) and did not contain any transfer with _abort set. The remainder of the packet (padding) is dropped.

If the packet is not padded, or if the packet is padded but the padding fits in the last transfer of the packet together with valid data bytes, this component will give one clock cycle of backpressure per packet (for efficiency reasons). Otherwise, it runs at full throughput.

depacketizerC Source #

Arguments

:: forall (headerBytes :: Nat) header metaIn metaOut (dataWidth :: Nat) (dom :: Domain). (HiddenClockResetEnable dom, BitPack header, BitSize header ~ (headerBytes * 8), NFDataX metaIn, KnownNat headerBytes, KnownNat dataWidth, 1 <= headerBytes, 1 <= dataWidth) 
=> (header -> metaIn -> metaOut)

Mapping from the parsed header and input _meta to the output _meta

-> Circuit (PacketStream dom dataWidth metaIn) (PacketStream dom dataWidth metaOut) 

Reads bytes at the start of each packet into _meta. If a packet contains less valid bytes than headerBytes + 1, it will silently drop that packet.

If dataWidth divides headerBytes, this component runs at full throughput. Otherwise, it gives backpressure for one clock cycle per packet larger than headerBytes + 1 valid bytes.

Packetizers

packetizeFromDfC Source #

Arguments

:: forall (dom :: Domain) (dataWidth :: Nat) a metaOut header (headerBytes :: Nat). (HiddenClockResetEnable dom, NFDataX metaOut, BitPack header, BitSize header ~ (headerBytes * 8), KnownNat headerBytes, KnownNat dataWidth, 1 <= headerBytes, 1 <= dataWidth) 
=> (a -> metaOut)

Mapping from Df input to output _meta

-> (a -> header)

Mapping from Df input to the header that will be packetized

-> Circuit (Df dom a) (PacketStream dom dataWidth metaOut) 

Starts a packet stream upon receiving some data over a Df channel. The bytes to be packetized and the output metadata are specified by the input functions.

packetizerC Source #

Arguments

:: forall (dom :: Domain) (dataWidth :: Nat) metaIn metaOut header (headerBytes :: Nat). (HiddenClockResetEnable dom, NFDataX metaOut, BitPack header, BitSize header ~ (headerBytes * 8), KnownNat headerBytes, 1 <= dataWidth, 1 <= headerBytes, KnownNat dataWidth) 
=> (metaIn -> metaOut)

Mapping from input _meta to output _meta

-> (metaIn -> header)

Mapping from input _meta to the header that will be packetized

-> Circuit (PacketStream dom dataWidth metaIn) (PacketStream dom dataWidth metaOut) 

Writes a portion of the metadata to the front of the packet stream, and shifts the stream accordingly. This portion is defined by the (metaIn -> header) input function. If this function is id, the entire metadata is put in front of the packet stream.

Padding removal

stripPaddingC Source #

Arguments

:: forall (dataWidth :: Nat) meta (p :: Nat) (dom :: Domain). (HiddenClockResetEnable dom, KnownNat dataWidth, KnownNat p, NFDataX meta) 
=> (meta -> Unsigned p)

Function that extracts the expected packet length from the metadata

-> Circuit (PacketStream dom dataWidth meta) (PacketStream dom dataWidth meta) 

Removes padding from packets according to some expected packet length field in the metadata. If the actual length of a packet is smaller than expected, the packet is aborted.

Has one clock cycle of latency, because all M2S outputs are registered. Runs at full throughput.

NB: dataWidth must be smaller than 2^p. Because this should never occur in practice, this constraint is not enforced on the type-level.

Routing components

packetArbiterC Source #

Arguments

:: forall (dataWidth :: Nat) (sources :: Nat) meta (dom :: Domain). (HiddenClockResetEnable dom, KnownNat sources, 1 <= sources) 
=> CollectMode

Determines the mode of arbitration. See CollectMode

-> Circuit (Vec sources (PacketStream dom dataWidth meta)) (PacketStream dom dataWidth meta) 

Merges multiple packet streams into one, respecting packet boundaries.

packetDispatcherC Source #

Arguments

:: forall (dataWidth :: Nat) (sinks :: Nat) meta (dom :: Domain). (HiddenClockResetEnable dom, KnownNat sinks) 
=> Vec sinks (meta -> Bool)

Dispatch function

-> Circuit (PacketStream dom dataWidth meta) (Vec sinks (PacketStream dom dataWidth meta)) 

Routes packets depending on their metadata, using given routing functions.

Data is sent to at most one sink, for which the dispatch function evaluates to True when applied to the input metadata. If none of the predicates hold, the input packet is dropped. If more than one of the predicates hold, the sink that occurs first in the vector is picked.

Sends out packets in the same clock cycle as they are received, this component has zero latency and runs at full throughput.

routeBy :: forall a meta (sinks :: Nat). Eq a => (meta -> a) -> Vec sinks a -> Vec sinks (meta -> Bool) Source #

Routing function for packetDispatcherC that matches against values with an Eq instance. Useful to route according to a record field.