generated from chipsalliance/chisel-template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TL-UH implementation added via LFX Mentorship by RISC-V
Add logics for Atomic Operation and Burst Messages. All tests passing.
- Loading branch information
Showing
14 changed files
with
1,304 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// SPDX-FileCopyrightText: 2020 fabless Corporation | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//`default_nettype none | ||
// OpenRAM SRAM model | ||
// Words: 256 | ||
// Word size: 32 | ||
// Write size: 8 | ||
|
||
module sram #( | ||
parameter NUM_WMASKS = 4, | ||
parameter DATA_WIDTH = 32, | ||
parameter ADDR_WIDTH = 13, | ||
parameter RAM_DEPTH = 1 << ADDR_WIDTH, | ||
// FIXME: This delay is arbitrary. | ||
parameter DELAY = 3, | ||
parameter IZERO = 0 , // binary / Initial RAM with zeros (has priority over INITFILE) | ||
parameter IFILE = "" | ||
) | ||
( | ||
/*`ifdef USE_POWER_PINS | ||
vdd, | ||
gnd, | ||
`endif */ | ||
// Port 0: RW | ||
clk0,csb0,web0,wmask0,addr0,din0,dout0, | ||
// Port 1: R | ||
clk1,csb1,addr1,dout1 | ||
); | ||
|
||
|
||
/*`ifdef USE_POWER_PINS | ||
inout vdd; | ||
inout gnd; | ||
`endif | ||
*/ | ||
input clk0; // clock | ||
input csb0; // active low chip select | ||
input web0; // active low write control | ||
input [NUM_WMASKS-1:0] wmask0; // write mask | ||
input [ADDR_WIDTH-1:0] addr0; | ||
input [DATA_WIDTH-1:0] din0; | ||
output [DATA_WIDTH-1:0] dout0; | ||
input clk1; // clock | ||
input csb1; // active low chip select | ||
input [ADDR_WIDTH-1:0] addr1; | ||
output [DATA_WIDTH-1:0] dout1; | ||
|
||
reg csb0_reg; | ||
reg web0_reg; | ||
reg [NUM_WMASKS-1:0] wmask0_reg; | ||
reg [ADDR_WIDTH-1:0] addr0_reg; | ||
reg [DATA_WIDTH-1:0] din0_reg; | ||
reg [DATA_WIDTH-1:0] dout0; | ||
|
||
// All inputs are registers | ||
always @(posedge clk0) | ||
begin | ||
csb0_reg = csb0; | ||
web0_reg = web0; | ||
wmask0_reg = wmask0; | ||
addr0_reg = addr0; | ||
din0_reg = din0; | ||
//dout0 = 32'bx0; | ||
/*`ifdef DBG | ||
if ( !csb0_reg && web0_reg ) | ||
$display($time," Reading %m addr0=%b dout0=%b",addr0_reg,mem[addr0_reg]); | ||
if ( !csb0_reg && !web0_reg ) | ||
$display($time," Writing %m addr0=%b din0=%b wmask0=%b",addr0_reg,din0_reg,wmask0_reg); | ||
`endif | ||
*/ end | ||
|
||
reg csb1_reg; | ||
reg [ADDR_WIDTH-1:0] addr1_reg; | ||
reg [DATA_WIDTH-1:0] dout1; | ||
|
||
// All inputs are registers | ||
always @(posedge clk1) | ||
begin | ||
csb1_reg = csb1; | ||
addr1_reg = addr1; | ||
//`ifdef DBG | ||
// if (!csb0 && !web0 && !csb1 && (addr0 == addr1)) | ||
// $display($time," WARNING: Writing and reading addr0=%b and addr1=%b simultaneously!",addr0,addr1); | ||
// dout1 = 32'bx; | ||
// if ( !csb1_reg ) | ||
// $display($time," Reading %m addr1=%b dout1=%b",addr1_reg,mem[addr1_reg]); | ||
//`endif | ||
end | ||
integer i; | ||
reg [DATA_WIDTH-1:0] mem [0:RAM_DEPTH-1]; | ||
initial | ||
if (IZERO) | ||
for (i=0; i<RAM_DEPTH; i=i+1) mem[i] = {DATA_WIDTH{1'b0}}; | ||
else | ||
if (IFILE != "") $readmemh(IFILE, mem); | ||
|
||
// Memory Write Block Port 0 | ||
// Write Operation : When web0 = 0, csb0 = 0 | ||
always @ (negedge clk0) | ||
begin : MEM_WRITE0 | ||
if ( !csb0_reg && !web0_reg ) begin | ||
if (wmask0_reg[0]) | ||
mem[addr0_reg][7:0] = din0_reg[7:0]; | ||
if (wmask0_reg[1]) | ||
mem[addr0_reg][15:8] = din0_reg[15:8]; | ||
if (wmask0_reg[2]) | ||
mem[addr0_reg][23:16] = din0_reg[23:16]; | ||
if (wmask0_reg[3]) | ||
mem[addr0_reg][31:24] = din0_reg[31:24]; | ||
end | ||
end | ||
|
||
// Memory Read Block Port 0 | ||
// Read Operation : When web0 = 1, csb0 = 0 | ||
always @ (negedge clk0) | ||
begin : MEM_READ0 | ||
if (!csb0_reg && web0_reg) | ||
dout0 <= #(DELAY) mem[addr0_reg]; | ||
end | ||
|
||
// Memory Read Block Port 1 | ||
// Read Operation : When web1 = 1, csb1 = 0/ | ||
always @ (negedge clk1) | ||
begin : MEM_READ1 | ||
if (!csb1_reg) | ||
dout1 <= #(DELAY) mem[addr1_reg]; | ||
end | ||
|
||
endmodule | ||
//`default_nettype wire | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
module sram_top #( | ||
parameter IFILE_IN = "" | ||
) | ||
( | ||
input logic clk_i, | ||
input logic rst_i, | ||
|
||
// sram interface in | ||
input logic csb_i, | ||
input logic [12:0] addr_i, | ||
input logic [31:0] wdata_i, | ||
input logic [3:0] wmask_i, | ||
input logic we_i, | ||
output logic [31:0] rdata_o | ||
|
||
); | ||
|
||
logic csb; | ||
logic [12:0] addr_o; | ||
logic [31:0] wdata_o; | ||
logic [3:0] wmask_o; | ||
logic we_o; | ||
logic [31:0] rdata_i; | ||
|
||
logic rvalid; | ||
|
||
always_ff @(negedge clk_i) begin | ||
if(rst_i) begin | ||
csb <= '1; | ||
addr_o <= '0; | ||
wdata_o <= '0; | ||
wmask_o <= '0; | ||
we_o <= '1; | ||
end else begin | ||
csb <= csb_i; | ||
addr_o <= addr_i; | ||
wdata_o <= wdata_i; | ||
wmask_o <= wmask_i; | ||
we_o <= we_i; | ||
end | ||
end | ||
|
||
sram #( | ||
.NUM_WMASKS (4), | ||
.DATA_WIDTH (32), | ||
.ADDR_WIDTH (13), | ||
.RAM_DEPTH (1 << 13), | ||
// FIXME: This delay is arbitrary. | ||
.DELAY (3), | ||
.IZERO (0) , // binary / Initial RAM with zeros (has priority over INITFILE) | ||
.IFILE (IFILE_IN) | ||
) memory ( | ||
/*`ifdef USE_POWER_PINS | ||
.vdd, | ||
.gnd, | ||
`endif */ | ||
.clk0(clk_i), | ||
.csb0(csb_i), | ||
.web0(we_i), | ||
.wmask0(wmask_i), | ||
.addr0(addr_i), | ||
.din0(wdata_i), | ||
.dout0(rdata_o), | ||
.clk1('0), | ||
.csb1('1), | ||
.addr1('0), | ||
.dout1() | ||
); | ||
|
||
always_ff @(posedge clk_i or posedge rst_i) begin | ||
if (rst_i) begin | ||
rvalid <= 1'b0; | ||
end else if (!we_i) begin | ||
rvalid <= 1'b0; | ||
end else if(!csb_i && we_i) begin | ||
rvalid <= 1'b1; | ||
end | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package caravan.bus.tilelink | ||
|
||
import chisel3._ | ||
|
||
/** | ||
* This abstract class provides a template for other protocols to implement the transaction wires. | ||
* This is used as a template for e.g when the core wants to communicate with the memory or with the peripheral registers. | ||
* It will set these signals up in order to talk to the Host adapter of the relevant bus protocol | ||
*/ | ||
class MemRequestIO(implicit val config: TilelinkConfig) extends Bundle { | ||
val addrRequest: UInt = Input(UInt(32.W)) | ||
val dataRequest: UInt = Input(UInt(32.W)) | ||
val activeByteLane: UInt = Input(UInt(4.W)) | ||
val isWrite: Bool = Input(Bool()) | ||
val isArithmetic = if(config.uh) Some(Bool()) else None | ||
val isLogical = if(config.uh) Some(Bool()) else None | ||
val isIntent = if(config.uh) Some(Bool()) else None | ||
val param = if(config.uh) Some(UInt(3.W)) else None | ||
val size = if (config.uh) Some(UInt(config.z.W)) else None | ||
|
||
} | ||
|
||
class MemResponseIO(implicit val config: TilelinkConfig) extends Bundle { | ||
val dataResponse: UInt = Input(UInt((config.w * 8).W)) | ||
val error : Bool = Bool() | ||
} |
Oops, something went wrong.