OpenCores
URL https://opencores.org/ocsvn/usb_dongle_fpga/usb_dongle_fpga/trunk

Subversion Repositories usb_dongle_fpga

[/] [usb_dongle_fpga/] [tags/] [version_1_5/] [sw/] [dongle.py] - Blame information for rev 12

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 nuubik
#! /usr/bin/python
2
# -*- coding: utf-8 -*-
3
##########################################################################
4
# LPC Dongle programming software 
5
#
6
# Copyright (C) 2006 Artec Design
7
# 
8
# This library is free software; you can redistribute it and/or
9
# modify it under the terms of the GNU Lesser General Public
10
# License as published by the Free Software Foundation; either
11
# version 2.1 of the License, or (at your option) any later version.
12
# 
13
# This software is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
# Lesser General Public License for more details.
17
 
18
# You should have received a copy of the GNU Lesser General Public
19
# License along with this library; if not, write to the Free Software
20
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21
##########################################################################
22
 
23
#-------------------------------------------------------------------------
24
# Project:   LPC Dongle programming software 
25
# Name:      dongle.py
26
# Purpose:   Executable command line tool 
27
#
28
# Author:    Jüri Toomessoo <jyrit@artecdesign.ee>
29 8 nuubik
# Copyright: (c) 2006 by Artec Design
30 2 nuubik
# Licence:   LGPL
31
#
32
# Created:   06 Oct. 2006
33
# History:   12 oct. 2006  Version 1.0 released
34 8 nuubik
#            22 Feb. 2007  Test options added to test PCB board
35 2 nuubik
#            
36
#
37
#-------------------------------------------------------------------------
38
 
39
import os
40
import sys
41
import string
42
import time
43
from sets import *
44
from struct import *
45
from Uspp.uspp import *
46
 
47
#### global funcs ####
48
def usage(s):
49 12 nuubik
    print "Artec USB Dongle programming utility ver. 1.1"
50 2 nuubik
    print "Usage: ",s," -c comport [-fvdq] filename address"
51
    print "       ",s," [-fvdqr] offset length filename"
52 8 nuubik
    print ""
53 2 nuubik
    print "Options:"
54
    print " -c        COM port"
55
    print " -v        Verbose"
56
    print " -f        Forced"
57
    print " -d        Debug"
58
    print " -q        Query"
59
    print " -r        Readback "
60 9 nuubik
    print " -e        Erase device "
61 8 nuubik
    print ""
62
    print "Board test options: "
63
    print " -t        Marching one and zero test address + data (Device must be empty)"
64
    print " -b        Leave flash blanc after test "
65
    print ""
66 2 nuubik
    print "Examples:"
67
    print ""
68
    print " ",s," -c COM3 loader.bin 0"
69
    print " ",s," -c /dev/ttyS3 content.bin 256K"
70
    print " ",s," -c COM3 device 1M"
71
    print " ",s," -c COM3 -r 0x0000 256 flashcontent.bin"
72
######################
73
 
74
 
75
class DongleMode:
76
    def __init__(self):
77
        self.v = 0
78
        self.f = 0
79
        self.d = 0
80
        self.q = 0
81
        self.r = 0
82 8 nuubik
        self.t = 0
83
        self.e = 0
84
        self.b = 0
85 2 nuubik
        self.filename=""
86
        self.portname=""
87
        self.address=-1
88
        self.offset=-1
89
        self.length=-1
90
 
91
    def convParamStr(self,param):
92
        mult = 1
93
        value = 0
94
        str = param
95
        if str.find("K")>-1:
96
            mult = 1024
97
            str=str.strip("K")
98
        if str.find("M")>-1:
99
            mult = 1024*1024
100
            str=str.strip("M")
101
        try:
102
            if str.find("x")>-1:
103
                value = int(str,0)*mult  #conver hex string to int
104
            else:
105
                value = int(str)*mult  #conver demical string to int
106
        except ValueError:
