Skip to content

Commit c6d4f60

Browse files
committed
Updated mem_writer scripts and example output
1 parent 322fa85 commit c6d4f60

39 files changed

+150974
-427
lines changed

scripts/mem_writer.sh

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
# mem_writer.sh
4+
# published as part of https://github.com/pConst/basic_verilog
5+
# Konstantin Pavlov, [email protected]
6+
#
7+
# generates a bunch of .mem files to test block memory initialization
8+
#
9+
# see also for "./scripts/mem_writer_adv.py" for advanced
10+
# functional memory file generator
11+
12+
13+
# linear file contents =========================================================
14+
# looping file len
15+
for l in 16 32 64 128 256 512 1024 2048 4096 65536
16+
do
17+
# looping element width, in bits
18+
for w in 8 16 32
19+
do
20+
# calculating padded hex string width
21+
ws=$((w/8))
22+
# skipping erroneous widths
23+
if (( l <= 16 ** ${ws} )); then
24+
rm -rf ${l}x${w}bit_linear.mem
25+
# generating strings to the file
26+
for (( s=0; s <= ${l}-1; s++ ))
27+
do
28+
printf "%0${ws}X\n" ${s} >> ${l}x${w}bit_linear.mem
29+
done
30+
fi
31+
done
32+
done
33+
34+
35+
# ramdom file contents =========================================================
36+
# looping file len
37+
for l in 16 32 64 128 256 512 1024 2048 4096 65536
38+
do
39+
# looping element width, in bits
40+
for w in 8 16 32
41+
do
42+
# calculating padded hex string width
43+
ws=$((w/8))
44+
# skipping erroneous widths
45+
if (( l <= 16 ** ${ws} )); then
46+
rm -rf ${l}x${w}bit_random.mem
47+
# generating strings to the file
48+
for (( s=0; s <= ${l}-1; s++ ))
49+
do
50+
printf "%0${ws}X\n" $(($RANDOM % (2 ** ${w}) )) >> ${l}x${w}bit_random.mem
51+
done
52+
fi
53+
done
54+
done
55+
56+
printf "DONE\n"
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
#!/usr/bin/env python
2-
# coding: utf-8
3-
4-
# author: Konstantin Pavlov
5-
6-
7-
# boilerplate script to generate ASCII hex files to initialize RAMs in Verilog
8-
9-
import math
10-
import os
11-
12-
# settings =====================================================================
13-
N = 128
14-
tablename = "sin"
15-
filename = tablename + ".hex"
16-
17-
# main =========================================================================
18-
if os.path.exists(filename):
19-
os.remove(filename)
20-
print("Old file version removed")
21-
22-
f = open(filename, "x")
23-
f.write("// ascii hex file for " + tablename + " function\n\n")
24-
25-
for i in range(0, N):
26-
# computing and scaling
27-
rad = math.pi/4/N*i
28-
val = math.floor(math.sin(rad) * 256)
29-
# formatting to HEX string of specified length
30-
val_str = format(val, "#06x")
31-
# additional prefix
32-
prefix_str = format(i, "#04x")
33-
# cutting '0x' prefix away
34-
f.write(prefix_str[2:] + "_" + val_str[2:] + "\n")
35-
36-
f.close()
37-
1+
#!/usr/bin/env python
2+
# coding: utf-8
3+
4+
# author: Konstantin Pavlov
5+
# published as part of https://github.com/pConst/basic_verilog
6+
7+
8+
# boilerplate script to generate ASCII hex files to initialize RAMs in Verilog
9+
10+
import math
11+
import os
12+
13+
# settings =====================================================================
14+
N = 1024
15+
tablename = "1024sin"
16+
filename = tablename + ".mem"
17+
18+
# main =========================================================================
19+
if os.path.exists(filename):
20+
os.remove(filename)
21+
print("Old file version removed")
22+
23+
f = open(filename, "x")
24+
#f.write("// ascii hex file for " + tablename + " function\n\n")
25+
26+
for i in range(0, N):
27+
# computing and scaling
28+
rad = math.pi/4/N*i
29+
val = round(math.sin(rad) * 65535)
30+
# formatting to HEX string of specified length
31+
val_str = format(val, "#06x")
32+
# additional prefix
33+
prefix_str = format(i, "#06x")
34+
# cutting '0x' prefix away
35+
f.write(prefix_str[2:] + "_" + val_str[2:] + "\n")
36+
37+
f.close()
38+

0 commit comments

Comments
 (0)