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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [rtl/] [memdev.v] - Blame information for rev 50

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 dgisselq
////////////////////////////////////////////////////////////////////////////////
2 3 dgisselq
//
3
// Filename:    memdev.v
4
//
5
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
6
//
7
// Purpose:     This file is really simple: it creates an on-chip memory,
8
//              accessible via the wishbone bus, that can be used in this
9
//      project.  The memory has single cycle pipeline access, although the
10
//      memory pipeline here still costs a cycle and there may be other cycles
11
//      lost between the ZipCPU (or whatever is the master of the bus) and this,
12
//      thus costing more cycles in access.  Either way, operations can be
13
//      pipelined for single cycle access on subsequent transactions.
14
//
15
//
16
// Creator:     Dan Gisselquist, Ph.D.
17
//              Gisselquist Technology, LLC
18
//
19 30 dgisselq
////////////////////////////////////////////////////////////////////////////////
20 3 dgisselq
//
21 50 dgisselq
// Copyright (C) 2015-2017, Gisselquist Technology, LLC
22 3 dgisselq
//
23
// This program is free software (firmware): you can redistribute it and/or
24
// modify it under the terms of  the GNU General Public License as published
25
// by the Free Software Foundation, either version 3 of the License, or (at
26
// your option) any later version.
27
//
28
// This program is distributed in the hope that it will be useful, but WITHOUT
29
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
30
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
31
// for more details.
32
//
33 50 dgisselq
// You should have received a copy of the GNU General Public License along
34
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
35
// target there if the PDF file isn't present.)  If not, see
36
// <http://www.gnu.org/licenses/> for a copy.
37
//
38 3 dgisselq
// License:     GPL, v3, as defined and found on www.gnu.org,
39
//              http://www.gnu.org/licenses/gpl.html
40
//
41
//
42 30 dgisselq
////////////////////////////////////////////////////////////////////////////////
43 3 dgisselq
//
44
//
45 50 dgisselq
module  memdev(i_clk, i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data, i_wb_sel,
46 3 dgisselq
                o_wb_ack, o_wb_stall, o_wb_data);
47 50 dgisselq
        parameter       LGMEMSZ=15, DW=32, EXTRACLOCK= 0;
48
        localparam      AW = LGMEMSZ - 2;
49 3 dgisselq
        input                           i_clk, i_wb_cyc, i_wb_stb, i_wb_we;
50
        input           [(AW-1):0]       i_wb_addr;
51
        input           [(DW-1):0]       i_wb_data;
52 50 dgisselq
        input           [(DW/8-1):0]     i_wb_sel;
53 3 dgisselq
        output  reg                     o_wb_ack;
54
        output  wire                    o_wb_stall;
55
        output  reg     [(DW-1):0]       o_wb_data;
56
 
57 25 dgisselq
        wire                    w_wstb, w_stb;
58
        wire    [(DW-1):0]       w_data;
59
        wire    [(AW-1):0]       w_addr;
60 50 dgisselq
        wire    [(DW/8-1):0]     w_sel;
61 3 dgisselq
 
62 25 dgisselq
        generate
63
        if (EXTRACLOCK == 0)
64
        begin
65 3 dgisselq
 
66 25 dgisselq
                assign  w_wstb = (i_wb_stb)&&(i_wb_we);
67
                assign  w_stb  = i_wb_stb;
68
                assign  w_addr = i_wb_addr;
69
                assign  w_data = i_wb_data;
70 50 dgisselq
                assign  w_sel  = i_wb_sel;
71 25 dgisselq
 
72
        end else begin
73
 
74
                reg             last_wstb, last_stb;
75
                always @(posedge i_clk)
76
                        last_wstb <= (i_wb_stb)&&(i_wb_we);
77
                always @(posedge i_clk)
78
                        last_stb <= (i_wb_stb);
79
 
80 50 dgisselq
                reg     [(AW-1):0]       last_addr;
81 25 dgisselq
                reg     [(DW-1):0]       last_data;
82 50 dgisselq
                reg     [(DW/8-1):0]     last_sel;
83 25 dgisselq
                always @(posedge i_clk)
84
                        last_data <= i_wb_data;
85
                always @(posedge i_clk)
86
                        last_addr <= i_wb_addr;
87 50 dgisselq
                always @(posedge i_clk)
88
                        last_sel <= i_wb_sel;
89 25 dgisselq
 
90
                assign  w_wstb = last_wstb;
91
                assign  w_stb  = last_stb;
92
                assign  w_addr = last_addr;
93
                assign  w_data = last_data;
94 50 dgisselq
                assign  w_sel  = last_sel;
95 25 dgisselq
        end endgenerate
96
 
97 3 dgisselq
        reg     [(DW-1):0]       mem     [0:((1<<AW)-1)];
98 50 dgisselq
 
99 3 dgisselq
        always @(posedge i_clk)
100 25 dgisselq
                o_wb_data <= mem[w_addr];
101 3 dgisselq
        always @(posedge i_clk)
102 50 dgisselq
        begin
103
                if ((w_wstb)&&(w_sel[3]))
104
                        mem[w_addr][31:24] <= w_data[31:24];
105
                if ((w_wstb)&&(w_sel[2]))
106
                        mem[w_addr][23:16] <= w_data[23:16];
107
                if ((w_wstb)&&(w_sel[1]))
108
                        mem[w_addr][15: 8] <= w_data[15:8];
109
                if ((w_wstb)&&(w_sel[0]))
110
                        mem[w_addr][ 7: 0] <= w_data[7:0];
111
        end
112
 
113 3 dgisselq
        always @(posedge i_clk)
114 25 dgisselq
                o_wb_ack <= (w_stb);
115 3 dgisselq
        assign  o_wb_stall = 1'b0;
116
 
117
endmodule

powered by: WebSVN 2.1.0

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