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> Simulation<T>
impl<T> 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)
pub fn add_clock<F>(&mut self, interval: u64, clock_fn: F)
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,
)
pub fn add_phased_clock<F>( &mut self, interval: u64, phase_delay: u64, clock_fn: F, )
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());
Sourcepub fn add_testbench<F>(&mut self, testbench: F)
pub fn add_testbench<F>(&mut self, testbench: F)
pub fn add_custom_logic<F>(&mut self, logic: F)
pub fn endpoint(&mut self) -> Sim<T>
pub fn run(&mut self, x: Box<T>, max_time: u64) -> Result<(), SimError>
pub fn run_to_file( &mut self, x: Box<T>, max_time: u64, name: &str, ) -> Result<(), SimError>
pub fn run_traced<W>(
&mut self,
x: Box<T>,
max_time: u64,
trace: W,
) -> Result<(), SimError>where
W: Write,
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Simulation<T>
impl<T> !RefUnwindSafe for Simulation<T>
impl<T> !Send for Simulation<T>
impl<T> !Sync for Simulation<T>
impl<T> Unpin for Simulation<T>
impl<T> !UnwindSafe for Simulation<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more