107
            print "Bad parameter format given for: ",param
108
 
109
        return value
110
 
111
 
112
 
113
 
114
class Dongle:
115
    def __init__(self,name, baud, timeout):  #time out in millis 1000 = 1s baud like 9600, 57600
116
        try:
117
            self.tty = SerialPort(name,timeout, baud)
118
        except:
119
            print "Unable to open port"
120
            sys.exit();
121 9 nuubik
 
122
    def testReturn(self,byteCount):
123
        i=0
124
        while don.tty.inWaiting()<byteCount:
125
            i=i+1
126
            if i==10000*byteCount:
127
                break
128
        if i==10000*byteCount:
129
            return 0
130
        return don.tty.inWaiting()  ## ret two bytes            
131
 
132 2 nuubik
    def getReturn(self,byteCount):
133
        i=0
134
        while don.tty.inWaiting()<byteCount:
135
            i=i+1
136
            if i==10000*byteCount:
137
                break
138
        if i==10000*byteCount:
139 9 nuubik
            print "Dongle not communicating"
140
            sys.exit()
141 2 nuubik
        return don.tty.read(byteCount)  ## ret two bytes
142 9 nuubik
 
143 2 nuubik
 
144
    def write_command(self,command):
145
        lsb = command&0xff
146
        msb = (command>>8)&0xff
147
        self.tty.write_2bytes(msb,lsb)
148
 
149
    def get_address_buf(self,address):  #set word address
150
        lsbyte = address&0xff
151
        byte = (address>>8)&0xff
152
        msbyte = (address>>16)&0xff
153
        buffer = ""
154
        buffer += chr(lsbyte)
155
        buffer += chr(0xA0)
156
        buffer +=  chr(byte)
157
        buffer +=  chr(0xA1)
158
        buffer +=  chr(msbyte)
159
        buffer +=  chr(0xA2)
160
        evaluate = (address>>24)
161
        if evaluate != 0:
162
            print "Addressign fault. Too large address passed"
163
            sys.exit()
164
        return buffer
165
 
166
 
167
    def set_address(self,address):  #set word address
168
        lsbyte = address&0xff
169
        byte = (address>>8)&0xff
170
        msbyte = (address>>16)&0xff
171
        evaluate = (address>>24)
172
        if evaluate != 0:
173
            print "Addressign fault. Too large address passed"
174
            sys.exit()
175
        self.tty.write_2bytes(lsbyte,0xA0)            #set internal address to dongle
176
        self.tty.write_2bytes(byte,0xA1)            #set internal address to dongle
177
        self.tty.write_2bytes(msbyte,0xA2)            #send query command
178
 
179
    def read_data(self,wordCount,address):
180
        command = 0
181
        byteCount = wordCount<<1  #calc byte count
182
        if wordCount>0 :
183
            command = (command|wordCount)<<8;
184
            command = command|0xCD
185
            self.set_address(address)    # send read address
186
            self.write_command(command)  # send get data command
187
            return self.getReturn(byteCount)
188
        else:
189
            print "Word count can't be under 1"
190
            sys.exit()
191
 
192
    def read_status(self):
193
        don.write_command(0x0070) # 0x0098 //clear status
194
        command = 0
195
        wordCount= 1  #calc byte count
196
        byteCount = wordCount<<1
197
        command = (command|wordCount)<<8;
198
        command = command|0xCD
199
        self.write_command(command)  # send get data command
200
        return self.getReturn(byteCount)
201
 
202
 
203
    def get_block_no(self,address):
204
        return address >> 16 # 16 bit mode block is 64Kwords
205
 
206
    def wait_on_busy(self):
207
        exit=0
208
        while exit==0:
209
            buf=self.read_status()
210
            statReg = ord(buf[0])  #8 bit reg
211
            if statReg>>7 == 1:
212
                exit=1
213
 
214
    def parse_status(self):  # use only after wait on busy commad to get result of the operation
215
        exit = 0
216
        buf=self.read_status()
217
        statReg = ord(buf[0])  #8 bit reg
218
        if (statReg>>5)&1 == 1:
219
            print "Block erase suspended"
220
            exit = 1
221
        if (statReg>>4)&3 == 3:
222
            print "Error in command order"  #if bits 4 and 5 are set then 
223
            exit = 1
224
        if (statReg>>4)&3 == 1:
225
            print "Error in setting lock bit"
226
            exit = 1
227
        if (statReg>>3)&1 == 1:
228
            print "Low Programming Voltage Detected, Operation Aborted"
229
            exit = 1
230
        if (statReg>>2)&1 == 1:
231
            print "Programming suspended"
232
            exit = 1
233
        if (statReg>>1)&1 == 1:
234
            print "Block lock bit detected"
235
            exit = 1
236
        if exit == 1:
237
            sys.exit()
238
 
239
    def erase_block(self,blockNo):
240
        blockAddress = blockNo << 16
241
        command = 0x0020
242
        self.set_address(blockAddress)
243
        self.write_command(command)  #issue block erase
244
        command = 0x00D0
245
        self.write_command(command)  #issue block erase confirm
246
        self.wait_on_busy()
247
        self.parse_status()
248
 
249
    def buffer_write(self,wordCount,startAddress,buffer):
250
        # to speed up buffer writing compose all commands into one buffer
251
        # instead of multiple single writes this is needed as the FTDI chip
252
        # round lag is amazingly large with VCOM drivers
253
        #u = len(buffer)
254
        if len(buffer)<32:            #don't ever make unaligned writes
255
            i=len(buffer)
256
            while len(buffer)<32:
257
                buffer += "\xff"
258
        adrBuf = self.get_address_buf(startAddress)   #6 bytes total
259
        cmd_e8=""  #8 bytes total
260
        cmd_e8+= chr(16)   #make it always 16 wordCount
261
        cmd_e8+= chr(0xE8)
262
        cmd_wcnt=""  #10 bytes total
263
        cmd_wcnt+= chr(0x00)
264
        cmd_wcnt+= chr(16-1)
265
        cmd_buf=""  #12 bytes total
266
        cmd_buf+= chr(0x00)
267
        cmd_buf+= chr(0xD0)
268
        wr_buffer_cmd = adrBuf + cmd_e8 + cmd_wcnt + buffer + cmd_buf   #44 bytes total
269
        self.tty.write_buf_cmd(wr_buffer_cmd)
270
        # no wait needad as the FTDI chip is so slow
271
 
272
 
273
################## Main program #########################
274
 
275
 
276
last_ops = 0
277
mode = DongleMode()
278
# PARSE ARGUMENTS 
279
for arg in sys.argv:
280
    if len(sys.argv) == 1: # if no arguments display help
281 8 nuubik
       #usage(sys.argv[0])
282
       usage("dongle.py")
283 2 nuubik
       sys.exit()
284
    if arg in ("-h","--help","/help","/h"):
285 8 nuubik
        #usage(sys.argv[0])
286
        usage("dongle.py")
287 2 nuubik
        sys.exit()
288
    if arg in ("-c"):
289
        last_ops = sys.argv.index(arg) + 1  #if remains last set of options from here start ordered strings
290
        i = sys.argv.index(arg)
291
        print "Opening port: "+sys.argv[i+1]
292
        mode.portname = sys.argv[i+1]   # next element after -c open port for usage
293
    if arg[0]=="-" and arg[1]!="c": # if other opptions
294
        # parse all options in this
295
        last_ops = sys.argv.index(arg)  #if remains last set of options from here start ordered strings
296
        ops = arg[1:]# get all besides the - sign
297
        for op in ops:
298
            if op=="q":
299
                mode.q = 1
300
            if op=="v":
301
                mode.v = 1
302
            if op=="f":
303
                mode.f = 1
