URL
https://opencores.org/ocsvn/yifive/yifive/trunk
Subversion Repositories yifive
[/] [yifive/] [trunk/] [caravel_yifive/] [verilog/] [rtl/] [spi_master/] [src/] [spim_fifo.sv] - Rev 18
Compare with Previous | Blame | View Log
////////////////////////////////////////////////////////////////////////// //////// YiFive cores common library Module //////// //////// This file is part of the YIFive cores project //////// http://www.opencores.org/cores/yifive/ //////// //////// Description //////// Sync Fifo with full and empty //////// //////// To Do: //////// nothing //////// //////// Author(s): //////// - Dinesh Annayya, dinesha@opencores.org //////// //////// Revision : June 7, 2021 //////// ////////////////////////////////////////////////////////////////////////////// //////// Copyright (C) 2000 Authors and OPENCORES.ORG //////// //////// This source file may be used and distributed without //////// restriction provided that this copyright statement is not //////// removed from the file and that any derivative work contains //////// the original copyright notice and the associated disclaimer. //////// //////// This source file is free software; you can redistribute it //////// and/or modify it under the terms of the GNU Lesser General //////// Public License as published by the Free Software Foundation; //////// either version 2.1 of the License, or (at your option) any //////// later version. //////// //////// This source is distributed in the hope that it will be //////// useful, but WITHOUT ANY WARRANTY; without even the implied //////// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //////// PURPOSE. See the GNU Lesser General Public License for more //////// details. //////// //////// You should have received a copy of the GNU Lesser General //////// Public License along with this source; if not, download it //////// from http://www.opencores.org/lgpl.shtml //////// //////////////////////////////////////////////////////////////////////////module spim_fifo #(parameter DATA_WIDTH = 32, // Data Widthparameter ADDR_WIDTH = 1, // Address Widthparameter FIFO_DEPTH = 2 // FIFO DEPTH)(input rstn,input srst,input clk,input wr_en, // Writeinput [DATA_WIDTH-1:0] din,output ready_o,input rd_en, // Readoutput [DATA_WIDTH-1:0] dout,output valid_o);reg [DATA_WIDTH-1:0] ram [FIFO_DEPTH-1:0];reg [ADDR_WIDTH-1:0] wptr; // write ptrreg [ADDR_WIDTH-1:0] rptr; // write ptrreg [ADDR_WIDTH:0] status_cnt; // status counterreg empty;reg full;wire ready_o = ! full;wire valid_o = ! empty;//-----------Code Start---------------------------always @ (negedge rstn or posedge clk)begin : WRITE_POINTERif (rstn==1'b0) beginwptr <= 0;end else if (srst ) beginwptr <= 0;end else if (wr_en ) beginwptr <= wptr + 1;endendalways @ (negedge rstn or posedge clk)begin : READ_POINTERif (rstn==1'b0) beginrptr <= 0;end else if (srst ) beginrptr <= 0;end else if (rd_en) beginrptr <= rptr + 1;endendalways @ (negedge rstn or posedge clk)begin : STATUS_COUNTERif (rstn==1'b0) beginstatus_cnt <= 0;end else if (srst ) beginstatus_cnt <= 0;// Read but no write.end else if (rd_en && (!wr_en) && (status_cnt != 0)) beginstatus_cnt <= status_cnt - 1;// Write but no read.end else if (wr_en && (!rd_en) && (status_cnt != FIFO_DEPTH)) beginstatus_cnt <= status_cnt + 1;endend// underflow is not handledalways @ (negedge rstn or posedge clk)begin : EMPTY_FLAGif (rstn==1'b0) beginempty <= 1;end else if (srst ) beginempty <= 1;// Read but no write.end else if (rd_en && (!wr_en) && (status_cnt == 1)) beginempty <= 1;// Writeend else if (wr_en) beginempty <= 0;end else if (status_cnt == 0) beginempty <= 1;endend// overflow is not handledalways @ (negedge rstn or posedge clk)begin : FULL_FLAGif (rstn==1'b0) beginfull <= 0;end else if (srst ) beginfull <= 0;// Write but no read.end else if (wr_en && (!rd_en) && (status_cnt == (FIFO_DEPTH-1))) beginfull <= 1;// Readend else if (rd_en && (!wr_en) ) beginfull <= 0;end else if (status_cnt == FIFO_DEPTH) beginfull <= 1;endendassign dout = ram[rptr];always @ (posedge clk)beginif (wr_en) ram[wptr] <= din;endendmodule
