Bug fix for timers being errorneously put twice into the cycle list. This also adds some simple checks to AddToResetList and AddToCycleList. They should not be too performance-critical (- ?)
Signed-off-by: Onno Kortmann <[email protected]> --- src/avrdevice.cpp | 16 ++++++++++++++++ src/avrdevice.h | 4 ++-- src/hwtimer.cpp | 12 ++++-------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/avrdevice.cpp b/src/avrdevice.cpp index 1007b67..8b7e399 100644 --- a/src/avrdevice.cpp +++ b/src/avrdevice.cpp @@ -32,6 +32,22 @@ #include "avrdevice_impl.h" +void AvrDevice::AddToResetList(Hardware *hw) { + if (find(hwResetList.begin(), hwResetList.end(), hw)!=hwResetList.end()) { + cerr << "INTERNAL ERROR: device would be twice in reset list.\n"; + exit(1); + } + hwResetList.push_back(hw); +} + +void AvrDevice::AddToCycleList(Hardware *hw) { + if (find(hwCycleList.begin(), hwCycleList.end(), hw)!=hwCycleList.end()) { + cerr << "INTERNAL ERROR: device would be twice in cycle list.\n"; + exit(1); + } + hwCycleList.push_back(hw); +} + void AvrDevice::RemoveFromCycleList(Hardware *hw) { vector<Hardware*>::iterator element; diff --git a/src/avrdevice.h b/src/avrdevice.h index d4ff640..b0d3977 100644 --- a/src/avrdevice.h +++ b/src/avrdevice.h @@ -82,8 +82,8 @@ class AvrDevice: public SimulationMember { vector<Hardware *> hwResetList; vector<Hardware *> hwCycleList; - void AddToResetList(Hardware *hw){ hwResetList.push_back(hw) ; } - void AddToCycleList(Hardware *hw){ hwCycleList.push_back(hw) ; } + void AddToResetList(Hardware *hw); + void AddToCycleList(Hardware *hw); void RemoveFromCycleList(Hardware *hw); void Load(const char* n); void ReplaceIoRegister(unsigned int offset, RWMemoryMembers *); diff --git a/src/hwtimer.cpp b/src/hwtimer.cpp index 9ff3ca8..887f954 100644 --- a/src/hwtimer.cpp +++ b/src/hwtimer.cpp @@ -48,11 +48,9 @@ void HWTimer0::SetTccr(unsigned char val) { tccr=val; if ((tccr & 0x07 ) != ( tccrold & 0x07)) { - if ( tccr & 0x07) { + core->RemoveFromCycleList(this); + if ( tccr & 0x07) core->AddToCycleList(this); - } else { - core->RemoveFromCycleList(this); - } } } @@ -354,11 +352,9 @@ void HWTimer1::SetTccr1b(unsigned char val) { tccr1b=val; if ((tccr1b & 0x07 ) != ( tccrold & 0x07 ) ) { - if (tccr1b & 0x07) { + core->RemoveFromCycleList(this); + if (tccr1b & 0x07) core->AddToCycleList(this); - } else { - core->RemoveFromCycleList(this); - } } } -- 1.5.6.5 _______________________________________________ Simulavr-devel mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/simulavr-devel
