artiq/artiq/sim/devices.py

62 lines
1.5 KiB
Python
Raw Normal View History

from random import Random
2014-12-03 18:20:30 +08:00
from artiq.language.core import delay, kernel
from artiq.language import units
from artiq.sim import time
2014-09-05 12:03:22 +08:00
2015-07-14 04:08:20 +08:00
class Core:
def __init__(self, dmgr):
2015-07-02 04:22:53 +08:00
self.ref_period = 1
self._level = 0
2014-12-03 18:20:30 +08:00
2014-09-05 12:03:22 +08:00
def run(self, k_function, k_args, k_kwargs):
2015-07-02 04:22:53 +08:00
self._level += 1
2014-12-03 18:20:30 +08:00
r = k_function(*k_args, **k_kwargs)
2015-07-02 04:22:53 +08:00
self._level -= 1
if self._level == 0:
2014-12-03 18:20:30 +08:00
print(time.manager.format_timeline())
return r
2014-09-05 12:03:22 +08:00
2015-07-14 04:08:20 +08:00
class Input:
def __init__(self, dmgr, name):
self.core = dmgr.get("core")
self.name = name
2014-08-13 18:16:40 +08:00
2014-09-05 12:03:22 +08:00
self.prng = Random()
2014-12-03 18:20:30 +08:00
@kernel
2014-09-05 12:03:22 +08:00
def wait_edge(self):
duration = self.prng.randrange(0, 20)*units.ms
time.manager.event(("wait_edge", self.name, duration))
delay(duration)
2014-12-03 18:20:30 +08:00
@kernel
2014-09-05 12:03:22 +08:00
def count_gate(self, duration):
result = self.prng.randrange(0, 100)
time.manager.event(("count_gate", self.name, duration, result))
delay(duration)
return result
2015-07-14 04:08:20 +08:00
class WaveOutput:
def __init__(self, dmgr, name):
self.core = dmgr.get("core")
self.name = name
2014-09-05 12:03:22 +08:00
2014-12-03 18:20:30 +08:00
@kernel
2014-09-05 12:03:22 +08:00
def pulse(self, frequency, duration):
time.manager.event(("pulse", self.name, frequency, duration))
delay(duration)
2015-07-14 04:08:20 +08:00
class VoltageOutput:
def __init__(self, dmgr, name):
self.core = dmgr.get("core")
self.name = name
2014-12-03 18:20:30 +08:00
@kernel
2014-09-05 12:03:22 +08:00
def set(self, value):
time.manager.event(("set_voltage", self.name, value))