Permalink
Browse files

patch 0.1.0119: Fix TIFR register (m328p).

ticket: https://trac.mcusim.org/ticket/29
author: Pawel Obarzanek <paweo90@gmail.com>

This patch contains a fix to replace incorrectly updated TIFR register
of ATmega328P while simulating Timer/Counter0 (closes #18).
The correct one is TIFR0.

Signed-off-by: Dmitry Salychev <darkness.bsd@gmail.com>
  • Loading branch information...
dsalychev committed Nov 1, 2018
1 parent 6962597 commit c6d480a08ad222080f20c9fb2ba72d2829b8e499
Showing with 10 additions and 8 deletions.
  1. +3 −1 CMakeLists.txt
  2. +7 −7 src/avr/avr_m328p.c
@@ -26,11 +26,13 @@
#
# MCUSim build configuration file.
#
# Verbose output of the build process can be activated using 'make VERBOSE=1'.
#
cmake_minimum_required(VERSION 3.2)
project(MCUSim C)

# Program version
set(MSIM_VERSION "0.1.0118")
set(MSIM_VERSION "0.1.0119")

# Program name
set(MCUSIM "mcusim")
@@ -123,7 +123,7 @@ static void tick_timer0(struct MSIM_AVR *mcu)
/* Reset Timer/Counter0 */
DM(TCNT0) = 0;
/* Timer/Counter0 overflow occured */
DM(TIFR) |= (1<<TOV0);
DM(TIFR0) |= (1<<TOV0);
} else { /* Count UP on tick */
DM(TCNT0)++;
}
@@ -138,7 +138,7 @@ static void tick_timer0(struct MSIM_AVR *mcu)
/* Reset Timer/Counter0 */
DM(TCNT0) = 0;
/* Timer/Counter0 overflow occured */
DM(TIFR) |= (1<<TOV0);
DM(TIFR0) |= (1<<TOV0);
} else { /* Count UP on tick */
DM(TCNT0)++;
}
@@ -166,7 +166,7 @@ static void tick_timer0(struct MSIM_AVR *mcu)
/* Reset Timer/Counter0 */
DM(TCNT0) = 0;
/* Timer/Counter0 overflow occured */
DM(TIFR) |= (1<<TOV0);
DM(TIFR0) |= (1<<TOV0);
} else { /* Count UP on tick */
DM(TCNT0)++;
}
@@ -212,13 +212,13 @@ static void timer0_normal(struct MSIM_AVR *mcu,
"(prescaler-1)=%" PRIu32 ". Timer1 will not "
"be updated!\n", *ticks, (presc-1U));
} else {
if (mcu->dm[TCNT0] == 0xFF) {
if (DM(TCNT0) == 0xFF) {
/* Reset Timer/Counter0 */
mcu->dm[TCNT0] = 0;
DM(TCNT0) = 0;
/* Set Timer/Counter0 overflow flag */
mcu->dm[TIFR] |= (1<<TOV0);
DM(TIFR0) |= (1<<TOV0);
} else {
mcu->dm[TCNT0]++;
DM(TCNT0)++;
}
*ticks = 0;
return;

0 comments on commit c6d480a

Please sign in to comment.