OpenCores
URL https://opencores.org/ocsvn/cryptosorter/cryptosorter/trunk

Subversion Repositories cryptosorter

[/] [cryptosorter/] [trunk/] [lib/] [bsv/] [BRAM/] [BRAM.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 kfleming
//----------------------------------------------------------------------//
2
// The MIT License 
3
// 
4
// Copyright (c) 2008 Kermin Fleming, kfleming@mit.edu 
5
// 
6
// Permission is hereby granted, free of charge, to any person 
7
// obtaining a copy of this software and associated documentation 
8
// files (the "Software"), to deal in the Software without 
9
// restriction, including without limitation the rights to use,
10
// copy, modify, merge, publish, distribute, sublicense, and/or sell
11
// copies of the Software, and to permit persons to whom the
12
// Software is furnished to do so, subject to the following conditions:
13
// 
14
// The above copyright notice and this permission notice shall be
15
// included in all copies or substantial portions of the Software.
16
// 
17
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
// OTHER DEALINGS IN THE SOFTWARE.
25
//----------------------------------------------------------------------//
26
 
27
 
28
module BRAM(CLK, RST_N,
29
            RD_ADDR, RD_RDY,   RD_EN,
30
            DOUT,    DOUT_RDY, DOUT_EN,
31
            WR_ADDR, WR_VAL,   WR_EN);
32
 
33
   // synopsys template   
34
   parameter                   addr_width = 1;
35
   parameter                   data_width = 1;
36
   parameter                   lo = 0;
37
   parameter                   hi = 1;
38
 
39
   input                       CLK;
40
   input                       RST_N;
41
 
42
   // Read Port
43
   // req
44
   input [addr_width - 1 : 0]  RD_ADDR;
45
   input                       RD_EN;
46
   output                      RD_RDY;
47
   // resp
48
   output [data_width - 1 : 0] DOUT;
49
   output                      DOUT_RDY;
50
   input                       DOUT_EN;
51
 
52
   // Write Port
53
   // req
54
   input [addr_width - 1 : 0]  WR_ADDR;
55
   input [data_width - 1 : 0]  WR_VAL;
56
   input                       WR_EN;
57
 
58
   reg [data_width - 1 : 0]    arr[lo:hi]; /*synthesis syn_ramstyle = "block_ram"*/
59
 
60
   reg                         RD_REQ_MADE;
61
   reg [data_width - 1 : 0]    RAM_OUT;
62
 
63
   reg  [1:0] CTR;
64
 
65
   FIFOL2#(.width(data_width)) q(.RST_N(RST_N),
66
                                             .CLK(CLK),
67
                                             .D_IN(RAM_OUT),
68
                                             .ENQ(RD_REQ_MADE),
69
                                             .DEQ(DOUT_EN),
70
                                             .CLR(1'b0),
71
                                             .D_OUT(DOUT),
72
                                             .FULL_N(),
73
                                             .EMPTY_N(DOUT_RDY));
74
 
75
   assign RD_RDY = (CTR > 0) || DOUT_EN;
76
 
77
   integer x;
78
 
79
   always@(posedge CLK)
80
     begin
81
 
82
 
83
       if (!RST_N)
84
         begin  //Make simulation behavior consistent with Xilinx synthesis
85
           // synopsys translate_off
86
           for (x = lo; x < hi; x = x + 1)
87
           begin
88
             arr[x] <= 0;
89
           end
90
           // synopsys translate_on
91
           CTR <= 2;
92
         end
93
       else
94
         begin
95
 
96
           RD_REQ_MADE <= RD_EN;
97
 
98
           if (WR_EN)
99
             arr[WR_ADDR] <= WR_VAL;
100
 
101
           CTR <= (RD_EN) ?
102
                    (DOUT_EN) ? CTR : CTR - 1 :
103
                    (DOUT_EN) ? CTR + 1 : CTR;
104
 
105
           RAM_OUT <= arr[RD_ADDR];
106
 
107
         end
108
     end // always@ (posedge CLK)
109
 
110
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.