summaryrefslogtreecommitdiff
path: root/rtl/cpu/cpu_fetch.sv
blob: 00fcbd0ef12e747b1e156c668e08eac1169b978f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// Copyright (c) 2026, Apollo Telephone Laboratories.
// Provided under the BSD-3 clause.
//

`include "bus/ari.svh"

//
// Represents a CPU fetch
//
module cpu_fetch (
    input wire clk_i,
    input wire reset_i,
    input wire memop_done_i,

    output logic mem_req_o,
    output logic [PMA_XLEN-1:0] mem_ad_o
);
    parameter FSM_STAGE_REQUEST   = 0;
    parameter FSM_STAGE_WAIT      = 1;

    logic [63:0] pc;
    logic [2:0] fsm_stage;

    always_ff @(posedge clk_i) begin
        if (reset_i) begin
            mem_req_o   <= 0;
            mem_ad_o    <= 0;
            pc          <= 0;
            fsm_stage   <= 0;
        end else begin
            case (fsm_stage)
                FSM_STAGE_REQUEST: begin
                    mem_ad_o  <= pc;
                    mem_req_o <= 1;
                    fsm_stage <= FSM_STAGE_WAIT;
                end
                FSM_STAGE_WAIT: begin
                    if (memop_done_i) begin
                        mem_req_o  <= 0;
                        pc         <=  pc + 4;
                        fsm_stage  <= FSM_STAGE_REQUEST;
                    end
                end
            endcase
        end
    end
endmodule