From 04a63b0d5660f1c0c0b7e8123e4f56d188e52a5d Mon Sep 17 00:00:00 2001 From: Leo C Date: Wed, 17 Sep 2014 22:23:17 +0200 Subject: Disable all peripheral functions globally. Enable used functions when needed. --- avr/z80-if.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'avr/z80-if.c') diff --git a/avr/z80-if.c b/avr/z80-if.c index c0f128e..dd0dd96 100644 --- a/avr/z80-if.c +++ b/avr/z80-if.c @@ -144,6 +144,7 @@ struct bits { #define MASK(n) ((1<<(n))-1) #define SMASK(w,s) (MASK(w) << (s)) +#define LOWSPEED 50000 typedef union { @@ -157,6 +158,13 @@ static zstate_t zstate; /*--------------------------------------------------------------------------*/ +static +uint8_t is_lowspeed() +{ + return (TCCR1B & 7) < 2 && + OCR1A > (F_CPU / 2 / LOWSPEED); +} + static void z80_setup_clock(void) { @@ -206,12 +214,10 @@ int z80_clock_set(unsigned long freq) TCCR1A = (0b01 << COM1C0) | (0b00 << WGM10); TCCR1B = (0b01 << WGM12) | ((prescale+1) << CS10); - if (ocrval == 0) { -// TCCR1C |= _BV(FOC1C); + if (ocrval == 0) ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { TCNT1 = 0xFFFF; } - } PINB |= _BV(6); /* Debug */ @@ -229,7 +235,6 @@ uint32_t z80_clock_get(void) else count *= 8; pre--; - } return F_CPU/count; -- cgit v1.2.3