Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for true PHY toggling via software #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/hyperbus_phy.sv
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module hyperbus_phy import hyperbus_pkg::*; #(
input logic test_mode_i,
// Config registers
input hyper_cfg_t cfg_i,
// PHY control status
output logic busy_o,
// Transactions
input logic trans_valid_i,
output logic trans_ready_o,
Expand Down Expand Up @@ -230,6 +232,8 @@ module hyperbus_phy import hyperbus_pkg::*; #(
assign ctl_timer_one = (timer_q == 1);
assign ctl_timer_zero = (timer_q == 0);

assign busy_o = (state_q != Idle);

// FSM logic
always_comb begin : proc_comb_phy_fsm
// Default outputs
Expand Down
58 changes: 42 additions & 16 deletions src/hyperbus_phy_if.sv
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ module hyperbus_phy_if import hyperbus_pkg::*; #(
logic [NumPhys-1:0] fifo_axi_valid;
logic fifo_axi_ready;

logic [NumPhys-1:0][1:0] fifo_axi_usage;

logic tx_both_ready, ts_both_ready;
logic rx_both_valid, b_both_valid;

logic [NumPhys-1:0] phy_tx_ready;
logic phy_tx_valid;

logic [NumPhys-1:0] phy_trans_ready;
logic phy_trans_valid;
logic [NumPhys-1:0] phy_trans_valid;

logic [NumPhys-1:0] phy_b_valid;
logic [NumPhys-1:0] phy_b_error;
Expand All @@ -77,24 +79,44 @@ module hyperbus_phy_if import hyperbus_pkg::*; #(

if (NumPhys==2) begin : phy_wrap

assign rx_both_valid = & fifo_axi_valid;
assign rx_valid_o = rx_both_valid;
logic [NumPhys-1:0] phy_enable;
logic [NumPhys-1:0] phy_busy;
logic [NumPhys-1:0] phy_active_q, phy_active_d;
logic change_phy_active;

assign change_phy_active = phy_active_q != phy_enable;
assign phy_enable = cfg_i.phys_in_use ? '1 : (1 << cfg_i.which_phy);
assign phy_active_d = change_phy_active && fifo_axi_usage == '0 ?
phy_enable | phy_busy : phy_active_q;

always_ff @(posedge clk_i or negedge rst_ni ) begin
if (!rst_ni) begin
phy_active_q <= '1;
end else begin
phy_active_q <= phy_active_d;
end
end

assign rx_both_valid = & (fifo_axi_valid | ~phy_active_q);
assign rx_valid_o = rx_both_valid;
assign fifo_axi_ready = rx_ready_i && rx_both_valid;

assign rx_o.error = fifo_axi_rx[0].error || fifo_axi_rx[1].error;
assign rx_o.last = fifo_axi_rx[0].last && fifo_axi_rx[1].last;
assign tx_both_ready = & phy_tx_ready;
assign tx_ready_o = tx_both_ready;
assign phy_tx_valid = tx_both_ready && tx_valid_i;
assign rx_o.error = | ({fifo_axi_rx[1].error, fifo_axi_rx[0].error} & phy_active_q);
assign rx_o.last = & ({fifo_axi_rx[1].last, fifo_axi_rx[0].last} | ~phy_active_q);
assign tx_both_ready = & (phy_tx_ready | ~phy_active_q);
assign tx_ready_o = tx_both_ready;
assign phy_tx_valid = tx_both_ready && tx_valid_i;

assign b_both_valid = & phy_b_valid;
assign b_valid_o = b_both_valid;
assign phy_b_ready = b_ready_i && b_both_valid;
assign b_error_o = | phy_b_error;
assign b_both_valid = & (phy_b_valid | ~phy_active_q);
assign b_valid_o = b_both_valid;
assign phy_b_ready = b_ready_i && b_both_valid;
assign b_error_o = | (phy_b_error & phy_active_q);

assign ts_both_ready = & phy_trans_ready;
assign ts_both_ready = change_phy_active ? '0 :
& (phy_trans_ready | ~phy_active_q);
assign trans_ready_o = ts_both_ready;
assign phy_trans_valid = ts_both_ready && trans_valid_i;
assign phy_trans_valid = change_phy_active ? '0 :
phy_trans_ready & {NumPhys{trans_valid_i}} & phy_active_q;

for ( i=0; i<NumPhys;i++) begin : phy_unroll
assign rx_o.data[i*16 +:16] = fifo_axi_rx[i].data;
Expand All @@ -108,7 +130,7 @@ module hyperbus_phy_if import hyperbus_pkg::*; #(
.rst_ni ( rst_ni ),
.flush_i ( 1'b0 ),
.testmode_i ( 1'b0 ),
.usage_o ( ),
.usage_o ( fifo_axi_usage[i] ),
.data_i ( phy_fifo_rx[i] ),
.valid_i ( phy_fifo_valid[i] ),
.ready_o ( phy_fifo_ready[i] ),
Expand All @@ -132,6 +154,8 @@ module hyperbus_phy_if import hyperbus_pkg::*; #(

.cfg_i ( cfg_i ),

.busy_o ( phy_busy[i] ),

.rx_data_o ( phy_fifo_rx[i].data ),
.rx_last_o ( phy_fifo_rx[i].last ),
.rx_error_o ( phy_fifo_rx[i].error ),
Expand All @@ -150,7 +174,7 @@ module hyperbus_phy_if import hyperbus_pkg::*; #(

.trans_i ( trans_i ),
.trans_cs_i ( trans_cs_i ),
.trans_valid_i ( phy_trans_valid ),
.trans_valid_i ( phy_trans_valid[i] ),
.trans_ready_o ( phy_trans_ready[i] ),

.hyper_cs_no ( hyper_cs_no[i] ),
Expand Down Expand Up @@ -182,6 +206,8 @@ module hyperbus_phy_if import hyperbus_pkg::*; #(

.cfg_i ( cfg_i ),

.busy_o ( ),

.rx_data_o ( rx_o.data ),
.rx_last_o ( rx_o.last ),
.rx_error_o ( rx_o.error ),
Expand Down
1 change: 1 addition & 0 deletions test/axi_hyper_tb.sv
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ module axi_hyper_tb
$display("===========================");

reg_master.send_write(32'h20,1'b0,'1,s_reg_error);
reg_master.send_write(32'h24,1'b0,'1,s_reg_error);
if (s_reg_error != 1'b0) $error("unexpected error");

axi_master.reset();
Expand Down