Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ROMDualPort's Verilog export template #1218

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/de/neemann/digital/hdl/hgs/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ public void setVar(String name, Object val) throws HGSEvalException {
if (v != null) {
if (v.getClass().isAssignableFrom(val.getClass()))
map.put(name, val);
else if (v instanceof Integer && val instanceof Long)
map.put(name, Math.toIntExact((Long) val));
else
throw new HGSEvalException("Variable '" + name + "' has wrong type. Needs to be "
+ v.getClass().getSimpleName() + ", is " + val.getClass().getSimpleName());
Expand Down
11 changes: 9 additions & 2 deletions src/main/resources/verilog/DIG_ROM.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
data=loadHex(elem.lastDataFile, elem.Bits);
}
romSize := sizeOf(data);
if (romSize = 0) {
romSize = 1;
}
moduleName = format("%s_%dX%d_%s", moduleName, romMaxSize, elem.Bits, identifier(elem.Label));
dBitRange := format("[%d:0]", elem.Bits - 1);
aBitRange := format("[%d:0]", elem.AddrBits - 1);
Expand All @@ -32,9 +35,13 @@
end

initial begin<?

for (i := 0; i < romSize; i++) { ?>
if( sizeOf(data) = 0) { ?>
my_rom[0]=0;<?
}
else {
for (i := 0; i < romSize; i++) { ?>
my_rom[<?= i ?>] = <?= format("%d'h%x", elem.Bits, data[i]) ?>;<?
}
} ?>
end
endmodule
62 changes: 62 additions & 0 deletions src/main/resources/verilog/DIG_ROMDualPort.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?
if (elem.Label="")
panic("err_romNeedsALabelToBeExported");

romMaxSize := 1 << elem.AddrBits;
data:=elem.Data;
if (elem.autoReload) {
data=loadHex(elem.lastDataFile, elem.Bits);
}
romSize := sizeOf(data);
if (romSize = 0) {
romSize = 1;
}
moduleName = format("%s_%dX%d_%s", moduleName, romMaxSize, elem.Bits, identifier(elem.Label));
dBitRange := format("[%d:0]", elem.Bits - 1);
aBitRange := format("[%d:0]", elem.AddrBits - 1);

?>module <?= moduleName ?> (
input <?= aBitRange ?> A1,
input <?= aBitRange ?> A2,
input s1,
input s2,
output reg <?= dBitRange ?> D1,
output reg <?= dBitRange ?> D2
);
reg <?= dBitRange ?> my_rom [0:<?= (romSize - 1) ?>];

always @ (*) begin
if (~s1)
D1 = <?= elem.Bits ?>'hz;<?
if (romSize < romMaxSize) {
lastAddr := format("%d'h%x", elem.AddrBits, romSize - 1); ?>
else if (A1 > <?= lastAddr ?>)
D1 = <?= elem.Bits ?>'h0;<?
} ?>
else
D1 = my_rom[A1];
end

always @ (*) begin
if (~s2)
D2 = <?= elem.Bits ?>'hz;<?
if (romSize < romMaxSize) {
lastAddr := format("%d'h%x", elem.AddrBits, romSize - 1); ?>
else if (A2 > <?= lastAddr ?>)
D2 = <?= elem.Bits ?>'h0;<?
} ?>
else
D2 = my_rom[A2];
end

initial begin<?
if( sizeOf(data) = 0) { ?>
my_rom[0]=0;<?
}
else {
for (i := 0; i < romSize; i++) { ?>
my_rom[<?= i ?>] = <?= format("%d'h%x", elem.Bits, data[i]) ?>;<?
}
} ?>
end
endmodule