304
            if op=="d":
305
                mode.d = 1
306
            if op=="r":
307 8 nuubik
                mode.r = 1
308
            if op=="t":
309
                mode.t = 1
310
            if op=="e":
311
                mode.e = 1
312
            if op=="b":
313
                mode.b = 1
314 2 nuubik
    else:
315
        i = sys.argv.index(arg)
316
        if i ==  last_ops + 1:
317
            if mode.r==1:
318
                mode.offset=mode.convParamStr(arg)
319
            else:
320
                mode.filename=arg
321
        if i ==  last_ops + 2:
322
            if mode.r==1:
323
                mode.length=mode.convParamStr(arg)
324
            else:
325
                mode.address=mode.convParamStr(arg)
326
 
327
        if i ==  last_ops + 3:
328
            if mode.r==1:
329
                mode.filename=arg
330
            else:
331
                print "Too many parameters provided"
332
                sys.exit()
333
        if i >  last_ops + 3:
334
             print "Too many parameters provided"
335
             sys.exit()
336
 
337
# END PARSE ARGUMENTS             
338
 
339
if mode.portname=="":
340
    print "No port name given see -h for help"
341
    sys.exit()
342
else:
343
    # test PC speed to find sutable delay for linux driver
344
    # to get 250 us 
345
    mytime = time.clock()
346
    n = 0
347
    while (n < 100000):
348
        n += 1;
349
    k10Time = time.clock() - mytime   # time per 10000 while cycles
350
    wait = k10Time/100000.0     # time per while cycle
351
    wait = (0.00025/wait) * 1.20   # count for 250us + safe margin
352
    # ok done
353 9 nuubik
    reopened = 0
354
 
355
    don  = Dongle(mode.portname,115200,100)
356
    don.tty.wait = wait
357
    while 1:
358
        don.write_command(0x0050) # 0x0098
359
        don.write_command(0x00C5)            #send dongle check internal command
360
        don_ret=don.testReturn(2)
361
        if don_ret==2:
362
            break
363
        if reopened == 3:
364
             print 'Dongle connected, but does not communicate'
365
             sys.exit()
366
        reopened = reopened + 1
367
        # reopen and do new cycle
368
        don = Dongle(mode.portname,115200,100)
369
        don.tty.wait = wait
370
 
371 2 nuubik
    buf=don.getReturn(2)  # two bytes expected to this command
372 9 nuubik
 
373 2 nuubik
    if ord(buf[1])==0x32 and  ord(buf[0])==0x10:
374
        print "Dongle OK"
375
    else:
376
        print 'Dongle returned on open: %02x %02x '%(ord(buf[1]), ord(buf[0]))
377
 
378
 
379
if mode.q == 1:   # perform a query from dongle
380 9 nuubik
 
381
    buf=don.read_data(4,0x0)  # word count and word address
382 2 nuubik
    don.write_command(0x0050) # 0x0098
383
    don.write_command(0x0098) # 0x0098
384
    buf=don.read_data(3,0x000010)  # word count and word address
385
    if ord(buf[0])==0x51 and  ord(buf[2])==0x52 and  ord(buf[4])==0x59:
386
        buf=don.read_data(2,0x000000)  # word count and word address
387
        print 'Query  OK, Factory: 0x%02x device: 0x%02x '%(ord(buf[0]),ord(buf[2]))
388
        buf=don.read_data(2,0x000002)
389
        print 'lock bit is 0x%02x 0x%02x'%(ord(buf[0]),ord(buf[1]))
390
    else:
391
        print "Got bad query data:"
392
        print 'Query address 0x10 = 0x%02x%02x '%(ord(buf[1]),ord(buf[0]))
393 9 nuubik
        print 'Query address 0x12 = 0x%02x%02x '%(ord(buf[3]),ord(buf[2]))
394
        print 'Query address 0x14 = 0x%02x%02x '%(ord(buf[5]),ord(buf[4]))
