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

Subversion Repositories eco32

[/] [eco32/] [tags/] [eco32-0.23/] [fpga/] [src/] [rom/] [rom.v] - Blame information for rev 248

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

Line No. Rev Author Line
1 118 hellwig
//
2
// rom.v -- parallel flash ROM interface
3
//
4
 
5
 
6 27 hellwig
module rom(clk, reset,
7
           en, wr, size, addr,
8
           data_out, wt,
9
           ce_n, oe_n, we_n, rst_n, byte_n, a, d);
10
    // internal interface signals
11
    input clk;
12
    input reset;
13
    input en;
14
    input wr;
15
    input [1:0] size;
16
    input [20:0] addr;
17
    output reg [31:0] data_out;
18
    output reg wt;
19 118 hellwig
    // flash ROM interface signals
20 27 hellwig
    output ce_n;
21
    output oe_n;
22
    output we_n;
23
    output rst_n;
24
    output byte_n;
25
    output [19:0] a;
26
    input [15:0] d;
27
 
28
  reg [3:0] state;
29
  reg a0;
30
 
31
  // the following control signals are all
32
  // either constantly asserted or deasserted
33
  assign ce_n = 0;
34
  assign oe_n = 0;
35
  assign we_n = 1;
36
  assign rst_n = 1;
37
  assign byte_n = 1;
38
 
39 118 hellwig
  // the flash ROM is organized in 16-bit halfwords
40 27 hellwig
  // address line a0 is controlled by the state machine
41 118 hellwig
  // (this is necessary for word accesses)
42 27 hellwig
  assign a[19:1] = addr[20:2];
43
  assign a[0] = a0;
44
 
45
  // the state machine
46
  always @(posedge clk) begin
47
    if (reset == 1) begin
48
      state <= 0;
49
      wt <= 1;
50
    end else begin
51
      if (state == 0) begin
52
        // wait for start of access
53
        if (en == 1 && wr == 0) begin
54
          state <= 1;
55
          if (size[1] == 1) begin
56
            // word access
57
            a0 <= 0;
58
          end else begin
59
            // halfword or byte access
60
            a0 <= addr[1];
61
          end
62
        end
63
      end else
64
      if (state == 6) begin
65
        if (size[1] == 1) begin
66
          // word access
67
          // latch upper halfword
68
          data_out[31:24] <= d[7:0];
69
          data_out[23:16] <= d[15:8];
70
          state <= 7;
71
          a0 <= 1;
72
        end else begin
73
          // halfword or byte access
74
          data_out[31:16] <= 16'h0000;
75
          if (size[0] == 1) begin
76
            // halfword access
77
            data_out[15:8] <= d[7:0];
78
            data_out[7:0] <= d[15:8];
79
          end else begin
80
            // byte access
81
            data_out[15:8] <= 8'h00;
82
            if (addr[0] == 0) begin
83
              // even address
84
              data_out[7:0] <= d[7:0];
85
            end else begin
86
              // odd address
87
              data_out[7:0] <= d[15:8];
88
            end
89
          end
90
          state <= 13;
91
          wt <= 0;
92
        end
93
      end else
94
      if (state == 12) begin
95
        // word access (state is only reached in this case)
96
        // latch lower halfword
97
        data_out[15:8] <= d[7:0];
98
        data_out[7:0] <= d[15:8];
99
        state <= 13;
100
        wt <= 0;
101
      end else
102
      if (state == 13) begin
103
        // end of access
104
        wt <= 1;
105
        state <= 0;
106
      end else begin
107 118 hellwig
        // wait for flash ROM access time to pass
108 27 hellwig
        state <= state + 1;
109
      end
110
    end
111
  end
112
 
113
endmodule

powered by: WebSVN 2.1.0

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