Skip to content

Commit

Permalink
fix #150, #151, #131
Browse files Browse the repository at this point in the history
  • Loading branch information
sgherbst committed May 7, 2024
1 parent ac9fb35 commit a558c0a
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 5 deletions.
54 changes: 54 additions & 0 deletions random/mkqueues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3

# Copyright (c) 2024 Zero ASIC Corporation
# This code is licensed under Apache License 2.0 (see LICENSE for details)

# Small script that generates sample queues for inspection with a command-line tool

import numpy as np
from switchboard import PySbTx, PySbPacket, UmiTxRx, random_umi_packet


def main():
#######################################
# generate native switchboard packets #
#######################################

print('*** Native packets ***')
print()

tx = PySbTx('sb.q', fresh=True)

txp = PySbPacket(
destination=2,
flags=1,
data=np.arange(32, dtype=np.uint8)
)

for k in range(3):
print(txp)
tx.send(txp)

txp.data += 1
txp.flags = 1 - txp.flags
txp.destination = (txp.destination * 10) + (k + 3)

print()

########################
# generate UMI packets #
########################

print('*** UMI packets ***')
print()

tx = UmiTxRx(tx_uri='umi.q', fresh=True)

for k in range(3):
txp = random_umi_packet()
print(txp)
tx.send(txp)


if __name__ == '__main__':
main()
32 changes: 32 additions & 0 deletions switchboard/switchboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,43 @@ def path():
return Path(__file__).resolve().parent


def inspect(file, format):
import shutil
import tempfile

with tempfile.NamedTemporaryFile() as temp:
shutil.copyfile(file, temp.name)

if format == 'sb':
from switchboard import PySbRx
rx = PySbRx(temp.name, fresh=False)
elif format == 'umi':
from switchboard import UmiTxRx
rx = UmiTxRx(rx_uri=temp.name, fresh=False)
else:
raise ValueError(f'Format not supported: "{format}"')

while True:
rxp = rx.recv(False)

if rxp is not None:
print(rxp)
else:
break


def main():
parser = ArgumentParser()
parser.add_argument('--path', action='store_true')
parser.add_argument('-i', '--inspect', type=str, default=None, help='Print the contents'
' of the given switchboard queue.')
parser.add_argument('-f', '--format', type=str, default='sb', choices=['sb', 'umi'],
help='Format assumed for the contents of the switchboard queue passed via the'
' -i/--inspect argument.')

args = parser.parse_args()

if args.path:
print(path())
elif args.inspect is not None:
inspect(file=args.inspect, format=args.format)
5 changes: 3 additions & 2 deletions switchboard/verilog/fpga/umi_fpga_queues.sv
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ module umi_fpga_queues #(

wire [NUM_TX_QUEUES*SB_DW-1:0] sb_tx_data;
wire [NUM_TX_QUEUES*32-1:0] sb_tx_dest;
wire [NUM_TX_QUEUES-1:0] sb_tx_last;
for (i = 0; i < NUM_TX_QUEUES; i = i + 1) begin
assign sb_tx_data[i*SB_DW+:SB_DW] = {
tx_data[i*DW+:DW], tx_srcaddr[i*AW+:AW], tx_dstaddr[i*AW+:AW], tx_cmd[i*CW+:CW]
};
assign sb_tx_dest[i*32+:32] = {16'h0000, tx_dstaddr[i*AW+55:i*AW+40]};
assign sb_tx_last[i] = tx_cmd[(i*CW)+22];
end

sb_fpga_queues #(
Expand All @@ -131,8 +133,7 @@ module umi_fpga_queues #(

.tx_data(sb_tx_data),
.tx_dest(sb_tx_dest),
// TODO: support burst mode
.tx_last({NUM_TX_QUEUES{1'b1}}),
.tx_last(sb_tx_last),
.tx_ready(tx_ready),
.tx_valid(tx_valid),

Expand Down
4 changes: 1 addition & 3 deletions switchboard/verilog/sim/umi_to_queue_sim.sv
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ module umi_to_queue_sim #(
input valid
);

// TODO: support burst mode (through "last")

sb_to_queue_sim #(
.READY_MODE_DEFAULT(READY_MODE_DEFAULT),
.DW(DW+AW+AW+CW),
Expand All @@ -29,7 +27,7 @@ module umi_to_queue_sim #(
.clk(clk),
.data({data, srcaddr, dstaddr, cmd}),
.dest({16'h0000, dstaddr[55:40]}),
.last(1'b1),
.last(cmd[22]),
.ready(ready),
.valid(valid)
);
Expand Down

0 comments on commit a558c0a

Please sign in to comment.