aboutsummaryrefslogtreecommitdiff
path: root/check_inst_eeprom.py
blob: c70a320ae8069629a8c165783fc2605f120c3c9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
## check afterwards if everything is written out correctly

import eeprom_pi as ep

import inst

## for cmd line args access
import sys

## checks the actual content of the EEPROM against the should have one
def check_micro_inst(address, instruction):
	data = ep.read_data_at(address)
	ctl_word_half = 0x00
	if eeprom_n == 1:
		ctl_word_half = instruction & 0xff
	elif eeprom_n == 2:
		ctl_word_half = (instruction >> 8) & 0xff

	print("data type: %s, content: %s" % (type(data), hex(data)))
	print("ctl_word_half type: %s, contet: %s" % (type(ctl_word_half), 
			hex(ctl_word_half)))

	if(data != ctl_word_half):
		print("error at address %s: %s, should be: %s" % (hex(address), 
				hex(data), hex(ctl_word_half)))



## look for cmd line parameter to known which EEPROM we write to currently
if(len(sys.argv) != 2):
	print("usage: %s <number eeprom>" % sys.argv[0])
	print("please specify the eeprom you want to check.")
	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("checking eeprom %s" % eeprom_n)

## setup board in read mode
ep.init_board(False)

raw_input("plug EEPROM in and continue with any key...")


## for every instruction
nr_inst = 1
for instruction_data in inst.INST:
	print("checking 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:
		check_micro_inst(base_address+n, fi_mop)
		n += 1

	for mop in mops:
		check_micro_inst(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:
		check_micro_inst(base_address+n, 0x0000)
		n += 1

	print("------------")


	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:
	check_micro_inst(base_address+n, fi_mop)
	n += 1

## write NULLs
while n < inst.MAX_MICRO_OPS:
	check_micro_inst(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*2:
	check_micro_inst(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()