impl. CALL and CHECKSUM bootloader cmds, untested
[pyfrprog.git] / frprog.py
index 260fda1d1908f35a62b060318903d25fa1647411..66e6d477e30cd49120b5839fa0080cf6b4b343ac 100755 (executable)
--- a/frprog.py
+++ b/frprog.py
@@ -2,6 +2,13 @@
 import sys, time
 from SerialPort_linux import *
 
+# serial device to communicate with
+DEVICE="/dev/ttyUSB0"
+# baudrate used for initialization
+INIT_BAUDRATE=9600
+# baudrate used for communication after init
+REAL_BAUDRATE=38400
+
 # contains the last received checksum from a READ, WRITE or CHECKSUM command
 last_checksum = 0
 
@@ -25,7 +32,6 @@ def recvByte():
 
 def recvChecksum():
        global last_checksum
-       # get checksum
        last_checksum = recvByte()
        last_checksum |= (recvByte() << 8)
 
@@ -65,6 +71,32 @@ def cmdWRITE(address, size, data):
        # get checksum
        recvChecksum()
 
+# TODO: test this function!
+def cmdCALL(address):
+       # send CALL command
+       sendByte(0x01)
+       if (recvByte() != 0xF1):
+               raise Exception
+       sendByte(0x04)
+       if (recvByte() != 0x84):
+               raise Exception
+       # tell desired address
+       sendDWord(address)
+       # wait for return parameter - not needed here!
+       #return recvByte()
+
+# TODO: test this function!
+def cmdCHECKSUM():
+       # call CHECKSUM command
+       sendByte(0x01)
+       if (recvByte() != 0xF1):
+               raise Exception
+       sendByte(0x05)
+       if (recvByte() != 0x84):
+               raise Exception
+       # get checksum
+       recvChecksum()
+
 def cmdBAUDRATE(baudrate):
        global last_checksum
 
@@ -82,7 +114,7 @@ def cmdBAUDRATE(baudrate):
        sendByte((baudrate >> 24) & 0xFF)
 
 print "Initializing serial port..."
-tty = SerialPort("/dev/ttyUSB0", 100, 9600)
+tty = SerialPort(DEVICE, 100, INIT_BAUDRATE)
 
 print "Please press RESET on your 1337 board..."
 
@@ -99,8 +131,8 @@ while 1:
 print "OK, trying to set baudrate..."
 
 # set baudrate
-cmdBAUDRATE(38400)
-tty = SerialPort("/dev/ttyUSB0", 100, 38400)
+cmdBAUDRATE(REAL_BAUDRATE)
+tty = SerialPort(DEVICE, 100, REAL_BAUDRATE)
 """
 print
 sendByte(0x01)