395 2 nuubik
        print "Read byte count:",len(buf)
396
 
397
    don.write_command(0x00FF) # 0x0098
398 9 nuubik
    buf=don.read_data(4,0xff57c0>>1)  # word count and word address
399
 
400 2 nuubik
    print 'Data: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x '%(ord(buf[1]),ord(buf[0]),ord(buf[3]),ord(buf[2]),ord(buf[5]),ord(buf[4]),ord(buf[7]),ord(buf[6]) )
401
 
402
 
403
 
404
if mode.filename!="" and mode.address!=-1:
405
    #Calculate number of blocks and start of blocks
406
    size = 0
407
    mode.address = mode.address>>1  #make word address
408
    try:
409
        f=open(mode.filename,"rb")
410
        f.seek(0,2) #seek to end
411
        size = f.tell()
412
        f.seek(0) #seek to start
413
        print 'File size %iK '%(size/1024)
414
        f.close()
415
    except IOError:
416
         print "IO Error on file open"
417
         sys.exit()
418
    #clear blockLock bits
419
    don.write_command(0x0060) # 0x0098
420
    don.write_command(0x00D0) # 0x0098
421
    don.wait_on_busy()
422
    don.parse_status()
423
    wordSize = (size+ (size&1))>> 1    # round byte count up and make word address
424
    endBlock = don.get_block_no(mode.address+wordSize - 1)
425
    startBlock = don.get_block_no(mode.address)
426
    i=startBlock
427 9 nuubik
    print 'Erasing from block %i to %i '%(i,endBlock)
428 2 nuubik
    while i <= endBlock:
429 9 nuubik
        if mode.v == 1:
430
            print 'Erasing block %i '%(i)
431
        else:
432
            sys.stdout.write(".")
433
            sys.stdout.flush()
434 2 nuubik
        don.erase_block(i)
435
        don.wait_on_busy()
436
        don.parse_status()   #do this after programming all but uneaven ending
437
        i=i+1
438 9 nuubik
    if mode.v == 0:
439
        print " "
440 2 nuubik
    #don.write_command(0x00FF) # 0x0098
441
    #buf=don.read_data(4,0x000000)  # word count and word address     
442
    #print 'Data: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x '%(ord(buf[0]),ord(buf[1]),ord(buf[2]),ord(buf[3]),ord(buf[4]),ord(buf[5]),ord(buf[6]),ord(buf[7]) )
443
 
444
    f=open(mode.filename,"rb")
445
    f.seek(0) #seek to start
446
    address= mode.address
447
    #don.set_address(address)
448 9 nuubik
    print 'Writing %iK'%(size/1024)
449 2 nuubik
    while 1:
450 9 nuubik
        if (address/(1024*64) != (address-16)/(1024*64)) and address != mode.address:  # get bytes from words if 512
451
            if mode.v == 1:
452
                print 'Progress: %iK of %iK at 0x%06x'%((address-mode.address)/512,size/1024,address)
453
            else:
454
                sys.stdout.write(".")
455
                sys.stdout.flush()
456 2 nuubik
        buf = f.read(32)  #16 words is maximum write here bytes are read
457
        if len(buf)==32:
458
            don.buffer_write(16,address,buf)
459
            address = address + 16
460
        elif len(buf)>0:
461
            don.parse_status()   #do this after programming all but uneaven ending
462
            print "Doing an unaligned write..."
463
            length = len(buf)
464
            length = (length + (length&1))>> 1   #round up to get even word count
465
            buf = buf+"\xff"   #pad just in case rounding took place
466
            don.buffer_write(len,address,buf)
467
            address = address + 16     #inc word address
468
            break
469
        else:
470
            break
471 9 nuubik
    if mode.v == 0:
472
        print " "
473 2 nuubik
    print "Write DONE!"
474
    don.parse_status()   #do this after programming all but uneaven ending
475
    f.close()
476
 
