File: example_io.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 (53 lines) | stat: -rw-r--r-- 1,517 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
# 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, dev, name, state = None):
    pysimulavr.Pin.__init__(self)
    self.name = name
    if state is not None: self.SetPin(state)
    # hold the connecting net here, it have not be destroyed, if we leave this method
    self.__net = pysimulavr.Net()
    self.__net.Add(self)
    self.__net.Add(dev.GetPin(name))
    
  def SetInState(self, pin):
    pysimulavr.Pin.SetInState(self, pin)
    print "%s='%s' (t=%dns)" % (self.name, pin.toChar(), sim.getCurrentTime())

if __name__ == "__main__":

  proc, elffile = argv[1].split(":")
  
  sim = SimulavrAdapter()
  sim.dmanSingleDeviceApplication()
  dev = sim.loadDevice(proc, elffile)
  
  a0 = XPin(dev, "A0")
  a1 = XPin(dev, "A1", "H")
  a7 = XPin(dev, "A7", "H")
  
  sim.dmanStart()
  print "simulation start: (t=%dns)" % sim.getCurrentTime()
  sim.doRun(sim.getCurrentTime() + 7000000)
  a1.SetPin("L")
  sim.doRun(sim.getCurrentTime() + 5000000)
  a7.SetPin("L")
  sim.doRun(sim.getCurrentTime() + 2000000)
  a1.SetPin("H")
  sim.doRun(sim.getCurrentTime() + 1000000)
  print "simulation end: (t=%dns)" % sim.getCurrentTime()
  
  print "value 'timer2_ticks'=%d" % sim.getWordByName(dev, "timer2_ticks")
  print "value 'port_val'=0x%x" % sim.getWordByName(dev, "port_val")
  print "value 'port_cnt'=%d" % sim.getWordByName(dev, "port_cnt")
  
  sim.dmanStop()
  del dev
  
# EOF