add time measurement for performance comparisons
[pyfrprog.git] / frprog.py
index 6c394183aecaf4680ff1f0b6d235ef62552ac31f..b9432a85c2a67f698ced568193561155cb65fb9e 100755 (executable)
--- a/frprog.py
+++ b/frprog.py
@@ -15,7 +15,6 @@ KERNEL_BAUDRATE=115200
 last_checksum = 0
 
 def sendByte(byte):
-       time.sleep(0.001) # just to get sure, wait 1ms
        tty.write(chr(byte))
 
 def sendWord(word):
@@ -36,7 +35,7 @@ def recvChecksum():
        last_checksum = recvByte()
        last_checksum |= (recvByte() << 8)
 
-def cmdREAD(address, size):
+def bootromREAD(address, size):
        # send READ command
        sendByte(0x01)
        if (recvByte() != 0xF1):
@@ -55,7 +54,7 @@ def cmdREAD(address, size):
        recvChecksum()
        return data
 
-def cmdWRITE(address, size, data):
+def bootromWRITE(address, size, data):
        # send WRITE command
        sendByte(0x01)
        if (recvByte() != 0xF1):
@@ -73,7 +72,7 @@ def cmdWRITE(address, size, data):
        recvChecksum()
 
 # TODO: test this function!
-def cmdCALL(address):
+def bootromCALL(address):
        # send CALL command
        sendByte(0x01)
        if (recvByte() != 0xF1):
@@ -87,7 +86,7 @@ def cmdCALL(address):
        #return recvByte()
 
 # TODO: test this function!
-def cmdCHECKSUM():
+def bootromCHECKSUM():
        # call CHECKSUM command
        sendByte(0x01)
        if (recvByte() != 0xF1):
@@ -98,7 +97,7 @@ def cmdCHECKSUM():
        # get checksum
        recvChecksum()
 
-def cmdBAUDRATE(baudrate):
+def bootromBAUDRATE(baudrate):
        # send BAUDRATE command
        sendByte(0x01)
        if (recvByte() != 0xF1):
@@ -211,9 +210,13 @@ while True:
                # timeout happened, who cares ;-)
                pass
 
+starttime = time.time() # save time at this point for evaluating the duration at the end
+
 print "OK, trying to set baudrate..."
 # set baudrate
-cmdBAUDRATE(BOOTLOADER_BAUDRATE)
+bootromBAUDRATE(BOOTLOADER_BAUDRATE)
+time.sleep(0.1) # just to get sure that the bootloader is really running in new baudrate mode!
+del tty
 tty = SerialPort(DEVICE, 100, BOOTLOADER_BAUDRATE)
 
 print "Transfering pkernel program to IRAM",
@@ -224,21 +227,20 @@ for seq in bootloaderseqs:
        else:
                continue
        #print "RAMing", len(seq.data), "bytes at address", hex(addr)
-       cmdWRITE(addr, len(seq.data), seq.data)
+       bootromWRITE(addr, len(seq.data), seq.data)
        tty.flush()
        sys.stdout.write(".")
        sys.stdout.flush()
 print
 
 # execute our pkernel finally and set pkernel conform baudrate
-cmdCALL(0x30000)
-time.sleep(0.5) # just to get sure that the pkernel is really running!
+bootromCALL(0x30000)
+time.sleep(0.1) # just to get sure that the pkernel is really running!
 del tty
 tty = SerialPort(DEVICE, None, KERNEL_BAUDRATE)
 
 print "Performing ChipErase..."
 pkernCHIPERASE()
-print "Chip erasing done."
 
 print "Flashing",
 for seq in pkernelseqs:
@@ -252,7 +254,9 @@ for seq in pkernelseqs:
        sys.stdout.write(".")
        sys.stdout.flush()
 print
-print "Flashing done."
+
+duration = time.time() - starttime
+print "Procedure complete, took", round(duration, 2), "seconds."
 
 sendByte(0x97) # exit and restart
 print "Program was started. Have fun!"