1+ import argparse
2+ import os .path
3+ import os
4+
5+ # parser = argparse.ArgumentParser(description='Convert Binary to MIF.')
6+ # parser.add_argument('input', help='Input bin file')
7+
8+ # args = parser.parse_args()
9+
10+ input_path = r"/mnt/c/Users/gusta/OneDrive/Arquivos da Faculdade/2017 - 1/Lab de AOC/Repositório/Verilogs/ExternalMemory/"
11+
12+ quartus_proj_path = r"/mnt/c/Users/gusta/OneDrive/Arquivos da Faculdade/2017 - 1/Lab de AOC/Quartus/"
13+
14+ proj_name = "ARMAria.qpf"
15+
16+ islinux = True
17+
18+ if ( not os .path .exists (input_path ) ):
19+ islinux = False
20+ quartus_proj_path = r"C:\Users\gusta\OneDrive\Arquivos da Faculdade\2017 - 1\Lab de AOC\Quartus" + "\\ "
21+ input_path = r"C:\Users\gusta\OneDrive\Arquivos da Faculdade\2017 - 1\Lab de AOC\Repositório\Verilogs\ExternalMemory" + "\\ "
22+
23+ output_path = quartus_proj_path + "db/"
24+
25+ output_file = output_path + "ARMAria.ram0_Memory_a0c6519c.hdl.mif"
26+
27+ input_file = input_path + "ProgramaMIF.txt"
28+
29+ quartus_proj = quartus_proj_path + proj_name
30+
31+ file_content = '''-- begin_signature
32+ -- Memory
33+ -- end_signature
34+ WIDTH=32;
35+ DEPTH=16384;
36+
37+ ADDRESS_RADIX=UNS;
38+ DATA_RADIX=BIN;
39+
40+ CONTENT BEGIN
41+ '''
42+
43+ file_end = "END;"
44+
45+ instructions = []
46+ with open (input_file , 'r' ) as inputFile :
47+ for line in inputFile :
48+ instructions .append ("0000000000000000{}" .format (line [:16 ]))
49+
50+ print ("loaded {} instructions" .format (len (instructions )))
51+
52+ for i in range (0 , 16384 - len (instructions )):
53+ file_content += "\t {} : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX;\n " .format (16383 - i )
54+
55+ for i , inst in enumerate (instructions [::- 1 ]):
56+ file_content += "\t {} : {};\n " .format (len (instructions ) - i - 1 , inst )
57+
58+
59+ file_content += file_end
60+
61+ with open (output_file , 'w' ) as output :
62+ output .write (file_content )
63+
64+ if not islinux :
65+ os .system ("quartus_cdb.exe --update_mif \" {}\" " .format (quartus_proj ))
66+ os .system ("quartus_asm.exe \" %s\" " % quartus_proj )
0 commit comments