simulavr-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Simulavr-devel] Simulation of the interactive, UART using firmware with


From: wzab
Subject: [Simulavr-devel] Simulation of the interactive, UART using firmware with pysimulavr
Date: Thu, 04 Nov 2010 00:15:34 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.15) Gecko/20101030 Icedove/3.0.10

Hi,
I want to use simulavrxx to test my AVR code (the original
AVR studio was way too slow, and possibilities to interface
the simulated core with my programs and Verilog are really
important to me).
My AVR code intensively uses the UART interface.
Unfortunately it also sends smetimes the double quote character
("), which caused the Tcl/Tk GUI to crash.
Additionally I wanted to have more tight integration between my code
and the simulavr, and therefore I have decided to use pysimulavr.

My first finding was, that I'm unable to access periferials
defined in serialtx and serialrx from pysimulavr, but I've worked around this by adding
  #include "ui/ui.h"
  #include "ui/extpin.h"
  #include "ui/keyboard.h"
  #include "ui/lcd.h"
  #include "ui/scope.h"
  #include "ui/serialrx.h"
  #include "ui/serialtx.h"
and
  %include "ui/ui.h"
  %include "ui/extpin.h"
  %include "ui/keyboard.h"
  %include "ui/lcd.h"
  %include "ui/scope.h"
  %include "ui/serialrx.h"
  %include "ui/serialtx.h"
lines to the pysimulavr.i file (I attach the modified version).

After recompilation, I have built my simulation file mytest.py (attached).

i have found, that if I instantiated my UART receiver as below:
class AVRtest(SimulavrAdapter):

  def __init__(self):
    self.dmanSingleDeviceApplication()
    proc, elffile = argv[1].split(":")
    self.device = self.loadDevice(proc, elffile)
    self.device.SetClockFreq(125)

rs_in=pysimulavr.Net()
mytest = AVRtest()
mytest.dmanStart()
d1=mytest.device.GetPin("D1")
rs_in.Add(d1)
rx=pysimulavr.SerialRxBuffered()
rx.SetBaudRate(9600)
r0=rx.GetPin("rx")
rs_in.Add(r0)

the UART receiver was not simulated.
To cure it, I had to modify the SimulavrAdapter class, adding the following method:

def addComponent(self,c):
    self.__sc.Add(c)
    return 0

Then I could register mu UART interface with:
  mytest.addComponent(rx)
right after its creation.

What's interesting, is that when I have done the same with the SerialTxBuffered component, I got the following error after invocation of mytest.doRun:

FATAL: file ui/serialtx.cpp: line 98: Illegal state in SerialTx
It appears, that SerialTxBuffered must register itself in its
void SerialTxBuffered::Send(unsigned char data) procedure:
[...]
      SystemClock::Instance().Add(this);
[...]
to work correctly.

The final version of my test file "mytest.py" is also attached.

My test is put in the examples/python directory and may be run with:
LD_LIBRARY_PATH=../../src/.libs \
PYTHONPATH=../../src \
/usr/bin/python -i mytest.py atmega16:code.elf

I hope, that this code may be useful for someone else, and I'd also
appretiate any improvements and corrections, if I've done something in a wrong way.
--
Regards,
WZab

Attachment: mytest.py
Description: Text Data

Attachment: pysimulavr.i
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]