📄 update.py
字号:
if self.pport.getInSelected():
byte=byte|0x01
self.setPPDataBit(0) # make rising edge for read
i+=1
#print "-------------------"
return byte
######################### EPCS command calls #############################
def getDeviceID(self):
self.startCycle()
self.writeCommand(self.CMD_READ_ID)
self.writeCommand(0x00) # dummy write
self.writeCommand(0x00) # dummy write
self.writeCommand(0x00) # dummy write
byte = self.readByte()
self.endCycle()
return byte
def setWriteEnable(self):
self.startCycle()
self.writeCommand(self.CMD_WRITE_ENABLE)
self.endCycle()
def setWriteDisable(self):
self.startCycle()
self.writeCommand(self.CMD_WRITE_DISABLE)
self.endCycle()
def getStatusReg(self):
self.startCycle()
self.writeCommand(self.CMD_READ_STATUS)
byte = self.readByte()
self.endCycle()
return byte
def readBytes(self,address,count):
buffer = ""
i = 0
self.startCycle()
self.writeCommand(self.CMD_READ_BYTES)
self.writeAddress(address)
while(i<count):
byte = self.readByte()
#print "Reading %2x"%(byte)
buffer = buffer + chr(byte) #this can continue endlessly if needed the address is auto INC'ed and is freerunning
i+=1
self.endCycle()
return buffer
def readFlippedBytes(self,address,count):
buffer = ""
i = 0
self.startCycle()
self.writeCommand(self.CMD_READ_BYTES)
self.writeAddress(address)
while(i<count):
byte = self.readByte()
etyb = ((byte&0x01)<<7)|((byte&0x02)<<5)|((byte&0x04)<<3)|((byte&0x08)<<1)|((byte&0x10)>>1)|((byte&0x20)>>3)|((byte&0x40)>>5)|((byte&0x80)>>7)
#print "Reading %2x"%(byte)
buffer = buffer + chr(etyb) #this can continue endlessly if needed the address is auto INC'ed and is freerunning
i+=1
self.endCycle()
return buffer
def writeBytes(self,address,buffer): #256 is maximum and is physical page limit of EPCS devices
count = len(buffer)
i = 0
self.setWriteEnable() #will be autoreset after this
self.startCycle()
self.writeCommand(self.CMD_WRITE_BYTES)
self.writeAddress(address)
while(i<count):
#print "Writing %2x"%(ord(buffer[i]))
self.writeByte(ord(buffer[i])) #used also to write a data byte
i+=1
self.endCycle()
time.sleep(0.0001) #wait untill write compleate, wite time is in order of millis
while(self.getStatusReg()&0x01==1):
time.sleep(0.00001)
def writeFlippedBytes(self,address,buffer): #256 is maximum and is physical page limit of EPCS devices (Altera RPD file is allready byte flipped)
#This is used to programm altera byte flipped programming files
count = len(buffer)
i = 0
self.setWriteEnable() #will be autoreset after this
self.startCycle()
self.writeCommand(self.CMD_WRITE_BYTES)
self.writeAddress(address)
while(i<count):
#print "Writing %2x"%(ord(buffer[i]))
self.writeFlippedByte(ord(buffer[i])) #used also to write a data byte
i+=1
self.endCycle()
time.sleep(0.0001) #wait untill write compleate, wite time is in order of millis
while(self.getStatusReg()&0x01==1):
time.sleep(0.00001)
def eraseBulk(self):
self.setWriteEnable() #will be autoreset after this
self.startCycle()
self.writeCommand(self.CMD_ERASE_BULK)
self.endCycle()
time.sleep(3) #wait untill write compleate, wite time is in order of secs
while(self.getStatusReg()&0x01==1):
time.sleep(0.1)
def eraseSector(self,address):
self.setWriteEnable() #will be autoreset after this
self.startCycle()
self.writeCommand(self.CMD_ERASE_SECTOR)
self.writeAddress(address)
self.endCycle()
time.sleep(1) #wait untill write compleate, wite time is in order of secs
while(self.getStatusReg()&0x01==1):
time.sleep(0.2)
######################### end EPCS command calls #########################
################## Main program #########################
last_ops = 0
mode = DeviceMode()
# PARSE ARGUMENTS
for arg in sys.argv:
if len(sys.argv) == 1: # if no arguments display help
#usage(sys.argv[0])
usage("update.py")
sys.exit()
if arg in ("-h","--help","/help","/h"):
#usage(sys.argv[0])
usage("update.py")
sys.exit()
if arg[0]=="-": # if options
# parse all options in this
last_ops = sys.argv.index(arg) #if remains last set of options from here start ordered strings
ops = arg[1:]# get all besides the - sign
for op in ops:
if op=="q":
mode.q = 1
if op=="v":
mode.v = 1
if op=="r":
mode.r = 1
if op=="e":
mode.e = 1
else:
i = sys.argv.index(arg)
if i == last_ops + 1:
mode.filename=arg
if i >= last_ops + 2:
print "Too many parameters provided"
sys.exit()
############## END PARSE ARGUMENTS ###############################################33
epcs = EPCSDevice()
epcs.open()
if epcs.pport.getInError():
print "No Voltage source detected"
else:
print "Voltage source OK"
byte = epcs.getDeviceID()
if byte == 0x10:
print "EPCS1 Configuration device found"
if mode.q == 1:
print "EPCS Silicon ID = 0x%2x"%(byte)
sys.exit() # if q then exit
elif not byte == 0xFF:
print "Not supported device found"
if mode.q == 1:
print "Silicon ID = 0x%2x"%(byte)
sys.exit()
else:
if not epcs.pport.getInError():
print "No device attached to cable"
if mode.q == 1:
print "Got 0x%2x for ID "%(byte)
epcs.close()
sys.exit()
if mode.e == 1:
print "Erasing EPCS device"
epcs.eraseBulk()
print "Done"
if mode.filename!="" and mode.r==0:
print "Erasing EPCS device"
epcs.eraseBulk()
print "Done"
size = 0
mode.address = 0
try:
f=open(mode.filename,"rb")
f.seek(0,2) #seek to end
size = f.tell()
f.seek(0) #seek to start
print 'File size %iK '%(size/1024)
f.close()
except IOError:
print "IO Error on file open"
sys.exit()
#all seems in order so lest start
f=open(mode.filename,"rb")
f.seek(0) #seek to start
address = mode.address
print 'Writing %iK'%(size/1024)
while 1:
if (address/(1024*4) != (address-16)/(1024*4)) and address != mode.address: # get bytes from words if 512
if mode.v == 1:
print 'Progress: %iK of %iK at 0x%06x'%((address-mode.address)/1024,size/1024,address)
else:
sys.stdout.write(".")
sys.stdout.flush()
buf = f.read(256) #we can write 256 bytes at a time
if len(buf)==256:
epcs.writeFlippedBytes(address,buf)
address = address + 256 #we use byte address
elif len(buf)>0:
epcs.writeFlippedBytes(address,buf) #write last bytes
break
else:
break
if mode.v == 0:
print " "
print "Write DONE!"
f.close()
elif mode.filename!="": # then read flag must be up
size = 0x20000 #byte count of EPCS1 device
try:
f=open(mode.filename,"wb") #if this fails no point in reading as there is nowhere to write
address = 0 # set word address
buf=""
print "Start readback"
buf=epcs.readFlippedBytes(address,size)
print "Read done"
f.write(buf)
f.close()
print "Done"
except IOError:
print "IO Error on file open"
sys.exit()
epcs.close()
time.sleep(0.5)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -