## This file writes the in inst.py defined instruction to the AT28C EEPROM ## conntected to a raspberry pi via GPIO pins import inst import eeprom_pi as ep ## for cmd line args access import sys ## given an address and an instruction this writes corredsponding bytes to the ## EEPROM def write_micro_inst_out(address, instruction): ctl_word_half = 0x00 if eeprom_n == 1: ctl_word_half = instruction & 0xff elif eeprom_n == 2: ctl_word_half = (instruction >> 8) & 0xff print("%s: %s (%s)" % (hex(address), hex(ctl_word_half), hex(instruction))) ep.write_data_at(address, ctl_word_half) ## look for cmd line parameter to known which EEPROM we write to currently if(len(sys.argv) != 2): print("usage: %s " % sys.argv[0]) print("please specify the eeprom you want to write to.") exit() eeprom_n = int(sys.argv[1]) if not (eeprom_n == 1 or eeprom_n == 2): print("error: only two eeproms supported right now") exit() print("writing eeprom %s" % eeprom_n) ## setup board ep.init_board() ## for every instruction nr_inst = 1 for instruction_data in inst.INST: print("writing instruction %s" % nr_inst) base_address = instruction_data[0] mops = instruction_data[1] n = 0 # write fetch instruction micro ops for every instruction for fi_mop in inst.INST_MICRO_OP_FETCH_INSTRUCTION: write_micro_inst_out(base_address+n, fi_mop) n += 1 print("------------") for mop in mops: write_micro_inst_out(base_address+n, mop) n += 1 ## insert 0x00 for not used micro instuctions, so all control signals 0 ## and the pc is not doing some unwanted stuff while n < inst.MAX_MICRO_OPS: write_micro_inst_out(base_address+n, 0x0000) n += 1 nr_inst += 1 ## write a fetch instruction at address 0x0, so that after a reset we are ## fetching the first instruction print("\n") print("writing inst fetch instruction at address 0x0, so we begin executing" "after reset:") n = 0 base_address = 0x0 for fi_mop in inst.INST_MICRO_OP_FETCH_INSTRUCTION: write_micro_inst_out(base_address+n, fi_mop) n += 1 ## write NULLs while n < inst.MAX_MICRO_OPS: write_micro_inst_out(base_address+n, 0x0000) n += 1 ## write HLT instruction aka, everything 0x00, no new instruction fetch cycle n = 0 base_address = inst.INST_HLT while n < inst.MAX_MICRO_OPS: write_micro_inst_out(base_address+n, 0x0000) n += 1 trash = raw_input("please unplug the power to the EEPORM now and press any key to continue...") ep.cleanup()