////////////////////////////////////////////////////////////////////////////////// //END USER LICENCE AGREEMENT // // // //Copyright (c) 2012, ARM All rights reserved. // // // //THIS END USER LICENCE AGREEMENT (“LICENCE”) IS A LEGAL AGREEMENT BETWEEN // //YOU AND ARM LIMITED ("ARM") FOR THE USE OF THE SOFTWARE EXAMPLE ACCOMPANYING // //THIS LICENCE. ARM IS ONLY WILLING TO LICENSE THE SOFTWARE EXAMPLE TO YOU ON // //CONDITION THAT YOU ACCEPT ALL OF THE TERMS IN THIS LICENCE. BY INSTALLING OR // //OTHERWISE USING OR COPYING THE SOFTWARE EXAMPLE YOU INDICATE THAT YOU AGREE // //TO BE BOUND BY ALL OF THE TERMS OF THIS LICENCE. IF YOU DO NOT AGREE TO THE // //TERMS OF THIS LICENCE, ARM IS UNWILLING TO LICENSE THE SOFTWARE EXAMPLE TO // //YOU AND YOU MAY NOT INSTALL, USE OR COPY THE SOFTWARE EXAMPLE. // // // //ARM hereby grants to you, subject to the terms and conditions of this Licence,// //a non-exclusive, worldwide, non-transferable, copyright licence only to // //redistribute and use in source and binary forms, with or without modification,// //for academic purposes provided the following conditions are met: // //a) Redistributions of source code must retain the above copyright notice, this// //list of conditions and the following disclaimer. // //b) Redistributions in binary 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 SOFTWARE EXAMPLE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ARM // //EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING // //WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // //PURPOSE, WITH RESPECT TO THIS SOFTWARE EXAMPLE. IN NO EVENT SHALL ARM BE LIABLE/ //FOR ANY DIRECT, INDIRECT, INCIDENTAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES OF ANY/ //KIND WHATSOEVER WITH RESPECT TO THE SOFTWARE EXAMPLE. ARM SHALL NOT BE LIABLE // //FOR ANY CLAIMS, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // //TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE // //EXAMPLE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EXAMPLE. FOR THE AVOIDANCE/ // OF DOUBT, NO PATENT LICENSES ARE BEING LICENSED UNDER THIS LICENSE AGREEMENT.// ////////////////////////////////////////////////////////////////////////////////// module FIFO #(parameter DWIDTH=8, AWIDTH=1) ( input wire clk, input wire resetn, input wire rd, input wire wr, input wire [DWIDTH-1:0] w_data, output wire empty, output wire full, output wire [DWIDTH-1:0] r_data ); //Internal Signal declarations reg [DWIDTH-1:0] array_reg [2**AWIDTH-1:0]; reg [AWIDTH-1:0] w_ptr_reg; reg [AWIDTH-1:0] w_ptr_next; reg [AWIDTH-1:0] w_ptr_succ; reg [AWIDTH-1:0] r_ptr_reg; reg [AWIDTH-1:0] r_ptr_next; reg [AWIDTH-1:0] r_ptr_succ; reg full_reg; reg empty_reg; reg full_next; reg empty_next; wire w_en; always @ (posedge clk) if(w_en) begin array_reg[w_ptr_reg] <= w_data; end assign r_data = array_reg[r_ptr_reg]; assign w_en = wr & ~full_reg; //State Machine always @ (posedge clk, negedge resetn) begin if(!resetn) begin w_ptr_reg <= 0; r_ptr_reg <= 0; full_reg <= 1'b0; empty_reg <= 1'b1; end else begin w_ptr_reg <= w_ptr_next; r_ptr_reg <= r_ptr_next; full_reg <= full_next; empty_reg <= empty_next; end end //Next State Logic always @* begin w_ptr_succ = w_ptr_reg + 1; r_ptr_succ = r_ptr_reg + 1; w_ptr_next = w_ptr_reg; r_ptr_next = r_ptr_reg; full_next = full_reg; empty_next = empty_reg; case({w_en,rd}) //2'b00: nop 2'b01: if(~empty_reg) begin r_ptr_next = r_ptr_succ; full_next = 1'b0; if (r_ptr_succ == w_ptr_reg) empty_next = 1'b1; end 2'b10: if(~full_reg) begin w_ptr_next = w_ptr_succ; empty_next = 1'b0; if (w_ptr_succ == r_ptr_reg) full_next = 1'b1; end 2'b11: begin w_ptr_next = w_ptr_succ; r_ptr_next = r_ptr_succ; end endcase end //Set Full and Empty assign full = full_reg; assign empty = empty_reg; endmodule