forked from M-Labs/artiq
1
0
Fork 0
artiq/artiq/sim/devices.py

64 lines
1.4 KiB
Python

from random import Random
from artiq.language.core import delay, kernel
from artiq.language.db import *
from artiq.language import units
from artiq.sim import time
class Core(AutoDB):
def build(self):
self.ref_period = 1
self._level = 0
def run(self, k_function, k_args, k_kwargs):
self._level += 1
r = k_function(*k_args, **k_kwargs)
self._level -= 1
if self._level == 0:
print(time.manager.format_timeline())
return r
class Input(AutoDB):
class DBKeys:
core = Device()
name = Argument()
def build(self):
self.prng = Random()
@kernel
def wait_edge(self):
duration = self.prng.randrange(0, 20)*units.ms
time.manager.event(("wait_edge", self.name, duration))
delay(duration)
@kernel
def count_gate(self, duration):
result = self.prng.randrange(0, 100)
time.manager.event(("count_gate", self.name, duration, result))
delay(duration)
return result
class WaveOutput(AutoDB):
class DBKeys:
core = Device()
name = Argument()
@kernel
def pulse(self, frequency, duration):
time.manager.event(("pulse", self.name, frequency, duration))
delay(duration)
class VoltageOutput(AutoDB):
class DBKeys:
core = Device()
name = Argument()
@kernel
def set(self, value):
time.manager.event(("set_voltage", self.name, value))