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

Adapted osd_event_packetization for module specific TYPE_SUB #48

Open
wants to merge 2 commits into
base: osd-next
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
22 changes: 17 additions & 5 deletions blocks/eventpacket/common/osd_event_packetization.sv
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ module osd_event_packetization #(
input [15:0] dest,
// Generate an overflow packet
input overflow,


// Module specific sub-type (TYPE_SUB)
input [2:0] mod_type_sub,

// a new event is available
input event_available,
// the packet has been sent
Expand Down Expand Up @@ -105,8 +108,9 @@ module osd_event_packetization #(
assign data_req_idx = word_cnt;
assign data_req_valid = (state == PAYLOAD || state == OVERFLOW);

localparam TYPE_SUB_LAST = 4'h0;
localparam TYPE_SUB_CONTINUE = 4'h1;
localparam TYPE_SUB_LAST = 1'b0;
localparam TYPE_SUB_CONTINUE = 1'b1;

localparam TYPE_SUB_OVERFLOW = 4'h5;

always_ff @(posedge clk) begin
Expand Down Expand Up @@ -157,15 +161,23 @@ module osd_event_packetization #(
debug_out.data[15:14] = 2'b10; // TYPE == EVENT

// TYPE_SUB
if (overflow) begin
debug_out.data[13:11] = mod_type_sub[2:0];

if (pkg_cnt == num_pkgs - 1) begin
debug_out.data[10] = TYPE_SUB_LAST;
end else begin
debug_out.data[10] = TYPE_SUB_CONTINUE;
end

/*if (overflow) begin
debug_out.data[13:10] = TYPE_SUB_OVERFLOW;
end else begin
if (pkg_cnt == num_pkgs - 1) begin
debug_out.data[13:10] = TYPE_SUB_LAST;
end else begin
debug_out.data[13:10] = TYPE_SUB_CONTINUE;
end
end
end*/

debug_out.data[9:0] = 10'h0; // reserved
debug_out.valid = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ module osd_event_packetization_fixedwidth #(
input [15:0] dest,
// Generate an overflow packet
input overflow,

// Module specific sub-type (TYPE_SUB)
input [2:0] mod_type_sub,

// a new event is available
input event_available,
Expand Down Expand Up @@ -100,6 +103,7 @@ module osd_event_packetization_fixedwidth #(
.id(id),
.dest(dest),
.overflow(overflow),
.mod_type_sub(mod_type_sub),
.event_available(event_available),
.event_consumed(event_consumed),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def test_fixedwidth(dut):
data_int = int.from_bytes(data_bytes, byteorder='little', signed=False)
dut.data.value = BinaryValue(data_int)

dut.mod_type_sub <= 0
dut.overflow <= 0
dut.event_available <= 1

Expand Down
116 changes: 116 additions & 0 deletions modules/dem_uart/common/fifo_singleclock_fwft.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/* Copyright (c) 2017 by the author(s)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* =============================================================================
*
* Synchronous First-Word Fall-Through (FWFT) FIFO
*
* This FIFO implementation wraps the FIFO with standard read characteristics
* to have first-word fall-through read characteristics.
*
* Author(s):
* Philipp Wagner <[email protected]>
*/

module fifo_singleclock_fwft #(
parameter WIDTH = 8,
parameter DEPTH = 32,
parameter PROG_FULL = (DEPTH / 2)
)(
input clk,
input rst,

input [(WIDTH-1):0] din,
input wr_en,
output full,
output prog_full,

output reg [(WIDTH-1):0] dout,
input rd_en,
output empty,

output [$clog2(DEPTH)-1:0] count
);

reg fifo_valid, middle_valid, dout_valid;
reg [(WIDTH-1):0] middle_dout;

wire [(WIDTH-1):0] fifo_dout;
wire fifo_empty, fifo_rd_en;
wire will_update_middle, will_update_dout;

// synchronous FIFO with standard (non-FWFT) read characteristics
fifo_singleclock_standard
#(.WIDTH(WIDTH),
.DEPTH(DEPTH),
.PROG_FULL(PROG_FULL))
u_fifo (
.rst(rst),
.clk(clk),
.rd_en(fifo_rd_en),
.dout(fifo_dout),
.empty(fifo_empty),
.wr_en(wr_en),
.din(din),
.full(full),
.prog_full(prog_full),
.count(count)
);

// create FWFT FIFO out of non-FWFT FIFO
// public domain code from Eli Billauer
// see http://www.billauer.co.il/reg_fifo.html
assign will_update_middle = fifo_valid && (middle_valid == will_update_dout);
assign will_update_dout = (middle_valid || fifo_valid) && (rd_en || !dout_valid);
assign fifo_rd_en = (!fifo_empty) && !(middle_valid && dout_valid && fifo_valid);
assign empty = !dout_valid;

always_ff @(posedge clk) begin
if (rst) begin
fifo_valid <= 0;
middle_valid <= 0;
dout_valid <= 0;
dout <= 0;
middle_dout <= 0;
end else begin
if (will_update_middle)
middle_dout <= fifo_dout;

if (will_update_dout)
dout <= middle_valid ? middle_dout : fifo_dout;

if (fifo_rd_en)
fifo_valid <= 1;
else if (will_update_middle || will_update_dout)
fifo_valid <= 0;

if (will_update_middle)
middle_valid <= 1;
else if (will_update_dout)
middle_valid <= 0;

if (will_update_dout)
dout_valid <= 1;
else if (rd_en)
dout_valid <= 0;
end
end

endmodule
111 changes: 111 additions & 0 deletions modules/dem_uart/common/fifo_singleclock_standard.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/* Copyright (c) 2017 by the author(s)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* =============================================================================
*
* Synchronous Standard FIFO (one clock)
*
* The memory block in this FIFO is following the "RAM HDL Coding Guidelines"
* of Xilinx (UG901) to enable placing the FIFO memory into block ram during
* synthesis.
*
* Author(s):
* Philipp Wagner <[email protected]>
*/

module fifo_singleclock_standard #(
parameter WIDTH = 8,
parameter DEPTH = 32,
parameter PROG_FULL = DEPTH / 2
)(
input clk,
input rst,

input [(WIDTH-1):0] din,
input wr_en,
output full,
output prog_full,

output reg [(WIDTH-1):0] dout,
input rd_en,
output empty,

output [$clog2(DEPTH) - 1:0] count
);
localparam AW = $clog2(DEPTH);

// ensure that parameters are set to allowed values
initial begin
if ((1 << $clog2(DEPTH)) != DEPTH) begin
$fatal("fifo_singleclock_standard: the DEPTH must be a power of two.");
end
end

reg [AW-1:0] wr_addr;
reg [AW-1:0] rd_addr;
wire fifo_read;
wire fifo_write;
reg [AW-1:0] rd_count;

// generate control signals
assign empty = (rd_count[AW-1:0] == 0);
assign prog_full = (rd_count[AW-1:0] >= PROG_FULL);
assign full = (rd_count[AW-1:0] == (DEPTH-1));
assign fifo_read = rd_en & ~empty;
assign fifo_write = wr_en & ~full;
assign count = rd_count;

// address logic
always_ff @(posedge clk) begin
if (rst) begin
wr_addr[AW-1:0] <= 'd0;
rd_addr[AW-1:0] <= 'b0;
rd_count[AW-1:0] <= 'b0;
end else begin
if (fifo_write & fifo_read) begin
wr_addr[AW-1:0] <= wr_addr[AW-1:0] + 'd1;
rd_addr[AW-1:0] <= rd_addr[AW-1:0] + 'd1;
end else if (fifo_write) begin
wr_addr[AW-1:0] <= wr_addr[AW-1:0] + 'd1;
rd_count[AW-1:0]<= rd_count[AW-1:0] + 'd1;
end else if (fifo_read) begin
rd_addr[AW-1:0] <= rd_addr[AW-1:0] + 'd1;
rd_count[AW-1:0]<= rd_count[AW-1:0] - 'd1;
end
end
end

// generic dual-port, single clock memory
reg [WIDTH-1:0] ram [DEPTH-1:0];

// write
always_ff @(posedge clk) begin
if (fifo_write) begin
ram[wr_addr] <= din;
end
end

// read
always_ff @(posedge clk) begin
if (fifo_read) begin
dout <= ram[rd_addr];
end
end
endmodule
Loading