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 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 from artiq.sim import time
class Core: class Core:
def __init__(self, dmgr): def __init__(self, dmgr):
self.ref_period = 1 self.ref_period = 1e-6
self._level = 0 self._level = 0
def run(self, k_function, k_args, k_kwargs): def run(self, k_function, k_args, k_kwargs):
self._level += 1 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 self._level -= 1
if self._level == 0: if self._level == 0:
print(time.manager.format_timeline()) print(time.manager.format_timeline())
@ -20,33 +20,35 @@ class Core:
return r return r
def seconds_to_mu(self, seconds): 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): def mu_to_seconds(self, mu):
return mu*self.ref_period return mu*self.ref_period
def delay(self, seconds):
delay_mu(self.seconds_to_mu(seconds))
class Input: class Input:
def __init__(self, dmgr, name): def __init__(self, dmgr, name):
self.core = dmgr.get("core") self.core = dmgr.get("core")
self.name = name self.name = name
self.prng = Random() self.prng = Random()
@kernel @kernel
def gate_rising(self, duration): def gate_rising(self, duration):
time.manager.event(("gate_rising", self.name, duration)) time.manager.event(("gate_rising", self.name, duration))
delay(duration) self.core.delay(duration)
@kernel @kernel
def gate_falling(self, duration): def gate_falling(self, duration):
time.manager.event(("gate_falling", self.name, duration)) time.manager.event(("gate_falling", self.name, duration))
delay(duration) self.core.delay(duration)
@kernel @kernel
def gate_both(self, duration): def gate_both(self, duration):
time.manager.event(("gate_both", self.name, duration)) time.manager.event(("gate_both", self.name, duration))
delay(duration) self.core.delay(duration)
@kernel @kernel
def count(self, up_to_timestamp_mu): def count(self, up_to_timestamp_mu):
@ -75,7 +77,7 @@ class Output:
@kernel @kernel
def pulse(self, duration): def pulse(self, duration):
time.manager.event(("pulse", self.name, duration)) time.manager.event(("pulse", self.name, duration))
delay(duration) self.core.delay(duration)
@kernel @kernel
def on(self): def on(self):
@ -94,7 +96,7 @@ class WaveOutput:
@kernel @kernel
def pulse(self, frequency, duration): def pulse(self, frequency, duration):
time.manager.event(("pulse", self.name, frequency, self.core.seconds_to_mu(duration))) time.manager.event(("pulse", self.name, frequency, self.core.seconds_to_mu(duration)))
delay(duration) self.core.delay(duration)
class VoltageOutput: class VoltageOutput: