summaryrefslogtreecommitdiffstats
path: root/chip_atmega8dip28.py
blob: 338ad2f86f12f9d1aadf4693130c7040922ca84e (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
"""
#    TOP2049 Open Source programming suite
#
#    Atmel Mega8 DIP28 support
#
#    Copyright (c) 2009-2010 Michael Buesch <mb@bu3sch.de>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""

from chip import *
import time


class ATMega8DIP28(Chip):
	def __init__(self):
		Chip.__init__(self, "atmega8dip28")

	def initializeChip(self):
		self.top.cmdSetGNDPin(18)
		self.top.cmdSetVCCXVoltage(5)
		self.top.cmdFlush()
		self.top.cmdSetVPPVoltage(0)
		self.top.cmdFlush()
		self.top.cmdSetVPPVoltage(12)

	def readImage(self):
		# First check if the chip is properly inserted
		self.top.blockCommands()
		self.top.cmdFlush()
		self.top.send("\x0A\x1D\x86")
		self.top.unblockCommands()

		self.top.cmdSetGNDPin(0)
		self.top.cmdLoadVPPLayout(0)
		self.top.cmdLoadVCCXLayout(0)

		self.top.blockCommands()
		self.top.cmdFlush(2)
		self.top.send("\x0A\x1B\xFF")
		self.top.unblockCommands()

		self.top.send("\x0E\x28\x00\x00")
		self.top.cmdSetVPPVoltage(0)
		self.top.cmdFlush()
		self.top.cmdSetVPPVoltage(5)
		self.top.cmdFlush(21)
		self.top.cmdLoadVPPLayout(14)
		self.top.send("\x1B\x1B\x0B\x16\x0B\x17\x0B\x18\x0B\x19\x0B\x1A\x0B\x1B\x07")
		stat = self.top.cmdReadStatusReg32()
		if stat != 0xFFFFFFC0:
			self.throwError("Did not detect chip. Please check connections.")

		self.top.cmdLoadVPPLayout(0)
		self.top.cmdLoadVCCXLayout(0)
		self.top.cmdFlush()
		self.top.send("\x0E\x28\x01\x00")
		self.top.send("\x0A\x1B\x00")
		self.top.cmdSetVPPVoltage(0)
		self.top.cmdFlush()
		self.top.cmdSetVPPVoltage(12)
		self.top.cmdFlush()
		self.top.cmdSetGNDPin(18)
		self.top.cmdFlush()
		self.top.cmdSetVCCXVoltage(4.4)
		self.top.cmdFlush()
		self.top.send("\x0A\x12\x05\x0A\x12\x06\x0A\x12\x04\x0A\x12\x03")
		self.top.cmdSetGNDPin(18)
		self.top.cmdLoadVCCXLayout(13)
		self.top.send("\x1B\x19\x0A\x12\x01\x34\x0A\x12\x01\x0A\x12\x02\x0A\x12\x83\x0A" +\
			      "\x12\x07\x0A\x12\x05\x0A\x12\x06\x0A\x12\x08\x0A\x12\x04\x0A\x12" +\
			      "\x0A\x0A\x12\x09\x0A\x12\x87\x0A\x12\x07\x0A\x12\x87\x0A\x12\x07" +\
			      "\x0A\x12\x87\x0A\x12\x07\x0A\x12\x87\x0A\x12\x07\x0A\x12\x87\x00")
		self.top.send("\x0A\x12\x07\x0A\x12\x87\x0A\x12\x07\x0A\x12\x87\x0A\x12\x07\x0A" +\
			      "\x12\x87\x0A\x12\x07\x0A\x12\x87\x0A\x12\x07\x0A\x12\x87\x0A\x12" +\
			      "\x07\x19")
		self.top.cmdLoadVPPLayout(7)
		self.top.send("\x34\x0A\x12\x88\x1B")
		self.top.cmdFlush(10)
		self.top.send("\x0E\x1F\x00\x00")
		time.sleep(0.1)
		stat = self.top.cmdReadStatusReg32()
		if stat != 0xFFFFFFC0:
			self.throwError("read: Unexpected status value 0x%X012" % stat)

		# Now read the image
		self.printInfo("Reading image ", newline=False)
		image = ""
		self.top.send("\x0A\x12\x81")
		high = 0
		for chunk in range(0, 256, 2):
			if chunk % 8 == 0:
				percent = (chunk * 100 / 256)
				if percent % 25 == 0:
					self.printInfo("%d%%" % percent, newline=False)
				else:
					self.printInfo(".", newline=False)
			self.top.send("\x34\x0A\x12\x01\x0A\x12\x82\x0A\x12\x04\x34\x0A\x12\x05\x0A\x12" +\
				      "\x86\x10\x02\x0A\x12\x87\x0A\x12\x07\x0A\x12\x05\x0A\x12\x06\x10" +\
				      chr((chunk << 4) & 0xFF) +\
				      "\x0A\x12\x87\x0A\x12\x07\x0A\x12\x84\x0A\x12\x05\x0A\x12\x06" +\
				      "\x10" + chr(high) + "\x0A\x12\x87\x0A\x12\x07\x0A\x12\x81")
			for word in range(0, 31, 1):
				value = (chunk << 4) + (word + 1)
				high = (value >> 8) & 0xFF
				self.top.send("\x0A\x12\x04\x0A\x12\x02\x01\x0A\x12\x84\x01\x0A\x12\x82\x0A\x12" +\
					      "\x01\x34\x0A\x12\x01\x0A\x12\x82\x0A\x12\x04\x34\x0A\x12\x05\x0A" +\
					      "\x12\x86\x10\x02\x0A\x12\x87\x0A\x12\x07\x0A\x12\x05\x0A\x12\x06" +\
					      "\x10" + chr(value & 0xFF) + "\x0A\x12\x87\x0A\x12\x07\x0A\x12\x84\x0A\x12\x05\x00\x00")
				self.top.send("\x0A\x12\x06\x10" + chr(high) + "\x0A\x12\x87\x0A\x12\x07\x0A\x12\x81")
			self.top.send("\x0A\x12\x04\x0A\x12\x02\x01\x0A\x12\x84\x01\x0A\x12\x82\x0A\x12" +\
				      "\x01\x07")
			data = self.top.cmdReadStatusReg()
			image += data
		self.printInfo("100%")
		return image

	def writeImage(self, image):
		pass#TODO

supportedChips.append(ATMega8DIP28())
bues.ch cgit interface