sim/devices: port to NAC3

This commit is contained in:
Sebastien Bourdeauducq 2022-04-12 16:01:56 +08:00
parent 125572b553
commit 89aa3a3d9d
1 changed files with 13 additions and 11 deletions

View File

@ -1,18 +1,18 @@
from random import Random
import numpy
from artiq.language.core import kernel
from artiq.language.core import kernel, sequential, delay_mu
from artiq.sim import time
class Core:
def __init__(self, dmgr):
self.ref_period = 1
self.ref_period = 1e-6
self._level = 0
def run(self, k_function, k_args, k_kwargs):
self._level += 1
r = k_function.artiq_embedded.function(*k_args, **k_kwargs)
with sequential:
r = getattr(k_function.__self__, k_function.__name__).__wrapped__(k_function.__self__, *k_args, **k_kwargs)
self._level -= 1
if self._level == 0:
print(time.manager.format_timeline())
@ -20,33 +20,35 @@ class Core:
return r
def seconds_to_mu(self, seconds):
return numpy.int64(seconds//self.ref_period)
return round(seconds/self.ref_period)
def mu_to_seconds(self, mu):
return mu*self.ref_period
def delay(self, seconds):
delay_mu(self.seconds_to_mu(seconds))
class Input:
def __init__(self, dmgr, name):
self.core = dmgr.get("core")
self.name = name
self.prng = Random()
@kernel
def gate_rising(self, duration):
time.manager.event(("gate_rising", self.name, duration))
delay(duration)
self.core.delay(duration)
@kernel
def gate_falling(self, duration):
time.manager.event(("gate_falling", self.name, duration))
delay(duration)
self.core.delay(duration)
@kernel
def gate_both(self, duration):
time.manager.event(("gate_both", self.name, duration))
delay(duration)
self.core.delay(duration)
@kernel
def count(self, up_to_timestamp_mu):
@ -75,7 +77,7 @@ class Output:
@kernel
def pulse(self, duration):
time.manager.event(("pulse", self.name, duration))
delay(duration)
self.core.delay(duration)
@kernel
def on(self):
@ -94,7 +96,7 @@ class WaveOutput:
@kernel
def pulse(self, frequency, duration):
time.manager.event(("pulse", self.name, frequency, self.core.seconds_to_mu(duration)))
delay(duration)
self.core.delay(duration)
class VoltageOutput: