source: XOpenSparcT1/trunk/T1-common/common/dbl_buf.v @ 6

Revision 6, 4.2 KB checked in by pntsvt00, 13 years ago (diff)

versione iniziale opensparc

Line 
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T1 Processor File: dbl_buf.v
4// Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
5// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
6//
7// The above named program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public
9// License version 2 as published by the Free Software Foundation.
10//
11// The above named program is distributed in the hope that it will be
12// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public
17// License along with this work; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19//
20// ========== Copyright Header End ============================================
21////////////////////////////////////////////////////////////////////////
22/*
23//  Module Name:        dbl_buf
24//      Description:    A simple double buffer
25//                      First-in first-out.  Asserts full when both entries
26//                      are occupied.
27*/ 
28////////////////////////////////////////////////////////////////////////
29// Global header file includes
30////////////////////////////////////////////////////////////////////////
31`include        "sys.h" // system level definition file which
32                        // contains the time scale definition
33
34
35////////////////////////////////////////////////////////////////////////
36// Local header file includes / local defines
37////////////////////////////////////////////////////////////////////////
38
39module dbl_buf (/*AUTOARG*/
40   // Outputs
41   dout, vld, full, 
42   // Inputs
43   clk, rst_l, wr, rd, din
44   );
45   // synopsys template
46   
47   parameter BUF_WIDTH = 64;      // width of the buffer
48   
49
50   // Globals
51   input          clk;
52   input          rst_l;
53   
54   // Buffer Input
55   input          wr;
56   input          rd;
57   input [BUF_WIDTH-1:0] din;
58
59   // Buffer Output
60   output [BUF_WIDTH-1:0] dout;
61   output         vld;
62   output         full;
63   
64   // Buffer Output
65   wire           wr_buf0;
66   wire           wr_buf1;
67   wire           buf0_vld;
68   wire           buf1_vld;
69   wire           buf1_older;
70   wire           rd_buf0;
71   wire           rd_buf1;
72   wire           rd_buf;
73   wire           en_vld0;
74   wire           en_vld1;
75   wire [BUF_WIDTH-1:0] buf0_obj;
76   wire [BUF_WIDTH-1:0] buf1_obj;
77   
78   
79////////////////////////////////////////////////////////////////////////
80// Code starts here
81////////////////////////////////////////////////////////////////////////
82   // if both entries are empty, write to entry pointed to by the older pointer
83   // if only one entry is empty, then write to the empty entry (duh!)
84   assign         wr_buf0 = wr &
85                            (buf1_vld | (~buf0_vld & ~buf1_older));
86   assign         wr_buf1 = wr &
87                            (buf0_vld | (~buf1_vld & buf1_older));
88
89   // read from the older entry
90   assign         rd_buf0 = rd & ~buf1_older;
91   assign         rd_buf1 = rd & buf1_older;
92
93   // flip older pointer when an entry is read
94   assign         rd_buf = rd & (buf0_vld | buf1_vld);
95   dffrle_ns buf1_older_ff (.din(~buf1_older),
96                            .rst_l(rst_l),
97                            .en(rd_buf),
98                            .clk(clk),
99                            .q(buf1_older));
100
101   // set valid bit for writes and reset for reads
102   assign         en_vld0 = wr_buf0 | rd_buf0;
103   assign         en_vld1 = wr_buf1 | rd_buf1;
104
105   // the actual buffers
106   dffrle_ns buf0_vld_ff (.din(wr_buf0),
107                          .rst_l(rst_l),
108                          .en(en_vld0),
109                          .clk(clk),
110                          .q(buf0_vld));
111
112   dffrle_ns buf1_vld_ff (.din(wr_buf1),
113                          .rst_l(rst_l),
114                          .en(en_vld1),
115                          .clk(clk),
116                          .q(buf1_vld));
117
118   dffe_ns #(BUF_WIDTH) buf0_obj_ff (.din(din),
119                                     .en(wr_buf0),
120                                     .clk(clk),
121                                     .q(buf0_obj));
122   
123   dffe_ns #(BUF_WIDTH) buf1_obj_ff (.din(din),
124                                     .en(wr_buf1),
125                                     .clk(clk),
126                                     .q(buf1_obj));
127   
128   // mux out the older entry
129   assign         dout = (buf1_older) ? buf1_obj:buf0_obj;
130
131   assign         vld = buf0_vld | buf1_vld;
132   assign         full = buf0_vld & buf1_vld;
133   
134         
135endmodule // dbl_buf
136
137
138
139// Local Variables:
140// verilog-library-directories:(".")
141// End:
142
143
144
145
146
147
148
Note: See TracBrowser for help on using the repository browser.