def setUp(self): SimTestCase.setUp(self) # create analog pin as injector and connect to ADC2 self.a2pin = pysimulavr.Pin(1.5) # set to 1.5V level self.__net1 = pysimulavr.Net() self.__net1.Add(self.a2pin) self.__net1.Add(self.dev.GetPin("B4")) # connect to ADC2 # create analog pin as injector and connect to ADC3 self.a3pin = pysimulavr.Pin(1.0) # set to 1V level self.__net2 = pysimulavr.Net() self.__net2.Add(self.a3pin) self.__net2.Add(self.dev.GetPin("B3")) # connect to ADC3
def __init__(self, dev, name, state=None): pysimulavr.Pin.__init__(self) 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 test_00(self): """check adc conversion on free running mode with interrupt""" self.assertDevice() self.assertStartTime() # create analog pin as injector and connect to ADC0 apin = pysimulavr.Pin(1.0) # set to 1V level net1 = pysimulavr.Net() net1.Add(apin) net1.Add(self.dev.GetPin( self.adc0_pin[self.processorName])) # connect to ADC0 # create analog pin as injector and connect to AREF rpin = pysimulavr.Pin(2.5) # set to 2.5V level net2 = pysimulavr.Net() net2.Add(rpin) net2.Add(self.dev.GetPin( self.aref_pin[self.processorName])) # connect to AREF # skip initialisation self.assertInitDone() # check, that we are not in idle loop ... self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 0, "not in idle loop") # run self.sim.doRun(self.sim.getCurrentTime() + (16 * self.ADC_CLOCK)) # check, that we are now in idle loop ... self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 1, "in idle loop") # check adc_value and isr_count to be (0x5555, 0) v = self.sim.getWordByName(self.dev, "adc_value") c = self.sim.getByteByName(self.dev, "isr_count") self.assertEqual(v, 0x5555, "expected adc value is 0x0, got 0x%x" % v) self.assertEqual(c, 0, "expected isr_count is 0, got %d" % c) # change input value for next conversion apin.SetAnalogValue(1.35) # run self.sim.doRun(self.sim.getCurrentTime() + (14 * self.ADC_CLOCK)) # check adc_value and isr_count self.assertComplete(1.0, 2.5, 1) # change input value for next conversion apin.SetAnalogValue(0.7) # run self.sim.doRun(self.sim.getCurrentTime() + (14 * self.ADC_CLOCK)) # check adc_value and isr_count self.assertComplete(1.35, 2.5, 2) # run self.sim.doRun(self.sim.getCurrentTime() + (14 * self.ADC_CLOCK)) # check adc_value and isr_count self.assertComplete(0.7, 2.5, 3)
def __init__(self, dev, sim, name): pysimulavr.Pin.__init__(self) self.ct = sim.getCurrentTime self.name = name # hold the connecting net here, must not be destroyed till deleting XPin self.__net = pysimulavr.Net() self.__net.Add(self) self.__net.Add(dev.GetPin(name))
def test_00(self): """check adc conversion, differential channel""" self.assertDevice() self.assertStartTime() # create analog pin as injector and connect to ADC1 a1pin = pysimulavr.Pin(1.0) # set to 1V level net1 = pysimulavr.Net() net1.Add(a1pin) net1.Add(self.dev.GetPin(self.adc1_pin[self.processorName])) # connect to ADC1 # create analog pin as injector and connect to ADC2 a2pin = pysimulavr.Pin(1.32) # set to 1.32V level net2 = pysimulavr.Net() net2.Add(a2pin) net2.Add(self.dev.GetPin(self.adc2_pin[self.processorName])) # connect to ADC2 # create analog pin as injector and connect to ADC3 a3pin = pysimulavr.Pin(0.4) # set to 0.4V level net3 = pysimulavr.Net() net3.Add(a3pin) net3.Add(self.dev.GetPin(self.adc3_pin[self.processorName])) # connect to ADC3 # skip initialisation self.assertInitDone() # check, that we are not in idle loop ... self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 0, "not in idle loop") # run self.sim.doRun(self.sim.getCurrentTime() + (15 * self.ADC_CLOCK)) # check, that we are now in idle loop ... self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 1, "in idle loop") c = self.sim.getByteByName(self.dev, "complete") self.assertEqual(c, 0, "conversion is not completed") # run, first conversion, channel A2 / A1 self.sim.doRun(self.sim.getCurrentTime() + (12 * self.ADC_CLOCK)) # get ADC value self.assertComplete(1.32, 1.0, 2.56) # start next conversion self.sim.setByteByName(self.dev, "complete", 2) # run, further conversion, channel A3 / A1 self.sim.doRun(self.sim.getCurrentTime() + (15 * self.ADC_CLOCK)) # get ADC value self.assertComplete(0.4, 1.0, 2.56)
def test_00(self): """check state of analog comparator (with interrupt)""" self.assertDevice() self.assertStartTime() # create analog pin as injector and connect to D7 apin = pysimulavr.Pin(1.0) # below bandgap voltage level net = pysimulavr.Net() net.Add(apin) net.Add(self.dev.GetPin(self.ain1_pin[self.processorName])) # connect to AIN1 if self.processorName == "at90s8515": # create analog pin as injector and connect to AIN0, because at90s8515 has no bandgap source to AIN0 rpin = pysimulavr.Pin(1.5) net2 = pysimulavr.Net() net2.Add(rpin) net2.Add(self.dev.GetPin("B2")) # connect to AIN0 # skip initialisation self.assertInitDone() # check, that we are not in idle loop ... self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 0, "not in idle loop") # get a output pin opin = self.dev.GetPin("B0") # check initial isr counter self.assertEqual(self.sim.getByteByName(self.dev, "isr_count"), 0, "isr counter is 0") # run till in idle loop self.sim.doRun(self.sim.getCurrentTime() + self.DELAY) # check, that we are now in idle loop ... self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 1, "in idle loop") # check isr counter is 0 self.assertEqual(self.sim.getByteByName(self.dev, "isr_count"), 0, "isr counter is 0") # check output state self.assertEqual(opin.toChar(), "H", "output value wrong: got=%s, exp=H" % opin.toChar()) # set voltage on apin to 2.0V apin.SetAnalogValue(2.0) # run self.sim.doRun(self.sim.getCurrentTime() + self.DELAY) # check output state self.assertEqual(opin.toChar(), "L", "output value wrong: got=%s, exp=L" % opin.toChar()) # check isr counter self.assertEqual(self.sim.getByteByName(self.dev, "isr_count"), 1, "isr counter is 1")
def test_00(self): """check adc conversion""" self.assertDevice() self.assertStartTime() # create analog pin as injector and connect to ADC0 input apin = pysimulavr.Pin(1.0) # set to 1V level net1 = pysimulavr.Net() net1.Add(apin) net1.Add(self.dev.GetPin( self.adc0_pin[self.processorName])) # connect to ADC0 # create analog pin as injector and connect to AREF rpin = pysimulavr.Pin(2.5) # set to 2.5V level net2 = pysimulavr.Net() net2.Add(rpin) net2.Add(self.dev.GetPin( self.aref_pin[self.processorName])) # connect to AREF # skip initialisation self.assertInitDone() # check, that we are not in idle loop ... self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 0, "not in idle loop") # run self.sim.doRun(self.sim.getCurrentTime() + (15 * self.ADC_CLOCK)) # check, that we are now in idle loop ... self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 1, "in idle loop") c = self.sim.getByteByName(self.dev, "complete") self.assertEqual(c, 0, "conversion is not completed") # run self.sim.doRun(self.sim.getCurrentTime() + (12 * self.ADC_CLOCK)) # get ADC value self.assertComplete(1.0, 2.5) # start next conversion self.sim.setByteByName(self.dev, "complete", 2) apin.SetAnalogValue(1.65) # run self.sim.doRun(self.sim.getCurrentTime() + (15 * self.ADC_CLOCK)) # get ADC value self.assertComplete(1.65, 2.5)
def test_00(self): """check state of analog comparator""" self.assertDevice() self.assertStartTime() # create analog pin as injector and connect to F1 (AIN1 over ADC1) a1pin = pysimulavr.Pin(1.0) net1 = pysimulavr.Net() net1.Add(a1pin) net1.Add(self.dev.GetPin( self.adc1_pin[self.processorName])) # connect to AIN1 # create analog pin as injector and connect to E2 (AIN0) a0pin = pysimulavr.Pin(1.8) net0 = pysimulavr.Net() net0.Add(a0pin) net0.Add(self.dev.GetPin( self.ain0_pin[self.processorName])) # connect to AIN0 # skip initialisation self.assertInitDone() # check, that we are not in idle loop ... self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 0, "not in idle loop") # get a output pin opin = self.dev.GetPin("B1") # run till in idle loop self.sim.doRun(self.sim.getCurrentTime() + self.DELAY) # check, that we are now in idle loop ... self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 1, "in idle loop") # check output state self.assertEqual(opin.toChar(), "H", "output value wrong: got=%s, exp=H" % opin.toChar()) # set voltage on a0pin == AIN0 to 0.3V a0pin.SetAnalogValue(0.3) # run self.sim.doRun(self.sim.getCurrentTime() + self.DELAY) # check output state self.assertEqual(opin.toChar(), "L", "output value wrong: got=%s, exp=L" % opin.toChar())
def test_00(self): """check port function (I/O)""" self.assertDevice() self.assertStartTime() # create digital pin as injector bpin = pysimulavr.Pin() bpin.SetPin("L") # set to L state bnet = pysimulavr.Net() bnet.Add(bpin) # connect to ports ports = self.create_connections(bnet) # skip initialisation self.assertInitDone() # check, that we are not in idle loop ... self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 0, "not in idle loop") # run till in idle loop self.sim.doRun(self.sim.getCurrentTime() + self.DELAY) # check, that we are now in idle loop ... self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 1, "in idle loop") # and 1 time processed the complete loop c = self.sim.getByteByName(self.dev, "loop_count") self.assertTrue(c > 0, "loop one time processed") # check output state for p in ports: p.assertState("L") # set input pin to H bpin.SetPin("H") # set to H state # run self.sim.doRun(self.sim.getCurrentTime() + self.DELAY) c2 = self.sim.getByteByName(self.dev, "loop_count") self.assertTrue(c2 > c, "loop count incremented") # check output state for p in ports: p.assertState("H")
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
def main(): usage = "%prog [options] <program.elf>" opts = optparse.OptionParser(usage) opts.add_option("-m", "--machine", type="string", dest="machine", default="atmega644", help="type of AVR machine to simulate") opts.add_option("-s", "--speed", type="int", dest="speed", default=8000000, help="machine speed") opts.add_option("-r", "--rate", type="float", dest="pacing_rate", default=0., help="real-time pacing rate") opts.add_option("-b", "--baud", type="int", dest="baud", default=38400, help="baud rate of the emulated serial port") opts.add_option("-t", "--trace", type="string", dest="trace", help="signals to trace (? for help)") opts.add_option("-p", "--port", type="string", dest="port", default="/tmp/pseudoserial", help="pseudo-tty device to create for serial port") deffile = os.path.splitext(os.path.basename(sys.argv[0]))[0] + ".vcd" opts.add_option("-f", "--tracefile", type="string", dest="tracefile", default=deffile, help="filename to write signal trace to") options, args = opts.parse_args() if len(args) != 1: opts.error("Incorrect number of arguments") elffile = args[0] proc = options.machine ptyname = options.port speed = options.speed baud = options.baud # launch simulator sc = pysimulavr.SystemClock.Instance() trace = Tracing(options.tracefile, options.trace) dev = pysimulavr.AvrFactory.instance().makeDevice(proc) dev.Load(elffile) dev.SetClockFreq(SIMULAVR_FREQ / speed) sc.Add(dev) pysimulavr.cvar.sysConHandler.SetUseExit(False) trace.load_options() # Do optional real-time pacing if options.pacing_rate: pacing = Pacing(options.pacing_rate) # Setup terminal io = TerminalIO() # Setup rx pin rxpin = SerialRxPin(baud, io) net = pysimulavr.Net() net.Add(rxpin) net.Add(dev.GetPin("D1")) # Setup tx pin txpin = SerialTxPin(baud, io) net2 = pysimulavr.Net() net2.Add(dev.GetPin("D0")) net2.Add(txpin) # Display start banner msg = "Starting AVR simulation: machine=%s speed=%d\n" % (proc, speed) msg += "Serial: port=%s baud=%d\n" % (ptyname, baud) if options.trace: msg += "Trace file: %s\n" % (options.tracefile, ) sys.stdout.write(msg) sys.stdout.flush() # Create terminal device fd = create_pty(ptyname) # Run loop try: io.run(fd) trace.start() sc.RunTimeRange(0x7fff0000ffff0000) trace.finish() finally: os.unlink(ptyname)
def __init__(self, dev, name): pysimulavr.Pin.__init__(self) # hold the connecting net here, must not be destroyed till deleting XPin self.__net = pysimulavr.Net() self.__net.Add(self) self.__net.Add(dev.GetPin(name))
print(" create core A ...") devA = pysimulavr.AvrFactory.instance().makeDevice("atmega16") devA.Load("multicore_a.elf") devA.SetClockFreq(250) # clock period in ns! sc.Add(devA) # create core B: count rising edges, device clock 10MHz, calculated cnt_res = 156,25 nominal! print(" create core B ...") devB = pysimulavr.AvrFactory.instance().makeDevice("atmega16") devB.Load("multicore_b.elf") devB.SetClockFreq(100) # clock period in ns! sc.Add(devB) # create net: connect core A, Port B3 to core B, Port D2 print(" connect core A with core B ...") n = pysimulavr.Net() n.Add(devA.GetPin("B3")) n.Add(devB.GetPin("D2")) # get addresses for cnt_res and cnt_irq variables a = devB.data.GetAddressAtSymbol("cnt_irq") print(" core B: address(cnt_irq)=0x%x" % a) b = devB.data.GetAddressAtSymbol("cnt_res") print(" core B: address(cnt_res)=0x%x" % a) # run simulation, stop after given time and check values print(" run simulation ...") sc.RunTimeRange(4000000) print(" t= 4ms, cnt_irq=%d, cnt_res=%3d" % (devB.getRWMem(a), devB.getRWMem(b))) sc.RunTimeRange(4000000) print(" t= 8ms, cnt_irq=%d, cnt_res=%3d" % (devB.getRWMem(a), devB.getRWMem(b)))
def setUp(self): # Net instance self.net = pysimulavr.Net()
def main(): usage = "%prog [options] <program.elf>" opts = optparse.OptionParser(usage) opts.add_option("-m", "--machine", type="string", dest="machine", default="atmega644", help="type of AVR machine to simulate") opts.add_option("-s", "--speed", type="int", dest="speed", default=8000000, help="machine speed") opts.add_option("-b", "--baud", type="int", dest="baud", default=38400, help="baud rate of the emulated serial port") opts.add_option("-t", "--trace", type="string", dest="trace", help="signals to trace (? for help)") opts.add_option("-p", "--port", type="string", dest="port", default="/tmp/pseudoserial", help="pseudo-tty device to create for serial port") deffile = os.path.splitext(os.path.basename(sys.argv[0]))[0] + ".vcd" opts.add_option("-f", "--tracefile", type="string", dest="tracefile", default=deffile, help="filename to write signal trace to") options, args = opts.parse_args() if len(args) != 1: opts.error("Incorrect number of arguments") elffile = args[0] proc = options.machine ptyname = options.port speed = options.speed baud = options.baud # launch simulator sc = pysimulavr.SystemClock.Instance() trace = Tracing(options.tracefile, options.trace) dev = pysimulavr.AvrFactory.instance().makeDevice(proc) dev.Load(elffile) dev.SetClockFreq(10**9 / speed) sc.Add(dev) trace.load_options() # Setup rx pin rxpin = SerialRxPin(baud) net = pysimulavr.Net() net.Add(rxpin) net.Add(dev.GetPin("D1")) # Setup tx pin txpin = SerialTxPin(baud) net2 = pysimulavr.Net() net2.Add(dev.GetPin("D0")) net2.Add(txpin) # Display start banner msg = "Starting AVR simulation: machine=%s speed=%d\n" % (proc, speed) msg += "Serial: port=%s baud=%d\n" % (ptyname, baud) if options.trace: msg += "Trace file: %s\n" % (options.tracefile, ) sys.stdout.write(msg) sys.stdout.flush() # Create terminal device fd = create_pty(ptyname) # Run loop try: trace.start() while 1: starttime = sc.GetCurrentTime() r = sc.RunTimeRange(speed / 1000) endtime = sc.GetCurrentTime() if starttime == endtime: break d = rxpin.popChars() if d: os.write(fd, d) txsize = txpin.needChars() if txsize: res = select.select([fd], [], [], 0) if res[0]: try: d = os.read(fd, txsize) except os.error, e: if e.errno in (errno.EAGAIN, errno.EWOULDBLOCK): continue break txpin.pushChars(d) trace.finish()
def __init__(self, name, pin): pysimulavr.Pin.__init__(self) self.name = name self.__net = pysimulavr.Net() self.__net.Add(self) self.__net.Add(pin)