477
if mode.r == 1:   # perform a readback
478
    if mode.offset!=-1 and mode.length!=-1 and mode.filename!="":
479
        mode.offset=mode.offset>>1    #make word offset
480
        mode.length= mode.length>>1   #make word length
481 9 nuubik
        print 'Reading %iK'%(mode.length/512)
482 2 nuubik
        try:
483
            f=open(mode.filename,"wb")
484
            don.write_command(0x00FF) #  put flash to data read mode
485
            address = mode.offset    # set word address
486
            while 1:
487
                if address/(1024*32) != (address-128)/(1024*32):  # get K bytes from words if 512
488 9 nuubik
                    if mode.v == 1:
489
                        print 'Progress: %iK of %iK'%((address-mode.offset)/512,mode.length/512)
490
                    else:
491
                        sys.stdout.write(".")
492
                        sys.stdout.flush()
493 2 nuubik
                buf=don.read_data(128,address)  # word count and byte address read 64 words to speed up
494
                f.write(buf)
495
                #print "from address:",address<<1," ", len(buf)
496
                if address+128 >= (mode.offset + mode.length):  # 2+64 estimates the end to end in right place
497
                    break
498
                address = address + 128    #this is word address
499
            f.close()
500 9 nuubik
            if mode.v == 0:
501
                print " "
502 2 nuubik
            print "Readback done!"
503
        except IOError:
504
            print "IO Error on file open"
505
            sys.exit()
506 9 nuubik
 
507 2 nuubik
    else:
508
       print "Some of readback parameters missing..."
509
       print mode.offset,mode.length, mode.filename
510
       sys.exit()
511 8 nuubik
 
512
if mode.t == 1:   # perform dongle test
513
        print "Dongle TEST"
514
        if mode.e == 1:
515
            #Erase Dongle
516 9 nuubik
            print "Erasing"
517 8 nuubik
            don.write_command(0x0060) # 0x0098
518
            don.write_command(0x00D0) # 0x0098
519
            don.wait_on_busy()
520
            don.parse_status()
521
            endBlock = 31
522
            startBlock = 0
523
            i=startBlock
524
            while i <= endBlock:
525 9 nuubik
                if mode.v == 1:
526
                    print 'Erasing block %i '%(i)
527
                else:
528
                     sys.stdout.write(".")
529
                     sys.stdout.flush()
530 8 nuubik
                don.erase_block(i)
531
                don.wait_on_busy()
532
                don.parse_status()   #do this after programming all but uneaven ending
533 9 nuubik
                i=i+1
534
            if mode.v == 0: # add CRTL return to dots
535
                print ""
536 8 nuubik
        #Do marching one test on data and address
537
        mode.length= 0   #make word length
538
        try:
539
            #Marching one test
540
            #---------------------------------------------------------------------------
541
            address = 0x100000    # set word address
542
            data = 0x100000
543
            while mode.length<20: # last address to test 0x20 0000  
544
                buf1=pack('BBBB', (0x000000FF&data),(0x0000FF00&data)>>8 ,(0x00FF0000&data)>>16 ,(0xFF0000&data)>>24 )
545
                don.buffer_write(2,address,buf1)
546
                don.parse_status()   #do this after programming all but uneaven ending
547
                don.write_command(0x00FF) #  put flash to data read mode   
548
                buf2=don.read_data(2,address)  # word count and byte address read 64 words to speed up
549
                if buf1 != buf2:
550
                    print 'IN  %02x %02x %02x %02x '%(ord(buf1[3]), ord(buf1[2]),ord(buf1[1]), ord(buf1[0]))
551
                    print 'OUT %02x %02x %02x %02x '%(ord(buf2[3]), ord(buf2[2]),ord(buf2[1]), ord(buf2[0]))
552
                    print "Test FAIL!!!!!"
553
                    sys.exit()
554
                address = address >> 1
555
                if address == 0x2:
556
                    address = address >> 1  # 0x2 is written and will return zero on read as write new write will fail
