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.y[2].r 0
set e.y[3].r 0
set e.y[4].r 0
set e.y[5].r 0
set e.y[6].r 0
set e.y[7].r 0

set e.x[0].r 0
set e.x[1].r 0
set e.x[2].r 0
set e.x[3].r 0
set e.x[4].r 0
set e.x[5].r 0
set e.x[6].r 0
set e.x[7].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 

mode run
status X
status 0
set Reset 0
cycle



system "echo '[] Single Neuron Spikes (2,5), raise y[5].r'"

set e.y[5].r 1
# set e.x[2].r 1
cycle

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



system "echo '[] Raise x[2].r'"
# set e.y[5].r 1
set e.x[2].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 0
assert e.y[1].a 0
assert e.y[2].a 0
assert e.y[3].a 0
assert e.y[4].a 0
assert e.y[5].a 1
assert e.y[6].a 0
assert e.y[7].a 0
assert e.e.Yarb.out.a 1


assert e.x[0].a 0
assert e.x[1].a 0
assert e.x[2].a 1
assert e.x[3].a 0
assert e.x[4].a 0
assert e.x[5].a 0
assert e.x[6].a 0
assert e.x[7].a 0
assert e.e.Xarb.out.a 1

system "echo '[] Check Encoders'"

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

assert e.e.y_enc_out.d[0].t 1
assert e.e.y_enc_out.d[0].f 0
assert e.e.y_enc_out.d[1].t 0
assert e.e.y_enc_out.d[1].f 1
assert e.e.y_enc_out.d[2].t 1
assert e.e.y_enc_out.d[2].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 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
assert e.out.d.d[2].t 0
assert e.out.d.d[2].f 1
assert e.out.d.d[3].t 1
assert e.out.d.d[3].f 0
assert e.out.d.d[4].t 0
assert e.out.d.d[4].f 1
assert e.out.d.d[5].t 1
assert e.out.d.d[5].f 0


system "echo '[] Finish Neuron Handshake'"

set e.y[5].r 0
set e.x[2].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[5].a 0
assert e.x[2].a 0

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

system "echo '[] Neuron (2,5) Encoded'"

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.y[2].a 0
assert e.y[3].a 0
assert e.y[4].a 0
assert e.y[5].a 0
assert e.y[6].a 0
assert e.y[7].a 0
assert e.e.Yarb.out.a 1


assert e.x[0].a 1
assert e.x[1].a 0
assert e.x[2].a 0
assert e.x[3].a 0
assert e.x[4].a 0
assert e.x[5].a 0
assert e.x[6].a 0
assert e.x[7].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.y_enc_out.d[1].t 0
assert e.e.y_enc_out.d[1].f 1
assert e.e.y_enc_out.d[2].t 0
assert e.e.y_enc_out.d[2].f 1

assert e.e.x_enc_out.d[0].t 0
assert e.e.x_enc_out.d[0].f 1
assert e.e.x_enc_out.d[1].t 0
assert e.e.x_enc_out.d[1].f 1
assert e.e.x_enc_out.d[2].t 0
assert e.e.x_enc_out.d[2].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
assert e.out.d.d[2].t 0
assert e.out.d.d[2].f 1
assert e.out.d.d[3].t 0
assert e.out.d.d[3].f 1
assert e.out.d.d[4].t 0
assert e.out.d.d[4].f 1
assert e.out.d.d[5].t 0
assert e.out.d.d[5].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'"