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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [rtl/] [cpu/] [memops.v] - Blame information for rev 49

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

Line No. Rev Author Line
1 3 dgisselq
///////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    memops.v
4
//
5
// Project:     Zip CPU -- a small, lightweight, RISC CPU soft core
6
//
7
// Purpose:     A memory unit to support a CPU.
8
//
9
//      In the interests of code simplicity, this memory operator is 
10
//      susceptible to unknown results should a new command be sent to it
11
//      before it completes the last one.  Unpredictable results might then
12
//      occurr.
13
//
14
//      20150919 -- Added support for handling BUS ERR's (i.e., the WB
15
//              error signal).
16
//
17
// Creator:     Dan Gisselquist, Ph.D.
18
//              Gisselquist Technology, LLC
19
//
20
///////////////////////////////////////////////////////////////////////////
21
//
22
// Copyright (C) 2015, Gisselquist Technology, LLC
23
//
24
// This program is free software (firmware): you can redistribute it and/or
25
// modify it under the terms of  the GNU General Public License as published
26
// by the Free Software Foundation, either version 3 of the License, or (at
27
// your option) any later version.
28
//
29
// This program is distributed in the hope that it will be useful, but WITHOUT
30
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
31
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
32
// for more details.
33
//
34
// License:     GPL, v3, as defined and found on www.gnu.org,
35
//              http://www.gnu.org/licenses/gpl.html
36
//
37
//
38
///////////////////////////////////////////////////////////////////////////
39
//
40
module  memops(i_clk, i_rst, i_stb, i_lock,
41
                i_op, i_addr, i_data, i_oreg,
42
                        o_busy, o_valid, o_err, o_wreg, o_result,
43
                o_wb_cyc_gbl, o_wb_cyc_lcl,
44
                        o_wb_stb_gbl, o_wb_stb_lcl,
45
                        o_wb_we, o_wb_addr, o_wb_data,
46
                i_wb_ack, i_wb_stall, i_wb_err, i_wb_data);
47 49 dgisselq
        parameter       ADDRESS_WIDTH=32, IMPLEMENT_LOCK=0;
48
        localparam      AW=ADDRESS_WIDTH;
49 3 dgisselq
        input                   i_clk, i_rst;
50
        input                   i_stb, i_lock;
51
        // CPU interface
52
        input                   i_op;
53
        input           [31:0]   i_addr;
54
        input           [31:0]   i_data;
55
        input           [4:0]    i_oreg;
56
        // CPU outputs
57
        output  wire            o_busy;
58
        output  reg             o_valid;
59
        output  reg             o_err;
60
        output  reg     [4:0]    o_wreg;
61
        output  reg     [31:0]   o_result;
62
        // Wishbone outputs
63
        output  wire            o_wb_cyc_gbl;
64
        output  reg             o_wb_stb_gbl;
65
        output  wire            o_wb_cyc_lcl;
66
        output  reg             o_wb_stb_lcl;
67
        output  reg             o_wb_we;
68
        output  reg     [(AW-1):0]       o_wb_addr;
69
        output  reg     [31:0]   o_wb_data;
70
        // Wishbone inputs
71
        input                   i_wb_ack, i_wb_stall, i_wb_err;
72
        input           [31:0]   i_wb_data;
73
 
74
        reg     r_wb_cyc_gbl, r_wb_cyc_lcl;
75
        wire    gbl_stb, lcl_stb;
76 49 dgisselq
        assign  lcl_stb = (i_stb)&&(i_addr[31:24]==8'hff);
77
        assign  gbl_stb = (i_stb)&&(i_addr[31:24]!=8'hff);
78 3 dgisselq
 
79
        initial r_wb_cyc_gbl = 1'b0;
80
        initial r_wb_cyc_lcl = 1'b0;
81
        always @(posedge i_clk)
82
                if (i_rst)
83
                begin
84
                        r_wb_cyc_gbl <= 1'b0;
85
                        r_wb_cyc_lcl <= 1'b0;
86
                end else if ((r_wb_cyc_gbl)||(r_wb_cyc_lcl))
87
                begin
88
                        if ((i_wb_ack)||(i_wb_err))
89
                        begin
90
                                r_wb_cyc_gbl <= 1'b0;
91
                                r_wb_cyc_lcl <= 1'b0;
92
                        end
93
                end else if (i_stb) // New memory operation
94
                begin // Grab the wishbone
95
                        r_wb_cyc_lcl <= lcl_stb;
96
                        r_wb_cyc_gbl <= gbl_stb;
97
                end
98
        always @(posedge i_clk)
99
                if (o_wb_cyc_gbl)
100
                        o_wb_stb_gbl <= (o_wb_stb_gbl)&&(i_wb_stall);
101
                else
102
                        o_wb_stb_gbl <= gbl_stb; // Grab wishbone on new operation
103
        always @(posedge i_clk)
104
                if (o_wb_cyc_lcl)
105
                        o_wb_stb_lcl <= (o_wb_stb_lcl)&&(i_wb_stall);
106
                else
107
                        o_wb_stb_lcl  <= lcl_stb; // Grab wishbone on new operation
108
        always @(posedge i_clk)
109
                if (i_stb)
110
                begin
111
                        o_wb_we   <= i_op;
112
                        o_wb_data <= i_data;
113
                        o_wb_addr <= i_addr[(AW-1):0];
114
                end
115
 
116
        initial o_valid = 1'b0;
117
        always @(posedge i_clk)
118
                o_valid <= ((o_wb_cyc_gbl)||(o_wb_cyc_lcl))&&(i_wb_ack)&&(~o_wb_we);
119
        initial o_err = 1'b0;
120
        always @(posedge i_clk)
121
                o_err <= ((o_wb_cyc_gbl)||(o_wb_cyc_lcl))&&(i_wb_err);
122
        assign  o_busy = (o_wb_cyc_gbl)||(o_wb_cyc_lcl);
123
 
124
        always @(posedge i_clk)
125
                if (i_stb)
126
                        o_wreg    <= i_oreg;
127
        always @(posedge i_clk)
128
                if (i_wb_ack)
129
                        o_result <= i_wb_data;
130
 
131
        generate
132
        if (IMPLEMENT_LOCK != 0)
133
        begin
134
                reg     lock_gbl, lock_lcl;
135
 
136
                initial lock_gbl = 1'b0;
137
                initial lock_lcl = 1'b0;
138
 
139
                always @(posedge i_clk)
140
                begin
141
                        lock_gbl <= (i_lock)&&((r_wb_cyc_gbl)||(lock_gbl));
142
                        lock_lcl <= (i_lock)&&((r_wb_cyc_lcl)||(lock_lcl));
143
                end
144
 
145
                assign  o_wb_cyc_gbl = (r_wb_cyc_gbl)||(lock_gbl);
146
                assign  o_wb_cyc_lcl = (r_wb_cyc_lcl)||(lock_lcl);
147
        end else begin
148
                assign  o_wb_cyc_gbl = (r_wb_cyc_gbl);
149
                assign  o_wb_cyc_lcl = (r_wb_cyc_lcl);
150
        end endgenerate
151
endmodule

powered by: WebSVN 2.1.0

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