557
                data = data >> 1
558
                mode.length =  mode.length + 1
559
                buf2=don.read_data(1,0)  #read first byte
560
                if ord(buf2[0]) != 0xFF:
561
                    print "Test FAIL (At least one address line const. 0)!!!!!"
562 9 nuubik
                    sys.exit()
563 8 nuubik
            #-----------------------------------------------------------------------
564
            #Marching zero test
565
            address = 0xFFEFFFFF    # set word address
566
            data = 0x100000
567
            while mode.length<18: # last address to test 0x20 0000  
568
                buf1=pack('BBBB', (0x000000FF&data),(0x0000FF00&data)>>8 ,(0x00FF0000&data)>>16 ,(0xFF0000&data)>>24 )
569
                don.buffer_write(2,address,buf1)
570
                don.parse_status()   #do this after programming all but uneaven ending
571
                don.write_command(0x00FF) #  put flash to data read mode   
572
                buf2=don.read_data(2,address&0x1FFFFF)  # word count and byte address read 64 words to speed up
573
                if buf1 != buf2:
574
                    print 'IN  %02x %02x %02x %02x '%(ord(buf1[3]), ord(buf1[2]),ord(buf1[1]), ord(buf1[0]))
575
                    print 'OUT %02x %02x %02x %02x '%(ord(buf2[3]), ord(buf2[2]),ord(buf2[1]), ord(buf2[0]))
576
                    print "Test FAIL!!!!!"
577
                    sys.exit()
578
                address = (address >> 1)|0xFF000000
579
                data = data >> 1
580
                mode.length =  mode.length + 1
581
                buf2=don.read_data(1,0x1FFFFF)  #read first byte
582
                if ord(buf2[0]) != 0xFF:
583
                    print "Test FAIL (At least two address lines bonded)!!!!!"
584 9 nuubik
                    sys.exit()
585 8 nuubik
            if mode.b == 1:
586
                #Erase Dongle
587 9 nuubik
                print "Erasing"
588 8 nuubik
                don.write_command(0x0060) # 0x0098
589
                don.write_command(0x00D0) # 0x0098
590
                don.wait_on_busy()
591
                don.parse_status()
592
                endBlock = 31
593
                startBlock = 0
594
                i=startBlock
595
                while i <= endBlock:
596 9 nuubik
                    if mode.v == 1:
597
                        print 'Blanking block %i '%(i)
598
                    else:
599
                        sys.stdout.write(".")
600
                        sys.stdout.flush()
601 8 nuubik
                    don.erase_block(i)
602
                    don.wait_on_busy()
603
                    don.parse_status()   #do this after programming all but uneaven ending
604 9 nuubik
                    i=i+1
605
                if mode.v == 0:
606
                    print " "
607 8 nuubik
            print "Test SUCCESSFUL!"
608 9 nuubik
            sys.exit()
609 8 nuubik
        except IOError:
610
            print "IO Error on file open"
611
            sys.exit()
612
 
613 9 nuubik
if mode.e == 1:   # perform dongle test
614
            #Erase Dongle
615
            print "Erasing all"
616
            don.write_command(0x0060) # 0x0098
617
            don.write_command(0x00D0) # 0x0098
618
            don.wait_on_busy()
619
            don.parse_status()
620
            endBlock = 31
621
            startBlock = 0
622
            i=startBlock
623
            while i <= endBlock:
624
                if mode.v == 1:
625
                    print 'Erasing block %i '%(i)
626
                else:
627
                     sys.stdout.write(".")
628
                     sys.stdout.flush()
629
                don.erase_block(i)
630
                don.wait_on_busy()
631
                don.parse_status()   #do this after programming all but uneaven ending
632
                i=i+1
633
            if mode.v == 0: # add CRTL return to dots
634
                print ""
635
            print "Erase done."
636 8 nuubik
 
637 2 nuubik
##########################################################

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.