-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add top-level MAC module and improve its documentation
- Loading branch information
Showing
8 changed files
with
169 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{- | | ||
Copyright : (C) 2024, QBayLogic B.V. | ||
License : BSD2 (see the file LICENSE) | ||
Maintainer : QBayLogic B.V. <devops@qbaylogic.com> | ||
Provides various components to handle the Ethernet protocol, both the physical- | ||
and link-layer. | ||
-} | ||
module Clash.Cores.Ethernet.Mac ( | ||
-- * Data types and constants | ||
module Clash.Cores.Ethernet.Mac.EthernetTypes, | ||
-- * Frame check sequence | ||
module Clash.Cores.Ethernet.Mac.FrameCheckSequence, | ||
-- * Interpacket gap | ||
module Clash.Cores.Ethernet.Mac.InterpacketGapInserter, | ||
-- * MAC header | ||
module Clash.Cores.Ethernet.Mac.MacPacketizers, | ||
-- * Padding | ||
module Clash.Cores.Ethernet.Mac.PaddingInserter, | ||
-- * Preamble | ||
module Clash.Cores.Ethernet.Mac.Preamble, | ||
) where | ||
|
||
import Clash.Cores.Ethernet.Mac.EthernetTypes | ||
import Clash.Cores.Ethernet.Mac.FrameCheckSequence | ||
import Clash.Cores.Ethernet.Mac.InterpacketGapInserter | ||
import Clash.Cores.Ethernet.Mac.MacPacketizers | ||
import Clash.Cores.Ethernet.Mac.PaddingInserter | ||
import Clash.Cores.Ethernet.Mac.Preamble |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,67 @@ | ||
{-# OPTIONS_HADDOCK hide #-} | ||
|
||
{-| | ||
Module : Clash.Cores.Ethernet.Mac.EthernetTypes | ||
Description : Provides various data types, aliases and constants for the Ethernet protocol. | ||
-} | ||
module Clash.Cores.Ethernet.Mac.EthernetTypes | ||
( MacAddress(..) | ||
, EthernetHeader(..) | ||
, broadcastMac | ||
, constToEthernetC | ||
) where | ||
|
||
import Clash.Prelude | ||
module Clash.Cores.Ethernet.Mac.EthernetTypes ( | ||
MacAddress (..), | ||
EthernetHeader (..), | ||
broadcastMac, | ||
constToEthernetC, | ||
) where | ||
|
||
import Protocols | ||
import Protocols.PacketStream | ||
import Control.DeepSeq (NFData) | ||
|
||
import Control.DeepSeq ( NFData ) | ||
import Clash.Prelude | ||
|
||
import Protocols (Circuit) | ||
import Protocols.PacketStream (PacketStream, mapMetaS) | ||
|
||
-- | Stores a MAC address, which is always 6 bytes long. | ||
newtype MacAddress = MacAddress (Vec 6 (BitVector 8)) | ||
deriving (BitPack, Eq, Generic, NFData, NFDataX, Show, ShowX) | ||
|
||
-- | Stores a link-layer Ethernet header, that is, a destination MAC address, | ||
-- a source MAC address, and an EtherType. | ||
data EthernetHeader = EthernetHeader { | ||
_macDst :: MacAddress, | ||
_macSrc :: MacAddress, | ||
_etherType :: BitVector 16 | ||
} deriving (BitPack, Eq, Generic, NFData, NFDataX, Show, ShowX) | ||
-- | Stores a link-layer Ethernet header. | ||
data EthernetHeader = EthernetHeader | ||
{ _macDst :: MacAddress | ||
-- ^ Destination MAC address | ||
, _macSrc :: MacAddress | ||
-- ^ Source MAC address | ||
, _etherType :: BitVector 16 | ||
-- ^ EtherType | ||
} | ||
deriving (BitPack, Eq, Generic, NFData, NFDataX, Show, ShowX) | ||
|
||
-- | Broadcast MAC address. | ||
broadcastMac :: MacAddress | ||
broadcastMac = MacAddress (repeat 0xFF) | ||
|
||
{- | | ||
Convert an arbitrary stream to an Ethernet stream with a hardcoded destination | ||
MAC address. | ||
Convert an arbitrary packet stream to an Ethernet stream with a hardcoded | ||
destination MAC address. | ||
Runs at full throughput and provides zero latency. | ||
-} | ||
constToEthernetC :: | ||
HiddenClockResetEnable dom | ||
(HiddenClockResetEnable dom) => | ||
-- | EtherType | ||
=> BitVector 16 | ||
-- | Hardcoded Target MAC address | ||
-> MacAddress | ||
BitVector 16 -> | ||
-- | Hardcoded destination MAC address | ||
MacAddress -> | ||
-- | Our MAC address | ||
-> Signal dom MacAddress | ||
-> Circuit | ||
(PacketStream dom dataWidth meta) | ||
(PacketStream dom dataWidth EthernetHeader) | ||
constToEthernetC etherType macDst ourMac = mapMetaS (const <$> hdr) | ||
where | ||
hdr = (\src -> EthernetHeader | ||
{ | ||
_macDst = macDst, | ||
_macSrc = src, | ||
_etherType = etherType | ||
}) <$> ourMac | ||
Signal dom MacAddress -> | ||
Circuit | ||
(PacketStream dom dataWidth meta) | ||
(PacketStream dom dataWidth EthernetHeader) | ||
constToEthernetC etherType macDst ourMacS = mapMetaS (const <$> hdr) | ||
where | ||
hdr = | ||
( \ourMac -> | ||
EthernetHeader | ||
{ _macDst = macDst | ||
, _macSrc = ourMac | ||
, _etherType = etherType | ||
} | ||
) | ||
<$> ourMacS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.