@@ -0,0 +1,1631 @@
+%22%22%22Simulation primitives.%22%22%22%0A%0Afrom hdltools.sim import HDLSimulationObject%0A%0A%0Aclass ClockGenerator(HDLSimulationObject):%0A    %22%22%22Simple clock generator.%22%22%22%0A%0A    def __init__(self, identifier, clk_period=1, clk_pol=False):%0A        %22%22%22Initialize.%22%22%22%0A        super().__init__(identifier, clk_period=clk_period, clk_pol=clk_pol)%0A%0A    def initialstate(self):%0A        %22%22%22Set initial state.%22%22%22%0A        if self.clk_pol:%0A            self._state = %22high%22%0A        else:%0A            self._state = %22low%22%0A%0A    def structure(self):%0A        %22%22%22Set up structure.%22%22%22%0A        self.add_output(%22clk%22, initial=1 if self.clk_pol else 0)%0A%0A    def logic(self, **kwargs):%0A        %22%22%22Describe simulation logic.%22%22%22%0A        if self._state == %22low%22:%0A            self._state = %22high%22%0A            self.clk = True%0A        else:%0A            self._state = %22low%22%0A            self.clk = False%0A%0A%0Aclass OneshotSignal(HDLSimulationObject):%0A    %22%22%22Oneshot signal generator.%22%22%22%0A%0A    def __init__(self, identifier, wait_for, initial_value=False):%0A        %22%22%22Initialize.%22%22%22%0A        super().__init__(%0A            identifier, wait_for=wait_for, initial_value=initial_value%0A        )%0A%0A    def initialstate(self):%0A        %22%22%22Set initial state.%22%22%22%0A        self._count = 0%0A%0A    def structure(self):%0A        %22%22%22Set up structure.%22%22%22%0A        self.add_output(%22sig%22, initial=True if self.initial_value else False)%0A%0A    def logic(self, **kwargs):%0A        %22%22%22Describe simulation logic.%22%22%22%0A        if self._count %3C self.wait_for:%0A            self._count += 1%0A        else:%0A            if self.initial_value:%0A                self.sig = False%0A            else:%0A                self.sig = True%0A

Implement simulation primitives