Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision Next revisionBoth sides next revision | ||
amforth [2007-06-08 00:05] – external edit 127.0.0.1 | amforth [2007-07-09 19:21] – added upload script nik | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== amforth ====== | ====== amforth ====== | ||
- | amforth is a [[forth language]] implementation for the Atmel AVR family of [[microcontrollers]]. | + | amforth is a [[forth language]] implementation for the Atmel AVR family of [[microcontrollers]]. |
- | * (http:// | + | all input and output is in hex by default |
- | all input and output is in hex by default (this can be changed with the **decimal** | ||
- | |||
when defining new words, the words are written immediately to flash. so they are still there after losing power. | when defining new words, the words are written immediately to flash. so they are still there after losing power. | ||
Line 12: | Line 10: | ||
you can set a startup procedure (called the " | you can set a startup procedure (called the " | ||
| | ||
- | |||
- | |||
===== examples ===== | ===== examples ===== | ||
Line 182: | Line 178: | ||
--PiX - 01 Mar 2007 | --PiX - 01 Mar 2007 | ||
+ | ---- | ||
+ | |||
+ | |||
---- | ---- | ||
Libarynth > Libarynth Web > AmForth r4 - 09 Mar 2007 - 11:56 | Libarynth > Libarynth Web > AmForth r4 - 09 Mar 2007 - 11:56 | ||
---- | ---- | ||
+ | |||
+ | amforth-upload.py.txt | ||
+ | < | ||
+ | |||
+ | |||
+ | # | ||
+ | |||
+ | # amforth-upload.py | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # also waits for a prompt after each line to allow the compiler a chance to run | ||
+ | # | ||
+ | # in theory it should never overrun the input buffer on the controller, | ||
+ | # but it will easily get stuck if the output from the controller is unusual | ||
+ | # | ||
+ | # you have to kill any other processes that are accessing the serial port before running this, | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # like x/y/zmodem for minicom (except for the difficulty of killing it when it gets confused). oh well. | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | |||
+ | |||
+ | import sys | ||
+ | import getopt | ||
+ | import os | ||
+ | import re | ||
+ | |||
+ | def write_line_flow(string, | ||
+ | # strip comments | ||
+ | # these probably will strip comment-like structures out of ." .." strings as well. | ||
+ | |||
+ | if debug: | ||
+ | print >> | ||
+ | |||
+ | string = re.sub(" | ||
+ | string = re.sub(" | ||
+ | string = re.sub(" | ||
+ | |||
+ | if re.match(" | ||
+ | if verbose: | ||
+ | print >> | ||
+ | return | ||
+ | |||
+ | if debug: | ||
+ | print >> | ||
+ | |||
+ | if verbose: | ||
+ | print >> | ||
+ | for o in list(string): | ||
+ | dest.write(o); | ||
+ | |||
+ | if o == " | ||
+ | o = " " | ||
+ | |||
+ | while True: | ||
+ | i = dest.read(1) | ||
+ | #print "<" | ||
+ | #print >> | ||
+ | sys.stdout.write(i) | ||
+ | sys.stdout.flush() | ||
+ | if i == o: | ||
+ | #print " | ||
+ | break | ||
+ | # | ||
+ | if verbose: | ||
+ | print >> | ||
+ | |||
+ | start, nl, space, o, gt = range(5) | ||
+ | |||
+ | state = start | ||
+ | |||
+ | while True: | ||
+ | #print >> | ||
+ | # | ||
+ | i = dest.read(1) | ||
+ | #print "<" | ||
+ | #print >> | ||
+ | sys.stdout.write(i) | ||
+ | sys.stdout.flush() | ||
+ | if state == start: | ||
+ | if i == " | ||
+ | state = nl | ||
+ | elif i == " ": | ||
+ | state = space | ||
+ | continue | ||
+ | elif state == nl: | ||
+ | if i == ">": | ||
+ | state = gt | ||
+ | else: | ||
+ | state = start | ||
+ | continue | ||
+ | elif state == gt: | ||
+ | if i == " ": | ||
+ | if debug: | ||
+ | print >> | ||
+ | break | ||
+ | else: | ||
+ | state = start | ||
+ | continue | ||
+ | elif state == space: | ||
+ | if i == " | ||
+ | state = o | ||
+ | else: | ||
+ | state = start | ||
+ | continue | ||
+ | elif state == o: | ||
+ | if i == " | ||
+ | if debug: | ||
+ | print >> | ||
+ | break | ||
+ | else: | ||
+ | state = start | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | def write_file_flow(in_file, | ||
+ | while(True): | ||
+ | line = in_file.readline() | ||
+ | if len(line)> | ||
+ | write_line_flow(line, | ||
+ | else: | ||
+ | break | ||
+ | |||
+ | def main(argv): | ||
+ | |||
+ | global verbose, debug | ||
+ | |||
+ | #in_file = file(" | ||
+ | #tty_dev = file("/ | ||
+ | |||
+ | tty_dev_name = "/ | ||
+ | force = False | ||
+ | verbose = False | ||
+ | debug = False | ||
+ | |||
+ | try: | ||
+ | opts, args = getopt.getopt(argv," | ||
+ | except getopt.GetoptError: | ||
+ | print >> | ||
+ | sys.exit(1) | ||
+ | |||
+ | for opt, arg in opts: | ||
+ | if opt == " | ||
+ | print >> | ||
+ | print >> | ||
+ | print >> | ||
+ | print >> | ||
+ | print >> | ||
+ | sys.exit(1) | ||
+ | elif opt == " | ||
+ | tty_dev_name = arg | ||
+ | elif opt == " | ||
+ | verbose = True | ||
+ | elif opt == " | ||
+ | force = True | ||
+ | elif opt == " | ||
+ | debug = True | ||
+ | |||
+ | if not force: | ||
+ | if not os.system(" | ||
+ | if not os.system(" | ||
+ | print >> | ||
+ | print >> | ||
+ | sys.exit(1) | ||
+ | else: | ||
+ | print >> | ||
+ | print >> | ||
+ | |||
+ | |||
+ | tty_dev = file(tty_dev_name," | ||
+ | |||
+ | if len(args)< | ||
+ | if verbose: | ||
+ | print >> | ||
+ | write_file_flow(sys.stdin, | ||
+ | else: | ||
+ | for filename in args: | ||
+ | in_file = file(filename," | ||
+ | if verbose: | ||
+ | print >> | ||
+ | write_file_flow(in_file, | ||
+ | in_file.close() | ||
+ | |||
+ | |||
+ | |||
+ | if __name__ == " | ||
+ | main(sys.argv[1: | ||
+ | |||
+ | </ |