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

Subversion Repositories qrisc32

[/] [qrisc32/] [trunk/] [qrisc32_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
import risc_pack::*;
25
 
26
module qrisc32_MEM(
27
                input                           clk,reset,
28
                interface                       avm_data_read,//avalon master port only for  reading data
29
                interface                       avm_data_write,//avalon master port only for  writing data
30
                input   pipe_struct     pipe_mem_in,
31
                output  pipe_struct     pipe_mem_out,
32
                output  bit                     pipe_stall,
33
                input                           verbose
34
        );
35
 
36
        import risc_pack::*;
37
 
38
        bit             rd_stall;
39
        bit             wr_stall;
40
        wire[31:0] addr_w = pipe_mem_in.val_r1;
41
 
42
        pipe_struct     pipe_mem_in0,pipe_mem_in1;
43
 
44
        always_comb
45
                pipe_stall<=rd_stall | wr_stall;
46
 
47
        always@(posedge clk)
48
        if(reset)
49
        begin
50
                avm_data_read.address_r<='0;
51
                avm_data_read.rd<='0;
52
                avm_data_read.wr<='0;
53
                rd_stall<=0;
54
                pipe_mem_out<='0;
55
                pipe_mem_in0<='0;
56
                pipe_mem_in1<='0;
57
        end
58
        else
59
        begin
60
                if(pipe_mem_in.read_mem==1)
61
                        avm_data_read.address_r<=addr_w;//asserted addr
62
 
63
                avm_data_read.rd<=pipe_mem_in.read_mem;//||pipe_mem_in0.read_mem||pipe_mem_in1.read_mem;
64
 
65
                pipe_mem_in0<=pipe_mem_in;//addr asserted
66
                pipe_mem_in1<=pipe_mem_in0;//just wait cycle
67
 
68
                if(avm_data_read.wait_req==0 && pipe_mem_in1.read_mem==1)// it has been read ok(sram access is 2 cycles)
69
                begin
70
                        //if(~pipe_mem_in.write_reg)
71
                        begin
72
                                if(verbose)
73
                                        $display("[MEM stage] access to dst register");
74
                                rd_stall<=0;
75
                                pipe_mem_out<=pipe_mem_in;
76
                                pipe_mem_out.dst_r<=pipe_mem_in1.dst_r;
77
                                pipe_mem_out.val_dst<=avm_data_read.data_r;//result of read
78
                                pipe_mem_out.write_reg<=1;
79
                        end
80
                        //else
81
                        //if(~pipe_mem_in.incr_r2_enable)
82
                        //begin
83
                        //      if(verbose)
84
                        //              $display("[MEM stage] access to src2 register");
85
                        //      rd_stall<=0;
86
                        //      pipe_mem_out<=pipe_mem_in;
87
                        //
88
                        //      pipe_mem_out.src_r2<=pipe_mem_in1.dst_r;
89
                        //      pipe_mem_out.incr_r2_enable<=1;
90
                        //      pipe_mem_out.val_r2<=avm_data_read.data_r;//result of read
91
                        //end
92
                        //else
93
                        //begin
94
                        //      if(verbose)
95
                        //              $display("[MEM stage] access to dst register and STALL pipeline!");
96
                        //      rd_stall<=1;
97
                        //      pipe_mem_out<=pipe_mem_in1;
98
                        //      pipe_mem_out.val_dst<=avm_data_read.data_r;//result of read
99
                        //end
100
                end
101
                else
102
                begin
103
                        rd_stall<=0;
104
                        if(rd_stall)//if previous op was stalled
105
                        begin
106
                                pipe_mem_out<=pipe_mem_in0;
107
                        end
108
                        else
109
                        begin
110
                                pipe_mem_out<=pipe_mem_in;
111
                                if(pipe_mem_in.read_mem)//if read access then
112
                                        pipe_mem_out.write_reg<='0;//clear write bit register
113
                        end
114
                end
115
        end
116
 
117
        always@(posedge clk)
118
        if(reset)
119
        begin
120
                avm_data_write.address_r<='0;
121
                avm_data_write.data_w<='0;
122
                avm_data_write.rd<='0;
123
                avm_data_write.wr<='0;
124
                wr_stall<='0;
125
        end
126
        else
127
        begin
128
                if(pipe_mem_in.write_mem)
129
                begin
130
                        avm_data_write.address_r<=addr_w;
131
                        avm_data_write.data_w<=pipe_mem_in.val_dst;
132
                        avm_data_write.wr<=1;
133
                        wr_stall<=0;
134
                end
135
                else
136
                begin
137
                        avm_data_write.wr<='0;
138
                        wr_stall<=0;
139
                end
140
        end
141
 
142
endmodule

powered by: WebSVN 2.1.0

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