From 50a3d3a7c8d25c09048ceec99b82911b335eaaac Mon Sep 17 00:00:00 2001 From: Nidan Date: Sat, 14 Jan 2012 01:19:02 +0100 Subject: [PATCH] removed some unnecessary bitshifts in mmc code, a bit of cleaning in gg.c, documented pin usage in README --- README | 15 +++++++++++++++ gg.c | 28 +++++++++++++--------------- mmc.c | 11 ++++------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/README b/README index ef50282..7f0a740 100644 --- a/README +++ b/README @@ -1,3 +1,18 @@ +pin belegung: + +PA0 - MMC - +PA1 - MMC - +PA2 - MMC - +PA3 - MMC - + +PA7 - "Ausschalter" + +PB0 - Progger - MOSI +PB1 - Progger - MISO +PB2 - Progger - SCK + +PB7 - Reset + mmc-code from http://www.ulrichradig.de/home/index.php/avr/mmc-sd diff --git a/gg.c b/gg.c index c0f0ac3..3f78dd8 100644 --- a/gg.c +++ b/gg.c @@ -26,16 +26,10 @@ void timer_init_tiny26(void) TIMSK = 1 << TOIE1;/* interrupt on overflow */ } - -uint8_t length[4];/* remaining samples */ -uint32_t mmc_position;/* current reading position on mmc */ - -uint8_t overflows = 1;/* remaining counter overflows until next sample */ -#define SAMPLE_BITS 11 -ringbuf_t rb; - #define BUFFER_SIZE 32 uint16_t buffer[BUFFER_SIZE];/* buffer for mmc data */ +ringbuf_t rb; +uint32_t length;/* remaining samples */ /*ISR(TIMER1_OVF1_vect, ISR_NAKED) { @@ -52,7 +46,7 @@ uint16_t buffer[BUFFER_SIZE];/* buffer for mmc data */ } __asm__("out 0x3f,r2"); // restore sreg reti(); -}//*/ +}// */ ISR(TIMER1_OVF1_vect){ // next try: simplistic, not too much looking at speed @@ -61,26 +55,30 @@ ISR(TIMER1_OVF1_vect){ if(--cnt_to_next){ ringbuf_get(&rb, &next); OCR1A = next>>8; - cnt_to_ocr_incr = 7-(next & 0x7); + cnt_to_ocr_incr = 7-(next & 0x7); cnt_to_next = 7; + if(!--length) + { + /* shut down */ + PORTA &= ~(1 << PA7); + } } else { if(--cnt_to_ocr_incr){ OCR1A += 1; } } -} - - - +} int main(void) __attribute__((noreturn)); int main(void) { + DDRA |= (1 << PA7); + PORTA |= (1 << PA7); ringbuf_init(&rb, buffer, BUFFER_SIZE); if(mmc_init() != 0) {/* mmc fail */;} - mmc_read_part(0, length, 4); + mmc_read_part(0, (unsigned char *) &length, 4); timer_init_tiny26(); sei(); diff --git a/mmc.c b/mmc.c index 7df9a42..11e6808 100644 --- a/mmc.c +++ b/mmc.c @@ -145,12 +145,9 @@ unsigned char mmc_read_byte (void) if(bit_is_set(MMC_Read,SPI_DI) > 0) //Lesen des Pegels von MMC_DI { - Byte |= (1<<(a-1)); - } - else - { - Byte &=~(1<<(a-1)); + Byte |= 1; } + Byte <<= 1; MMC_Write |=(1<0; a--) //das Byte wird Bitweise nacheinander Gesendet MSB First + for(uint8_t current_bit = 1 << 7; current_bit; current_bit >>= 1) //das Byte wird Bitweise nacheinander Gesendet MSB First { - if(bit_is_set(Byte,(a-1))>0) //Ist Bit a in Byte gesetzt + if(Byte & current_bit) //Ist Bit a in Byte gesetzt { MMC_Write |= (1<