From 2551d7cf0e28099ebbb7fe0e8e053bcd46b9d6f6 Mon Sep 17 00:00:00 2001 From: Tom Haber Date: Fri, 23 May 2008 00:13:37 +0200 Subject: [PATCH] Moved interrupt table to Bus --- Bus.cpp | 35 +++++++++++++++++++++++++++++++++-- Bus.h | 43 +++++++++++++++++++++++++++++++++++++++---- Device.h | 12 ------------ 3 files changed, 72 insertions(+), 18 deletions(-) diff --git a/Bus.cpp b/Bus.cpp index e3c7464..142afab 100644 --- a/Bus.cpp +++ b/Bus.cpp @@ -2,11 +2,14 @@ #include "Hardware.h" #include "Util.h" +#include "RuntimeException.h" +#include "Format.h" + namespace avr { Bus::Bus() { - irqPending.resize( intVectorsSize ); - std::fill( irqPending.begin(), irqPending.end(), false ); + irqPending = 0; + intVectors.resize( intVectorsSize ); } Bus::~Bus() { @@ -33,4 +36,32 @@ namespace avr { return holding; } + void Bus::addInterrupt(unsigned int vector, unsigned int address, + const char *name) { + if( vector >= intVectorsSize ) + throw util::RuntimeException( + util::format("Tried to add not existing interrupt %d") % vector ); + + intVectors[vector] = IntVect( address, name ); + } + + void Bus::claimInterrupt(unsigned int vector, Hardware *hw) { + if( vector >= intVectorsSize ) + throw util::RuntimeException( + util::format("Hardware tried to claim not existing interrupt %d") % vector ); + + if( intVectors[vector].hw != 0 ) + throw util::RuntimeException( + util::format("Hardware tried to claim already claimed interrupt %d") % vector ); + + intVectors[vector].hw = hw; + } + + + void Bus::beforeInvokeInterrupt(unsigned int vector) { + clearInterrupt(vector); + + if( intVectors[vector].hw != 0 ) + intVectors[vector].hw->beforeInvokeInterrupt(vector); + } } diff --git a/Bus.h b/Bus.h index f2e1e9a..0e8f587 100644 --- a/Bus.h +++ b/Bus.h @@ -3,6 +3,7 @@ #include #include +#include #include "Clock.h" namespace avr { @@ -23,13 +24,34 @@ namespace avr { static const unsigned int intVectorsSize = 28; void raiseInterrupt(unsigned int vector); void clearInterrupt(unsigned int vector); - bool pendingInterrupt(unsigned int & vector) const; - unsigned int pendingInterrupts() const; + + public: + unsigned int pendingInterrupt() const; + bool isInterruptPending() const; + unsigned int interruptVectorAddress(unsigned int vector) const; + void beforeInvokeInterrupt(unsigned int vector); + + public: + void addInterrupt(unsigned int vector, unsigned int address, + const char *name); + void claimInterrupt(unsigned int vector, Hardware *hw); private: std::list hardware; private: + struct IntVect { + IntVect() : hw(0) {} + IntVect(unsigned int addr, const std::string & name) + : address(addr), name(name), hw(0) {} + unsigned int address; + std::string name; + Hardware *hw; + }; + typedef std::vector< IntVect > InterruptTable; + + private: + InterruptTable intVectors; unsigned int irqPending; }; @@ -45,8 +67,21 @@ namespace avr { irqPending &= ~(1< -#include namespace avr { typedef unsigned long long ClockFrequency; @@ -57,16 +55,6 @@ namespace avr { Bus bus; Eeprom *eeprom; - private: - struct IntVect { - IntVect() {} - IntVect(unsigned int addr, const std::string & name) - : address(addr), name(name) {} - unsigned int address; - std::string name; - }; - std::vector< IntVect > intVectors; - friend class DeviceSettings; }; -- 2.11.4.GIT