Trait hazardflow_designs::std::interface::Interface
source · pub trait Interface: Sized {
type Fwd: Copy;
type Bwd: Copy;
// Provided methods
unsafe fn fsm<E: Interface, S: Copy>(
self,
_init_state: S,
_f: impl Fn(Self::Fwd, E::Bwd, S) -> (E::Fwd, Self::Bwd, S)
) -> E { ... }
fn comb<E: Interface>(self, m: impl FnOnce(Self) -> E) -> E { ... }
}
Expand description
Interface trait.
Required Associated Types§
Provided Methods§
sourceunsafe fn fsm<E: Interface, S: Copy>(
self,
_init_state: S,
_f: impl Fn(Self::Fwd, E::Bwd, S) -> (E::Fwd, Self::Bwd, S)
) -> E
unsafe fn fsm<E: Interface, S: Copy>( self, _init_state: S, _f: impl Fn(Self::Fwd, E::Bwd, S) -> (E::Fwd, Self::Bwd, S) ) -> E
A generic FSM combinator.
We assume that the function f
is combinational logic. The returned egress payload and ingress resolver are
immediately propagated, and the state is updated to the returned next state from the next cycle.
Safety
When using this combinator, you need to guarantee that it satisfies the specification of the interface’s protocol.
In particular, for a hazard interface I<H, D>
, you must follow the specification described in the “Safety”
section of I::fsm
.
How it is compiled?
In the HazardFlow compiler, the fsm function is not actually executed (which would lead to a panic).
Instead, the HazardFlow compiler captures the High-level IR
generated by the Rust compiler and extracts information about the ingress/egress/state types (Self
, E
, S
)
and the arguments (init_state
, f
) of the fsm function.
Using this information, the HazardFlow compiler generates the corresponding Verilog code.
Type parameters
Self
: The ingress interface type.E
: The egress interface type.S
: The state type.
Parameters
self
: The ingress interface.init_state
: The initial state.- Whenever
rst
signal is turned on, the state will be initialized to this value. - For example, set
init_state
asNone
for a state with anOption<_>
type.
- Whenever
f
: Output calculation and state transition logic. Iflet (ep, ir, s_next) = f(ip, er, s)
,ip
: The ingress payload.er
: The egress resolver.s
: The current state.ep
: The egress payload.ir
: The ingress resolver.s_next
: The next state.