nac3_sca/nac3artiq/demo.py

105 lines
1.9 KiB
Python
Raw Normal View History

2020-12-18 23:44:45 +08:00
from language import *
2021-09-24 11:39:26 +08:00
from numpy import int32, int64
2021-09-27 10:13:03 +08:00
@extern
2021-09-24 14:45:44 +08:00
def now_mu() -> int64:
raise NotImplementedError("syscall not simulated")
2021-09-27 10:13:03 +08:00
@extern
2021-09-24 14:45:44 +08:00
def at_mu(t: int64):
raise NotImplementedError("syscall not simulated")
2021-09-27 10:13:03 +08:00
@extern
2021-09-24 14:45:44 +08:00
def delay_mu(dt: int64):
raise NotImplementedError("syscall not simulated")
2021-09-27 10:13:03 +08:00
@extern
2021-09-24 11:39:26 +08:00
def rtio_init():
raise NotImplementedError("syscall not simulated")
2021-09-27 10:13:03 +08:00
@extern
2021-09-24 11:39:26 +08:00
def rtio_get_counter() -> int64:
raise NotImplementedError("syscall not simulated")
2021-09-27 10:13:03 +08:00
@extern
2021-09-24 11:39:26 +08:00
def rtio_output(target: int32, data: int32):
raise NotImplementedError("syscall not simulated")
2021-09-27 10:13:03 +08:00
@extern
2021-09-24 11:39:26 +08:00
def rtio_input_timestamp(timeout_mu: int64, channel: int32) -> int64:
raise NotImplementedError("syscall not simulated")
2021-09-27 10:13:03 +08:00
@extern
2021-09-24 11:39:26 +08:00
def rtio_input_data(channel: int32) -> int32:
raise NotImplementedError("syscall not simulated")
2020-12-18 23:44:45 +08:00
2021-09-24 14:45:44 +08:00
@kernel
class Core:
@kernel
def reset(self):
rtio_init()
at_mu(rtio_get_counter() + int64(125000))
@kernel
def break_realtime(self):
min_now = rtio_get_counter() + int64(125000)
if now_mu() < min_now:
at_mu(min_now)
2021-09-25 14:17:11 +08:00
@kernel
class TTLOut:
channel: int32
target_o: int32
@kernel
def __init__(self, channel: int32):
self.channel = channel
self.target_o = channel << 8
@kernel
def output(self):
pass
@kernel
def set_o(self, o: bool):
rtio_output(self.target_o, 1 if o else 0)
@kernel
def on(self):
self.set_o(True)
@kernel
def off(self):
self.set_o(False)
@kernel
def pulse_mu(self, duration: int64):
self.on()
delay_mu(duration)
self.off()
2020-12-18 23:44:45 +08:00
2021-09-23 19:30:03 +08:00
@kernel
2020-12-18 23:44:45 +08:00
class Demo:
@kernel
2021-09-23 19:30:03 +08:00
def run(self):
2021-09-24 14:45:44 +08:00
core = Core()
2021-09-25 14:17:11 +08:00
led = TTLOut(0)
2021-09-24 14:45:44 +08:00
core.reset()
2021-09-25 14:17:11 +08:00
while True:
led.pulse_mu(int64(100000000))
delay_mu(int64(100000000))
2020-12-18 23:44:45 +08:00
if __name__ == "__main__":
Demo().run()