watchall
mode run

system "echo '[] Set Out Ack/Valid Low'"

set e.out.a 0
set e.out.v 0
cycle

system "echo '[] Setting Neuron Req Low'"

set e.y[0].r 0
set e.y[1].r 0

set e.x[0].r 0
set e.x[1].r 0
cycle

# # Slightly confused as to whether Reset should be set to 1 given A_2C_RB_X1 needs active high to change y
# # status X
# # set Reset 1
# # cycle

cycle 
set Reset 0
cycle

system "echo '[] Single Neuron Spikes (0,0)'"

set e.y[0].r 1
set e.x[0].r 1

cycle

assert e.e.Yarb.out.r 1
assert e.e.Xarb.out.r 1

assert e.e._x_v 1

system "echo '[] Check Arbiter Acks'"

assert e.e._x_a_B 1

assert e.y[0].a 1
assert e.y[1].a 0
assert e.e.Yarb.out.a 1
assert e.x[0].a 1
assert e.x[1].a 0
assert e.e.Xarb.out.a 1

system "echo '[] Check Encoders'"

assert e.e.y_enc_out.d[0].t 0
assert e.e.y_enc_out.d[0].f 1

assert e.e.x_enc_out.d[0].t 0
assert e.e.x_enc_out.d[0].f 1

system "echo '[] Check Buffer'"

assert e.e._in_x_v 1
assert e.e._in_y_v 1
assert e.e._en 1

assert e.out.d.d[0].t 0
assert e.out.d.d[0].f 1
assert e.out.d.d[1].t 0
assert e.out.d.d[1].f 1

system "echo '[] Finish Neuron Handshake'"

set e.y[0].r 0
set e.x[0].r 0
cycle

assert e.e.Yarb.out.r 0
assert e.e.Xarb.out.r 0

set e.out.a 1
set e.out.v 1
cycle

assert e.e.Yarb.out.a 0
assert e.e.Xarb.out.a 0
assert e.y[0].a 0
assert e.x[0].a 0

set e.out.a 0
set e.out.v 0
cycle

system "echo '[] Neuron (0,0) Encoded'"

system "echo '[] Single Neuron Spikes (1,1)'"

set e.y[1].r 1
set e.x[1].r 1
cycle

assert e.e.Yarb.out.r 1
assert e.e.Xarb.out.r 1

system "echo '[] Check Arbiter Acks'"

assert e.e._x_a_B 1

assert e.y[0].a 0
assert e.y[1].a 1
assert e.e.Yarb.out.a 1
assert e.x[0].a 0
assert e.x[1].a 1
assert e.e.Xarb.out.a 1

system "echo '[] Check Encoders'"

assert e.e.y_enc_out.d[0].t 1
assert e.e.y_enc_out.d[0].f 0

assert e.e.x_enc_out.d[0].t 1
assert e.e.x_enc_out.d[0].f 0

system "echo '[] Check Buffer'"

assert e.e._in_x_v 1
assert e.e._in_y_v 1
assert e.e._en 1

assert e.out.d.d[0].t 1
assert e.out.d.d[0].f 0
assert e.out.d.d[1].t 1
assert e.out.d.d[1].f 0

system "echo '[] Finish Neuron Handshake'"

set e.y[1].r 0
set e.x[1].r 0
cycle

assert e.e.Yarb.out.r 0
assert e.e.Xarb.out.r 0

set e.out.a 1
set e.out.v 1
cycle

assert e.e.Yarb.out.a 0
assert e.e.Xarb.out.a 0
assert e.y[1].a 0
assert e.x[1].a 0

set e.out.a 0
set e.out.v 0
cycle

system "echo '[] Neuron (1,1) Encoded'"

system "echo '[] Neuron Spikes (0,0), (1,0)'"

set e.x[0].r 1
set e.y[0].r 1
set e.x[1].r 1
cycle

assert e.e.Yarb.out.r 1
assert e.e.Xarb.out.r 1

system "echo '[] Check Arbiter Acks (0,0)'"

assert e.e._x_a_B 1

assert e.y[0].a 1
assert e.y[1].a 0
assert e.e.Yarb.out.a 1
assert e.x[0].a 1
assert e.x[1].a 0
assert e.e.Xarb.out.a 1

system "echo '[] Check Encoders'"

assert e.e.y_enc_out.d[0].t 0
assert e.e.y_enc_out.d[0].f 1

assert e.e.x_enc_out.d[0].t 0
assert e.e.x_enc_out.d[0].f 1


system "echo '[] Check Buffer'"

assert e.e._in_x_v 1
assert e.e._in_y_v 1
assert e.e._en 1

