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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [rtl/] [MemArbiter.sv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
// Copyright Jamie Iles, 2017
2
//
3
// This file is part of s80x86.
4
//
5
// s80x86 is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// s80x86 is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with s80x86.  If not, see .
17
 
18
module MemArbiter(input logic clk,
19
                  input logic reset,
20
                  // Instruction bus
21
                  input logic [19:1] instr_m_addr,
22
                  output logic [15:0] instr_m_data_in,
23
                  input logic instr_m_access,
24
                  output logic instr_m_ack,
25
                  // Data bus
26
                  input logic [19:1] data_m_addr,
27
                  output logic [15:0] data_m_data_in,
28
                  input logic [15:0] data_m_data_out,
29
                  input logic data_m_access,
30
                  output logic data_m_ack,
31
                  input logic data_m_wr_en,
32
                  input logic [1:0] data_m_bytesel,
33
                  // Output bus
34
                  output logic [19:1] q_m_addr,
35
                  input logic [15:0] q_m_data_in,
36
                  output logic [15:0] q_m_data_out,
37
                  output logic q_m_access,
38
                  input logic q_m_ack,
39
                  output logic q_m_wr_en,
40
                  output logic [1:0] q_m_bytesel);
41
 
42
reg grant_to_data;
43
reg grant_active;
44
 
45
wire q_data = (grant_active && grant_to_data) || (!grant_active && data_m_access);
46
 
47
assign q_m_addr = q_data ? data_m_addr : grant_active ? instr_m_addr : 19'b0;
48
assign q_m_data_out = data_m_data_out;
49
assign q_m_access = ~q_m_ack & (q_data ? data_m_access : grant_active ? instr_m_access : 1'b0);
50
assign q_m_wr_en = q_data ? data_m_wr_en : 1'b0;
51
assign q_m_bytesel = q_data ? data_m_bytesel : 2'b11;
52
 
53
assign instr_m_data_in = grant_active & ~grant_to_data ? q_m_data_in : 16'b0;
54
assign instr_m_ack = grant_active & ~grant_to_data & q_m_ack;
55
assign data_m_data_in = grant_active & grant_to_data ? q_m_data_in : 16'b0;
56
assign data_m_ack = grant_active & grant_to_data & q_m_ack;
57
 
58
always_ff @(posedge clk or posedge reset) begin
59
    if (reset) begin
60
        grant_active <= 1'b0;
61
    end else begin
62
        if (q_m_ack)
63
            grant_active <= 1'b0;
64
        else if (!grant_active && (data_m_access || instr_m_access)) begin
65
            grant_active <= 1'b1;
66
            grant_to_data <= data_m_access;
67
        end
68
    end
69
end
70
 
71
endmodule

powered by: WebSVN 2.1.0

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