OpenCores
URL https://opencores.org/ocsvn/bluespec-h264/bluespec-h264/trunk

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [src_fpga/] [build/] [SRAM.v] - Blame information for rev 100

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 jamey.hick
/*
2
  Notes -> We target a ZTB SRAM. It data is presented 2 cycles after the address data is presented.
3
 
4
cyc action
5
 1  assign addr.
6
 2  latch addr.
7
 3  assign data.
8
 4  latch data.
9
 
10
*/
11
 
12
//`include "FIFOL2.v"
13
 
14
`define NOP    0
15
`define RD_REQ 1
16
`define WR_REQ 2
17
 
18
module SRAM(CLK, RST_N,
19
            // Bluespec method wires
20
            RD_ADDR, RD_RDY,   RD_EN,
21
            DOUT,    DOUT_RDY, DOUT_EN,
22
            WR_ADDR, WR_VAL,   WR_EN,
23
            // Physical SRAM wires
24
            DATA_BUS_O, DATA_BUS_I, DATA_BUS_T,
25
            ADDR_O, WE_BYTES_N_O, WE_N_O, CE_N_O,
26
            OE_N_O, CEN_N_O, ADV_LD_N_O, DUMMY_EN
27
            );
28
 
29
   // synopsys template   
30
   parameter                   addr_width = 1;
31
   parameter                   data_width = 1;
32
   parameter                   lo = 0;
33
   parameter                   hi = 1;
34
 
35
   input                       CLK;
36
   input                       RST_N;
37
 
38
   // Read Port
39
   // req
40
   input [addr_width - 1 : 0]  RD_ADDR;
41
   input                       RD_EN;
42
   output                      RD_RDY;
43
   // resp
44
   output [data_width - 1 : 0] DOUT;
45
   output                      DOUT_RDY;
46
   input                       DOUT_EN;
47
 
48
   // Write Port
49
   // req
50
   input [addr_width - 1 : 0]  WR_ADDR;
51
   input [data_width - 1 : 0]  WR_VAL;
52
   input                       WR_EN;
53
 
54
   //Physical SRAM Wires
55
   output [31 : 0]               DATA_BUS_O;
56
   input  [31 : 0]               DATA_BUS_I;
57
   output                        DATA_BUS_T;
58 78 jamey.hick
   output [18 : 0]               ADDR_O;
59 7 jamey.hick
   output [3 : 0]                WE_BYTES_N_O;
60
   output                        WE_N_O;
61
   output                        CE_N_O;
62
   output                        OE_N_O;
63
   output                        CEN_N_O;
64
   output                        ADV_LD_N_O;
65
   input                         DUMMY_EN; // this signal is a dummy enable to 
66
                                           // make bluespec happy.
67
 
68
 
69
   wire                          RD_REQ_MADE;
70
 
71 78 jamey.hick
   //reg  [1:0] CTR;
72
   reg  [2:0] CTR;
73
 
74
 
75 7 jamey.hick
   // Regs to pipeline incoming commands 
76
   reg [1:0] op_command_pipelined;
77
   reg [1:0] op_command_active;
78
 
79
   reg [data_width - 1:0] write_data_pipelined;
80
   reg [data_width - 1:0] write_data_active;
81
 
82 78 jamey.hick
  SizedFIFO #(.p1width(32),
83
              .p2depth(4),
84
              .p3cntr_width(2),
85
              .guarded(1)) q(.RST_N(RST_N),
86
                                       .CLK(CLK),
87
                                       .D_IN(DATA_BUS_I[data_width-1:0]),
88
                                       .ENQ(RD_REQ_MADE),
89
                                       .DEQ(DOUT_EN),
90
                                       .CLR(1'b0),
91
                                       .D_OUT(DOUT),
92
                                       .FULL_N(),
93
                                       .EMPTY_N(DOUT_RDY));
94
 
95
 
96
/*   FIFOL2#(.width(data_width)) q(.RST_N(RST_N),
97 7 jamey.hick
                                             .CLK(CLK),
98
                                             .D_IN(DATA_BUS_I[data_width-1:0]),
99
                                             .ENQ(RD_REQ_MADE),
100
                                             .DEQ(DOUT_EN),
101
                                             .CLR(1'b0),
102
                                             .D_OUT(DOUT),
103
                                             .FULL_N(),
104 78 jamey.hick
                                             .EMPTY_N(DOUT_RDY));*/
105 7 jamey.hick
 
106
 
107
 
108
 
109
   assign RD_RDY = (CTR > 0) || DOUT_EN;
110
 
111
   // Some lines that enable the SRAM.
112
   assign ADV_LD_N_O = 0;
113
   assign CE_N_O = 0;
114
   assign OE_N_O = 0;
115
   assign CEN_N_O = 0;
116
 
117
   // Tie the WE_N lines to the WR_EN.
118
   assign WE_N_O = ~WR_EN;
119
   assign WE_BYTES_N_O = {~WR_EN, ~WR_EN, ~WR_EN, ~WR_EN};
120
 
121
 
122
 
123
 
124 78 jamey.hick
   assign ADDR_O = (WR_EN)?(19'h0 | WR_ADDR): (19'h0 | RD_ADDR);
125 7 jamey.hick
   assign DATA_BUS_O = (op_command_active != `WR_REQ)?32'bzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz: (32'h0 | write_data_active);
126
   assign DATA_BUS_T = (op_command_active != `WR_REQ);  // deasserting data_bus_T will allow 
127
                                                        // data_bus_O to drive the bus, which 
128
                                                        // need only occur if write requests 
129
                                                        // have been made.
130
   // This line enqueues data into the data fifo.
131
   assign RD_REQ_MADE = (op_command_active == `RD_REQ);
132
 
133
   always@(posedge CLK)
134
     begin
135
       if(RD_REQ_MADE)
136
         begin
137
           $display("SRAM.v: Enqueuing %d", DATA_BUS_I);
138
         end
139
 
140
       if (!RST_N)
141
         begin  //Make simulation behavior consistent with Xilinx synthesis
142
           op_command_pipelined <= `NOP;
143
           op_command_active <= `NOP;
144
           write_data_pipelined <= 0;
145
           write_data_active <= 0;
146 78 jamey.hick
           CTR <= 4;
147 7 jamey.hick
         end
148
       else
149
         begin
150
           write_data_pipelined <= WR_VAL;
151
           write_data_active <= write_data_pipelined;
152
 
153
           op_command_active <= op_command_pipelined;
154
           if(RD_EN)
155
             begin
156
               op_command_pipelined <= `RD_REQ;
157
             end
158
           else if(WR_EN)
159
             begin
160
               op_command_pipelined <= `WR_REQ;
161
             end
162
           else
163
             begin
164
               op_command_pipelined <= `NOP;
165
             end
166
 
167
           CTR <= (RD_EN) ?
168
                    (DOUT_EN) ? CTR : CTR - 1 :
169
                    (DOUT_EN) ? CTR + 1 : CTR;
170
         end
171
     end // always@ (posedge CLK)
172
 
173
endmodule

powered by: WebSVN 2.1.0

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