From d89df867f8ae7f41c5185c5bce13506b19301c29 Mon Sep 17 00:00:00 2001 From: Paul Goeser Date: Fri, 13 Jan 2012 20:49:56 +0100 Subject: [PATCH] accelerated naked ISR, still has bugs and possible performance improvements --- gg.c | 29 +++++++++++++++-------------- gg.h | 13 +++++++++++++ 2 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 gg.h diff --git a/gg.c b/gg.c index 219a054..db968ba 100644 --- a/gg.c +++ b/gg.c @@ -2,8 +2,10 @@ #include #include +#include "ringbuf_small.c" #include "mmc.h" +#include "gg.h" void timer_init_tiny26(void) { @@ -38,21 +40,20 @@ uint8_t buffer[BUFFER_SIZE];/* buffer for mmc data */ uint8_t pos = 0;/* current playing position */ uint8_t refresh_buffer = 0;/* position to start buffer refreshing */ -ISR(TIMER1_OVF1_vect) +ISR(TIMER1_OVF1_vect, ISR_NAKED) { - //if(!(TIFR & (1 << TOV1))) {continue;}/* interrupt flag polling */ - //TIFR |= (1 << TOV1);/* done by hardware */ - - overflows--; - if(!overflows) - { - overflows = 1 << (SAMPLE_BITS - 8); - pos = (pos + 1) % BUFFER_SIZE; - } - - /* TODO: a-law decoding */ - /* TODO: 11bit PWM emulation */ - OCR1A = buffer[pos];/* play sample */ + __asm__("in r2, 0x3f"); // save sreg + if(--cnt_to_ocr_incr){ + OCR1A = cur_ocr + 1; + } + if(--cnt_to_next){ + cur_ocr = next_ocr; + cnt_to_ocr_incr = next_cnt_to_incr; + cnt_to_next = 8; + needs_new_data_flag = 1; + } + __asm__("out 0x2f,r2"); // restore sreg + reti(); } diff --git a/gg.h b/gg.h new file mode 100644 index 0000000..a2f2eb1 --- /dev/null +++ b/gg.h @@ -0,0 +1,13 @@ +// contains locked registers + +#include + + +register uint8_t sreg_tmp __asm__("r2"); +register uint8_t cur_ocr __asm__("r3"); +register uint8_t cnt_to_ocr_incr __asm__("r4"); +register uint8_t next_ocr __asm__("r5"); +register uint8_t next_cnt_to_incr __asm__("r6"); +register uint8_t cnt_to_next __asm__("r7"); +register uint8_t needs_new_data_flag __asm__("r8"); +