2021-01-29 06:07:17 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// ahblite.sv
|
|
|
|
//
|
|
|
|
// Written: David_Harris@hmc.edu 9 January 2021
|
|
|
|
// Modified:
|
|
|
|
//
|
|
|
|
// Purpose: AHB Lite External Bus Unit
|
|
|
|
// See ARM_HIH0033A_AMBA_AHB-Lite_SPEC 1.0
|
|
|
|
// Arbitrates requests from instruction and data streams
|
|
|
|
// Connects hart to peripherals and I/O pins on SOC
|
|
|
|
// Bus width presently matches XLEN
|
|
|
|
// Anticipate replacing this with an AXI bus interface to communicate with FPGA DRAM/Flash controllers
|
|
|
|
//
|
|
|
|
// A component of the Wally configurable RISC-V project.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2021 Harvey Mudd College & Oklahoma State University
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
|
|
|
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
|
|
|
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
|
|
|
|
// is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
|
|
|
// OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
|
|
|
`include "wally-config.vh"
|
|
|
|
|
|
|
|
module ahblite (
|
|
|
|
input logic clk, reset,
|
2021-01-30 04:43:48 +00:00
|
|
|
// Load control
|
|
|
|
input logic UnsignedLoadM,
|
2021-01-29 06:07:17 +00:00
|
|
|
// Signals from Instruction Cache
|
2021-02-02 20:09:24 +00:00
|
|
|
input logic [`XLEN-1:0] InstrPAdrF, // *** rename these to match block diagram
|
2021-01-30 06:43:49 +00:00
|
|
|
input logic IReadF,
|
2021-01-29 06:07:17 +00:00
|
|
|
output logic [`XLEN-1:0] IRData,
|
2021-01-30 06:43:49 +00:00
|
|
|
// output logic IReady,
|
2021-01-29 06:07:17 +00:00
|
|
|
// Signals from Data Cache
|
2021-02-02 20:09:24 +00:00
|
|
|
input logic [`XLEN-1:0] MemPAdrM,
|
2021-01-29 06:07:17 +00:00
|
|
|
input logic DReadM, DWriteM,
|
2021-02-02 20:09:24 +00:00
|
|
|
input logic [`XLEN-1:0] WriteDataM,
|
2021-01-29 06:07:17 +00:00
|
|
|
input logic [1:0] DSizeM,
|
2021-01-30 06:57:51 +00:00
|
|
|
// Return from bus
|
2021-01-29 06:07:17 +00:00
|
|
|
output logic [`XLEN-1:0] DRData,
|
2021-01-30 06:43:49 +00:00
|
|
|
// output logic DReady,
|
2021-01-29 06:07:17 +00:00
|
|
|
// AHB-Lite external signals
|
|
|
|
input logic [`AHBW-1:0] HRDATA,
|
|
|
|
input logic HREADY, HRESP,
|
2021-01-30 05:56:12 +00:00
|
|
|
output logic HCLK, HRESETn,
|
|
|
|
output logic [31:0] HADDR,
|
2021-01-29 06:07:17 +00:00
|
|
|
output logic [`AHBW-1:0] HWDATA,
|
2021-01-30 05:56:12 +00:00
|
|
|
output logic HWRITE,
|
2021-01-29 06:07:17 +00:00
|
|
|
output logic [2:0] HSIZE,
|
|
|
|
output logic [2:0] HBURST,
|
|
|
|
output logic [3:0] HPROT,
|
|
|
|
output logic [1:0] HTRANS,
|
2021-01-30 06:43:49 +00:00
|
|
|
output logic HMASTLOCK,
|
2021-02-02 20:09:24 +00:00
|
|
|
// Acknowledge
|
|
|
|
output logic InstrAckD, MemAckW
|
2021-01-30 06:43:49 +00:00
|
|
|
// Stalls
|
2021-02-02 20:09:24 +00:00
|
|
|
// output logic InstrStall, DataStall
|
2021-01-29 06:07:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
logic GrantData;
|
|
|
|
logic [2:0] ISize;
|
2021-01-30 04:43:48 +00:00
|
|
|
logic [`AHBW-1:0] HRDATAMasked;
|
2021-01-30 06:43:49 +00:00
|
|
|
logic IReady, DReady;
|
2021-01-29 06:07:17 +00:00
|
|
|
|
|
|
|
assign HCLK = clk;
|
|
|
|
assign HRESETn = ~reset;
|
|
|
|
|
|
|
|
// Arbitrate requests by giving data priority over instructions
|
|
|
|
assign GrantData = DReadM | DWriteM;
|
|
|
|
|
|
|
|
// *** initially support HABW = XLEN
|
|
|
|
|
|
|
|
// Choose ISize based on XLen
|
|
|
|
generate
|
|
|
|
if (`AHBW == 32) assign ISize = 3'b010; // 32-bit transfers
|
|
|
|
else assign ISize = 3'b011; // 64-bit transfers
|
|
|
|
endgenerate
|
|
|
|
|
|
|
|
// drive bus outputs
|
2021-02-02 20:09:24 +00:00
|
|
|
assign HADDR = GrantData ? MemPAdrM[31:0] : InstrPAdrF[31:0];
|
|
|
|
assign HWDATA = WriteDataM;
|
2021-01-30 04:43:48 +00:00
|
|
|
//flop #(`XLEN) wdreg(HCLK, DWDataM, HWDATA); // delay HWDATA by 1 cycle per spec; *** assumes AHBW = XLEN
|
2021-01-30 05:56:12 +00:00
|
|
|
assign HWRITE = DWriteM;
|
2021-01-29 06:07:17 +00:00
|
|
|
assign HSIZE = GrantData ? {1'b0, DSizeM} : ISize;
|
|
|
|
assign HBURST = 3'b000; // Single burst only supported; consider generalizing for cache fillsfHPROT
|
|
|
|
assign HPROT = 4'b0011; // not used; see Section 3.7
|
2021-01-30 06:43:49 +00:00
|
|
|
assign HTRANS = IReadF | DReadM | DWriteM ? 2'b10 : 2'b00; // NONSEQ if reading or writing, IDLE otherwise
|
2021-01-29 06:07:17 +00:00
|
|
|
assign HMASTLOCK = 0; // no locking supported
|
|
|
|
|
|
|
|
// Route signals to Instruction and Data Caches
|
|
|
|
// *** assumes AHBW = XLEN
|
2021-01-30 04:43:48 +00:00
|
|
|
assign IRData = HRDATAMasked;
|
2021-01-30 06:43:49 +00:00
|
|
|
assign IReady = HREADY & IReadF & ~GrantData; // maybe unused?***
|
2021-01-30 04:43:48 +00:00
|
|
|
assign DRData = HRDATAMasked;
|
2021-01-30 06:43:49 +00:00
|
|
|
assign DReady = HREADY & GrantData; // ***unused?
|
|
|
|
|
|
|
|
// stalls
|
|
|
|
// Stall MEM stage if data is being accessed and bus isn't yet ready
|
2021-02-02 20:09:24 +00:00
|
|
|
//assign DataStall = GrantData & ~HREADY;
|
2021-01-30 06:43:49 +00:00
|
|
|
// Stall Fetch stage if instruction should be read but reading data or bus isn't ready
|
2021-02-02 20:09:24 +00:00
|
|
|
//assign InstrStall = IReadF & (GrantData | ~HREADY);
|
2021-01-29 06:07:17 +00:00
|
|
|
|
|
|
|
// *** consider adding memory access faults based on HRESP being high
|
|
|
|
// InstrAccessFaultF, DataAccessFaultM,
|
|
|
|
|
2021-01-30 04:43:48 +00:00
|
|
|
subwordread swr(.*);
|
|
|
|
|
2021-01-29 06:07:17 +00:00
|
|
|
endmodule
|
|
|
|
|