File: ex_pinout.py

package info (click to toggle)
simulavr 1.0.0%2Bgit20160221.e53413b-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 5,748 kB
  • sloc: cpp: 35,491; python: 6,991; ansic: 3,567; makefile: 1,072; sh: 653; asm: 414; tcl: 320
file content (55 lines) | stat: -rw-r--r-- 1,457 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Python Script
from sys import argv
from os.path import splitext, basename

import pysimulavr
from ex_utils import SimulavrAdapter

class XPin(pysimulavr.Pin):
  
  def __init__(self, name):
    pysimulavr.Pin.__init__(self)
    self.name = name
    
  def SetInState(self, pin):
    pysimulavr.Pin.SetInState(self, pin)
    print "%s set to '%s' (t=%dns)" % (self.name, pin.toChar(), sim.getCurrentTime())

if __name__ == "__main__":

  doVCD = False
  
  proc, elffile = argv[1].split(":")
  
  sim = SimulavrAdapter()
  sim.dmanSingleDeviceApplication()
  dev = sim.loadDevice(proc, elffile)
  #dev.SetClockFreq(100)
  
  if doVCD:
    print "all registrered trace values:\n ",
    print "\n  ".join(sim.getAllRegisteredTraceValues())
    sigs = ("IRQ.VECTOR9", "PORTA.PORT")
    sim.setVCDDump(splitext(basename(argv[0]))[0] + ".vcd", sigs)
    print "-" * 20
    
  xpin = XPin("port A.0")
  # watch out, that this Net instance will not be deleted until simulation is
  # done (for example, if you create this in a subfunction and do not save
  # this instance too, before you leave this subfunction)
  net = pysimulavr.Net()
  net.Add(xpin)
  net.Add(dev.GetPin("A0"))
    
  sim.dmanStart()
  
  print "simulation start: (t=%dns)" % sim.getCurrentTime()
  sim.doRun(15000000)
  print "simulation end: (t=%dns)" % sim.getCurrentTime()

  print "value 'timer2_ticks'=%d" % sim.getWordByName(dev, "timer2_ticks")
  
  sim.dmanStop()
  del dev
  
# EOF