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

Subversion Repositories qrisc32

[/] [qrisc32/] [trunk/] [mem.sv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 vinogradov
//////////////////////////////////////////////////////////////////////////////////////////////
2
//    Project Qrisc32 is risc cpu implementation, purpose is studying
3
//    Digital System Design course at Kyoung Hee University during my PhD earning
4
//    Copyright (C) 2010  Vinogradov Viacheslav
5
//
6
//    This library is free software; you can redistribute it and/or
7
//   modify it under the terms of the GNU Lesser General Public
8
//    License as published by the Free Software Foundation; either
9
//    version 2.1 of the License, or (at your option) any later version.
10
//
11
//    This library is distributed in the hope that it will be useful,
12
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
//    Lesser General Public License for more details.
15
//
16
//    You should have received a copy of the GNU Lesser General Public
17
//    License along with this library; if not, write to the Free Software
18
//    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
//
20
//
21
//////////////////////////////////////////////////////////////////////////////////////////////
22
 
23
 
24
 
25
module mem#(size=256,adr_limit=64)(
26
        input                           clk,
27
        input[31:0]                     add_r,add_w,data_w,
28
        input                           rd,wr,
29
        output bit[31:0]        data_r,
30
        output                          req
31
 
32
        ,input                          stop_enable//=1 will stop on each problem(non align access and out of adr access)
33
        ,output bit                     stop_active//=1 will indicate about stop signal
34
        ,input                          verbose
35
        );
36
 
37
        bit[31:0] sram[size-1:0];
38
 
39
        assign  req             =       1'b0;
40
        wire[$bits(size)-1:0]add_r_word =add_r[31:2];
41
        wire[$bits(size)-1:0]add_w_word =add_w[31:2];
42
 
43
        always@(posedge clk)
44
        begin
45
                stop_active=0;
46
                if(wr)
47
                begin
48
                        sram[add_w_word]<=data_w;
49
                        if(verbose)
50
                                $display(".................................[%m] write at address %08x with data %08x",add_w,data_w);
51
                end
52
                data_r  <=        sram[add_r_word];
53
 
54
                if(rd)
55
                begin
56
                        if(verbose)
57
                                $display(".................................[%m] read at address %08x with data %08x",add_r,sram[add_r_word]);
58
                end
59
 
60
                if(wr && add_w>adr_limit*4)
61
                begin
62
                        if(verbose)
63
                                $display(".................................[%m] write out of limit address %08x",add_w);
64
                        stop_active=1;
65
                        if(stop_enable)$stop;
66
                end
67
 
68
                if(rd && add_r>adr_limit*4)
69
                begin
70
                        if(verbose)
71
                                $display(".................................[%m] read out of limit address %08x",add_r);
72
                        if(stop_enable)$stop;
73
                        stop_active=1;
74
                end
75
 
76
                if(add_r[1:0]!=0 && rd)
77
                begin
78
                        if(verbose)
79
                                $display(".................................[%m] read by non align address  %08x",add_r);
80
                        if(stop_enable)$stop;
81
                        stop_active=1;
82
                end
83
 
84
                if(add_w[1:0]!=0 && wr)
85
                begin
86
                        if(verbose)
87
                                $display(".................................[%m] write by non align address %08x",add_w);
88
                        if(stop_enable)$stop;
89
                        stop_active=1;
90
                end
91
        end
92
 
93
endmodule

powered by: WebSVN 2.1.0

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