Hi,
unfortunately there is no complete guide for this task. Just a rough
howto for the first steps. (see attached file) But it's also difficult
to describe all faccets of the task to add a new device. Maybe it helps.
Other possibility to make it is using a allready available device and
strip all, what's not matching the new device. For atmega169 it's maybe
atmega128 (because of the port count).
You should hold in mind, that the lcd controller (maybe the reason for
using atmega169) isn't implemented in simulavr. And to implement a new
peripheral unit needs some more knowledge.
cu, Thomas
Am 03.03.2013 20:22, schrieb lode leroy:
is there a guideline on how to add new devices to simulavr?
I would like to simulate an atmega169...
_______________________________________________
Simulavr-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/simulavr-devel
Howto integrate a new device
============================
- choose a name for *.h and *.cpp file
- choose a name for device class definition (maybe see for other existing
devices)
Here, for example, it's for ATtiny25-85 devices!
- create header file (maybe copy other header file and edit)::
/*
****************************************************************************
*
* simulavr - A simulator for the Atmel AVR family of microcontrollers.
* Copyright (C) 2001, 2002, 2003 Klaus Rudolph
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
****************************************************************************
*
* $Id$
*/
#ifndef ATTINY25
#define ATTINY25
#include "avrdevice.h"
#include "hardware.h"
#include "rwmem.h"
#include "hwtimer/timerprescaler.h"
#include "hwtimer/timerirq.h"
#include "hwtimer/hwtimer.h"
#include "externalirq.h"
#include "hwuart.h"
//! AVRDevice class for ATTiny25/45/85
class AvrDevice_attiny85: public AvrDevice {
public:
AvrDevice_attiny85();
~AvrDevice_attiny85();
};
#endif
- create *.cpp file. You have to know: how much I/O registers are available
(except the
common registers), how much SRAM in byte, how much flash in byte, if JMP
instruction is
available, if MUL instruction is available, how much bytes for interrupt
vector entry,
how much interrupt vectors, size of EEPROM, what's the irq vector for EEPROM
ready interrupt,
is EEPROM a extendend device (e.g. EECR has 6 control bits, how much bits
does stackpointer use
(depends on flash size)::
/*
****************************************************************************
*
* simulavr - A simulator for the Atmel AVR family of microcontrollers.
* Copyright (C) 2001, 2002, 2003 Klaus Rudolph
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
****************************************************************************
*
* $Id$
*/
#include "attiny25_45_85.h"
#include "hardware.h"
#include "irqsystem.h"
#include "hwport.h"
#include "hwstack.h"
#include "hweeprom.h"
#include "hwwado.h"
#include "hwsreg.h"
#include "flashprog.h"
#include "avrfactory.h"
AVR_REGISTER(attiny85, AvrDevice_attiny85);
AvrDevice_attiny85::~AvrDevice_attiny85() {
// destroy subsystems in reverse order, you've created it in constructor
delete stack;
delete eeprom;
delete irqSystem;
}
AvrDevice_attiny85::AvrDevice_attiny85():
AvrDevice(64 , // I/O space above General Purpose Registers
512, // RAM size
0, // External RAM size
8 * 1024) // Flash Size
{
flagJMPInstructions = false;
flagMULInstructions = false;
irqSystem = new HWIrqSystem(this, 2, 15); // 2 bytes per vector, 15
vectors
eeprom = new HWEeprom(this, irqSystem, 512, 7,
HWEeprom::DEVMODE_EXTENDED);
stack = new HWStackSram(this, 16); // here, 16 bit is used, if RAM is
smaller than 256, only 8 bit is used
Reset();
}
/* EOF */
- add IO register set in device definition (*.cpp file), for the moment only
eeprom, status and
stack pointer register (see following snippet as example, you have to get
addresses for your device
from datasheet - register summary!)::
stack = new HWStackSram(this, 12);
// IO register set
rw[0x5f]= statusRegister;
rw[0x5e]= & ((HWStackSram *)stack)->sph_reg;
rw[0x5d]= & ((HWStackSram *)stack)->spl_reg;
//rw[0x5c] reserved
//rw[0x5b] reserved
//rw[0x5a] reserved
//rw[0x59] reserved
//rw[0x58] reserved
//rw[0x57] reserved
//rw[0x56] reserved
//rw[0x55] reserved
//rw[0x54] reserved
//rw[0x53] reserved
//rw[0x52] reserved
//rw[0x51] reserved
//rw[0x50] reserved
...
//rw[0x40] reserved
rw[0x3f]= & eeprom->eearh_reg;
rw[0x3e]= & eeprom->eearl_reg;
rw[0x3d]= & eeprom->eedr_reg;
rw[0x3c]= & eeprom->eecr_reg;
//rw[0x3b] reserved
...
Reset();
- create IO ports (as example, how much ports and how much bits on port depend
on your device!)
In *.h (snippet)::
public:
HWPort *portb; //!< port B (only 6 bit)
...
In *.cpp (snippet)::
// destroy subsystems in reverse order, you've created it in constructor
delete portb;
delete stack;
...
stack = new HWStackSram(this, 12);
portb = new HWPort(this, "B", true, 6);
// IO register set
...
//rw[0x39] reserved
rw[0x38]= & portb->port_reg;
rw[0x37]= & portb->ddr_reg;
rw[0x36]= & portb->pin_reg;
//rw[0x35] reserved
- add in src/Makefile.am for definition libsim_la_SOURCES the *.cpp file (for
example see following code)::
libsim_la_SOURCES = \
adcpin.cpp application.cpp at4433.cpp at8515.cpp atmega668base.cpp
atmega128.cpp \
at90canbase.cpp atmega8.cpp atmega1284abase.cpp attiny25_45_85.cpp
- add in src/Makefile.am for definition pkginclude_HEADERS the *.h file (for
example see following code)::
pkginclude_HEADERS = \
adcpin.h application.h at4433.h at8515.h atmega128.h atmega16_32.h
attiny2313.h \
at90canbase.h atmega8.h attiny25_45_85.h
Now you have created your new device with ports and EEPROM. Proceed with build
simulavr from
scratch, e.g. run make clean, make distclean, bootstrap, configure, make ...
Next steps are timer integration, integration of other peripheral units, extend
regression tests
with the new device ...
_______________________________________________
Simulavr-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/simulavr-devel