Since this example uses python, changing build to use distutils
[fx2lib.git] / examples / fx2 / py / fx2load.py
blob0822e944bb917416baaa1fd70b471514f9fcbb5e
1 from time import sleep
2 from fx2 import fx2
4 f=fx2.fx2()
5 f.open(0x04b4,0x0082)
7 def reset_device(reset):
8 print reset and "Put device in reset" or "Set device to run"
9 write_ram (0xe600,reset and '\x01' or '\x00', 1)
11 def write_ram(addr,data,length):
12 transferred=0
13 while(transferred<length):
14 this_transfer_size=length-transferred>1024 and 1024 or length-transferred
15 buf=data[transferred:]
16 ret=f.do_usb_command( buf,
17 0x40,
18 0xa0,
19 addr+transferred, 0,
20 this_transfer_size )
21 if (ret>0):
22 print "wrote %d bytes" % ret
23 transferred+=ret
24 else:
25 print "Error: %d" % ret
26 return
28 def reset_bix(filename):
29 """
30 Use this function to reset your firmware. You'll need to reopen the device afterward.
31 """
32 reset_device(True)
33 bix=open(filename).read()
34 print "loading bix file of length: %d" % len(bix)
35 write_ram( 0, bix,len(bix) );
36 reset_device(False)
37 print "Closing device after reset"
38 f.close();