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

Subversion Repositories usb_dongle_fpga

[/] [usb_dongle_fpga/] [trunk/] [sw/] [dongle.py] - Blame information for rev 9

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
    print "Artec USB Dongle programming utility"
50
    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
    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]) )
383
 
384
 
385 2 nuubik
    don.write_command(0x0050) # 0x0098
386
    don.write_command(0x0098) # 0x0098
387
    buf=don.read_data(3,0x000010)  # word count and word address
388
    if ord(buf[0])==0x51 and  ord(buf[2])==0x52 and  ord(buf[4])==0x59:
389
        buf=don.read_data(2,0x000000)  # word count and word address
390
        print 'Query  OK, Factory: 0x%02x device: 0x%02x '%(ord(buf[0]),ord(buf[2]))
391
        buf=don.read_data(2,0x000002)
392
        print 'lock bit is 0x%02x 0x%02x'%(ord(buf[0]),ord(buf[1]))
393
    else:
394
        print "Got bad query data:"
395
        print 'Query address 0x10 = 0x%02x%02x '%(ord(buf[1]),ord(buf[0]))
396 9 nuubik
        print 'Query address 0x12 = 0x%02x%02x '%(ord(buf[3]),ord(buf[2]))
397
        print 'Query address 0x14 = 0x%02x%02x '%(ord(buf[5]),ord(buf[4]))
398 2 nuubik
        print "Read byte count:",len(buf)
399
 
400
    don.write_command(0x00FF) # 0x0098
401 9 nuubik
    buf=don.read_data(4,0xff57c0>>1)  # word count and word address
402
 
403 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]) )
404
 
405
 
406
 
407
if mode.filename!="" and mode.address!=-1:
408
    #Calculate number of blocks and start of blocks
409
    size = 0
410
    mode.address = mode.address>>1  #make word address
411
    try:
412
        f=open(mode.filename,"rb")
413
        f.seek(0,2) #seek to end
414
        size = f.tell()
415
        f.seek(0) #seek to start
416
        print 'File size %iK '%(size/1024)
417
        f.close()
418
    except IOError:
419
         print "IO Error on file open"
420
         sys.exit()
421
    #clear blockLock bits
422
    don.write_command(0x0060) # 0x0098
423
    don.write_command(0x00D0) # 0x0098
424
    don.wait_on_busy()
425
    don.parse_status()
426
    wordSize = (size+ (size&1))>> 1    # round byte count up and make word address
427
    endBlock = don.get_block_no(mode.address+wordSize - 1)
428
    startBlock = don.get_block_no(mode.address)
429
    i=startBlock
430 9 nuubik
    print 'Erasing from block %i to %i '%(i,endBlock)
431 2 nuubik
    while i <= endBlock:
432 9 nuubik
        if mode.v == 1:
433
            print 'Erasing block %i '%(i)
434
        else:
435
            sys.stdout.write(".")
436
            sys.stdout.flush()
437 2 nuubik
        don.erase_block(i)
438
        don.wait_on_busy()
439
        don.parse_status()   #do this after programming all but uneaven ending
440
        i=i+1
441 9 nuubik
    if mode.v == 0:
442
        print " "
443 2 nuubik
    #don.write_command(0x00FF) # 0x0098
444
    #buf=don.read_data(4,0x000000)  # word count and word address     
445
    #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]) )
446
 
447
    f=open(mode.filename,"rb")
448
    f.seek(0) #seek to start
449
    address= mode.address
450
    #don.set_address(address)
451 9 nuubik
    print 'Writing %iK'%(size/1024)
452 2 nuubik
    while 1:
453 9 nuubik
        if (address/(1024*64) != (address-16)/(1024*64)) and address != mode.address:  # get bytes from words if 512
454
            if mode.v == 1:
455
                print 'Progress: %iK of %iK at 0x%06x'%((address-mode.address)/512,size/1024,address)
456
            else:
457
                sys.stdout.write(".")
458
                sys.stdout.flush()
459 2 nuubik
        buf = f.read(32)  #16 words is maximum write here bytes are read
460
        if len(buf)==32:
461
            don.buffer_write(16,address,buf)
462
            address = address + 16
463
        elif len(buf)>0:
464
            don.parse_status()   #do this after programming all but uneaven ending
465
            print "Doing an unaligned write..."
466
            length = len(buf)
467
            length = (length + (length&1))>> 1   #round up to get even word count
468
            buf = buf+"\xff"   #pad just in case rounding took place
469
            don.buffer_write(len,address,buf)
470
            address = address + 16     #inc word address
471
            break
472
        else:
473
            break
474 9 nuubik
    if mode.v == 0:
475
        print " "
476 2 nuubik
    print "Write DONE!"
477
    don.parse_status()   #do this after programming all but uneaven ending
478
    f.close()
479
 
480
if mode.r == 1:   # perform a readback
481
    if mode.offset!=-1 and mode.length!=-1 and mode.filename!="":
482
        mode.offset=mode.offset>>1    #make word offset
483
        mode.length= mode.length>>1   #make word length
484 9 nuubik
        print 'Reading %iK'%(mode.length/512)
485 2 nuubik
        try:
486
            f=open(mode.filename,"wb")
487
            don.write_command(0x00FF) #  put flash to data read mode
488
            address = mode.offset    # set word address
489
            while 1:
490
                if address/(1024*32) != (address-128)/(1024*32):  # get K bytes from words if 512
491 9 nuubik
                    if mode.v == 1:
492
                        print 'Progress: %iK of %iK'%((address-mode.offset)/512,mode.length/512)
493
                    else:
494
                        sys.stdout.write(".")
495
                        sys.stdout.flush()
496 2 nuubik
                buf=don.read_data(128,address)  # word count and byte address read 64 words to speed up
497
                f.write(buf)
498
                #print "from address:",address<<1," ", len(buf)
499
                if address+128 >= (mode.offset + mode.length):  # 2+64 estimates the end to end in right place
500
                    break
501
                address = address + 128    #this is word address
502
            f.close()
503 9 nuubik
            if mode.v == 0:
504
                print " "
505 2 nuubik
            print "Readback done!"
506
        except IOError:
507
            print "IO Error on file open"
508
            sys.exit()
509 9 nuubik
 
510 2 nuubik
    else:
511
       print "Some of readback parameters missing..."
512
       print mode.offset,mode.length, mode.filename
513
       sys.exit()
514 8 nuubik
 
515
if mode.t == 1:   # perform dongle test
516
        print "Dongle TEST"
517
        if mode.e == 1:
518
            #Erase Dongle
519 9 nuubik
            print "Erasing"
520 8 nuubik
            don.write_command(0x0060) # 0x0098
521
            don.write_command(0x00D0) # 0x0098
522
            don.wait_on_busy()
523
            don.parse_status()
524
            endBlock = 31
525
            startBlock = 0
526
            i=startBlock
527
            while i <= endBlock:
528 9 nuubik
                if mode.v == 1:
529
                    print 'Erasing block %i '%(i)
530
                else:
531
                     sys.stdout.write(".")
532
                     sys.stdout.flush()
533 8 nuubik
                don.erase_block(i)
534
                don.wait_on_busy()
535
                don.parse_status()   #do this after programming all but uneaven ending
536 9 nuubik
                i=i+1
537
            if mode.v == 0: # add CRTL return to dots
538
                print ""
539 8 nuubik
        #Do marching one test on data and address
540
        mode.length= 0   #make word length
541
        try:
542
            #Marching one test
543
            #---------------------------------------------------------------------------
544
            address = 0x100000    # set word address
545
            data = 0x100000
546
            while mode.length<20: # last address to test 0x20 0000  
547
                buf1=pack('BBBB', (0x000000FF&data),(0x0000FF00&data)>>8 ,(0x00FF0000&data)>>16 ,(0xFF0000&data)>>24 )
548
                don.buffer_write(2,address,buf1)
549
                don.parse_status()   #do this after programming all but uneaven ending
550
                don.write_command(0x00FF) #  put flash to data read mode   
551
                buf2=don.read_data(2,address)  # word count and byte address read 64 words to speed up
552
                if buf1 != buf2:
553
                    print 'IN  %02x %02x %02x %02x '%(ord(buf1[3]), ord(buf1[2]),ord(buf1[1]), ord(buf1[0]))
554
                    print 'OUT %02x %02x %02x %02x '%(ord(buf2[3]), ord(buf2[2]),ord(buf2[1]), ord(buf2[0]))
555
                    print "Test FAIL!!!!!"
556
                    sys.exit()
557
                address = address >> 1
558
                if address == 0x2:
559
                    address = address >> 1  # 0x2 is written and will return zero on read as write new write will fail
560
                data = data >> 1
561
                mode.length =  mode.length + 1
562
                buf2=don.read_data(1,0)  #read first byte
563
                if ord(buf2[0]) != 0xFF:
564
                    print "Test FAIL (At least one address line const. 0)!!!!!"
565 9 nuubik
                    sys.exit()
566 8 nuubik
            #-----------------------------------------------------------------------
567
            #Marching zero test
568
            address = 0xFFEFFFFF    # set word address
569
            data = 0x100000
570
            while mode.length<18: # last address to test 0x20 0000  
571
                buf1=pack('BBBB', (0x000000FF&data),(0x0000FF00&data)>>8 ,(0x00FF0000&data)>>16 ,(0xFF0000&data)>>24 )
572
                don.buffer_write(2,address,buf1)
573
                don.parse_status()   #do this after programming all but uneaven ending
574
                don.write_command(0x00FF) #  put flash to data read mode   
575
                buf2=don.read_data(2,address&0x1FFFFF)  # word count and byte address read 64 words to speed up
576
                if buf1 != buf2:
577
                    print 'IN  %02x %02x %02x %02x '%(ord(buf1[3]), ord(buf1[2]),ord(buf1[1]), ord(buf1[0]))
578
                    print 'OUT %02x %02x %02x %02x '%(ord(buf2[3]), ord(buf2[2]),ord(buf2[1]), ord(buf2[0]))
579
                    print "Test FAIL!!!!!"
580
                    sys.exit()
581
                address = (address >> 1)|0xFF000000
582
                data = data >> 1
583
                mode.length =  mode.length + 1
584
                buf2=don.read_data(1,0x1FFFFF)  #read first byte
585
                if ord(buf2[0]) != 0xFF:
586
                    print "Test FAIL (At least two address lines bonded)!!!!!"
587 9 nuubik
                    sys.exit()
588 8 nuubik
            if mode.b == 1:
589
                #Erase Dongle
590 9 nuubik
                print "Erasing"
591 8 nuubik
                don.write_command(0x0060) # 0x0098
592
                don.write_command(0x00D0) # 0x0098
593
                don.wait_on_busy()
594
                don.parse_status()
595
                endBlock = 31
596
                startBlock = 0
597
                i=startBlock
598
                while i <= endBlock:
599 9 nuubik
                    if mode.v == 1:
600
                        print 'Blanking block %i '%(i)
601
                    else:
602
                        sys.stdout.write(".")
603
                        sys.stdout.flush()
604 8 nuubik
                    don.erase_block(i)
605
                    don.wait_on_busy()
606
                    don.parse_status()   #do this after programming all but uneaven ending
607 9 nuubik
                    i=i+1
608
                if mode.v == 0:
609
                    print " "
610 8 nuubik
            print "Test SUCCESSFUL!"
611 9 nuubik
            sys.exit()
612 8 nuubik
        except IOError:
613
            print "IO Error on file open"
614
            sys.exit()
615
 
616 9 nuubik
if mode.e == 1:   # perform dongle test
617
            #Erase Dongle
618
            print "Erasing all"
619
            don.write_command(0x0060) # 0x0098
620
            don.write_command(0x00D0) # 0x0098
621
            don.wait_on_busy()
622
            don.parse_status()
623
            endBlock = 31
624
            startBlock = 0
625
            i=startBlock
626
            while i <= endBlock:
627
                if mode.v == 1:
628
                    print 'Erasing block %i '%(i)
629
                else:
630
                     sys.stdout.write(".")
631
                     sys.stdout.flush()
632
                don.erase_block(i)
633
                don.wait_on_busy()
634
                don.parse_status()   #do this after programming all but uneaven ending
635
                i=i+1
636
            if mode.v == 0: # add CRTL return to dots
637
                print ""
638
            print "Erase done."
639 8 nuubik
 
640 2 nuubik
##########################################################

powered by: WebSVN 2.1.0

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