forked from M-Labs/artiq
inter-experiment smooth handover
This commit is contained in:
parent
ef8f60c78d
commit
c8dc6ca07c
|
@ -37,6 +37,10 @@ class CompileError(Exception):
|
||||||
return "\n" + _render_diagnostic(self.diagnostic, colored=colors_supported)
|
return "\n" + _render_diagnostic(self.diagnostic, colored=colors_supported)
|
||||||
|
|
||||||
|
|
||||||
|
@syscall
|
||||||
|
def rtio_init():
|
||||||
|
raise NotImplementedError("syscall not simulated")
|
||||||
|
|
||||||
@syscall(flags={"nounwind", "nowrite"})
|
@syscall(flags={"nounwind", "nowrite"})
|
||||||
def rtio_get_counter() -> TInt64:
|
def rtio_get_counter() -> TInt64:
|
||||||
raise NotImplementedError("syscall not simulated")
|
raise NotImplementedError("syscall not simulated")
|
||||||
|
@ -121,10 +125,21 @@ class Core:
|
||||||
def get_rtio_counter_mu(self):
|
def get_rtio_counter_mu(self):
|
||||||
return rtio_get_counter()
|
return rtio_get_counter()
|
||||||
|
|
||||||
|
@kernel
|
||||||
|
def reset(self):
|
||||||
|
"""Clear RTIO FIFOs, release RTIO PHY reset, and set the time cursor
|
||||||
|
at the current value of the hardware RTIO counter plus a margin of
|
||||||
|
125000 machine units."""
|
||||||
|
rtio_init()
|
||||||
|
at_mu(rtio_get_counter() + 125000)
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def break_realtime(self):
|
def break_realtime(self):
|
||||||
"""Set the timeline to the current value of the hardware RTIO counter
|
"""Set the time cursor after the current value of the hardware RTIO
|
||||||
plus a margin of 125000 machine units."""
|
counter plus a margin of 125000 machine units.
|
||||||
|
|
||||||
|
If the time cursor is already after that position, this function
|
||||||
|
does nothing."""
|
||||||
min_now = rtio_get_counter() + 125000
|
min_now = rtio_get_counter() + 125000
|
||||||
if now_mu() < min_now:
|
if now_mu() < min_now:
|
||||||
at_mu(min_now)
|
at_mu(min_now)
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
from artiq.experiment import *
|
||||||
|
|
||||||
|
|
||||||
|
class IdleKernel(EnvExperiment):
|
||||||
|
def build(self):
|
||||||
|
self.setattr_device("core")
|
||||||
|
self.setattr_device("led")
|
||||||
|
|
||||||
|
@kernel
|
||||||
|
def run(self):
|
||||||
|
start_time = now_mu() + seconds_to_mu(500*ms)
|
||||||
|
while self.core.get_rtio_counter_mu() < start_time:
|
||||||
|
pass
|
||||||
|
self.core.reset()
|
||||||
|
while True:
|
||||||
|
self.led.pulse(250*ms)
|
||||||
|
delay(125*ms)
|
||||||
|
self.led.pulse(125*ms)
|
||||||
|
delay(125*ms)
|
||||||
|
self.led.pulse(125*ms)
|
||||||
|
delay(250*ms)
|
|
@ -38,6 +38,7 @@ class PDQ2Simple(EnvExperiment):
|
||||||
return self.pmt.count()
|
return self.pmt.count()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
offsets = np.arange(0, 3)
|
offsets = np.arange(0, 3)
|
||||||
for o in offsets:
|
for o in offsets:
|
||||||
self.setup(o)
|
self.setup(o)
|
||||||
|
|
|
@ -48,6 +48,7 @@ class PhotonHistogram(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
self.program_cooling()
|
self.program_cooling()
|
||||||
|
|
||||||
hist = [0 for _ in range(self.nbins)]
|
hist = [0 for _ in range(self.nbins)]
|
||||||
|
|
|
@ -9,6 +9,7 @@ class AD5360Test(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
self.dac.setup_bus(write_div=30, read_div=40)
|
self.dac.setup_bus(write_div=30, read_div=40)
|
||||||
self.dac.write_offsets()
|
self.dac.write_offsets()
|
||||||
self.led.on()
|
self.led.on()
|
||||||
|
|
|
@ -8,6 +8,7 @@ class BlinkForever(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
while True:
|
while True:
|
||||||
self.led.pulse(100*ms)
|
self.led.pulse(100*ms)
|
||||||
delay(100*ms)
|
delay(100*ms)
|
||||||
|
|
|
@ -17,6 +17,7 @@ class DDSTest(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
with self.core_dds.batch:
|
with self.core_dds.batch:
|
||||||
self.dds1.set(120*MHz)
|
self.dds1.set(120*MHz)
|
||||||
self.dds2.set(200*MHz)
|
self.dds2.set(200*MHz)
|
||||||
|
|
|
@ -12,5 +12,6 @@ class Handover(EnvExperiment):
|
||||||
delay(250*ms)
|
delay(250*ms)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
while True:
|
while True:
|
||||||
self.blink_once()
|
self.blink_once()
|
||||||
|
|
|
@ -36,6 +36,7 @@ class TDR(EnvExperiment):
|
||||||
self.setattr_device("ttl2")
|
self.setattr_device("ttl2")
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
n = 1000 # repetitions
|
n = 1000 # repetitions
|
||||||
latency = 50e-9 # calibrated latency without a transmission line
|
latency = 50e-9 # calibrated latency without a transmission line
|
||||||
pulse = 1e-6 # pulse length, larger than rtt
|
pulse = 1e-6 # pulse length, larger than rtt
|
||||||
|
|
|
@ -91,6 +91,7 @@ class Transport(EnvExperiment):
|
||||||
self.repeat()
|
self.repeat()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
# scan transport endpoint
|
# scan transport endpoint
|
||||||
stops = np.linspace(0, 10, 10)
|
stops = np.linspace(0, 10, 10)
|
||||||
self.scan(stops)
|
self.scan(stops)
|
||||||
|
|
|
@ -149,7 +149,7 @@ int kloader_is_essential_kmsg(int msgtype)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long long int now;
|
static long long int now = 0;
|
||||||
|
|
||||||
void kloader_service_essential_kmsg(void)
|
void kloader_service_essential_kmsg(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
#define KERNELCPU_LAST_ADDRESS (0x4fffffff - 1024*1024)
|
#define KERNELCPU_LAST_ADDRESS (0x4fffffff - 1024*1024)
|
||||||
#define KSUPPORT_HEADER_SIZE 0x80
|
#define KSUPPORT_HEADER_SIZE 0x80
|
||||||
|
|
||||||
extern long long int now;
|
|
||||||
|
|
||||||
int kloader_load_library(const void *code);
|
int kloader_load_library(const void *code);
|
||||||
void kloader_filter_backtrace(struct artiq_backtrace_item *backtrace,
|
void kloader_filter_backtrace(struct artiq_backtrace_item *backtrace,
|
||||||
size_t *backtrace_size);
|
size_t *backtrace_size);
|
||||||
|
|
|
@ -111,6 +111,7 @@ static const struct symbol runtime_exports[] = {
|
||||||
{"recv_rpc", &recv_rpc},
|
{"recv_rpc", &recv_rpc},
|
||||||
|
|
||||||
/* direct syscalls */
|
/* direct syscalls */
|
||||||
|
{"rtio_init", &rtio_init},
|
||||||
{"rtio_get_counter", &rtio_get_counter},
|
{"rtio_get_counter", &rtio_get_counter},
|
||||||
{"rtio_log", &rtio_log},
|
{"rtio_log", &rtio_log},
|
||||||
{"rtio_output", &rtio_output},
|
{"rtio_output", &rtio_output},
|
||||||
|
@ -351,11 +352,6 @@ static void now_init(void)
|
||||||
}
|
}
|
||||||
now = reply->now;
|
now = reply->now;
|
||||||
mailbox_acknowledge();
|
mailbox_acknowledge();
|
||||||
|
|
||||||
if(now < 0) {
|
|
||||||
rtio_init();
|
|
||||||
now = rtio_get_counter() + (272000 << CONFIG_RTIO_FINE_TS_WIDTH);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void now_save(void)
|
static void now_save(void)
|
||||||
|
|
|
@ -300,7 +300,6 @@ void session_startup_kernel(void)
|
||||||
{
|
{
|
||||||
struct msg_base *umsg;
|
struct msg_base *umsg;
|
||||||
|
|
||||||
now = -1;
|
|
||||||
watchdog_init();
|
watchdog_init();
|
||||||
if(!kloader_start_startup_kernel())
|
if(!kloader_start_startup_kernel())
|
||||||
return;
|
return;
|
||||||
|
@ -341,14 +340,12 @@ void session_start(void)
|
||||||
out_packet_reset();
|
out_packet_reset();
|
||||||
|
|
||||||
kloader_stop();
|
kloader_stop();
|
||||||
now = -1;
|
|
||||||
user_kernel_state = USER_KERNEL_NONE;
|
user_kernel_state = USER_KERNEL_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void session_end(void)
|
void session_end(void)
|
||||||
{
|
{
|
||||||
kloader_stop();
|
kloader_stop();
|
||||||
now = -1;
|
|
||||||
watchdog_init();
|
watchdog_init();
|
||||||
kloader_start_idle_kernel();
|
kloader_start_idle_kernel();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ class CreateTTLPulse(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def initialize_io(self):
|
def initialize_io(self):
|
||||||
|
self.core.reset()
|
||||||
self.loop_in.input()
|
self.loop_in.input()
|
||||||
self.loop_out.off()
|
self.loop_out.off()
|
||||||
|
|
||||||
|
@ -33,6 +34,7 @@ class WriteLog(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
rtio_log("foo", 32)
|
rtio_log("foo", 32)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ class _Roundtrip(EnvExperiment):
|
||||||
def roundtrip(self, obj, fn):
|
def roundtrip(self, obj, fn):
|
||||||
fn(obj)
|
fn(obj)
|
||||||
|
|
||||||
|
|
||||||
class RoundtripTest(ExperimentCase):
|
class RoundtripTest(ExperimentCase):
|
||||||
def assertRoundtrip(self, obj):
|
def assertRoundtrip(self, obj):
|
||||||
exp = self.create(_Roundtrip)
|
exp = self.create(_Roundtrip)
|
||||||
|
@ -55,6 +56,7 @@ class _DefaultArg(EnvExperiment):
|
||||||
def run(self):
|
def run(self):
|
||||||
return self.test()
|
return self.test()
|
||||||
|
|
||||||
|
|
||||||
class DefaultArgTest(ExperimentCase):
|
class DefaultArgTest(ExperimentCase):
|
||||||
def test_default_arg(self):
|
def test_default_arg(self):
|
||||||
exp = self.create(_DefaultArg)
|
exp = self.create(_DefaultArg)
|
||||||
|
@ -103,6 +105,7 @@ class _RPC(EnvExperiment):
|
||||||
def builtin(self):
|
def builtin(self):
|
||||||
sleep(1.0)
|
sleep(1.0)
|
||||||
|
|
||||||
|
|
||||||
class RPCTest(ExperimentCase):
|
class RPCTest(ExperimentCase):
|
||||||
def test_args(self):
|
def test_args(self):
|
||||||
exp = self.create(_RPC)
|
exp = self.create(_RPC)
|
||||||
|
@ -128,6 +131,7 @@ class _Payload1MB(EnvExperiment):
|
||||||
data = [0 for _ in range(1000000//4)]
|
data = [0 for _ in range(1000000//4)]
|
||||||
self.devnull(data)
|
self.devnull(data)
|
||||||
|
|
||||||
|
|
||||||
class LargePayloadTest(ExperimentCase):
|
class LargePayloadTest(ExperimentCase):
|
||||||
def test_1MB(self):
|
def test_1MB(self):
|
||||||
exp = self.create(_Payload1MB)
|
exp = self.create(_Payload1MB)
|
||||||
|
|
|
@ -24,6 +24,7 @@ class RTT(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
self.ttl_inout.output()
|
self.ttl_inout.output()
|
||||||
delay(1*us)
|
delay(1*us)
|
||||||
with interleave:
|
with interleave:
|
||||||
|
@ -48,6 +49,7 @@ class Loopback(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
self.loop_in.input()
|
self.loop_in.input()
|
||||||
self.loop_out.off()
|
self.loop_out.off()
|
||||||
delay(1*us)
|
delay(1*us)
|
||||||
|
@ -71,6 +73,7 @@ class ClockGeneratorLoopback(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
self.loop_clock_in.input()
|
self.loop_clock_in.input()
|
||||||
self.loop_clock_out.stop()
|
self.loop_clock_out.stop()
|
||||||
delay(1*us)
|
delay(1*us)
|
||||||
|
@ -89,6 +92,7 @@ class PulseRate(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
dt = seconds_to_mu(300*ns)
|
dt = seconds_to_mu(300*ns)
|
||||||
while True:
|
while True:
|
||||||
for i in range(10000):
|
for i in range(10000):
|
||||||
|
@ -113,6 +117,7 @@ class PulseRateDDS(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
dt = seconds_to_mu(5*us)
|
dt = seconds_to_mu(5*us)
|
||||||
while True:
|
while True:
|
||||||
delay(10*ms)
|
delay(10*ms)
|
||||||
|
@ -154,6 +159,7 @@ class LoopbackCount(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
self.loop_in.input()
|
self.loop_in.input()
|
||||||
self.loop_out.output()
|
self.loop_out.output()
|
||||||
delay(5*us)
|
delay(5*us)
|
||||||
|
@ -173,6 +179,7 @@ class Underflow(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
while True:
|
while True:
|
||||||
delay(25*ns)
|
delay(25*ns)
|
||||||
self.ttl_out.pulse(25*ns)
|
self.ttl_out.pulse(25*ns)
|
||||||
|
@ -185,6 +192,7 @@ class SequenceError(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
t = now_mu()
|
t = now_mu()
|
||||||
self.ttl_out.pulse(25*us)
|
self.ttl_out.pulse(25*us)
|
||||||
at_mu(t)
|
at_mu(t)
|
||||||
|
@ -198,6 +206,7 @@ class Collision(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
delay(5*ms) # make sure we won't get underflow
|
delay(5*ms) # make sure we won't get underflow
|
||||||
for i in range(16):
|
for i in range(16):
|
||||||
self.ttl_out_serdes.pulse_mu(1)
|
self.ttl_out_serdes.pulse_mu(1)
|
||||||
|
@ -211,6 +220,7 @@ class AddressCollision(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
self.loop_in.input()
|
self.loop_in.input()
|
||||||
self.loop_in.pulse(10*us)
|
self.loop_in.pulse(10*us)
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Collision(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
self.core.break_realtime()
|
self.core.reset()
|
||||||
t = now_mu()
|
t = now_mu()
|
||||||
try:
|
try:
|
||||||
self.spi0.set_config_mu()
|
self.spi0.set_config_mu()
|
||||||
|
@ -31,8 +31,8 @@ class Busy(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
try:
|
try:
|
||||||
self.core.break_realtime()
|
|
||||||
self.spi0.set_config_mu()
|
self.spi0.set_config_mu()
|
||||||
t = now_mu()
|
t = now_mu()
|
||||||
self.spi0.set_config_mu()
|
self.spi0.set_config_mu()
|
||||||
|
@ -54,6 +54,7 @@ class DrainErrors(EnvExperiment):
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def run(self):
|
def run(self):
|
||||||
|
self.core.reset()
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
self.core.break_realtime()
|
self.core.break_realtime()
|
||||||
|
|
Loading…
Reference in New Issue