Permalink
Browse files

Add cardnotbusy() to sdhc.c to keep diverting to sram

  • Loading branch information...
1 parent 5d81ffb commit b5bad97dbc5e11c4d760170d17a34024f85ec82d tz committed Mar 31, 2010
Showing with 14 additions and 5 deletions.
  1. +7 −0 fat32lib/sdhc.c
  2. +1 −0 fat32lib/sdhc.h
  3. +6 −5 sramlog/main.c
View
@@ -264,6 +264,13 @@ static void setblockaddr(u32 blkaddr)
rw1bcmd[5] = 0xff;
}
+u8 cardnotbusy(void) {
+ csact();
+ u8 ret = waitnotspi(0); // wait 8 cycles for not busy
+ csinact();
+ return ret;
+}
+
u8 readsec(u32 blkaddr)
{
u8 ret = 1;
View
@@ -15,3 +15,4 @@ u8 writesec(u32 addr);
u32 sdnumsectors;
void erasecard(void);
+u8 cardnotbusy(void);
View
@@ -163,10 +163,11 @@ int main(void)
extern volatile unsigned rxhead, rxtail;
extern unsigned char rxbuf[1 << RXBUFBITS];
if( rxhead == rxtail ) {
- while( wramaddr - rramaddr > 512 ) {
- readdat( filesectbuf, 512 );
- writenextsect();
- }
+ if( cardnotbusy() )
+ while( wramaddr - rramaddr > 512 ) {
+ readdat( filesectbuf, 512 );
+ writenextsect();
+ }
if( !cnt-- ) {
// UCSR0A &= ~0x10;
flushbuf();
@@ -202,7 +203,7 @@ extern unsigned char rxbuf[1 << RXBUFBITS];
rxtail &= (1 << RXBUFBITS) - 1;
}
}
- if( wramaddr - rramaddr > 512 ) { // for speed, just do one
+ if( wramaddr - rramaddr > 512 && cardnotbusy() ) { // for speed, just do one
readdat( filesectbuf, 512 );
writenextsect();
}

0 comments on commit b5bad97

Please sign in to comment.