removed some unnecessary bitshifts in mmc code, a bit of cleaning in gg.c, documented pin usage in README

master
Nidan 14 years ago
parent 42532aa047
commit 50a3d3a7c8

@ -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

28
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();

11
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<<SPI_Clock); //setzt Clock Impuls wieder auf (High)
WAIT_HALF_CLOCK;
}
@ -168,9 +165,9 @@ void mmc_write_byte (unsigned char Byte)
SPDR = Byte; //Sendet ein Byte
while(!(SPSR & (1 << SPIF))) {;}//Wartet bis Byte gesendet wurde
#else //Routine für Software SPI
for(unsigned char a=8; a>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<<SPI_DO); //Set Output High
}

Loading…
Cancel
Save