diff --git a/README.rst b/README.rst index 98df20b..6b3733f 100644 --- a/README.rst +++ b/README.rst @@ -81,8 +81,6 @@ Ubuntu 14.04 sudo apt-get install python-pip sudo apt-get install swig python-dev gcc libelf-dev arduino sudo pip install pysimavr - # optional for examples: - sudo pip install entrypoint2 # optional for some tests: sudo apt-get install freeglut3-dev scons @@ -94,6 +92,163 @@ Uninstall # as root pip uninstall pysimavr +Usage +===== + +pysimavr.examples.simple:: + + #-- include('examples/simple.py')--# + from pysimavr.avr import Avr + + if __name__ == "__main__": + avr = Avr(mcu='atmega48', f_cpu=8000000) + print( avr.pc ) + avr.step(1) + print( avr.pc ) + avr.step(1) + print( avr.pc ) + + avr.terminate() + #-# + +Output:: + + #-- sh('python -m pysimavr.examples.simple ')--# + 0 + 2 + 4 + #-# + +pysimavr.examples.hello:: + + #-- include('examples/hello.py')--# + from pysimavr.sim import ArduinoSim + + if __name__ == "__main__": + s= ArduinoSim(snippet='Serial.println("hello!");').get_serial() + print(s) + #-# + +Output:: + + #-- sh('python -m pysimavr.examples.hello ')--# + hello! + + #-# + +pysimavr.examples.delay:: + + #-- include('examples/delay.py')--# + from pysimavr.sim import ArduinoSim + import time + + snippet = ''' + int i=0; + while (1) + { + Serial.println(i++); + _delay_ms(1000); + } + ''' + t0 = None + + + def logger(x): + global t0 + t = time.time() + if not t0: + t0 = t + print t - t0, x + + + f_cpu=16000000 + fps=20 + speed=1 + timespan=5 + + if __name__ == "__main__": + ArduinoSim(snippet=snippet, + timespan=timespan, + serial_line_logger=logger, + f_cpu=f_cpu, + fps=fps, + speed=speed, + ).run() + #-# + +Output:: + + #-- sh('python -m pysimavr.examples.delay ')--# + 0.0 0 + + 1.00977802277 1 + + 2.01976013184 2 + + 3.02968215942 3 + + 4.03792500496 4 + + #-# + +vcd export example +------------------ + +pysimavr.examples.vcd:: + + #-- include('examples/vcd.py')--# + from pysimavr.sim import ArduinoSim + + + vcdfile='delay.vcd' + snippet = ''' + Serial.println("start"); + pinMode(0, OUTPUT); + digitalWrite(0, HIGH); + delay(100); + digitalWrite(0, LOW); + delay(100); + digitalWrite(0, HIGH); + delay(100); + digitalWrite(0, LOW); + delay(100); + Serial.println("end"); + ''' + + if __name__ == "__main__": + sim = ArduinoSim(snippet=snippet, vcd=vcdfile, timespan=0.5) + sim.run() + #-# + +.. image:: gtkwave_id0.png + +File hierarchy +============== + +:: + + |-docs sphinx documentation + |---.build generated documentation + |-pysimavr main python package, high level classes + |---examples examples + |---swig all swig files (simavr and parts) + |-----include copy of simavr generated *.h files + |-------avr copy from avr-libc + |-----parts some electronic parts in c + |-----simavr simavr as git submodule + |-tests unit tests + + + +How to update external sources +============================== + +1. copy avr-libc headers (Ubuntu folder: /usr/lib/avr/include/avr/) into pysimavr/swig/include/avr +2. simavr is a git submodule. Run 'make' inside simavr directory, + then copy generated sim_core_config.h and sim_core_decl.h into pysimavr/swig/include + + + .. _setuptools: http://peak.telecommunity.com/DevCenter/EasyInstall .. _pip: https://pypi.python.org/pypi/pip diff --git a/docs/files.rst b/docs/files.rst deleted file mode 100644 index cbdeaea..0000000 --- a/docs/files.rst +++ /dev/null @@ -1,40 +0,0 @@ -File hierarchy -================== - -:: - - |-docs sphinx documentation - |---_build generated documentation - |-pysimavr main python package, high level classes - |---examples examples - |---swig all swig files (simavr and parts) - |-----cores copy from simavr - |-----include copy from simavr - |-------avr copy from avr-libc - |-----parts some electronic parts in c - |-----sim copy from simavr - |-tests unit tests - - - -How to update simavr sources -============================= - -1. simavr is a git submodule -2. download avr-libc sources (Ubuntu folder: /usr/lib/avr/include/avr/) -3. download pysimavr sources -4. copy over files:: - - $AVR_LIBC_INCLUDE/avr -> $PYSIMAVR/pysimavr/swig/include/avr - -5. install pysimavr:: - - cd $PYSIMAVR - pip install . - - - - - - - \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst index 01d2e93..00b313b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,23 +1,15 @@ -**pysimavr** +======== +pysimavr +======== -:Date: |today| -:PDF: `pysimavr.pdf `_ -Contents: +About +===== -.. toctree:: - :maxdepth: 2 - readme - usage - files - api - -Indices and tables -================== +.. include:: ../README.rst + +.. include:: api.rst -* :ref:`genindex` -* :ref:`modindex` -* :ref:`search` diff --git a/docs/usage.rst b/docs/usage.rst deleted file mode 100644 index 88581bb..0000000 --- a/docs/usage.rst +++ /dev/null @@ -1,41 +0,0 @@ -Usage -================== - -pysimavr.examples.simple: - -.. literalinclude:: ../pysimavr/examples/simple.py - -.. program-output:: python -m pysimavr.examples.simple - :prompt: - -pysimavr.examples.hello: - -.. literalinclude:: ../pysimavr/examples/hello.py - -.. program-output:: python -m pysimavr.examples.hello - :prompt: - -vcd export example -------------------------- - -pysimavr.examples.vcd: - -.. literalinclude:: ../pysimavr/examples/vcd.py - -.. runblock:: pycon - - >>> from pysimavr.examples.vcd import run_sim - >>> run_sim(vcdfile='docs/vcd.vcd') - -.. gtkwave:: docs/vcd.vcd - - -unit test example -------------------------- - -pysimavr/examples/test_example.py - -.. literalinclude:: ../pysimavr/examples/test_example.py - -.. program-output:: nosetests --verbose ../pysimavr/examples/test_example.py - :prompt: diff --git a/pavement.py b/pavement.py index 674f03d..4364c10 100644 --- a/pavement.py +++ b/pavement.py @@ -1,132 +1,27 @@ -from setuptools.extension import Extension -from paver.easy import * +from path import Path +from paver.doctools import cog, html +from paver.easy import options +from paver.options import Bunch from paver.setuputils import setup -from setuptools import find_packages - -import paver.doctools -import paver.misctasks -from paved import * -from paved.dist import * -from paved.util import * -from paved.docs import * -from paved.pycheck import * -from paved.pkg import * - -# get info from setup.py -setup_py = ''.join( - [x for x in path('setup.py').lines() if 'setuptools' not in x]) -exec(setup_py) +IMPORTS=[cog, html, setup] + options( - sphinx=Bunch( - docroot='docs', - builddir="_build", - ), -# pdf=Bunch( -# builddir='_build', -# builder='latex', -# ), -) - -options.paved.clean.rmdirs += ['.tox', - 'dist', - 'build', - ] -options.paved.clean.patterns += ['*.pickle', - '*.doctree', - '*.gz', - 'nosetests.xml', - 'sloccount.sc', - # '*.pdf', '*.tex', - # '*.png', - '*.o', '*.os', # object files - '*.so', # libs - '*_wrap.c', # generated by swig - # '*.vcd', - '*.zip', - 'distribute_setup.py', - 'generated_*', - ] - -options.paved.dist.manifest.include.remove('distribute_setup.py') -options.paved.dist.manifest.include.remove('paver-minilib.zip') -options.paved.dist.manifest.recursive_include.add('pysimavr *.h') -options.paved.dist.manifest.include.add('requirements.txt') - - -@task -@needs( - # 'clean', - 'scons', - 'sloccount', - 'html', - 'pdf', - 'sdist', - 'nose', 'tox', + cog=Bunch( + basedir='.', + pattern='README.rst', + includedir='pysimavr', + beginspec='#--', + endspec='--#', + endoutput='#-#', + ) ) -def alltest(): - 'all tasks to check' - pass - -@task -# @needs('paved.paved.clean') # this does not work! strange -def clean(options, info): - paved.clean(options, info) - info("Cleaning swig files") - d = path('pysimavr') / 'swig' - for x in d.walkfiles('*.py'): - if path(x).stripext() + '.i' in d.files('*.i'): - x.remove() - - -@task -@needs( - 'simavr_make_all', # make generates some header file, scons needs them -) -def scons(): - sh('scons', cwd='pysimavr/swig') - -@task -def simavr_make_all(): - sh('make all', cwd='pysimavr/swig/simavr') - - -@task -def simavr_make_clean(): - sh('make clean', cwd='pysimavr/swig/simavr') - - -@task -@needs( - # 'bdist_egg', - 'sdist', - 'distutils.command.upload', -) -def upload(): - pass - - -@task -@needs('manifest', 'setuptools.command.sdist') -def sdist(): - """Overrides sdist to make sure that our MANIFEST.in is generated. - """ - pass - - -@task -@needs('scons', - 'paved.pycheck.nose') -def nose(): - """Overrides nose to make sure that scons is run. - """ - pass +# get info from setup.py +setup_py = ''.join( + [x for x in Path('setup.py').lines() if 'from setuptools import setup' not in x]) +exec(setup_py) -@task -@needs('scons') -def build(): - '' diff --git a/pysimavr/examples/delay.py b/pysimavr/examples/delay.py index 0952406..880b207 100644 --- a/pysimavr/examples/delay.py +++ b/pysimavr/examples/delay.py @@ -1,4 +1,3 @@ -from entrypoint2 import entrypoint from pysimavr.sim import ArduinoSim import time @@ -21,12 +20,16 @@ def logger(x): print t - t0, x -@entrypoint -def run_sim(timespan=5, f_cpu=16000000, speed=1, fps=20): +f_cpu=16000000 +fps=20 +speed=1 +timespan=5 + +if __name__ == "__main__": ArduinoSim(snippet=snippet, - timespan=timespan, - serial_line_logger=logger, - f_cpu=f_cpu, - fps=fps, - speed=speed, - ).run() + timespan=timespan, + serial_line_logger=logger, + f_cpu=f_cpu, + fps=fps, + speed=speed, + ).run() diff --git a/pysimavr/examples/hello.py b/pysimavr/examples/hello.py index 796f51c..328bddd 100644 --- a/pysimavr/examples/hello.py +++ b/pysimavr/examples/hello.py @@ -1,7 +1,5 @@ from pysimavr.sim import ArduinoSim -from entrypoint2 import entrypoint - -@entrypoint -def run_sim(): - print ArduinoSim(snippet='Serial.println("hello!");').get_serial() +if __name__ == "__main__": + s= ArduinoSim(snippet='Serial.println("hello!");').get_serial() + print(s) \ No newline at end of file diff --git a/pysimavr/examples/simple.py b/pysimavr/examples/simple.py index 2fc90ac..3dd969c 100644 --- a/pysimavr/examples/simple.py +++ b/pysimavr/examples/simple.py @@ -1,9 +1,11 @@ from pysimavr.avr import Avr -from entrypoint2 import entrypoint - -@entrypoint -def run_sim(): +if __name__ == "__main__": avr = Avr(mcu='atmega48', f_cpu=8000000) + print( avr.pc ) + avr.step(1) + print( avr.pc ) avr.step(1) - print avr.pc + print( avr.pc ) + + avr.terminate() \ No newline at end of file diff --git a/pysimavr/examples/test_example.py b/pysimavr/examples/test_example.py deleted file mode 100644 index 8f1d158..0000000 --- a/pysimavr/examples/test_example.py +++ /dev/null @@ -1,11 +0,0 @@ -''' unit test example''' - -from pysimavr.sim import ArduinoSim - - -def test_atmega88(): - mcu = 'atmega88' - snippet = 'Serial.print("hi");' - - output = ArduinoSim(snippet=snippet, mcu=mcu, timespan=0.01).get_serial() - assert output == 'hi' diff --git a/pysimavr/examples/vcd.py b/pysimavr/examples/vcd.py index 14593bd..1191a78 100644 --- a/pysimavr/examples/vcd.py +++ b/pysimavr/examples/vcd.py @@ -1,21 +1,21 @@ -from entrypoint2 import entrypoint from pysimavr.sim import ArduinoSim -@entrypoint -def run_sim(vcdfile='delay.vcd'): - snippet = ''' - Serial.println("start"); - pinMode(0, OUTPUT); - digitalWrite(0, HIGH); - delay(100); - digitalWrite(0, LOW); - delay(100); - digitalWrite(0, HIGH); - delay(100); - digitalWrite(0, LOW); - delay(100); - Serial.println("end"); - ''' +vcdfile='delay.vcd' +snippet = ''' + Serial.println("start"); + pinMode(0, OUTPUT); + digitalWrite(0, HIGH); + delay(100); + digitalWrite(0, LOW); + delay(100); + digitalWrite(0, HIGH); + delay(100); + digitalWrite(0, LOW); + delay(100); + Serial.println("end"); +''' + +if __name__ == "__main__": sim = ArduinoSim(snippet=snippet, vcd=vcdfile, timespan=0.5) sim.run()