1 |
11 |
rafaelcalc |
//////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Engineer: Rafael de Oliveira Calçada (rafaelcalcada@gmail.com)
|
3 |
|
|
//
|
4 |
|
|
// Create Date: 06.07.2020 21:30:07
|
5 |
|
|
// Module Name: bus_arbiter
|
6 |
|
|
// Project Name: Steel SoC
|
7 |
|
|
// Description: Bus arbiter
|
8 |
|
|
//
|
9 |
|
|
// Dependencies: -
|
10 |
|
|
//
|
11 |
|
|
// Version 0.01
|
12 |
|
|
//
|
13 |
|
|
//////////////////////////////////////////////////////////////////////////////////
|
14 |
|
|
|
15 |
|
|
/*********************************************************************************
|
16 |
|
|
|
17 |
|
|
MIT License
|
18 |
|
|
|
19 |
|
|
Copyright (c) 2020 Rafael de Oliveira Calçada
|
20 |
|
|
|
21 |
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
22 |
|
|
of this software and associated documentation files (the "Software"), to deal
|
23 |
|
|
in the Software without restriction, including without limitation the rights
|
24 |
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
25 |
|
|
copies of the Software, and to permit persons to whom the Software is
|
26 |
|
|
furnished to do so, subject to the following conditions:
|
27 |
|
|
|
28 |
|
|
The above copyright notice and this permission notice shall be included in all
|
29 |
|
|
copies or substantial portions of the Software.
|
30 |
|
|
|
31 |
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
32 |
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
33 |
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
34 |
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
35 |
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
36 |
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
37 |
|
|
SOFTWARE.
|
38 |
|
|
|
39 |
|
|
********************************************************************************/
|
40 |
|
|
|
41 |
|
|
`timescale 1ns / 1ps
|
42 |
|
|
|
43 |
|
|
module bus_arbiter(
|
44 |
|
|
input wire CLK,
|
45 |
|
|
input wire RESET,
|
46 |
|
|
|
47 |
|
|
// Connection with the core
|
48 |
|
|
input wire [31:0] D_ADDR,
|
49 |
|
|
input wire [31:0] DATA_OUT,
|
50 |
|
|
input wire WR_REQ,
|
51 |
|
|
input wire [3:0] WR_MASK,
|
52 |
|
|
output wire [31:0] DATA_IN,
|
53 |
|
|
|
54 |
|
|
// PORT #1 - Connected to UART
|
55 |
|
|
output wire [31:0] D_ADDR_1,
|
56 |
|
|
output wire [31:0] DATA_OUT_1,
|
57 |
|
|
output wire WR_REQ_1,
|
58 |
|
|
output wire [3:0] WR_MASK_1,
|
59 |
|
|
input wire [31:0] DATA_IN_1,
|
60 |
|
|
|
61 |
|
|
// PORT #2 - Connected to MAIN MEMORY
|
62 |
|
|
output wire [31:0] D_ADDR_2,
|
63 |
|
|
output wire [31:0] DATA_OUT_2,
|
64 |
|
|
output wire WR_REQ_2,
|
65 |
|
|
output wire [3:0] WR_MASK_2,
|
66 |
|
|
input wire [31:0] DATA_IN_2
|
67 |
|
|
);
|
68 |
|
|
|
69 |
|
|
reg last_access;
|
70 |
|
|
wire uart_access = D_ADDR[31:12] == 20'h00010;
|
71 |
|
|
|
72 |
|
|
always @(posedge CLK)
|
73 |
|
|
begin
|
74 |
|
|
if(RESET) last_access <= 1'b0;
|
75 |
|
|
else last_access <= uart_access;
|
76 |
|
|
end
|
77 |
|
|
|
78 |
|
|
assign D_ADDR_1 = uart_access ? D_ADDR : 32'b0;
|
79 |
|
|
assign DATA_OUT_1 = uart_access ? DATA_OUT : 32'b0;
|
80 |
|
|
assign WR_REQ_1 = uart_access ? WR_REQ : 1'b0;
|
81 |
|
|
assign WR_MASK_1 = uart_access ? WR_MASK : 4'b0;
|
82 |
|
|
|
83 |
|
|
assign D_ADDR_2 = ~uart_access ? D_ADDR : 32'b0;
|
84 |
|
|
assign DATA_OUT_2 = ~uart_access ? DATA_OUT : 32'b0;
|
85 |
|
|
assign WR_REQ_2 = ~uart_access ? WR_REQ : 1'b0;
|
86 |
|
|
assign WR_MASK_2 = ~uart_access ? WR_MASK : 4'b0;
|
87 |
|
|
|
88 |
|
|
assign DATA_IN = last_access ? DATA_IN_1 : DATA_IN_2;
|
89 |
|
|
|
90 |
|
|
endmodule
|