3 from SerialPort_linux import *
5 # serial device to communicate with
7 # baudrate used for initialization
9 # baudrate used for communication after init
12 # contains the last received checksum from a READ, WRITE or CHECKSUM command
16 time.sleep(0.001) # just to get sure, wait 1ms
22 sendByte((word >> 8) & 0xFF)
25 sendByte(dword & 0xFF)
26 sendByte((dword >> 8) & 0xFF)
27 sendByte((dword >> 16) & 0xFF)
28 sendByte((dword >> 24) & 0xFF)
31 return ord(tty.read())
35 last_checksum = recvByte()
36 last_checksum |= (recvByte() << 8)
38 def cmdREAD(address, size):
41 if (recvByte() != 0xF1):
44 if (recvByte() != 0x82):
46 # tell desired address and size
49 # get binary stream of data
51 for i in range(0, size):
52 data.append(recvByte())
57 def cmdWRITE(address, size, data):
60 if (recvByte() != 0xF1):
63 if (recvByte() != 0x83):
65 # tell desired address and size
68 # write binary stream of data
69 for i in range(0, size):
74 # TODO: test this function!
78 if (recvByte() != 0xF1):
81 if (recvByte() != 0x84):
83 # tell desired address
85 # wait for return parameter - not needed here!
88 # TODO: test this function!
90 # call CHECKSUM command
92 if (recvByte() != 0xF1):
95 if (recvByte() != 0x84):
100 def cmdBAUDRATE(baudrate):
103 # send BAUDRATE command
105 if (recvByte() != 0xF1):
108 if (recvByte() != 0x86):
110 # send desired baudrate
111 sendByte(baudrate & 0xFF)
112 sendByte((baudrate >> 8) & 0xFF)
113 sendByte((baudrate >> 16) & 0xFF)
114 sendByte((baudrate >> 24) & 0xFF)
116 print "Initializing serial port..."
117 tty = SerialPort(DEVICE, 100, INIT_BAUDRATE)
119 print "Please press RESET on your 1337 board..."
125 if tty.read() == 'F':
127 except SerialPortException:
128 # timeout happened, who cares ;-)
131 print "OK, trying to set baudrate..."
134 cmdBAUDRATE(REAL_BAUDRATE)
135 tty = SerialPort(DEVICE, 100, REAL_BAUDRATE)
149 # read something from the IRAM
150 #print cmdREAD(0x00030000, 32)
153 #for i in range(0, 32):
155 #cmdWRITE(0x00030000, 32, data)
158 # write something to the begin of the IRAM
161 for i in range(0, 0x400):
163 data_wr.append(value)
164 checksum = (checksum + value) % (2**16)
166 print "Calculated checksum:", checksum
167 print "Writing", data_wr, "to the IRAM..."
168 cmdWRITE(0x00030000, len(data_wr), data_wr)
169 print "Received Checksum:", last_checksum
172 print "Reading from the IRAM again..."
173 data_re = cmdREAD(0x00030000, len(data_wr))
174 print "Received data:", data_re, "Checksum:", last_checksum