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

Subversion Repositories edge

[/] [edge/] [trunk/] [HW/] [Boards/] [Atlys/] [memory_system.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 heshamelma
//////////////////////////////////////////////////////////////////
2
//                                                              //
3
//  Main memory system                                          // 
4
//                                                              //
5
//  This file is part of the Edge project                       //
6
//  http://www.opencores.org/project,edge                       //
7
//                                                              //
8
//  Description                                                 //
9
//   Main memory system is not only a wrapper to data memory    //
10
//   core, but also handling IO memory mapped operations.       //
11
//   The contents of this file are target dependent.            //
12
//   IO mapped regios, handles UART, Data memory stalling, timer//
13
//   and LEDs.                                                  //
14
//                                                              //
15
//  Author(s):                                                  //
16
//      - Hesham AL-Matary, heshamelmatary@gmail.com            //
17
//                                                              //
18
//////////////////////////////////////////////////////////////////
19
//                                                              //
20
// Copyright (C) 2014 Authors and OPENCORES.ORG                 //
21
//                                                              //
22
// This source file may be used and distributed without         //
23
// restriction provided that this copyright statement is not    //
24
// removed from the file and that any derivative work contains  //
25
// the original copyright notice and the associated disclaimer. //
26
//                                                              //
27
// This source file is free software; you can redistribute it   //
28
// and/or modify it under the terms of the GNU Lesser General   //
29
// Public License as published by the Free Software Foundation; //
30
// either version 2.1 of the License, or (at your option) any   //
31
// later version.                                               //
32
//                                                              //
33
// This source is distributed in the hope that it will be       //
34
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
35
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
36
// PURPOSE.  See the GNU Lesser General Public License for more //
37
// details.                                                     //
38
//                                                              //
39
// You should have received a copy of the GNU Lesser General    //
40
// Public License along with this source; if not, download it   //
41
// from http://www.opencores.org/lgpl.shtml                     //
42
//                                                              //
43
//////////////////////////////////////////////////////////////////
44
 
45
`define BYTE_REF  2'b01
46
`define HW_REF    2'b10
47
`define W_REF     2'b11
48
 
49
`define NO_REF    2'b01
50
`define LOADING   2'b10
51
`define STORING   2'b11
52
 
53
module Memory_System
54
#
55
(
56
  parameter N=32, H=16
57
)
58
(
59
  input clk,
60
 
61
  /* Processor Related */
62
  input[N-1:0] ProcessorAddress, /* Address coming from processor */
63
  input[N-1:0] WriteData,
64
  input[1:0] MemRefSize, /* Size of data to reference (01->byte, 10->hw,
65
11->word) */
66
  input WE,
67
  output[N-1:0] RD,
68
 
69
  output[N-1:0] UART_TX,
70
  output UART_VALID, /* There is valid data to send */
71
  input[7:0] UART_CTRL,
72
  input CP0_TimerIntMatch,
73
  output StallBusy,
74
  output[7:0] BRAM_dataOut,
75
  output[7:0] LEDs,
76
  output IO_TimerIntReset
77
);
78
 
79
wire[31:0] addr;
80
wire[31:0] ReadValue;
81
reg[31:0] ReadData;
82
wire IODev;
83
wire RODATA_MEM;
84
wire[31:0] IOReadData;
85
wire IO_LED;
86
wire IO_TimerInt;
87
wire IO_TimerIntReset;
88
 
89
reg[31:0] storeWord = 0;
90
wire[31:0] ClockCycleMax;
91
reg[31:0] ClockCycleLimit = 0;
92
wire BRAM_CLK;
93
wire[31:0] BRAM_ADDR;
94
wire[7:0] BRAM_DIN;
95
wire BRAM_WEA;
96
 
97
wire[7:0] BRAM_DOUT;
98
wire[7:0] BRAM_RODATA_DOUT;
99
reg[31:0] BRAM_LOADADDR = 32'h800;
100
reg       BRAM_LOAD_WEA = 0;
101
reg[7:0]  BRAM_LOAD_DIN = 0;
102
 
103
reg[31:0] BRAM_ProcessorADDR = 0;
104
reg       BRAM_PROC_WEA = 0;
105
reg[7:0]  BRAM_PROC_DIN = 0;
106
 
107
reg GetByte = 0;
108
wire Stall;
109
reg fire;
110
reg[2:0] i = 0;
111
reg[2:0] loadCounter = 0;
112
reg[7:0] LED = 0;
113
 
114
assign RD = (IODev)? IOReadData : ReadData;
115
 
116
assign LEDs = LED;
117
 
118
assign UART_VALID = ((ProcessorAddress == 32'hFFFF0100) && WE == 1)?
119
    1'b1
120
  :
121
    1'b0;
122
 
123
assign IO_TimerIntReset = ((ProcessorAddress == 32'hFFFF010C) && WE == 1)?
124
    1'b1
125
  :
126
    1'b0;
127
 
128
assign UART_TX = WriteData[7:0];
129
 
130
assign IODev = (ProcessorAddress >= 32'hFFFF0100)? 1'b1 : 1'b0;
131
 
132
assign IO_LED = (ProcessorAddress == 32'hFFFF0108 && WE == 1)? 1'b1 : 1'b0;
133
 
134
assign IO_TimerInt = (ProcessorAddress == 32'hFFFF010C)? 1'b1 : 1'b0;
135
 
136
assign IOReadData = (ProcessorAddress == 32'hFFFF0104)? UART_CTRL :
137
                    (ProcessorAddress == 32'hFFFF010C)? CP0_TimerIntMatch :
138
                     32'd0;
139
 
140
assign StallBusy = ((i > 0 && i<=ClockCycleMax) )? 1'b1 : 1'b0;
141
 
142
assign BRAM_CLK =  clk;
143
 
144
assign BRAM_ADDR = BRAM_ProcessorADDR;
145
 
146
assign BRAM_DIN = BRAM_PROC_DIN;
147
 
148
assign BRAM_WEA = BRAM_PROC_WEA;
149
 
150
assign GetByte_out = GetByte;
151
 
152
assign BRAM_dataOut = BRAM_DOUT;
153
 
154
assign RODATA_MEM =
155
  (ProcessorAddress >= 32'h00000800 &&
156
   ProcessorAddress <= 32'h00000BFF)?
157
   1'b1 : 1'b0;
158
 
159
assign ClockCycleMax = (MemRefSize != 2'b00)?
160
                        //Loads
161
                        (WE == 0)?
162
                          (MemRefSize == `BYTE_REF)? 32'd2 :
163
                          (MemRefSize == `HW_REF)? 32'd4   :
164
                          (MemRefSize == `W_REF)? 32'd5   :
165
                          32'd0
166
                         : //Stores
167
                          (MemRefSize == `BYTE_REF)? 32'd1 :
168
                          (MemRefSize == `HW_REF)? 32'd2   :
169
                          (MemRefSize == `W_REF)? 32'd4    :
170
                          32'd0
171
                         :
172
                         32'd0;
173
                         ;
174
 
175
always @(posedge clk)
176
  if(IO_LED)
177
    LED = WriteData[7:0];
178
 
179
always @(negedge clk)
180
begin
181
 
182
  //RD = 0;
183
  BRAM_PROC_WEA = 0;
184
  //BRAM_ADDR = 0;
185
  BRAM_PROC_DIN =0;
186
  if(i == 0)
187
  begin
188
    storeWord = WriteData;
189
    //ReadData = 0;
190
  end
191
 
192
  if(MemRefSize != 2'b00)
193
  begin
194
 
195
    if(i < ClockCycleMax)
196
    begin
197
      //StallBusy = 1;
198
      i = i + 1;
199
 
200
      /* Loads */
201
      if(IODev != 1'b1)
202
      begin
203
      BRAM_ProcessorADDR = ProcessorAddress + i - 1;
204
      //BRAM_DOUT = memory[BRAM_ADDR];
205
      ReadData =
206
        (RODATA_MEM)?
207
          (MemRefSize == `BYTE_REF)?
208
            {24'd0, BRAM_RODATA_DOUT}
209
          :
210
            (MemRefSize == `HW_REF)?
211
              {16'd0, BRAM_RODATA_DOUT, ReadData[15:8]}
212
            :
213
              (MemRefSize == `W_REF)?
214
                {BRAM_RODATA_DOUT, ReadData[31:8]}
215
              :
216
                32'd0
217
 
218
      :  /* Data memory */
219
        (MemRefSize == `BYTE_REF)?
220
          {24'd0, BRAM_DOUT}
221
        :
222
          (MemRefSize == `HW_REF)?
223
            {16'd0, BRAM_DOUT, ReadData[15:8]}
224
          :
225
            (MemRefSize == `W_REF)?
226
              {BRAM_DOUT, ReadData[31:8]}
227
            :
228
              32'd0;
229
      end
230
 
231
      /* Stores to data memory */
232
      if(WE && IODev != 1'b1)
233
      begin
234
        BRAM_ProcessorADDR = ProcessorAddress + i - 1;
235
        BRAM_PROC_DIN = storeWord[7:0];
236
        storeWord = {8'd0, storeWord[31:8]};
237
        BRAM_PROC_WEA = WE;
238
      end
239
 
240
   end
241
 
242
   /* i >= ClockCycleMax */
243
   else
244
   begin
245
     i = 0;
246
   end
247
 
248
 
249
  end
250
end
251
 
252
BRAM8x1024 data_memory
253
(
254
  .clka(BRAM_CLK), // input clka
255
  .wea(BRAM_WEA), // input [0 : 0] wea
256
  .addra(BRAM_ADDR), // input [9 : 0] addra
257
  .dina(BRAM_DIN), // input [7 : 0] dina
258
  .douta(BRAM_DOUT) // output [7 : 0] douta
259
);
260
 
261
ROM8x1024 rodata
262
(
263
  .clka(BRAM_CLK), // input clka
264
  .addra(BRAM_ADDR - 32'h00000800), // input [9 : 0] addra
265
  .douta(BRAM_RODATA_DOUT) // output [7 : 0] douta
266
);
267
 
268
endmodule

powered by: WebSVN 2.1.0

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