From 0f4c42b594895b363f239d6f86264f0c2c32bfc2 Mon Sep 17 00:00:00 2001 From: Paul Goeser Date: Fri, 13 Jan 2012 12:49:55 +0100 Subject: [PATCH] made it compile --- .gitignore | 3 +++ Makefile | 2 +- gg.c | 48 +++++++++---------------------------------- mmc.h | 13 ++++++++++-- other_architectures.c | 33 +++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 41 deletions(-) create mode 100644 other_architectures.c diff --git a/.gitignore b/.gitignore index 41d882d..17302c2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ /*.d headeredit /*.o +/disasm +/firmware.bin +/firmware.hex diff --git a/Makefile b/Makefile index 0141dd2..b874eeb 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CFLAGS += -Wall -Os -I. -mmcu=attiny26 +CFLAGS += -Wall -Os -I. -mmcu=attiny26 -std=c99 DEFINES += -DF_CPU=16e6 OBJECTS = gg.o mmc.o diff --git a/gg.c b/gg.c index 624c0b5..dbcb2a2 100644 --- a/gg.c +++ b/gg.c @@ -1,44 +1,14 @@ #include +#include +#include #include "mmc.h" -void timer_init_mega16(void) -{ - ICR1 = (1 << 11) - 1;/* 11 bit pwm */ - OCR1A = 0; - TCCR1A = (1 << COM1A1) | (1 << CS10) | (1 << WGM11);/* fast pwm, non inverted, top in ICR1 */ - TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10);/* fast pwm, top in ICR1, */ - DDRD |= (1 << PD5);/* set pwm pin as output */ - TIMSK = 1 << TOIE1;/* interrupt at top */ -} - -void timer_init_tiny45(void) -{ - PLLCSR = 1 << PLLE;/* pll enable */ - delay_us(100); - while(!(PLLCSR & (1 << PLOCK))) {;}/* wait for lock */ - PLLCSR |= 1 << PCKE;/* use pll */ - - OCR1C = 0xff; - - /* output pin: OC1A = PB1 = 6 */ - OCR1A = 0; - TCCR1 = (1 << PWM1A) | (1 << COM1A1) | (1 << CS10);/* pwm enable, non inverted, no prescaler */ - DDRB |= (1 << PB1); - - /* output pin: OC1B = PB5 = 3 */ - //OCR1B = 0; - //TCCR1 = (1 << CS10);/* no prescaler */ - //GTCCR = (1 << PWM1B) | (1 << COM1B1);/* pwm enable, non inverted */ - //DDRB |= (1 << PB5); - - TIMSK = 1 << TOIE1;/* interrupt on overflow */ -} void timer_init_tiny26(void) { PLLCSR = 1 << PLLE;/* pll enable */ - delay_us(100); + _delay_us(100); while(!(PLLCSR & (1 << PLOCK))) {;}/* wait for lock */ PLLCSR |= 1 << PCKE;/* use pll */ @@ -46,7 +16,7 @@ void timer_init_tiny26(void) /* output pin: OC1A = PB1 = 1 or OC1B = PB3 = 2 */ OCR1A = 0; - TCCR1A = (1 << COM1A1) (1 << PWM1A);/* pwm enable, not inverted */ + TCCR1A = (1 << COM1A1) | (1 << PWM1A);/* pwm enable, not inverted */ TCCR1B = (1 << CS10);/* fast pwm, no prescaler */ DDRB |= (1 << PB1); @@ -55,7 +25,7 @@ void timer_init_tiny26(void) uint8_t length[4];/* remaining samples */ -uint8_t mmc_position[4];/* current reading position on mmc */ +uint32_t mmc_position;/* current reading position on mmc */ uint8_t overflows = 1;/* remaining counter overflows until next sample */ #define SAMPLE_BITS 11 @@ -68,7 +38,7 @@ 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 */ -timerinterrupt() +ISR(TIMER1_OVF1_vect) { //if(!(TIFR & (1 << TOV1))) {continue;}/* interrupt flag polling */ //TIFR |= (1 << TOV1);/* done by hardware */ @@ -87,8 +57,10 @@ timerinterrupt() -void main(void) +int main(void) __attribute__((noreturn)); +int main(void) { + uint8_t ref; // TODO: what does this do? if(mmc_init() != 0) {/* mmc fail */;} timer_init_tiny26(); sei(); @@ -97,7 +69,7 @@ void main(void) { if(pos == refresh_buffer)/* refresh buffer if running low */ { - mmc_read(mmc_position, buffer + (ref + REFRESH_SIZE) % BUFFER_SIZE, BUFFER_SIZE - ref, buffer, REFRESH_AMOUNT - (BUFFER_SIZE - ref)); + mmc_read_sector(mmc_position, buffer + (ref + REFRESH_SIZE) % BUFFER_SIZE);//, BUFFER_SIZE - ref), buffer, REFRESH_AMOUNT - (BUFFER_SIZE - ref)); /* pos on sd , first buffer address , 1st buffer size ,2nd buf, 2nd buffer size */ refresh_buffer = (refresh_buffer + REFRESH_AMOUNT) % BUFFER_SIZE; } diff --git a/mmc.h b/mmc.h index d23fb0b..0354b5b 100755 --- a/mmc.h +++ b/mmc.h @@ -9,8 +9,8 @@ Copyright (C) 2004 Ulrich Radig #include -#define SPI_Mode 1 //1 = Hardware SPI | 0 = Software SPI -//#define SPI_Mode 0 +//#define SPI_Mode 1 //1 = Hardware SPI | 0 = Software SPI +#define SPI_Mode 0 #define MMC_Write PORTB //Port an der die MMC/SD-Karte angeschlossen ist also des SPI #define MMC_Read PINB @@ -40,6 +40,15 @@ Copyright (C) 2004 Ulrich Radig #define SPI_SS 4 //Nicht Benutz muß aber definiert werden #endif +#if defined (__AVR_ATtiny26__) + #define SPI_DI 6 //Port Pin an dem Data Output der MMC/SD-Karte angeschlossen ist + #define SPI_DO 5 //Port Pin an dem Data Input der MMC/SD-Karte angeschlossen ist + #define SPI_Clock 7 //Port Pin an dem die Clock der MMC/SD-Karte angeschlossen ist (clk) + #define MMC_Chip_Select 1 //Port Pin an dem Chip Select der MMC/SD-Karte angeschlossen ist + #define SPI_SS 4 //Nicht benutzt, muß aber definiert werden +#endif + + //Prototypes extern unsigned char mmc_read_byte(void); diff --git a/other_architectures.c b/other_architectures.c new file mode 100644 index 0000000..8c30a9f --- /dev/null +++ b/other_architectures.c @@ -0,0 +1,33 @@ + +void timer_init_mega16(void) +{ + ICR1 = (1 << 11) - 1;/* 11 bit pwm */ + OCR1A = 0; + TCCR1A = (1 << COM1A1) | (1 << CS10) | (1 << WGM11);/* fast pwm, non inverted, top in ICR1 */ + TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10);/* fast pwm, top in ICR1, */ + DDRD |= (1 << PD5);/* set pwm pin as output */ + TIMSK = 1 << TOIE1;/* interrupt at top */ +} + +void timer_init_tiny45(void) +{ + PLLCSR = 1 << PLLE;/* pll enable */ + delay_us(100); + while(!(PLLCSR & (1 << PLOCK))) {;}/* wait for lock */ + PLLCSR |= 1 << PCKE;/* use pll */ + + OCR1C = 0xff; + + /* output pin: OC1A = PB1 = 6 */ + OCR1A = 0; + TCCR1 = (1 << PWM1A) | (1 << COM1A1) | (1 << CS10);/* pwm enable, non inverted, no prescaler */ + DDRB |= (1 << PB1); + + /* output pin: OC1B = PB5 = 3 */ + //OCR1B = 0; + //TCCR1 = (1 << CS10);/* no prescaler */ + //GTCCR = (1 << PWM1B) | (1 << COM1B1);/* pwm enable, non inverted */ + //DDRB |= (1 << PB5); + + TIMSK = 1 << TOIE1;/* interrupt on overflow */ +}