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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [rtl/] [cpu/] [memops.v] - Blame information for rev 80

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

Line No. Rev Author Line
1 21 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
        parameter       ADDRESS_WIDTH=24, IMPLEMENT_LOCK=0, AW=ADDRESS_WIDTH;
48
        input                   i_clk, i_rst;
49
        input                   i_stb, i_lock;
50
        // CPU interface
51
        input                   i_op;
52
        input           [31:0]   i_addr;
53
        input           [31:0]   i_data;
54
        input           [4:0]    i_oreg;
55
        // CPU outputs
56
        output  wire            o_busy;
57
        output  reg             o_valid;
58
        output  reg             o_err;
59
        output  reg     [4:0]    o_wreg;
60
        output  reg     [31:0]   o_result;
61
        // Wishbone outputs
62
        output  wire            o_wb_cyc_gbl;
63
        output  reg             o_wb_stb_gbl;
64
        output  wire            o_wb_cyc_lcl;
65
        output  reg             o_wb_stb_lcl;
66
        output  reg             o_wb_we;
67
        output  reg     [(AW-1):0]       o_wb_addr;
68
        output  reg     [31:0]   o_wb_data;
69
        // Wishbone inputs
70
        input                   i_wb_ack, i_wb_stall, i_wb_err;
71
        input           [31:0]   i_wb_data;
72
 
73
        reg     r_wb_cyc_gbl, r_wb_cyc_lcl;
74
        wire    gbl_stb, lcl_stb;
75
        assign  lcl_stb = (i_stb)&&(i_addr[31:8]==24'hc00000)&&(i_addr[7:5]==3'h0);
76
        assign  gbl_stb = (i_stb)&&((i_addr[31:8]!=24'hc00000)||(i_addr[7:5]!=3'h0));
77
 
78
        initial r_wb_cyc_gbl = 1'b0;
79
        initial r_wb_cyc_lcl = 1'b0;
80
        always @(posedge i_clk)
81
                if (i_rst)
82
                begin
83
                        r_wb_cyc_gbl <= 1'b0;
84
                        r_wb_cyc_lcl <= 1'b0;
85
                end else if ((r_wb_cyc_gbl)||(r_wb_cyc_lcl))
86
                begin
87
                        if ((i_wb_ack)||(i_wb_err))
88
                        begin
89
                                r_wb_cyc_gbl <= 1'b0;
90
                                r_wb_cyc_lcl <= 1'b0;
91
                        end
92
                end else if (i_stb) // New memory operation
93
                begin // Grab the wishbone
94
                        r_wb_cyc_lcl <= lcl_stb;
95
                        r_wb_cyc_gbl <= gbl_stb;
96
                end
97
        always @(posedge i_clk)
98
                if (o_wb_cyc_gbl)
99
                        o_wb_stb_gbl <= (o_wb_stb_gbl)&&(i_wb_stall);
100
                else
101
                        o_wb_stb_gbl <= gbl_stb; // Grab wishbone on new operation
102
        always @(posedge i_clk)
103
                if (o_wb_cyc_lcl)
104
                        o_wb_stb_lcl <= (o_wb_stb_lcl)&&(i_wb_stall);
105
                else
106
                        o_wb_stb_lcl  <= lcl_stb; // Grab wishbone on new operation
107
        always @(posedge i_clk)
108
                if (i_stb)
109
                begin
110
                        o_wb_we   <= i_op;
111
                        o_wb_data <= i_data;
112
                        o_wb_addr <= i_addr[(AW-1):0];
113
                end
114
 
115
        initial o_valid = 1'b0;
116
        always @(posedge i_clk)
117
                o_valid <= ((o_wb_cyc_gbl)||(o_wb_cyc_lcl))&&(i_wb_ack)&&(~o_wb_we);
118
        initial o_err = 1'b0;
119
        always @(posedge i_clk)
120
                o_err <= ((o_wb_cyc_gbl)||(o_wb_cyc_lcl))&&(i_wb_err);
121
        assign  o_busy = (o_wb_cyc_gbl)||(o_wb_cyc_lcl);
122
 
123
        always @(posedge i_clk)
124
                if (i_stb)
125
                        o_wreg    <= i_oreg;
126
        always @(posedge i_clk)
127
                if (i_wb_ack)
128
                        o_result <= i_wb_data;
129
 
130
        generate
131
        if (IMPLEMENT_LOCK != 0)
132
        begin
133
                reg     lock_gbl, lock_lcl;
134
 
135
                initial lock_gbl = 1'b0;
136
                initial lock_lcl = 1'b0;
137
 
138
                always @(posedge i_clk)
139
                begin
140
                        lock_gbl <= (i_lock)&&((r_wb_cyc_gbl)||(lock_gbl));
141
                        lock_lcl <= (i_lock)&&((r_wb_cyc_lcl)||(lock_lcl));
142
                end
143
 
144
                assign  o_wb_cyc_gbl = (r_wb_cyc_gbl)||(lock_gbl);
145
                assign  o_wb_cyc_lcl = (r_wb_cyc_lcl)||(lock_lcl);
146
        end else begin
147
                assign  o_wb_cyc_gbl = (r_wb_cyc_gbl);
148
                assign  o_wb_cyc_lcl = (r_wb_cyc_lcl);
149
        end endgenerate
150
endmodule

powered by: WebSVN 2.1.0

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