Line 40... |
Line 40... |
input i_clk, i_stb;
|
input i_clk, i_stb;
|
input [35:0] i_word;
|
input [35:0] i_word;
|
output reg o_stb;
|
output reg o_stb;
|
output reg [35:0] o_word;
|
output reg [35:0] o_word;
|
|
|
|
|
|
// Clock zero
|
|
// { o_stb, r_stb } = 0
|
wire cmd_write_not_compressed = (i_word[35:33] == 3'h3);
|
wire cmd_write_not_compressed = (i_word[35:33] == 3'h3);
|
|
|
|
|
|
// Clock one: { o_stb, r_stb } = 4'h1 when done
|
reg [7:0] wr_addr;
|
reg [7:0] wr_addr;
|
initial wr_addr = 8'h0;
|
initial wr_addr = 8'h0;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
if ((i_stb)&&(cmd_write_not_compressed))
|
if ((i_stb)&&(cmd_write_not_compressed))
|
wr_addr <= wr_addr + 8'h1;
|
wr_addr <= wr_addr + 8'h1;
|
|
|
reg [31:0] compression_tbl [0:255];
|
reg [31:0] compression_tbl [0:255];
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
compression_tbl[wr_addr] <= { i_word[32:31], i_word[29:0] };
|
compression_tbl[wr_addr] <= { i_word[32:31], i_word[29:0] };
|
|
|
// Clock 0, calculate the table address ... 1 is the smallest address
|
reg [35:0] r_word;
|
wire [7:0] cmd_addr;
|
always @(posedge i_clk)
|
assign cmd_addr = wr_addr - { i_word[32:31], i_word[29:24] };
|
r_word <= i_word;
|
|
|
|
|
// Clock one, read the table value
|
// Clock two, calculate the table address ... 1 is the smallest address
|
reg [31:0] cword;
|
// { o_stb, r_stb } = 4'h2 when done
|
|
reg [7:0] cmd_addr;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
cword <= compression_tbl[cmd_addr];
|
cmd_addr = wr_addr - { r_word[32:31], r_word[29:24] };
|
|
|
// Let's also calculate the address, in case this is a compressed
|
// Let's also calculate the address, in case this is a compressed
|
// address word
|
// address word
|
reg [24:0] r_addr;
|
reg [24:0] r_addr;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
case(i_word[32:30])
|
case(r_word[32:30])
|
3'b000: r_addr <= { 19'h0, i_word[29:24] };
|
3'b000: r_addr <= { 19'h0, r_word[29:24] };
|
3'b010: r_addr <= { 13'h0, i_word[29:18] };
|
3'b010: r_addr <= { 13'h0, r_word[29:18] };
|
3'b100: r_addr <= { 7'h0, i_word[29:12] };
|
3'b100: r_addr <= { 7'h0, r_word[29:12] };
|
3'b110: r_addr <= { 1'h0, i_word[29: 6] };
|
3'b110: r_addr <= { 1'h0, r_word[29: 6] };
|
3'b001: r_addr <= { {(19){ i_word[29]}}, i_word[29:24] };
|
3'b001: r_addr <= { {(19){ r_word[29]}}, r_word[29:24] };
|
3'b011: r_addr <= { {(13){ i_word[29]}}, i_word[29:18] };
|
3'b011: r_addr <= { {(13){ r_word[29]}}, r_word[29:18] };
|
3'b101: r_addr <= { {( 7){ i_word[29]}}, i_word[29:12] };
|
3'b101: r_addr <= { {( 7){ r_word[29]}}, r_word[29:12] };
|
3'b111: r_addr <= { {( 1){ i_word[29]}}, i_word[29: 6] };
|
3'b111: r_addr <= { {( 1){ r_word[29]}}, r_word[29: 6] };
|
endcase
|
endcase
|
wire [31:0] w_addr;
|
wire [31:0] w_addr;
|
assign w_addr = { {(7){r_addr[24]}}, r_addr };
|
assign w_addr = { {(7){r_addr[24]}}, r_addr };
|
|
|
reg [9:0] rd_len;
|
reg [9:0] rd_len;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
if (~i_word[34])
|
if (~r_word[34])
|
rd_len <= 10'h01 + { 6'h00, i_word[33:31] };
|
rd_len <= 10'h01 + { 6'h00, r_word[33:31] };
|
else
|
else
|
rd_len <= 10'h08 + { 1'b0, i_word[33:31], i_word[29:24] };
|
rd_len <= 10'h08 + { 1'b0, r_word[33:31], r_word[29:24] };
|
|
|
|
// Clock three, read the table value
|
// Clock one, copy the input strobe, and input word
|
// { o_stb, r_stb } = 4'h4 when done
|
reg r_stb;
|
// Maintaining ...
|
reg [35:0] r_word;
|
// r_word (clock 1)
|
|
// r_addr, rd_len (clock 2)
|
|
reg [31:0] cword;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
r_stb <= i_stb;
|
cword <= compression_tbl[cmd_addr];
|
|
|
|
|
|
// Pipeline the strobe signal to create an output strobe, 3 clocks later
|
|
reg [2:0] r_stb;
|
|
initial r_stb = 0;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
r_word <= i_word;
|
r_stb <= { r_stb[1:0], i_stb };
|
|
|
// Clock two, now that the table value is valid, let's set our output
|
// Clock four, now that the table value is valid, let's set our output
|
// word.
|
// word.
|
|
// { o_stb, r_stb } = 4'h8 when done
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
o_stb <= r_stb;
|
o_stb <= r_stb[2];
|
|
// Maintaining ...
|
|
// r_word (clock 1)
|
|
// r_addr, rd_len (clock 2)
|
|
// cword (clock 3)
|
|
// Any/all of these can be pipelined for faster operation
|
|
// However, speed is really limited by the speed of the I/O port. At
|
|
// it's fastest, it's 1 bit per clock, 48 clocks per codeword therefore,
|
|
// thus ... things will hold still for much longer than just 5 clocks.
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
if (r_word[35:30] == 6'b101110)
|
if (r_word[35:30] == 6'b101110)
|
o_word <= r_word;
|
o_word <= r_word;
|
else casez(r_word[35:30])
|
else casez(r_word[35:30])
|
6'b001??0: o_word <= { 4'h0, w_addr[31:0] };
|
6'b001??0: o_word <= { 4'h0, w_addr[31:0] };
|