gateware

A collection of little open source FPGA hobby projects
git clone http://frotz.net/git/gateware.git
Log | Files | Refs | README

simram.sv (937B)


      1 // Copyright 2015, Brian Swetland <swetland@frotz.net>
      2 // Licensed under the Apache License, Version 2.0.
      3 
      4 `default_nettype none
      5 
      6 `timescale 1ns / 1ps
      7 
      8 import "DPI-C" function void dpi_mem_write(int addr, int data);
      9 import "DPI-C" function void dpi_mem_read(int addr, output int data);
     10 
     11 module simram(
     12 	input clk,
     13 	input [15:0]waddr,
     14 	input [15:0]wdata,
     15 	input we,
     16 	input [15:0]raddr,
     17 	output reg [15:0]rdata,
     18 	input re
     19 	);
     20 
     21 	wire [31:0]rawdata;
     22 	wire [31:0]junk;
     23 
     24 	// hack: this should be posedge but if we do that
     25 	// then the dpi_mem_write() happens too early
     26 	always @(negedge clk) begin
     27 		if (we) begin
     28 			$display(":WRI %08x %08x", waddr, wdata);
     29 			dpi_mem_write({16'd0, waddr}, {16'd0, wdata});
     30 		end
     31 	end
     32 	always @(posedge clk) begin
     33 		if (re) begin
     34 			dpi_mem_read({16'd0, raddr}, rawdata);
     35 			rdata <= rawdata[15:0];
     36 		end else begin
     37 			//junk = $random();
     38 			//rdata <= junk[15:0];
     39 			rdata <= 16'hEEEE;
     40 		end
     41 	end
     42 endmodule