Skip to content

Instantly share code, notes, and snippets.

@cfelton
Created March 9, 2018 11:56
Show Gist options
  • Save cfelton/d224a03a37e7c0aab6c27496c52422cb to your computer and use it in GitHub Desktop.
Save cfelton/d224a03a37e7c0aab6c27496c52422cb to your computer and use it in GitHub Desktop.
initial value support conversion error
import myhdl as hdl
from myhdl import Signal, ResetSignal, intbv, always_seq
@hdl.block
def test_mem_ivs_convert(clock, reset, wr, wrd, rdd, addr):
return memory(clock, reset, wr, wrd, rdd, addr)
@hdl.block
def memory(clock, reset, wr, wrd, rdd, addr):
mem = [Signal(intbv(0, min=wrd.min, max=wrd.max))
for _ in range(addr.max)]
@always_seq(clock.posedge, reset=reset)
def beh_mem():
rdd.next = mem[addr]
if wr:
mem[addr].next = wrd
return beh_mem
memory.verilog_code = """
initial begin
$mem = $$readmem("initial_values.mem");
end
"""
clock = Signal(bool(0))
reset = ResetSignal(0, active=0, async=True)
wr = Signal(bool(0))
wrd = Signal(intbv(0, min=0, max=32))
rdd = Signal(intbv(0, min=0, max=32))
addr = Signal(intbv(0, min=0, max=16))
inst = test_mem_ivs_convert(clock, reset, wr, wrd, rdd, addr)
inst.convert()
// File: test_mem_ivs_convert.v
// Generated by MyHDL 1.0dev
// Date: Fri Mar 9 05:54:45 2018
`timescale 1ns/10ps
module test_mem_ivs_convert (
clock,
reset,
wr,
wrd,
rdd,
addr
);
input clock;
input reset;
input wr;
input [4:0] wrd;
input [4:0] rdd;
input [3:0] addr;
initial begin
[Signal(intbv(0)), Signal(intbv(0)), Signal(intbv(0)), Signal(intbv(0)), Signal(intbv(0)), Signal(intbv(0)), Signal(intbv(0)), Signal(intbv(0)), Signal(intbv(0)), Signal(intbv(0)), Signal(intbv(0)), Signal(intbv(0)), Signal(intbv(0)), Signal(intbv(0)), Signal(intbv(0)), Signal(intbv(0))] = $readmem("initial_values.mem");
end
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment