Merge branch 'master' of wien.tomnetworks.com:pyfrprog
authorBernhard Urban <lewurm@gmx.net>
Mon, 14 Dec 2009 08:47:29 +0000 (09:47 +0100)
committerBernhard Urban <lewurm@gmx.net>
Mon, 14 Dec 2009 08:47:29 +0000 (09:47 +0100)
1  2 
pkernel/kernel.py

diff --combined pkernel/kernel.py
index 576c6807fa11f95d6c52418985579da38ec19eb0,e495a86b693f10d2a9557d15a57f1052898e5ca4..afadfcd4662e95c9a81625ed1cb75479b20ccbb5
@@@ -9,27 -9,8 +9,24 @@@ KERNEL_BAUDRATE=3840
  
  def recvByte():
        i = tty.read()
-       while len(i)==0:
-               time.sleep(0.03)
-               i = tty.read()
        return ord(i)
  
 +def recvByteTO(b): #with timeout
 +      j = 0
 +      i = tty.read()
 +      while len(i)==0 and j < 400:
 +              time.sleep(0.03)
 +              i = tty.read()
 +              j = j + 1
 +      if j == 400:
 +              print "ack it!"
 +              sendByte(0x23)
 +              if(recvByte() != 0xaa):
 +                      raise Exception #ok, something really failed
 +      else:
 +              if(ord(i) != b):
 +                      raise Exception
 +
  def sendByte(byte):
        time.sleep(0.005) # just to get sure, wait 5ms
        tty.write(chr(byte))
@@@ -69,16 -50,28 +66,16 @@@ def pkernWRITE(address, size, data)
        print "address:", hex(address), "size:", size
        # send WRITE command
        sendByte(0x13)
 -      if (recvByte() != 0x37):
 -              raise Exception
 +      recvByteTO(0x37)
 +
        # tell desired address and size
        sendDWord(address)
        sendWord(size)
  
 -      if (recvByte() != 0x04):
 -              raise Exception
 -      print "Received Metadata."
 -
        # write binary stream of data
        for i in range(0, size):
                sendByte(data[i])
  
 -      if (recvByte() != 0x08):
 -              raise Exception
 -      print "Received Data."
 -
 -      if (recvByte() != 0x28):
 -              raise Exception
 -      print "Flashing done."
 -
  
  class FlashSequence(object):
        def __init__(self, address, data):
@@@ -90,7 -83,7 +87,7 @@@ flashseqs = [
  
  
  print "Initializing serial port..."
- tty = SerialPort(DEVICE, 0, KERNEL_BAUDRATE)
+ tty = SerialPort(DEVICE, None, KERNEL_BAUDRATE)
  
  # check command line arguments
  if len(sys.argv) != 2:
@@@ -151,8 -144,6 +148,8 @@@ for seq in flashseqs
        print "Flashing", len(seq.data), "bytes at address", hex(seq.address)
        pkernWRITE(seq.address, len(seq.data), seq.data)
  
 -sendByte(0x99);
 +#sendByte(0x99); #exit and wait
 +#print "Reset your board now to run code from Flash"
 +
  
 -print "Reset your board now to run code from Flash"
 +sendByte(0x97); #exit and restart