If one applies this patch, one needs to call avr-fab.py from within the src/fab directory, with the Atmel .xml files in place. For now, it will create only two, incomplete small AVR device classes, for the tiny2313 and the tiny15l.
Signed-off-by: Onno Kortmann <[email protected]> --- src/Makefile.am | 5 ++ src/fab/avr-fab.py | 83 +++++++++++++++++++++++++++++++++ src/fab/avr_tmpl.cpp | 80 ++++++++++++++++++++++++++++++++ src/fab/avr_tmpl.h | 50 ++++++++++++++++++++ src/fab/avr_tmpl.v | 50 ++++++++++++++++++++ src/fab/converter.py | 95 +++++++++++++++++++++++++++++++++++++ src/fab/core.py | 118 +++++++++++++++++++++++++++++++++++++++++++++++ src/fab/eeprom_tmpl.cpp | 30 ++++++++++++ src/fab/irq.py | 50 ++++++++++++++++++++ src/fab/pins.py | 52 +++++++++++++++++++++ src/fab/port.py | 47 +++++++++++++++++++ src/fab/port_tmpl.cpp | 44 +++++++++++++++++ src/fab/timer.py | 29 ++++++++++++ src/fab/timer_tmpl.cpp | 48 +++++++++++++++++++ src/hwdecls.h | 20 ++++++++ 15 files changed, 801 insertions(+), 0 deletions(-) create mode 100755 src/fab/avr-fab.py create mode 100644 src/fab/avr_tmpl.cpp create mode 100644 src/fab/avr_tmpl.h create mode 100644 src/fab/avr_tmpl.v create mode 100644 src/fab/converter.py create mode 100644 src/fab/core.py create mode 100644 src/fab/eeprom_tmpl.cpp create mode 100644 src/fab/irq.py create mode 100644 src/fab/pins.py create mode 100644 src/fab/port.py create mode 100644 src/fab/port_tmpl.cpp create mode 100644 src/fab/timer.py create mode 100644 src/fab/timer_tmpl.cpp create mode 100644 src/hwdecls.h diff --git a/src/Makefile.am b/src/Makefile.am index 63a7c27..b3301cc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,6 +21,8 @@ libavrsim_pp_la_SOURCES = \ at4433.cpp \ at8515.cpp \ atmega128.cpp \ + avr_ATtiny15.cpp \ + avr_ATtiny2313.cpp \ avrdevice.cpp \ avrerror.cpp \ avrmalloc.cpp \ @@ -69,6 +71,8 @@ pkginclude_HEADERS = \ at4433.h \ at8515.h \ atmega128.h \ + avr_ATtiny15.h \ + avr_ATtiny2313.h \ avrdevice.h \ avrdevice_impl.h \ avrerror.h \ @@ -85,6 +89,7 @@ pkginclude_HEADERS = \ helper.h \ hwacomp.h \ hwad.h \ + hwdecls.h \ hweeprom.h \ hwextirq.h \ hwmegaextirq.h \ diff --git a/src/fab/avr-fab.py b/src/fab/avr-fab.py new file mode 100755 index 0000000..283e089 --- /dev/null +++ b/src/fab/avr-fab.py @@ -0,0 +1,83 @@ +#!/usr/bin/python +# Copyright (C) 2009 Onno Kortmann <[email protected]> +# +# 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. +# +from xml.dom.minidom import parse + +from Cheetah.Template import Template + +from core import Core +from port import Ports +from irq import IRQTable +from timer import Timer +from pins import Pins + +converters=[ + Core(), + IRQTable(), + Ports(), + Timer(), + Pins() + ] + + +from os import listdir + +# for fn in listdir("atmel-xml/"): +# if (fn.find(".xml")<0 +# or fn.find("ATxmega")>=0 +# or fn.find("AT89")>=0 +# or fn.find("AT86")>=0 +# or fn.find("ATtiny10")>=0 +# or fn.find("ATtiny28")>=0 # <- has weird port logic. FIXME: support this! +# or fn.find("HV")>=0 # 'smart battery devices' also have some weird port logic. +# or fn.find("CAN")>=0 # CAN devices are not implemented either +# or fn.find("USB")>=0 # USB devices are weird in general. +# or fn.find("M1")>=0 or fn.find("C1")>=0 # automotive stuff +# ): +# continue + + +for fn in ["ATtiny15.xml", + "ATtiny2313.xml" + ]: + print "Parsing %s" % fn + p=parse("atmel-xml/%s" % fn) + + CPPtmpl=Template(file="avr_tmpl.cpp") + Htmpl=Template(file="avr_tmpl.h") + Vtmpl=Template(file="avr_tmpl.v") + + for c in converters: + print "Extracting using %s." % c + c(p, CPPtmpl) + c(p, Htmpl) + c(p, Vtmpl) + + cpp_f=open("../avr_"+fn[:-4]+".cpp", "w") + h_f=open("../avr_"+fn[:-4]+".h", "w") + v_f=open("../verilog/avr_"+fn[:-4]+".v", "w") + + print "Writing files for %s" % fn[:-4] + print>>cpp_f, CPPtmpl + print>>h_f, Htmpl + print>>v_f, Vtmpl + + cpp_f.close() + h_f.close() + v_f.close() + + diff --git a/src/fab/avr_tmpl.cpp b/src/fab/avr_tmpl.cpp new file mode 100644 index 0000000..7aef630 --- /dev/null +++ b/src/fab/avr_tmpl.cpp @@ -0,0 +1,80 @@ + /* + **************************************************************************** + * + * simulavr - A simulator for the Atmel AVR family of microcontrollers. + * Copyright (C) 2001, 2002, 2003 Klaus Rudolph + * Copyright (C) 2008 Onno Kortmann + * 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 + * + **************************************************************************** + * + * THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM avr_tmpl.cpp. + * --- DO NOT EDIT MANUALLY! --- + */ +\#include "avr_$(part).h" + +## FIXME: Include only those parts which are needed! +\#include "irqsystem.h" +\#include "avrfactory.h" +\#include "hweeprom.h" +\#include "hwstack.h" +\#include "hwport.h" +\#include "hwwado.h" +\#include "hwtimer.h" +\#include "hwtimer01irq.h" +\#include "ioregs.h" + +AVR_REGISTER($(part), AVR_$(part)); + +AVR_$part::~AVR_$(part)() {} + +AVR_$part::AVR_$(part)() : AvrDevice($io_size, + $iram_size, + $eram_size, + $flash_size) { + irqSystem = new HWIrqSystem(this, $irq_vec_size); + +#include "eeprom_tmpl.cpp" + +#if $iram_size>0 + stack = new HWStack(this, Sram, $stack.ceil); +#else + stack = new HWStack(this, new ThreeLevelStack(), 0x06); +#endif + + wado = new HWWado(this); + rw[$io["WDTCR"].addr] = new RWWdtcr(this, wado); + + prescaler = new HWPrescaler(this); + mcucr = new HWMcucr(this); //FIXME! MCUCR reg! + rw[$io["SREG"].addr] = new RWSreg(this, status); + +#if "SPL" in $io + rw[$io["SPL"].addr]= new RWSpl(this, stack); +#endif +#if "SPH" in $io + rw[$io["SPH"].addr]= new RWSph(this, stack); +#endif + + + +#include "port_tmpl.cpp" + +#include "timer_tmpl.cpp" + + Reset(); +} + + diff --git a/src/fab/avr_tmpl.h b/src/fab/avr_tmpl.h new file mode 100644 index 0000000..2c4b3bf --- /dev/null +++ b/src/fab/avr_tmpl.h @@ -0,0 +1,50 @@ + /* + **************************************************************************** + * + * simulavr - A simulator for the Atmel AVR family of microcontrollers. + * Copyright (C) 2001, 2002, 2003 Klaus Rudolph + * Copyright (C) 2008 Onno Kortmann + * 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 + * + **************************************************************************** + * + * THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM avr_tmpl.h. + * --- DO NOT EDIT MANUALLY! --- + */ +\#ifndef AVR_PART_$(part) +\#define AVR_PART_$(part) +\#include "hwdecls.h" +\#include "avrdevice.h" + +class AVR_$(part) : public AvrDevice { + public: + AVR_$(part)(); + ~AVR_$(part)(); + private: +#for $Letter in $io_ports + HWPort *port$Letter.lower; +#endfor + + HWMcucr *mcucr; +#if $has_prescaler + HWPrescaler *prescaler; +#endif + +#if $has_timer1 + HWTimer01Irq *timer01irq; + HWTimer1 *timer1; +#endif +}; +\#endif diff --git a/src/fab/avr_tmpl.v b/src/fab/avr_tmpl.v new file mode 100644 index 0000000..b4b3946 --- /dev/null +++ b/src/fab/avr_tmpl.v @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2009 Onno Kortmann <[email protected]> + * + * 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. + * + * THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM avr_tmpl.v. + * --- DO NOT EDIT MANUALLY! --- + */ + +module $(part)(clk, +#set exclast=sorted($io_ports)[:-1] +#set onlylast=sorted($io_ports)[-1:][0] +#for $Letter in $exclast + P$Letter, +#endfor + P$onlylast +#slurp + ); + parameter progfile="UNSPECIFIED"; + input clk; +#for $Letter in $io_ports +##FIXME: Only specify needed bits! + inout [7:0] P$Letter; +#endfor + integer handle; + + defparam core.progfile=progfile; + defparam core.name="$part"; + AVRCORE core(clk); + +#for $Letter in $io_ports +#set $letter=$Letter.lower +#for $bit in range(8) + avr_pin #("$(Letter)$(bit)") p$(letter)$(bit)(P$(Letter)[$(bit)]); +#endfor +#endfor +endmodule + \ No newline at end of file diff --git a/src/fab/converter.py b/src/fab/converter.py new file mode 100644 index 0000000..8854290 --- /dev/null +++ b/src/fab/converter.py @@ -0,0 +1,95 @@ +# Copyright (C) 2009 Onno Kortmann <[email protected]> +# +# 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. +# +class Converter: + """ A converter converting parts of the XML description into settings for a template. """ + def __call__(self, xcfg, tmpl): + """ + xcfg: Atmel configuration XML object (DOM tree) + tmpl: output template + """ + self.xcfg=xcfg + self.tmpl=tmpl + + self.doit(xcfg, tmpl) + +def nav(xml, path): + """ Navigate in XML object xml. Path is a list of + element names to navigate into. Yields a list of all matching elements. + """ +# print "Path:", path + if not len(path): + return xml.childNodes + else: + res=[] + for c in xml.childNodes: +# print "Looking at", c + if path[0]=="*" or c.localName==path[0]: +# print "Navigating to ", c + res.extend(nav(c, path[1:])) +# print "done." + return res + +def navdir(xml, path, default=True): + """ Same as nav, but for a /-separated path. Includes the initial AVRPART/ automatically iff def is true. """ + if default: + p="AVRPART/"+path + else: + p=path + return nav(xml, p.split("/")) + +def navls(xml, path, default=True): + """ Do a 'list directory' for /-separated path path. """ + for i in navdir(xml, path, default): + if i.localName: + print i.localName + +def navcat(xml, path, default=True): + """ Print texts of an XML element. """ + for i in navdir(xml, path, default): + try: + print i.wholeText + except AttributeError: + print "<no attribute wholeText>" + +def navtxt(xml, path, default=True): + """ Gives texts of XML element(s). """ + t="" + try: + for i in navdir(xml, path, default): + t+=i.wholeText + except AttributeError, e: + raise AttributeError, ("XML-Path:"+str(path)+" : "+str(e)) + return t + +def avrnum(n): + """ Converts a integer number from an AVR XML file. + $-numbers and 0x-numbers are treated as hex, ones starting with digits as dec. """ + if n[0]=="$": + return int(n[1:], 16) + else: + return int(n, 0) + +def navnum(xml, path, default=True): + """ avrnum(navtxt(xml, path) """ + txt=navtxt(xml, path, default) + try: + return avrnum(txt) + except IndexError: + raise IndexError, ("String index out of range in XML tree at '%s'." % path) + except ValueError: + raise ValueError, ("Value '%s' can't be converted into an integer, (sub-)tree position '%s', element %s." % (txt, path, xml)) + diff --git a/src/fab/core.py b/src/fab/core.py new file mode 100644 index 0000000..eca11c7 --- /dev/null +++ b/src/fab/core.py @@ -0,0 +1,118 @@ +# Copyright (C) 2009 Onno Kortmann <[email protected]> +# +# 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. +# +from converter import * + +class IOReg: + def __init__(self, xe): + if navtxt(xe, "MEM_ADDR", False)!="NA": + self.addr=navnum(xe, "MEM_ADDR", False) + else: + # FIXME: 0x20 always right? + self.addr=0x20+navnum(xe, "IO_ADDR", False) + + self.name=xe.localName + if navtxt(xe, "IO_ADDR", False)!="NA": + assert(self.addr==0x20+navnum(xe, "IO_ADDR", False)) + + def __call__(self): + return self.addr + +class Core(Converter): + def doit(self, xml, tmpl): + """ Sets some core parameters. """ + + + regf="CORE/GP_REG_FILE/" + (tmpl.reg_num, + tmpl.reg_xl, tmpl.reg_xh, + tmpl.reg_yl, tmpl.reg_yh, + tmpl.reg_zl, tmpl.reg_zh, + tmpl.reg_start)=[navnum(xml, s) for s in [ + regf+"NMB_REG", + regf+"X_REG_LOW", + regf+"X_REG_HIGH", + regf+"Y_REG_LOW", + regf+"Y_REG_HIGH", + regf+"Z_REG_LOW", + regf+"Z_REG_HIGH", + regf+"START_ADDR" + ]] + + tmpl.part=navtxt(xml, "ADMIN/PART_NAME") + + # in bytes + (tmpl.flash_size, + tmpl.eeprom_size, + tmpl.iram_size) = ( + navnum(xml, "MEMORY/PROG_FLASH"), + navnum(xml, "MEMORY/EEPROM"), + navnum(xml, "MEMORY/INT_SRAM/SIZE")) + + if navtxt(xml, "MEMORY/EXT_SRAM/SIZE")!="NA": + tmpl.eram_size=navnum(xml, "MEMORY/EXT_SRAM/SIZE") + else: + tmpl.eram_size=0 + + if tmpl.iram_size: + tmpl.iram_start=navnum(xml, "MEMORY/INT_SRAM/START_ADDR") + if tmpl.eram_size: + tmpl.eram_start=navnum(xml, "MEMORY/EXT_SRAM/START_ADDR") + + tmpl.io_start, tmpl.io_stop=( + navnum(xml, "MEMORY/IO_MEMORY/IO_START_ADDR"), + navnum(xml, "MEMORY/IO_MEMORY/IO_STOP_ADDR")) + + tmpl.io_size=1+tmpl.io_stop-tmpl.io_start + + # read ioregisters + tmpl.io={} + for io in navdir(xml, "MEMORY/IO_MEMORY"): + if io.nodeType==io.ELEMENT_NODE and io.getElementsByTagName("MEM_ADDR"): + if io.localName in tmpl.io: + raise Exception, ("I/O-Register '%s' defined twice." % io.localName) + tmpl.io[io.localName]=IOReg(io) + + tmpl.stack={} + if "SPH" in tmpl.io: + # FIXME: This is surely not 100% right on all devices!! + tmpl.stack["ceil"]=0x10000 + else: + tmpl.stack["ceil"]=0x100 + + self.check(xml, tmpl) + + def check(self, xml, tmpl): + # Some simple checks + assert(tmpl.reg_num==32) + assert(tmpl.reg_start==0) + + assert(tmpl.io_start==0) + assert(tmpl.io_stop==0x3f) + + # some things which should be constant + for c, p in [ + (0x3f, "MEMORY/IO_MEMORY/SREG/IO_ADDR"), + (0x01, "MEMORY/IO_MEMORY/SREG/C_MASK"), + (0x02, "MEMORY/IO_MEMORY/SREG/Z_MASK"), + (0x04, "MEMORY/IO_MEMORY/SREG/N_MASK"), + (0x08, "MEMORY/IO_MEMORY/SREG/V_MASK"), + (0x10, "MEMORY/IO_MEMORY/SREG/S_MASK"), + (0x20, "MEMORY/IO_MEMORY/SREG/H_MASK"), + (0x40, "MEMORY/IO_MEMORY/SREG/T_MASK"), + (0x80, "MEMORY/IO_MEMORY/SREG/I_MASK") + ]: + assert(c==navnum(xml, p)) diff --git a/src/fab/eeprom_tmpl.cpp b/src/fab/eeprom_tmpl.cpp new file mode 100644 index 0000000..1712f2b --- /dev/null +++ b/src/fab/eeprom_tmpl.cpp @@ -0,0 +1,30 @@ +## Copyright (C) 2009 Onno Kortmann <[email protected]> +## +## 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. +## +##FIXME: any other eeprom types? +##FIXME#2: using right eeprom type? +{ +#if "EE_RDY" in $irq_bysrc + eeprom = new HWMegaEeprom(this, irqSystem, $eeprom_size, $irq_bysrc["EE_RDY"].addr); +#else + eeprom = new HWEeprom(this, irqSystem, $eeprom_size); +#endif +#if "EEAR" in $io + rw[$io["EEAR"].addr]= new RWEearl(this, eeprom); + rw[$io["EEDR"].addr]= new RWEedr(this, eeprom); + rw[$io["EECR"].addr]= new RWEecr(this, eeprom); +#endif +} diff --git a/src/fab/irq.py b/src/fab/irq.py new file mode 100644 index 0000000..00d36d1 --- /dev/null +++ b/src/fab/irq.py @@ -0,0 +1,50 @@ +# Copyright (C) 2009 Onno Kortmann <[email protected]> +# +# 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. +# +from converter import * + +class IRQVector: + def __init__(self, xml, n): + path="INTERRUPT_VECTOR/VECTOR%d/" % (n+1) + self.addr=navnum(xml, path+"PROGRAM_ADDRESS") + self.src=navtxt(xml, path+"SOURCE") # source of interrupt + + # the EEPROM ready interrupt seems to be named different for each device... + if (self.src=="EEPROM Ready" or + self.src=="EE READY" or + self.src=="EE_READY"): + self.src="EE_RDY" + + self.desc=navtxt(xml, path+"DEFINITION") # description + +class IRQTable(Converter): + def doit(self, xml, tmpl): + tmpl.irq_num=navnum(xml, "INTERRUPT_VECTOR/NMB_VECTORS") + tmpl.irq_vec_size=2 # FIXME!! + tmpl.irqs=[] + for i in range(tmpl.irq_num): + # FIXME: for some reason, irq_num can be different to the number of declared vectors. + # example is the AT90USB162. + if navtxt(xml, "INTERRUPT_VECTOR/VECTOR%d/PROGRAM_ADDRESS" % (i+1)): + tmpl.irqs.append(IRQVector(xml, i)) + + # map source to interrupts + tmpl.irq_bysrc={} + for i in tmpl.irqs: + if i.src in tmpl.irq_bysrc: + raise Exception, ("At least two interrupts with the same source %s." % i.src) + tmpl.irq_bysrc[i.src]=i + diff --git a/src/fab/pins.py b/src/fab/pins.py new file mode 100644 index 0000000..110a747 --- /dev/null +++ b/src/fab/pins.py @@ -0,0 +1,52 @@ +# Copyright (C) 2009 Onno Kortmann <[email protected]> +# +# 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. +# +from converter import * + +def sls(s): + return s.replace("[", "").replace("]", "").split(":") + +# FIXME: Support different package types! +class Pins(Converter): + def doit(self, xml, tmpl): + tmpl.pkg_types=sls(navtxt(xml, "PACKAGE/PACKAGES")) + + p=tmpl.pkg_types[0] + tmpl.pkg_pincnt=navnum(xml, "PACKAGE/%s/NMB_PIN" % p) + + tmpl.pkg_pins=[] + tmpl.pkg_portlet={} # mapping of pkg_pins indices to port letters (lower case) + tmpl.pkg_portbit={} # mapping of pkg_pins indices to port bits + + for i in range(1, tmpl.pkg_pincnt+1): + s=sls(navtxt(xml, "PACKAGE/%s/PIN%d/NAME" % (p, i))) + port=False + portlet=None + portbit=None + for sl in s: + if len(sl)==3 and sl[0]=="P": + if port: + raise Exception, "Weird PACKAGE/.../PIN structure." + portlet=sl[1].lower() + portbit=int(sl[2]) + port=True + + for sl in s: + tmpl.pkg_portlet[sl]=portlet + tmpl.pkg_portbit[sl]=portbit + + tmpl.pkg_pins.append(s) + diff --git a/src/fab/port.py b/src/fab/port.py new file mode 100644 index 0000000..a1b52dd --- /dev/null +++ b/src/fab/port.py @@ -0,0 +1,47 @@ +# Copyright (C) 2009 Onno Kortmann <[email protected]> +# +# 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. +# +from converter import * + +class Port: + def __init__(self, xml, letter): + self.letter=letter # upper case port letter (PORTB -> 'B', etc.) + pre="IO_MODULE/PORT%s/" % letter + + for s, us in [("port_", "PORT%s/"), + ("pin_", "PIN%s/"), + ("ddr_", "DDR%s/")]: + for e in ["mask", "wmask", "imask"]: + self.__dict__[s+e]=0x00 + + for i in range(8): + if navdir(xml, (pre+us+"BIT%d") % (letter, i)): + self.__dict__[s+"mask"]|=1<<i + assert(navtxt(xml, (pre+us+"BIT%d/ACCESS") % (letter, i)) in ["R", "RW"]) + + if "W" in navtxt(xml, (pre+us+"BIT%d/ACCESS") % (letter, i)): + self.__dict__[s+"wmask"]|=1<<i + if navtxt(xml, (pre+us+"BIT%d/INIT_VAL") % (letter, i)): + self.__dict__[s+"imask"]|=1<<i + + +class Ports(Converter): + def doit(self, xml, tmpl): + tmpl.io_ports={} + for l in "ABCDEF": + if navdir(xml, "IO_MODULE/PORT%s" % l): + tmpl.io_ports[l]=self.__dict__["port"+l.lower()]=Port(xml, l) + diff --git a/src/fab/port_tmpl.cpp b/src/fab/port_tmpl.cpp new file mode 100644 index 0000000..01735ad --- /dev/null +++ b/src/fab/port_tmpl.cpp @@ -0,0 +1,44 @@ +## Copyright (C) 2009 Onno Kortmann <[email protected]> +## +## 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. +## + +#for $Letter in $io_ports +#set $letter=$Letter.lower +#set $port=$io_ports[$Letter] +## +#if ("PIN"+$Letter) in $io + port$letter=new HWPort(this, "$Letter"); +#else + // output-only port + port$letter=new HWPort(this, "$Letter", 0xff); +#endif +## +#if ("PORT"+$Letter) in $io + rw[$io["PORT"+$Letter].addr]=new RWPort(this, port$letter); +#endif +## +## some ports are output only (e.g. mega103/portc) +## some other ports are input only (e.g. mega103/portf) +#if ("PIN"+$Letter) in $io + rw[$io["PIN"+$Letter].addr]=new RWPin (this, port$letter); + #if ("PORT"+$Letter) in $io + rw[$io["DDR"+$Letter].addr]=new RWDdr (this, port$letter); + #else + // ^^ input-only port + #endif + #endif + +#endfor diff --git a/src/fab/timer.py b/src/fab/timer.py new file mode 100644 index 0000000..23c5d66 --- /dev/null +++ b/src/fab/timer.py @@ -0,0 +1,29 @@ +# Copyright (C) 2009 Onno Kortmann <[email protected]> +# +# 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. +# +from converter import * + +class Timer(Converter): + def doit(self, xml, tmpl): + # there does not seem to be a timerless device + tmpl.has_prescaler=True + try: + tmpl.has_timer1=navtxt(xml, "IO_MODULE/TIMER_COUNTER_1/ID")[:3]=="t16" + except: + tmpl.has_timer1=False + + + diff --git a/src/fab/timer_tmpl.cpp b/src/fab/timer_tmpl.cpp new file mode 100644 index 0000000..142ad63 --- /dev/null +++ b/src/fab/timer_tmpl.cpp @@ -0,0 +1,48 @@ +## Copyright (C) 2009 Onno Kortmann <[email protected]> +## +## 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. +## +{ +#if $has_timer1 + timer01irq = new HWTimer01Irq(this, + irqSystem, + $irq_bysrc["TIMER1 CAPT"].addr, + $irq_bysrc["TIMER1 COMPA"].addr, + $irq_bysrc["TIMER1 COMPB"].addr, + $irq_bysrc["TIMER1 OVF"].addr, + $irq_bysrc["TIMER0 OVF"].addr + ); + + timer1 = new HWTimer1(this, + prescaler, + timer01irq, + PinAtPort(port$pkg_portlet["T1"],$pkg_portbit["T1"]), + PinAtPort(port$pkg_portlet["OC1A"],$pkg_portbit["OC1A"]), + PinAtPort(port$pkg_portlet["OC1B"],$pkg_portbit["OC1B"]), + PinAtPort(port$pkg_portlet["ICP"],$pkg_portbit["ICP"])); + + rw[$io["TIMSK"].addr]= new RWTimsk(this, timer01irq); + rw[$io["TIFR"].addr]= new RWTifr(this, timer01irq); + rw[$io["TCCR1A"].addr]= new RWTccra(this, timer1); + rw[$io["TCCR1B"].addr]= new RWTccrb(this, timer1); + rw[$io["TCNT1H"].addr]= new RWTcnth(this, timer1); + rw[$io["TCNT1L"].addr]= new RWTcntl(this, timer1); + rw[$io["OCR1AH"].addr]= new RWOcrah(this, timer1); + rw[$io["OCR1AL"].addr]= new RWOcral(this, timer1); + + rw[$io["ICR1H"].addr]= new RWIcrh(this, timer1); + rw[$io["ICR1L"].addr]= new RWIcrl(this, timer1); +#endif +} diff --git a/src/hwdecls.h b/src/hwdecls.h new file mode 100644 index 0000000..cd41eec --- /dev/null +++ b/src/hwdecls.h @@ -0,0 +1,20 @@ +#ifndef HWDECLS_H +#define HWDECLS_H +//----------------------------------------------------------------------------- +/* List of all hardware class declarations, to be used with the automatically + generated AVR device classes. */ +class HWPort; +class HWSpi; +class HWUart; +class HWAcomp; +class HWPrescaler; +class HWTimer0; +class HWTimer1; +class HWMcucr; +class HWExtIrq; +class HWTimer01Irq; +class HWAdmux; +class HWAd; +class HWMcucr; +//----------------------------------------------------------------------------- +#endif -- 1.5.6.5 _______________________________________________ Simulavr-devel mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/simulavr-devel
