diff options
author | Christian Pointner <equinox@spreadspace.org> | 2013-07-03 21:02:45 +0000 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2013-07-03 21:02:45 +0000 |
commit | c843e1ea6b9ccaf7cfe70182f04e82f143cb289a (patch) | |
tree | c2a5d9d940372c1386fe18c3ed250d2cd987277a /downloader | |
parent | small reordering (diff) |
implemented basic commands
git-svn-id: https://svn.spreadspace.org/pic/trunk@26 a09c6847-51d9-44de-8ef2-e725cf50f3c7
Diffstat (limited to 'downloader')
-rwxr-xr-x | downloader/downloader.py | 49 | ||||
-rw-r--r-- | downloader/proto.txt | 12 |
2 files changed, 37 insertions, 24 deletions
diff --git a/downloader/downloader.py b/downloader/downloader.py index 41e60c2..936f459 100755 --- a/downloader/downloader.py +++ b/downloader/downloader.py @@ -125,13 +125,13 @@ def exec_command(dev, cmd, answer): 3: "not implemented", 4: "flash write error", 5: "address invalid", 6: "address prohibited" } - answer = "=cB" + answer + "B" + answer = '<cB' + answer + 'B' answer_len = struct.calcsize(answer) cstr = cmd + calc_csum(cmd) os.write(dev, cstr) - astr = "" + astr = b'' while len(astr) < answer_len: astr += os.read(dev, answer_len - len(astr)) data = list(struct.unpack(answer, astr)) @@ -158,39 +158,49 @@ def exec_command(dev, cmd, answer): ### Commands def identify(dev): - data = exec_command(dev, "i", "BB10sHBB") + data = exec_command(dev, 'i', 'BB10sHBB') id = { 'ver_maj': data[0], 'ver_min': data[1], 'name': data[2], 'devid': data[3], 'fss': data[4], 'supported': data[5] } if id['ver_maj'] != VERSION_MAJ: - print "Incomaptible protocol version, expected: %d, got: %d" % (VERSION_MAJ, id['ver_maj']) + print "incompatible protocol version, expected: %d, got: %d" % (VERSION_MAJ, id['ver_maj']) + sys.exit(4) + if id['fss'] == 0: + print "FSS value is 0 " sys.exit(4) print "connected with Bootloader '%s', (ID=%04X, FSS=%d)" % (id['name'], id['devid'], id['fss']) return id def boot(dev): - exec_command(dev, "b", "") + exec_command(dev, 'b', '') -def reset(dev): - exec_command(dev, "r", "") +def reset(dev, id): + exec_command(dev, 'r', '') -def read_flash(dev): - return None +def read_flash_segment(dev, id, addr): + cmd = struct.pack('<cH', 'f', addr) + return exec_command(dev, cmd, '%dH' % id['fss']) -def write_flash(dev): - return None +def write_flash_segment(dev, id, addr, data): + cmd = struct.pack('<cH%dH' % id['fss'], 'F', addr, *data) + return exec_command(dev, cmd, '') -def read_eeprom(dev): - return None +def read_eeprom(dev, id, addr, len): + cmd = struct.pack('<cHH', 'e', addr, len) + return exec_command(dev, cmd, '%dH' % len) -def write_eeprom(dev): - return None +def write_eeprom(dev, id, addr, len, data): + cmd = struct.pack('<cHH%dH' % len, 'E', addr, len, *data) + return exec_command(dev, cmd, '') -def read_config(dev): - return None +def read_config(dev, id, nr): + cmd = struct.pack('<cB', 'c', nr) + data = exec_command(dev, cmd, 'H') + return data[0] -def write_confi(dev): - return None +def write_config(dev, id, nr, word): + cmd = struct.pack('<cBH', 'C', nr, word) + return exec_command(dev, cmd, '') ### Main @@ -199,6 +209,7 @@ if __name__ == '__main__': import getopt import sys import os + import struct usage = '''spreadspace simple pic downloader. Usage: diff --git a/downloader/proto.txt b/downloader/proto.txt index 1228811..826be5f 100644 --- a/downloader/proto.txt +++ b/downloader/proto.txt @@ -17,7 +17,7 @@ Description: Every command consits of one byte command code, a fixed number of bytes as arguments and ends with a XOR checksum over all bytes sent. All data is -transferred LSB first. +transferred LSB first (aka little endian). All addresses and words are 2bytes long. Every answer to a command starts with the command code. One byte return value, optionally some data and a checksum (XOR over all bytes received) The return codes have the following meaning: @@ -138,7 +138,7 @@ read eeprom: 'e' | <ret> | data | <csum> The bootloader reads <len> bytes from eeprom at address <addr> and returns it as - <data>. + <data>. len is 2bytes long. write eeprom: @@ -151,7 +151,7 @@ write eeprom: 'E' | <ret> | <csum> The bootloader writes <data> (which has to contain exactly <len> bytes) to address - <addr> inside the eeprom. + <addr> inside the eeprom. len is 2bytes long. read config: @@ -163,7 +163,8 @@ read config: answer: 'c' | <ret> | word | <csum> - The bootloader reads and returns the configuration word number <nr>. + The bootloader reads and returns the configuration word number <nr>. <nr> is one + byte long. write config: @@ -175,4 +176,5 @@ write config: answer: 'C' | <ret> | <csum> - The bootloader writes <word> onto configuration word number <nr>. + The bootloader writes <word> onto configuration word number <nr>. <nr> is one + byte long |