assert e.out.d.d[0].t 0
assert e.out.d.d[0].f 1
assert e.out.d.d[1].t 0
assert e.out.d.d[1].f 1

system "echo '[] Finish Neuron Handshake (0,0)'"

set e.x[0].r 0
cycle

set e.out.a 1
set e.out.v 1
cycle

set e.out.a 0
set e.out.v 0
cycle

system "echo '[] Neuron (0,0) Encoded'"

system "echo '[] Check Neuron (1,0) Waiting'"

assert e.e.Yarb.out.r 1
assert e.e.Xarb.out.r 1

system "echo '[] Check Arbiter Acks (1,0)'"

assert e.e._x_a_B 1

assert e.y[0].a 1
assert e.y[1].a 0
assert e.e.Yarb.out.a 1
assert e.x[0].a 0
assert e.x[1].a 1
assert e.e.Xarb.out.a 1

system "echo '[] Check Encoders'"

assert e.e.y_enc_out.d[0].t 0
assert e.e.y_enc_out.d[0].f 1

assert e.e.x_enc_out.d[0].t 1
assert e.e.x_enc_out.d[0].f 0

system "echo '[] Check Buffer'"

assert e.e._in_x_v 1
assert e.e._in_y_v 1
assert e.e._en 1

assert e.out.d.d[0].t 1
assert e.out.d.d[0].f 0
assert e.out.d.d[1].t 0
assert e.out.d.d[1].f 1


system "echo '[] Finish Neuron Handshake (1,0)'"

set e.x[1].r 0
set e.y[0].r 0
cycle

set e.out.a 1
set e.out.v 1
cycle

set e.out.a 0
set e.out.v 0
cycle

system "echo '[] Neuron (1,0) Encoded'"

system "echo '[] Neuron Spikes (1,0), (0,1)'"

set e.x[1].r 1
set e.y[0].r 1

set e.x[0].r 1
set e.y[1].r 1
cycle

assert e.e.Yarb.out.r 1
assert e.e.Xarb.out.r 1

system "echo '[] Check Arbiter Acks (1,0)'"

assert e.e._x_a_B 1

assert e.y[0].a 0
assert e.y[1].a 1
assert e.e.Yarb.out.a 1
assert e.x[0].a 0
assert e.x[1].a 1
assert e.e.Xarb.out.a 1

system "echo '[] Check Encoders'"

assert e.e.y_enc_out.d[0].t 1
assert e.e.y_enc_out.d[0].f 0

assert e.e.x_enc_out.d[0].t 1
assert e.e.x_enc_out.d[0].f 0

system "echo '[] Check Buffer'"

assert e.e._in_x_v 1
assert e.e._in_y_v 1
assert e.e._en 1

assert e.out.d.d[0].t 1
assert e.out.d.d[0].f 0
assert e.out.d.d[1].t 1
assert e.out.d.d[1].f 0

system "echo '[] Finish Neuron Handshake (1,0)'"

set e.x[1].r 0
set e.y[0].r 0
cycle

set e.out.a 1
set e.out.v 1
cycle

set e.out.a 0
set e.out.v 0
cycle

system "echo '[] Neuron (1,0) Encoded'"

system "echo '[] Check Neuron (0,1) Waiting'"

assert e.e.Yarb.out.r 1
assert e.e.Xarb.out.r 1


system "echo '[] Check Arbiter Acks (0,1)'"

assert e.e._x_a_B 1

assert e.y[0].a 0
assert e.y[1].a 1
assert e.e.Yarb.out.a 1
assert e.x[0].a 1
assert e.x[1].a 0
assert e.e.Xarb.out.a 1

system "echo '[] Check Encoders'"

assert e.e.y_enc_out.d[0].t 1
assert e.e.y_enc_out.d[0].f 0

assert e.e.x_enc_out.d[0].t 0
assert e.e.x_enc_out.d[0].f 1

system "echo '[] Check Buffer'"

assert e.e._in_x_v 1
assert e.e._in_y_v 1
assert e.e._en 1

assert e.out.d.d[0].t 0
assert e.out.d.d[0].f 1
assert e.out.d.d[1].t 1
assert e.out.d.d[1].f 0

system "echo '[] Finish Neuron Handshake (1,0)'"

set e.x[0].r 0
set e.y[1].r 0
cycle

set e.out.a 1
set e.out.v 1
cycle

set e.out.a 0
set e.out.v 0
cycle

assert e.e._in_x_v 0
assert e.e._in_y_v 0
assert e.e._x_v 0

system "echo '[] Neuron (1,0) Encoded'"