found bugs, still debugging

master
Paul Goeser 14 years ago
parent b3d30ca742
commit 4d9f2efbfe

19
gg.c

@ -86,15 +86,22 @@ int main(void)
// while(debug){
debug=mmc_init();
// }
// debug = 2;
debug = 2-debug;
mmc_read_part(0, (unsigned char *) &length, 4);
debug = mmc_read_part(0, (unsigned char *) &length, 4);
debug = 1;
if(length==0){
debug = 2;
}
debug = ((length>>0)&0x3) + 1;
debug += 1;
timer_init_tiny26();
sei();
/*
unsigned long block = 0;
/* unsigned long block = 0;
for(;; block++)
{
mmc_read_to_ringbuffer(block, &rb);
@ -102,8 +109,8 @@ int main(void)
// debug = 0;
uint8_t i,r;
uint16_t a;
for(;;){
uint16_t a,to;
for(to=0; to<16000; to++){
i += debug*8;
a = i<<8;
r=1;

18
mmc.c

@ -33,6 +33,7 @@ unsigned char mmc_init ()
//############################################################################
{
unsigned int Timeout = 0;
uint8_t debug;
//Konfiguration des Ports an der die MMC/SD-Karte angeschlossen wurde
MMC_Direction_REG &=~(1<<SPI_DI); //Setzen von Pin MMC_DI auf Input
@ -61,7 +62,7 @@ unsigned char mmc_init ()
//Sendet Commando CMD0 an MMC/SD-Karte
unsigned char CMD[] = {0x40,0x00,0x00,0x00,0x00,0x95};
while(mmc_write_command (CMD) !=1)
while(mmc_write_command (CMD) != 1)
{
if (Timeout++ > 200)
{
@ -69,6 +70,7 @@ unsigned char mmc_init ()
return(1); //Abbruch bei Commando1 (Return Code1)
}
}
// return(((debug >>1) & 1)+1); //FIXME
//Sendet Commando CMD1 an MMC/SD-Karte
Timeout = 0;
CMD[0] = 0x41;//Commando 1
@ -151,6 +153,7 @@ unsigned char mmc_read_byte (void)
#else //Routine für Software SPI
for(unsigned char a=8; a>0; a--) //das Byte wird Bitweise nacheinander Empangen MSB First
{
Byte <<= 1;
MMC_Write &=~(1<<SPI_Clock); //erzeugt ein Clock Impuls (Low)
WAIT_HALF_CLOCK;
@ -158,7 +161,6 @@ unsigned char mmc_read_byte (void)
{
Byte |= 1;
}
Byte <<= 1;
MMC_Write |=(1<<SPI_Clock); //setzt Clock Impuls wieder auf (High)
WAIT_HALF_CLOCK;
}
@ -310,13 +312,13 @@ unsigned char mmc_read_sector (unsigned long addr,unsigned char *Buffer)
//############################################################################
//Routine zum lesen des CID Registers von der MMC/SD-Karte (16Bytes)
void mmc_read_block_part(unsigned char *cmd,unsigned char *Buffer,uint16_t count, unsigned int Bytes)
uint8_t mmc_read_block_part(unsigned char *cmd,unsigned char *Buffer,uint16_t count, unsigned int Bytes)
//############################################################################
{
//Sendet Commando cmd an MMC/SD-Karte
if (mmc_write_command (cmd) != 0)
{
return;
return(1);
}
//Wartet auf Start Byte von der MMC/SD-Karte (FEh/Start Byte)
@ -326,7 +328,7 @@ void mmc_read_block_part(unsigned char *cmd,unsigned char *Buffer,uint16_t count
//Lesen des Bolcks (normal 512Bytes) von MMC/SD-Karte
for (unsigned int a=0;a<Bytes;a++)
{
if(Bytes < count) {*Buffer++ = mmc_read_byte();}
if(a < count) {*Buffer++ = mmc_read_byte();}
else {mmc_read_byte();}
}
//CRC-Byte auslesen
@ -336,12 +338,12 @@ void mmc_read_block_part(unsigned char *cmd,unsigned char *Buffer,uint16_t count
//set MMC_Chip_Select to high (MMC/SD-Karte Inaktiv)
MMC_Disable();
return;
return(0);
}
//############################################################################
//Routine zum lesen eines Blocks(512Byte) von der MMC/SD-Karte
void mmc_read_part(unsigned long addr,unsigned char *Buffer, uint16_t count)
uint8_t mmc_read_part(unsigned long addr,unsigned char *Buffer, uint16_t count)
//############################################################################
{
//Commando 16 zum lesen eines Blocks von der MMC/SD - Karte
@ -357,7 +359,7 @@ void mmc_read_part(unsigned long addr,unsigned char *Buffer, uint16_t count)
cmd[2] = ((addr & 0x00FF0000) >>16 );
cmd[3] = ((addr & 0x0000FF00) >>8 );
mmc_read_block_part(cmd, Buffer, count, 512);
return mmc_read_block_part(cmd, Buffer, count, 512);
}
//############################################################################

@ -14,7 +14,7 @@ Copyright (C) 2004 Ulrich Radig
//#define SPI_Mode 1 //1 = Hardware SPI | 0 = Software SPI
#define SPI_Mode 0
#define WAIT_HALF_CLOCK _delay_us(50)
#define WAIT_HALF_CLOCK _delay_us(18)
#define MMC_Write PORTA //Port an der die MMC/SD-Karte angeschlossen ist also des SPI
#define MMC_Read PINA
@ -64,9 +64,9 @@ extern unsigned char mmc_init(void);
extern unsigned char mmc_read_sector (unsigned long,unsigned char *);
extern void mmc_read_block_part(unsigned char *, unsigned char *, uint16_t, unsigned int);
extern uint8_t mmc_read_block_part(unsigned char *, unsigned char *, uint16_t, unsigned int);
extern void mmc_read_part(unsigned long, unsigned char *, uint16_t);
extern uint8_t mmc_read_part(unsigned long, unsigned char *, uint16_t);
extern void mmc_read_block_to_ringbuffer(unsigned char *, ringbuf_t *, unsigned int);

Loading…
Cancel
Save