summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2013-07-03 01:11:43 +0000
committerChristian Pointner <equinox@spreadspace.org>2013-07-03 01:11:43 +0000
commitc6e84d843cd28f38f0cec8d6bdfe46146b8c6af0 (patch)
treea1786e0d8de3adce31933ae1d8fce3e638fccb5e
parentadded some constants and first version for serial send,recv routines (diff)
small reordering
git-svn-id: https://svn.spreadspace.org/pic/trunk@25 a09c6847-51d9-44de-8ef2-e725cf50f3c7
-rwxr-xr-xdownloader/downloader.py107
1 files changed, 67 insertions, 40 deletions
diff --git a/downloader/downloader.py b/downloader/downloader.py
index c6cb3ed..41e60c2 100755
--- a/downloader/downloader.py
+++ b/downloader/downloader.py
@@ -26,44 +26,11 @@
VERSION_MAJ = 0
VERSION_MIN = 1
-def open_serial(device, baud):
- import os
- import tty
- import termios
-
- print "opening %s (%s Baud)" % (device, baud)
-
- baudrates = { 50: termios.B50, 75: termios.B75, 110: termios.B110, 134: termios.B134,
- 150: termios.B150, 200: termios.B200, 300: termios.B300, 600: termios.B600,
- 1200: termios.B1200, 1800: termios.B1800, 2400: termios.B2400, 4800: termios.B4800,
- 9600: termios.B9600, 19200: termios.B19200, 38400: termios.B38400,
- 57600: termios.B57600, 115200: termios.B115200, 230400: termios.B230400 }
-
- baudreate = termios.B19200
- try:
- baudrate = baudrates[int(baud)]
- except (KeyError, ValueError):
- print "ERROR: invalid baudrate"
- sys.exit(3)
-
- try:
- dev = os.open(device, os.O_RDWR | os.O_NOCTTY)
- tty.setraw(dev, termios.TCSAFLUSH)
- tio = termios.tcgetattr(dev)
- tio[4] = tio[5] = baudrate
- termios.tcsetattr(dev, termios.TCSAFLUSH, tio)
- termios.tcflush(dev, termios.TCIFLUSH)
- return dev
-
- except OSError, msg:
- print "ERROR: opening serial device: %s" % msg
- sys.exit(3)
- except termios.error, msg:
- print "ERROR: configuring serial device: %s" % msg
- sys.exit(3)
-
+### HEX File Magic
def load_hex(file):
+ from intelhex import IntelHex
+
fin = file
if fin == '-':
fin = sys.stdin
@@ -107,6 +74,44 @@ def create_flash_segments(codedata, fss):
yield (i, slice)
+### Interface to Bootloader
+
+def open_serial(device, baud):
+ import os
+ import tty
+ import termios
+
+ print "opening %s (%s Baud)" % (device, baud)
+
+ baudrates = { 50: termios.B50, 75: termios.B75, 110: termios.B110, 134: termios.B134,
+ 150: termios.B150, 200: termios.B200, 300: termios.B300, 600: termios.B600,
+ 1200: termios.B1200, 1800: termios.B1800, 2400: termios.B2400, 4800: termios.B4800,
+ 9600: termios.B9600, 19200: termios.B19200, 38400: termios.B38400,
+ 57600: termios.B57600, 115200: termios.B115200, 230400: termios.B230400 }
+
+ baudreate = termios.B19200
+ try:
+ baudrate = baudrates[int(baud)]
+ except (KeyError, ValueError):
+ print "ERROR: invalid baudrate"
+ sys.exit(3)
+
+ try:
+ dev = os.open(device, os.O_RDWR | os.O_NOCTTY)
+ tty.setraw(dev, termios.TCSAFLUSH)
+ tio = termios.tcgetattr(dev)
+ tio[4] = tio[5] = baudrate
+ termios.tcsetattr(dev, termios.TCSAFLUSH, tio)
+ termios.tcflush(dev, termios.TCIFLUSH)
+ return dev
+
+ except OSError, msg:
+ print "ERROR: opening serial device: %s" % msg
+ sys.exit(3)
+ except termios.error, msg:
+ print "ERROR: configuring serial device: %s" % msg
+ sys.exit(3)
+
def calc_csum(str):
cs = 0
for c in str:
@@ -150,7 +155,7 @@ def exec_command(dev, cmd, answer):
return data
-### commands
+### Commands
def identify(dev):
data = exec_command(dev, "i", "BB10sHBB")
@@ -163,16 +168,38 @@ def identify(dev):
print "connected with Bootloader '%s', (ID=%04X, FSS=%d)" % (id['name'], id['devid'], id['fss'])
return id
+def boot(dev):
+ exec_command(dev, "b", "")
-### main
+def reset(dev):
+ exec_command(dev, "r", "")
+
+def read_flash(dev):
+ return None
+
+def write_flash(dev):
+ return None
+
+def read_eeprom(dev):
+ return None
+
+def write_eeprom(dev):
+ return None
+
+def read_config(dev):
+ return None
+
+def write_confi(dev):
+ return None
+
+
+### Main
if __name__ == '__main__':
import getopt
import sys
import os
- from intelhex import IntelHex
-
usage = '''spreadspace simple pic downloader.
Usage:
python downloader.py [options] INFILE