Struct 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> Simulation<T>
where T: Send + 'static + Block,

Source

pub fn new() -> Simulation<T>

Construct a simulation struct

Source

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 closure
  • clock_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.
Source

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 called
  • phase_delay - the number of picoseconds to wait before the clock starts being toggled
  • clock_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());
Source

pub fn add_testbench<F>(&mut self, testbench: F)
where F: Fn(Sim<T>) -> Result<(), SimError> + Send + 'static + RefUnwindSafe,

Add a testbench to the simulation

§Arguments
  • testbench - a testbench function that will be executed through the simulation. Needs to return a simulation Result, be Send and [RefUnwindSafe] (no FFI).
§Example
Source

pub fn add_custom_logic<F>(&mut self, logic: F)
where F: Fn(&mut T) + 'static,

Source

pub fn endpoint(&mut self) -> Sim<T>

Source

pub fn run(&mut self, x: Box<T>, max_time: u64) -> Result<(), SimError>

Source

pub fn run_to_file( &mut self, x: Box<T>, max_time: u64, name: &str, ) -> Result<(), SimError>

Source

pub fn run_traced<W>( &mut self, x: Box<T>, max_time: u64, trace: W, ) -> Result<(), SimError>
where W: Write,

Trait Implementations§

Source§

impl<T> Default for Simulation<T>
where T: Send + 'static + Block,

Source§

fn default() -> Simulation<T>

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V