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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [rtl/] [core/] [prefetch.v] - Blame information for rev 22

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

Line No. Rev Author Line
1 2 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    prefetch.v
4
//
5
// Project:     Zip CPU -- a small, lightweight, RISC CPU soft core
6
//
7
// Purpose:     This is a very simple instruction fetch approach.  It gets
8
//              one instruction at a time.  Future versions should pipeline
9
//              fetches and perhaps even cache results--this doesn't do that.
10
//              It should, however, be simple enough to get things running.
11
//
12
//              The interface is fascinating.  The 'i_pc' input wire is just
13
//              a suggestion of what to load.  Other wires may be loaded
14
//              instead. i_pc is what must be output, not necessarily input.
15
//
16
// Creator:     Dan Gisselquist, Ph.D.
17
//              Gisselquist Tecnology, LLC
18
//
19
////////////////////////////////////////////////////////////////////////////////
20
//
21
// Copyright (C) 2015, Gisselquist Technology, LLC
22
//
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
// License:     GPL, v3, as defined and found on www.gnu.org,
34
//              http://www.gnu.org/licenses/gpl.html
35
//
36
//
37
////////////////////////////////////////////////////////////////////////////////
38
//
39
// Flash requires a minimum of 4 clocks per byte to read, so that would be
40
// 4*(4bytes/32bit word) = 16 clocks per word read---and that's in pipeline
41
// mode which this prefetch does not support.  In non--pipelined mode, the
42
// flash will require (16+6+6)*2 = 56 clocks plus 16 clocks per word read,
43
// or 72 clocks to fetch one instruction.
44
module  prefetch(i_clk, i_rst, i_ce, i_pc, i_aux,
45
                        o_i, o_pc, o_aux, o_valid,
46
                o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data,
47
                        i_wb_ack, i_wb_stall, i_wb_data);
48
        parameter               AW = 1;
49
        input                   i_clk, i_rst, i_ce;
50
        input           [31:0]   i_pc;
51
        input   [(AW-1):0]       i_aux;
52
        output  reg     [31:0]   o_i;
53
        output  reg     [31:0]   o_pc;
54
        output  reg [(AW-1):0]   o_aux;
55
        output  wire            o_valid;
56
        // Wishbone outputs
57
        output  reg             o_wb_cyc, o_wb_stb;
58
        output  wire            o_wb_we;
59
        output  reg     [31:0]   o_wb_addr;
60
        output  wire    [31:0]   o_wb_data;
61
        // And return inputs
62
        input                   i_wb_ack, i_wb_stall;
63
        input           [31:0]   i_wb_data;
64
 
65
        assign  o_wb_we = 1'b0;
66
        assign  o_wb_data = 32'h0000;
67
 
68
        // Let's build it simple and upgrade later: For each instruction
69
        // we do one bus cycle to get the instruction.  Later we should
70
        // pipeline this, but for now let's just do one at a time.
71
        initial o_wb_cyc = 1'b0;
72
        initial o_wb_stb = 1'b0;
73
        initial o_wb_addr= 0;
74
        always @(posedge i_clk)
75
                if (i_rst)
76
                begin
77
                        o_wb_cyc <= 1'b0;
78
                        if (o_wb_cyc)
79
                                o_wb_addr <= 0;
80
                end else if ((i_ce)&&(~o_wb_cyc)&&(o_wb_addr == i_pc))
81
                begin // Single value cache check
82
                        o_aux   <= i_aux;
83
                        // o_i was already set during the last bus cycle
84
                end else if ((i_ce)&&(~o_wb_cyc)) // Initiate a bus cycle
85
                begin
86
                        o_wb_cyc <= 1'b1;
87
                        o_wb_stb <= 1'b1;
88
                        o_wb_addr <= i_pc;
89
                        o_aux   <= i_aux;
90
                end else if (o_wb_cyc) // Independent of ce
91
                begin
92
                        if ((o_wb_cyc)&&(o_wb_stb)&&(~i_wb_stall))
93
                                o_wb_stb <= 1'b0;
94
                        if (i_wb_ack)
95
                                o_wb_cyc <= 1'b0;
96
                end
97
 
98
        always @(posedge i_clk)
99
                if ((o_wb_cyc)&&(i_wb_ack))
100
                        o_i <= i_wb_data;
101
        always @(posedge i_clk)
102
                if ((o_wb_cyc)&&(i_wb_ack))
103
                        o_pc <= o_wb_addr;
104
 
105
        assign o_valid = (i_pc == o_pc)&&(i_aux == o_aux)&&(~o_wb_cyc);
106
 
107
endmodule

powered by: WebSVN 2.1.0

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