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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [fpga/] [experiments/] [memdelay/] [ram.v] - Blame information for rev 317

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 297 hellwig
//
2
// ram.v -- simulate external RAM
3
//          8M x 32 bit = 32 MB
4
//
5
 
6
 
7
`timescale 1ns/10ps
8
`default_nettype none
9
 
10
 
11
//
12
// use this set of parameters for minimal access times
13
//
14
//`define RD_CYCLES     4'd2    // # cycles for read, min = 2
15
//`define WR_CYCLES     4'd2    // # cycles for write, min = 2
16
 
17
//
18
// use this set of parameters for realistic access times
19
//
20
`define RD_CYCLES       4'd14   // # cycles for read, min = 2
21
`define WR_CYCLES       4'd6    // # cycles for write, min = 2
22
 
23
 
24
module ram(clk, rst,
25
           stb, we, addr,
26
           data_in, data_out, ack);
27
    input clk;
28
    input rst;
29
    input stb;
30
    input we;
31
    input [24:2] addr;
32
    input [31:0] data_in;
33
    output reg [31:0] data_out;
34
    output ack;
35
 
36
  reg [31:0] mem[0:8388607];
37
  reg [3:0] counter;
38
 
39
  always @(posedge clk) begin
40
    if (stb) begin
41
      if (we) begin
42
        // write cycle
43
        mem[addr] <= data_in;
44
      end else begin
45
        // read cycle
46
        data_out <= mem[addr];
47
      end
48
    end
49
  end
50
 
51
  always @(posedge clk) begin
52
    if (rst) begin
53
      counter[3:0] <= 4'h0;
54
    end else begin
55
      if (counter[3:0] == 4'h0) begin
56
        if (stb & ~we) begin
57
          // a read may need some clock cycles
58 300 hellwig
          counter[3:0] <= `RD_CYCLES - 1;
59 297 hellwig
        end
60
        if (stb & we) begin
61
          // a write may need some clock cycles
62 300 hellwig
          counter[3:0] <= `WR_CYCLES - 1;
63 297 hellwig
        end
64
      end else begin
65
        counter[3:0] <= counter[3:0] - 1;
66
      end
67
    end
68
  end
69
 
70
  assign ack = (counter[3:0] == 4'h1) ? 1 : 0;
71
 
72
endmodule

powered by: WebSVN 2.1.0

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