Struct rust_hdl_core::simulate::Simulation
source · pub struct Simulation<T> { /* private fields */ }
Expand description
This type represents a simulation over a circuit T
. To simulate
a circuit, you will need to construct one of these structs.
Implementations§
source§impl<T: Send + 'static + Block> Simulation<T>
impl<T: Send + 'static + Block> Simulation<T>
sourcepub fn new() -> Simulation<T>
pub fn new() -> Simulation<T>
Construct a simulation struct
sourcepub fn add_clock<F>(&mut self, interval: u64, clock_fn: F)where
F: Fn(&mut Box<T>) + Send + 'static + RefUnwindSafe,
pub fn add_clock<F>(&mut self, interval: u64, clock_fn: F)where F: Fn(&mut Box<T>) + Send + 'static + RefUnwindSafe,
Add a clock function to the simulation
Arguments
interval
- the number of picoseconds between calls to the clock closureclock_fn
- a closure to change the clock state of the circuit
Example
#[derive(LogicBlock)]
struct Foo {
pub clock: Signal<In, Clock>
}
impl Logic for Foo {
#[hdl_gen]
fn update(&mut self) {
}
}
let mut sim : Simulation<Foo> = Default::default();
sim.add_clock(5, |x| x.clock.next = !x.clock.val()); // Toggles the clock every 5 picoseconds.
sourcepub fn add_phased_clock<F>(
&mut self,
interval: u64,
phase_delay: u64,
clock_fn: F
)where
F: Fn(&mut Box<T>) + Send + 'static + RefUnwindSafe,
pub fn add_phased_clock<F>( &mut self, interval: u64, phase_delay: u64, clock_fn: F )where F: Fn(&mut Box<T>) + Send + 'static + RefUnwindSafe,
Add a phased clock to the simulation
Sometimes you will need to control the phasing of a clock so that it starts at some non-zero time. This method allows you to add a clock to a simulation and control the initial delay.
Arguments
interval
- the delay in picoseconds between the clock function being calledphase_delay
- the number of picoseconds to wait before the clock starts being toggledclock_fn
- the function that toggles the actual clock.
Example
#[derive(LogicBlock)]
struct Foo {
pub clock: Signal<In, Clock>
}
impl Logic for Foo {
#[hdl_gen]
fn update(&mut self) {
}
}
let mut sim : Simulation<Foo> = Default::default();
// Toggles every 5 picoseconds, starting after 15 picoseconds
sim.add_phased_clock(5, 15, |x| x.clock.next = !x.clock.val());