Created
December 9, 2017 12:16
-
-
Save rafaelcorsi/888681614174a7c3da1b7f7799c126a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rafael Corsi @ insper.edu.br | |
# Dez/2017 | |
# Disciplina Elementos de Sistemas | |
# | |
# Convert program memmory to altera mif file | |
# that can be used to load FPGA and to Simulate (modelsim) | |
# http://quartushelp.altera.com/13.0/mergedProjects/reference/glossary/def_mif.htm | |
# | |
# TODO: | |
import os | |
import argparse | |
TAB = " " | |
END = "\n" | |
def toMIF(mem, mif): | |
cnt = 0 | |
try : | |
fw = open(mif,"w") | |
fr = open(mem,"r") | |
fw.write("-- Elementos de Sistema - INSPER.edu.br"+END) | |
fw.write("-- Rafael Corsi"+END) | |
fw.write("-- File generated by toMIF.py"+END) | |
fw.write("-- originated from"+mem+""+END) | |
fw.write("-- to be used on ALTERA FPGAs\r\n"+END) | |
fw.write("WIDTH=16;"+END) | |
fw.write("DEPTH=30;"+END) | |
fw.write(""+END) | |
fw.write("ADDRESS_RADIX=UNS;"+END) | |
fw.write("DATA_RADIX=BIN;"+END) | |
fw.write(""+END) | |
fw.write("CONTENT BEGIN"+END) | |
for line in fr: | |
fw.write( TAB | |
+ '{:4d}'.format(cnt) | |
+" : " | |
+line.rstrip() | |
+";" | |
+""+END) | |
cnt = cnt + 1 | |
# colocar for aqui | |
fw.write("END;"+END) | |
fw.close() | |
fr.close() | |
except IOError: | |
print("Arquivo não encontrado") | |
if __name__ == "__main__": | |
ap = argparse.ArgumentParser() | |
ap.add_argument("-i", "--in_mem_mif" , required=True, help="arquivo de entrada memoria") | |
ap.add_argument("-o", "--out_mif" , required=True, help="arquivo de saida mif para Altera") | |
args = vars(ap.parse_args()) | |
root = os.getcwd() | |
toMIF(mem=args["in_mem_mif"], mif=args["out_mif"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OutPut file