Skip to content

Commit

Permalink
Challenge avr: atmega2560 support (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
pro100kot authored and andrvb committed Mar 13, 2019
1 parent 3cc6718 commit aa51614
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 0 deletions.
1 change: 1 addition & 0 deletions challenge-avr/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ WORKDIR /root/vr_arduino_project
COPY simulavr_dependency.sh .
COPY simulavr_install.sh .
COPY arduino_dependency.sh .
COPY pysimulavr.i .

RUN ./simulavr_dependency.sh
RUN wget http://downloads.sourceforge.net/swig/swig-3.0.12.tar.gz && tar -xf swig-3.0.12.tar.gz && rm swig-3.0.12.tar.gz
Expand Down
210 changes: 210 additions & 0 deletions challenge-avr/pysimulavr.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
%module(directors="1") pysimulavr

%{

#include "systemclocktypes.h"
#include "avrdevice.h"
#include "systemclock.h"
#include "hardware.h"
#include "externaltype.h"
#include "irqsystem.h"
#include "pin.h"
#include "pinatport.h"
#include "net.h"
#include "rwmem.h"
#include "hwsreg.h"
#include "avrfactory.h"
#include "avrreadelf.h"
#include "memory.h"
#include "flash.h"
#include "hweeprom.h"
#include "avrerror.h"
#include "pysimulationmember.h"
#include "hwport.h"
#include "hwstack.h"
#include "avrsignature.h"
#include "specialmem.h"

#include "cmd/dumpargs.h"
#include "cmd/gdb.h"

// to get devices registered (automatically on linux, but necessary on windows)
#include "atmega128.h"
#include "at4433.h"
#include "at8515.h"
#include "atmega2560base.h"
#include "atmega668base.h"
#include "atmega16_32.h"
#include "attiny2313.h"
#include "attiny25_45_85.h"

// support module version and build date
#include "config.h"
//const char *_BUILD_DATE_ = __DATE__ ", " __TIME__;
//const char *_VERSION_ = PACKAGE_VERSION;
const char _BUILD_DATE_[] = __DATE__ ", " __TIME__;
const char _VERSION_[] = PACKAGE_VERSION;

%}

%include "std_vector.i"
%include "std_map.i"
%include "std_iostream.i"
%include "std_sstream.i"
%include "types.h"

namespace std {
%template(DWordVector) vector<dword>;
// templates for AvrNameToSignatureMap and AvrSignatureToNameMap
%template(map_string_int) map<string, unsigned int>;
%template(map_int_string) map<unsigned int, string>;
// template for SetDumpTraceArgs
%template(string_vector) vector<string>;
};

%exception {
try {
$action
} catch(char const* s) {
PyErr_SetString(PyExc_SystemError, s);
return NULL;
} catch(int i) {
PyErr_Format(PyExc_RuntimeError, "%d", i);
return NULL;
}
}

%include "config.h"

%include "systemclocktypes.h"
%include "simulationmember.h"

%feature("director") PySimulationMember;
%include "pysimulationmember.h"

%include "externaltype.h"
%feature("director") HasPinNotifyFunction;
%include "pinnotify.h"
%include "traceval.h"
%include "irqsystem.h"
%include "avrdevice.h"

%extend DumpManager {
void addDumpVCD(const std::string &vcdname,
const std::string &istr,
const std::string &timebase,
const bool rstrobe,
const bool wstrobe) {
DumpVCD *d = new DumpVCD(vcdname, timebase, rstrobe, wstrobe);
$self->addDumper(d, $self->load(istr));
}
}

%extend AvrDevice {
// getRWMem and setRWMem are deprecated, don't use it in new code!
unsigned char getRWMem(unsigned a) { return $self->GetRWMem(a); }
bool setRWMem(unsigned a, unsigned char v) { return $self->SetRWMem(a, v); }
}

%include "systemclock.h"

%extend SystemClock {
int Step() {
bool untilCoreStepFinished = false;
return $self->Step(untilCoreStepFinished);
}
}

%feature("director") Hardware;
%include "hardware.h"
%include "hwport.h"
%include "hwstack.h"

%feature("director") Pin;
%include "pin.h"

%extend Pin {
char toChar() {
char c = *$self;
return c;
}
void SetPin(const char c) {
*$self = c;
}
}

%include "pinatport.h"
%extend PinAtPort {
bool GetPinInput(void) {
return (bool)*$self;
}
}

%include "net.h"

%feature("director") RWMemoryMember;
%include "rwmem.h"
%include "specialmem.h"

%include "hwsreg.h"
%extend RWSreg {
unsigned char GetValue(void) {
unsigned char v = *$self;
return v;
}
void SetValue(unsigned char v) {
RWMemoryMember* m = $self;
*m = v;
}
}

%include "avrfactory.h"
%include "avrreadelf.h"
%include "memory.h"

%extend Memory {
unsigned char GetMemory(unsigned int a) {
if(a < $self->GetSize())
return $self->myMemory[a];
return 0;
}
void PyWriteMem(char *src, unsigned int offset, unsigned int secSize) {
$self->WriteMem((const unsigned char *)src, offset, secSize);
}
}

%include "flash.h"
%include "hweeprom.h"

%extend Breakpoints {
void RemoveBreakpoint(unsigned bp) {
Breakpoints::iterator ii;
if ((ii = find($self->begin(), $self->end(), bp)) != $self->end()) $self->erase(ii);
}
void AddBreakpoint(unsigned bp) {
$self->push_back(bp);
}
}

%include "avrsignature.h"

%include "avrerror.h"

%include "cmd/dumpargs.h"
%include "cmd/gdb.h"

// to get devices registered (automatically on linux, but necessary on windows)
%include "atmega128.h"
%include "at4433.h"
%include "at8515.h"
%include "atmega668base.h"
%include "atmega2560base.h"
%include "atmega16_32.h"
%include "attiny2313.h"
%include "attiny25_45_85.h"

// support version and build time information
const char _BUILD_DATE_[];
const char _VERSION_[];

// EOF
2 changes: 2 additions & 0 deletions challenge-avr/simulavr_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ if [ -z $1 ] || [ $1 == -h ] ; then
fi

SIMULAVR_HOME_DIR=$1
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"

if [ -f $SIMULAVR_HOME_DIR/bootstrap ]; then
cd $SIMULAVR_HOME_DIR
cp ${SCRIPT_DIR}"/pysimulavr.i" "./src/python/"
./bootstrap
./configure LDFLAGS="-L/usr/lib/python2.7" --enable-python --enable-tcl
make
Expand Down

0 comments on commit aa51614

Please sign in to comment.