AsyncFifo class
An asynchronous FIFO for safely passing data between two clock domains.
The AsyncFifo implements a dual-clock FIFO that allows data to be written in one clock domain and read in another, completely independent clock domain. This is essential for designs that need to transfer data between different clock frequencies or phases.
Key Features:
- Independent write and read clock domains
- Gray-coded pointers for safe clock domain crossing
- Proper synchronization to prevent metastability
- Full/empty flag generation
- Data integrity across clock domains
Implementation Details:
- Uses Gray code for pointer synchronization (only 1 bit changes at a time)
- Multi-stage synchronizers for crossing pointer values
- Write pointers synchronized to read domain for empty detection
- Read pointers synchronized to write domain for full detection
Important Notes:
- The
depthmust be a power of 2 for proper Gray code wrapping - Full/empty flags have synchronization latency (typically 2 cycles)
- FIFO appears empty for a few cycles after reset due to sync latency
Example:
final asyncFifo = AsyncFifo(
writeClk: wrClk,
readClk: rdClk,
writeReset: wrRst,
readReset: rdRst,
writeEnable: wrEn,
writeData: wrData,
readEnable: rdEn,
depth: 16,
);
Constructors
- AsyncFifo({required Logic writeClk, required Logic readClk, required Logic writeReset, required Logic readReset, required Logic writeEnable, required Logic writeData, required Logic readEnable, required int depth, int syncStages = 2, String name = 'async_fifo'})
- Constructs an AsyncFifo with the specified parameters.
Properties
- dataWidth → int
-
The width of the data being transmitted through the FIFO.
final
- definitionName → String
-
The definition name of this Module used when instantiating instances in
generated code.
no setterinherited
- depth → int
-
The depth of the FIFO (number of entries).
final
- empty → Logic
-
High if the FIFO is empty and has no data to read.
no setter
- full → Logic
-
High if the FIFO is full and cannot accept new writes.
no setter
- hasBuilt → bool
-
Indicates whether this Module has had the build method called on it.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- hierarchicalName → String
-
Returns the hierarchical name of this Module with the parent hierarchy
included, separated by
.s, e.g.top.mid.leaf. Because it depends on hierarchy, this is only valid after build has been called.no setterinherited -
inOuts
→ Map<
String, Logic> -
A map from inOut port names to this Module to corresponding Logic
signals.
no setterinherited
-
inputs
→ Map<
String, Logic> -
A map from input port names to this Module to corresponding Logic
signals.
no setterinherited
-
internalSignals
→ Iterable<
Logic> -
An Iterable of all Logics contained within this Module which are
not an input or output port of this Module.
no setterinherited
- name → String
-
The name of this Module.
finalinherited
-
outputs
→ Map<
String, Logic> -
A map from output port names to this Module to corresponding Logic
signals.
no setterinherited
- parent → Module?
-
The parent Module of this Module.
no setterinherited
- readData → Logic
-
Read data output.
no setter
- reserveDefinitionName → bool
-
If true, guarantees definitionName is maintained by a Synthesizer,
or else it will fail.
finalinherited
- reserveName → bool
-
If true, guarantees uniqueInstanceName matches name or else the
build will fail.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
signals
→ Iterable<
Logic> -
An Iterable of all Logics contained within this Module, including
inputs, outputs, and internal signals of this Module.
no setterinherited
-
subModules
→ Iterable<
Module> -
An Iterable of all Modules contained within this Module.
no setterinherited
- syncStages → int
-
Number of synchronization stages for CDC.
final
- uniqueInstanceName → String
-
If this module has a parent, after build this will be a guaranteed
unique name within its scope.
no setterinherited
Methods
-
addInOut(
String name, Logic source, {int width = 1}) → LogicNet -
Registers a signal as an inOut to this Module and returns an inOut
port that can be consumed inside this Module.
inherited
-
addInOutArray(
String name, Logic source, {List< int> dimensions = const [1], int elementWidth = 1, int numUnpackedDimensions = 0}) → LogicArray -
Registers and returns an inOut LogicArray port to this Module with
the specified
dimensions,elementWidth, andnumUnpackedDimensionsnamedname.inherited -
addInput(
String name, Logic source, {int width = 1}) → Logic -
Registers a signal as an input to this Module and returns an input
port that can be consumed.
inherited
-
addInputArray(
String name, Logic source, {List< int> dimensions = const [1], int elementWidth = 1, int numUnpackedDimensions = 0}) → LogicArray -
Registers and returns an input LogicArray port to this Module with
the specified
dimensions,elementWidth, andnumUnpackedDimensionsnamedname.inherited -
addInterfacePorts<
InterfaceType extends Interface< (TagType> , TagType extends Enum>InterfaceType source, {Iterable< TagType> ? inputTags, Iterable<TagType> ? outputTags, Iterable<TagType> ? inOutTags, String uniquify(String original)?}) → InterfaceType -
Connects the
sourceto this Module using Interface.connectIO and returns a copy of thesourcethat can be used within this module.inherited -
addOutput(
String name, {int width = 1}) → Logic -
Registers an output to this Module and returns an output port that
can be driven by this Module or consumed outside of it.
inherited
-
addOutputArray(
String name, {List< int> dimensions = const [1], int elementWidth = 1, int numUnpackedDimensions = 0}) → LogicArray -
Registers and returns an output LogicArray port to this Module with
the specified
dimensions,elementWidth, andnumUnpackedDimensionsnamedname.inherited -
addPairInterfacePorts<
InterfaceType extends PairInterface> (InterfaceType source, PairRole role, {String uniquify(String original)?}) → InterfaceType -
Connects the
sourceto this Module using PairInterface.pairConnectIO and returns a copy of thesourcethat can be used within this module.inherited -
addTypedInOut<
LogicType extends Logic> (String name, LogicType source) → LogicType -
Registers a signal as an inOut to this Module and returns an inOut
port that can be consumed inside this Module. The type of the port will
be
LogicTypeand constructed via Logic.clone, so it is required that thesourceimplements clone functionality that matches the type and properly updates the Logic.name as well.inherited -
addTypedInput<
LogicType extends Logic> (String name, LogicType source) → LogicType -
Registers a signal as an input to this Module and returns an input
port that can be consumed. The type of the port will be
LogicTypeand constructed via Logic.clone, so it is required that thesourceimplements clone functionality that matches the type and properly updates the Logic.name as well.inherited -
addTypedOutput<
LogicType extends Logic> (String name, LogicType logicGenerator({String name})) → LogicType -
Registers an output to this Module and returns an output port that
can be driven by this Module or consumed outside of it. The type of the
port will be
LogicTypeand constructed vialogicGenerator, which must properly update thenameof the generatedLogicTypeas well.inherited -
build(
) → Future< void> -
Builds the Module and all subModules within it.
inherited
-
generateSynth(
) → String -
Returns a synthesized version of this Module.
inherited
-
hierarchy(
) → Iterable< Module> -
Returns an Iterable of Modules representing the hierarchical path to
this Module.
inherited
-
hierarchyString(
[int indent = 0]) → String -
Returns a pretty-print String of the heirarchy of all Modules within
this Module.
inherited
-
inOut(
String name) → Logic -
Accesses the Logic associated with this Modules inOut port
named
name.inherited -
inOutSource(
String name) → Logic -
The original
sourceprovided to the creation of the inOut portnamevia addInOut or addInOutArray.inherited -
input(
String name) → Logic -
Accesses the Logic associated with this Modules input port
named
name.inherited -
inputSource(
String name) → Logic -
The original
sourceprovided to the creation of the input portnamevia addInput or addInputArray.inherited -
isInOut(
Logic signal) → bool -
Returns true iff
signalis the same Logic as the inOut port of this Module with the same name.inherited -
isInput(
Logic signal) → bool -
Returns true iff
signalis the same Logic as the input port of this Module with the same name.inherited -
isOutput(
Logic signal) → bool -
Returns true iff
signalis the same Logic as the output port of this Module with the same name.inherited -
isPort(
Logic signal) → bool -
Returns true iff
signalis the same Logic as an input, output, or inOut port of this Module with the same name.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
output(
String name) → Logic -
Accesses the Logic associated with this Modules output port
named
name.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
tryInOut(
String name) → Logic? -
Provides the inOut named
nameif it exists, otherwisenull.inherited -
tryInput(
String name) → Logic? -
Provides the input named
nameif it exists, otherwisenull.inherited -
tryOutput(
String name) → Logic? -
Provides the output named
nameif it exists, otherwisenull.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited