kopia lustrzana https://github.com/cariboulabs/cariboulite
added fifos - work in progress
rodzic
eb699bc363
commit
d61828c894
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* Copyright (c) 2012, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Based on vga_fifo_dc.v in Richard Herveille's VGA/LCD core
|
||||
* Copyright (C) 2001 Richard Herveille <richard@asics.ws>
|
||||
*
|
||||
* Redistribution and use in source and non-source forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in non-source form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS WORK IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* WORK, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
module dual_clock_fifo #(
|
||||
parameter ADDR_WIDTH = 8,
|
||||
parameter DATA_WIDTH = 16
|
||||
)
|
||||
(
|
||||
input wire wr_rst_i,
|
||||
input wire wr_clk_i,
|
||||
input wire wr_en_i,
|
||||
input wire [DATA_WIDTH-1:0] wr_data_i,
|
||||
|
||||
input wire rd_rst_i,
|
||||
input wire rd_clk_i,
|
||||
input wire rd_en_i,
|
||||
output reg [DATA_WIDTH-1:0] rd_data_o,
|
||||
|
||||
output reg full_o,
|
||||
output reg empty_o
|
||||
);
|
||||
|
||||
reg [ADDR_WIDTH-1:0] wr_addr;
|
||||
reg [ADDR_WIDTH-1:0] wr_addr_gray;
|
||||
reg [ADDR_WIDTH-1:0] wr_addr_gray_rd;
|
||||
reg [ADDR_WIDTH-1:0] wr_addr_gray_rd_r;
|
||||
reg [ADDR_WIDTH-1:0] rd_addr;
|
||||
reg [ADDR_WIDTH-1:0] rd_addr_gray;
|
||||
reg [ADDR_WIDTH-1:0] rd_addr_gray_wr;
|
||||
reg [ADDR_WIDTH-1:0] rd_addr_gray_wr_r;
|
||||
|
||||
function [ADDR_WIDTH-1:0] gray_conv;
|
||||
input [ADDR_WIDTH-1:0] in;
|
||||
begin
|
||||
gray_conv = {in[ADDR_WIDTH-1],
|
||||
in[ADDR_WIDTH-2:0] ^ in[ADDR_WIDTH-1:1]};
|
||||
end
|
||||
endfunction
|
||||
|
||||
always @(posedge wr_clk_i) begin
|
||||
if (wr_rst_i) begin
|
||||
wr_addr <= 0;
|
||||
wr_addr_gray <= 0;
|
||||
end else if (wr_en_i) begin
|
||||
wr_addr <= wr_addr + 1'b1;
|
||||
wr_addr_gray <= gray_conv(wr_addr + 1'b1);
|
||||
end
|
||||
end
|
||||
|
||||
// synchronize read address to write clock domain
|
||||
always @(posedge wr_clk_i) begin
|
||||
rd_addr_gray_wr <= rd_addr_gray;
|
||||
rd_addr_gray_wr_r <= rd_addr_gray_wr;
|
||||
end
|
||||
|
||||
always @(posedge wr_clk_i)
|
||||
if (wr_rst_i)
|
||||
full_o <= 0;
|
||||
else if (wr_en_i)
|
||||
full_o <= gray_conv(wr_addr + 2) == rd_addr_gray_wr_r;
|
||||
else
|
||||
full_o <= full_o & (gray_conv(wr_addr + 1'b1) == rd_addr_gray_wr_r);
|
||||
|
||||
always @(posedge rd_clk_i) begin
|
||||
if (rd_rst_i) begin
|
||||
rd_addr <= 0;
|
||||
rd_addr_gray <= 0;
|
||||
end else if (rd_en_i) begin
|
||||
rd_addr <= rd_addr + 1'b1;
|
||||
rd_addr_gray <= gray_conv(rd_addr + 1'b1);
|
||||
end
|
||||
end
|
||||
|
||||
// synchronize write address to read clock domain
|
||||
always @(posedge rd_clk_i) begin
|
||||
wr_addr_gray_rd <= wr_addr_gray;
|
||||
wr_addr_gray_rd_r <= wr_addr_gray_rd;
|
||||
end
|
||||
|
||||
always @(posedge rd_clk_i)
|
||||
if (rd_rst_i)
|
||||
empty_o <= 1'b1;
|
||||
else if (rd_en_i)
|
||||
empty_o <= gray_conv(rd_addr + 1) == wr_addr_gray_rd_r;
|
||||
else
|
||||
empty_o <= empty_o & (gray_conv(rd_addr) == wr_addr_gray_rd_r);
|
||||
|
||||
// generate dual clocked memory
|
||||
SB_RAM256x16 ram256x16_i_inst (
|
||||
.RDATA(RDATA_c[15:0]),
|
||||
.RADDR(RADDR_c[7:0]),
|
||||
.RCLK(RCLK_c),
|
||||
.RCLKE(RCLKE_c),
|
||||
.RE(RE_c),
|
||||
.WADDR(WADDR_c[7:0]),
|
||||
.WCLK(WCLK_c),
|
||||
.WCLKE(WCLKE_c),
|
||||
.WDATA(WDATA_c[15:0]),
|
||||
.WE(WE_c),
|
||||
.MASK(MASK_c[15:0]) );
|
||||
|
||||
SB_RAM256x16 ram256x16_q_inst (
|
||||
.RDATA(RDATA_c[15:0]),
|
||||
.RADDR(RADDR_c[7:0]),
|
||||
.RCLK(RCLK_c),
|
||||
.RCLKE(RCLKE_c),
|
||||
.RE(RE_c),
|
||||
.WADDR(WADDR_c[7:0]),
|
||||
.WCLK(WCLK_c),
|
||||
.WCLKE(WCLKE_c),
|
||||
.WDATA(WDATA_c[15:0]),
|
||||
.WE(WE_c),
|
||||
.MASK(MASK_c[15:0]) );
|
||||
|
||||
|
||||
reg [DATA_WIDTH-1:0] mem[(1<<ADDR_WIDTH)-1:0];
|
||||
|
||||
always @(posedge rd_clk_i)
|
||||
if (rd_en_i)
|
||||
rd_data_o <= mem[rd_addr];
|
||||
|
||||
always @(posedge wr_clk_i)
|
||||
if (wr_en_i)
|
||||
mem[wr_addr] <= wr_data_i;
|
||||
endmodule
|
|
@ -38,6 +38,12 @@ module lvds_rx
|
|||
// Main Process
|
||||
always @(negedge i_ddr_clk)
|
||||
begin
|
||||
if (i_reset) begin
|
||||
r_state_if = state_idle;
|
||||
r_push = 1'b0;
|
||||
r_phase_count = 3'b111;
|
||||
r_data = 0;
|
||||
end else begin
|
||||
case (r_state_if)
|
||||
state_idle: begin
|
||||
if (i_ddr_data == 2'b10 ) begin
|
||||
|
@ -72,4 +78,7 @@ module lvds_rx
|
|||
endcase
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
endmodule // smi_ctrl
|
6951
firmware/top.asc
6951
firmware/top.asc
Plik diff jest za duży
Load Diff
BIN
firmware/top.bin
BIN
firmware/top.bin
Plik binarny nie jest wyświetlany.
6838
firmware/top.json
6838
firmware/top.json
Plik diff jest za duży
Load Diff
|
@ -3,6 +3,7 @@
|
|||
`include "io_ctrl.v"
|
||||
`include "smi_ctrl.v"
|
||||
`include "lvds_rx.v"
|
||||
`include "dual_clock_fifo.v"
|
||||
|
||||
module top(
|
||||
input i_glob_clock,
|
||||
|
@ -71,7 +72,7 @@ module top(
|
|||
wire [3:0] w_cs;
|
||||
wire w_fetch;
|
||||
wire w_load;
|
||||
reg r_reset_b;
|
||||
reg r_reset;
|
||||
|
||||
wire [7:0] w_tx_data_sys;
|
||||
wire [7:0] w_tx_data_io;
|
||||
|
@ -82,7 +83,7 @@ module top(
|
|||
//=========================================================================
|
||||
initial begin
|
||||
r_counter = 2'b00;
|
||||
r_reset_b = 1'b1;
|
||||
r_reset = 1'b0;
|
||||
end
|
||||
|
||||
//=========================================================================
|
||||
|
@ -90,7 +91,7 @@ module top(
|
|||
//=========================================================================
|
||||
spi_if spi_if_ins
|
||||
(
|
||||
.i_rst_b (r_reset_b),
|
||||
.i_rst_b (r_reset),
|
||||
.i_sys_clk (w_clock_spi),
|
||||
.o_ioc (w_ioc),
|
||||
.o_data_in (w_rx_data),
|
||||
|
@ -237,14 +238,22 @@ module top(
|
|||
wire w_lvds_rx_09_d1; // 180 degree
|
||||
wire w_lvds_rx_24_d0; // 0 degree
|
||||
wire w_lvds_rx_24_d1; // 180 degree
|
||||
|
||||
wire w_rx_09_fifo_full;
|
||||
wire w_rx_09_fifo_empty;
|
||||
wire w_rx_09_fifo_write_clk;
|
||||
wire w_rx_09_fifo_push;
|
||||
wire [31:0] w_rx_09_fifo_data;
|
||||
wire w_rx_09_fifo_pull;
|
||||
wire [31:0] w_rx_09_fifo_pulled_data;
|
||||
|
||||
wire w_rx_24_fifo_full;
|
||||
wire w_rx_24_fifo_empty;
|
||||
wire w_rx_24_fifo_write_clk;
|
||||
wire w_rx_24_fifo_push;
|
||||
wire [31:0] w_rx_24_fifo_data;
|
||||
wire w_rx_24_fifo_pull;
|
||||
wire [31:0] w_rx_24_fifo_pulled_data;
|
||||
|
||||
lvds_rx lvds_rx_09_inst
|
||||
(
|
||||
|
@ -257,6 +266,19 @@ module top(
|
|||
.o_fifo_data (w_rx_09_fifo_data)
|
||||
);
|
||||
|
||||
dual_clock_fifo rx_09_fifo(
|
||||
.wr_rst_i (r_reset),
|
||||
.wr_clk_i (w_rx_09_fifo_write_clk),
|
||||
.wr_en_i (w_rx_09_fifo_push),
|
||||
.wr_data_i (w_rx_09_fifo_data),
|
||||
.rd_rst_i (r_reset),
|
||||
.rd_clk_i (w_clock_sys),
|
||||
.rd_en_i (w_rx_09_fifo_pull),
|
||||
.rd_data_o (w_rx_09_fifo_pulled_data),
|
||||
.full_o (w_rx_09_fifo_full),
|
||||
.empty_o (w_rx_09_fifo_empty)
|
||||
);
|
||||
|
||||
lvds_rx lvds_rx_24_inst
|
||||
(
|
||||
.i_reset (r_reset),
|
||||
|
@ -268,10 +290,25 @@ module top(
|
|||
.o_fifo_data (w_rx_24_fifo_data)
|
||||
);
|
||||
|
||||
dual_clock_fifo rx_24_fifo(
|
||||
.wr_rst_i (r_reset),
|
||||
.wr_clk_i (w_rx_24_fifo_write_clk),
|
||||
.wr_en_i (w_rx_24_fifo_push),
|
||||
.wr_data_i (w_rx_24_fifo_data),
|
||||
.rd_rst_i (r_reset),
|
||||
.rd_clk_i (w_clock_sys),
|
||||
.rd_en_i (w_rx_24_fifo_pull),
|
||||
.rd_data_o (w_rx_24_fifo_pulled_data),
|
||||
.full_o (w_rx_24_fifo_full),
|
||||
.empty_o (w_rx_24_fifo_empty)
|
||||
);
|
||||
|
||||
// Testing - output the clock signal (positive and negative) to the PMOD
|
||||
assign io_pmod[0] = lvds_clock_buf;
|
||||
assign io_pmod[1] = w_rx_09_fifo_push;
|
||||
assign io_pmod[2] = w_rx_24_fifo_push;
|
||||
assign io_pmod[7:3] = w_rx_09_fifo_data[29:26];
|
||||
assign io_pmod[3] = w_rx_09_fifo_empty;
|
||||
assign io_pmod[4] = w_rx_24_fifo_empty;
|
||||
assign io_pmod[7:5] = w_rx_09_fifo_data[29:27];
|
||||
|
||||
endmodule // top
|
||||
|
|
Ładowanie…
Reference in New Issue