]> cloudbase.mooo.com Git - avrcpm.git/blobdiff - mmc.asm
* Initial changes for FAT16 support.
[avrcpm.git] / mmc.asm
diff --git a/mmc.asm b/mmc.asm
index 1a04542157d96c74ab0a6076688fbfc3158d1831..49a1b9cd716a874542bedcf2d0ee2626c892c9cf 100644 (file)
--- a/mmc.asm
+++ b/mmc.asm
@@ -591,6 +591,81 @@ mmc_rdex:
 .endif
        ret
 
+\r
+;--------------------------------------------------------------
+; Read word \r
+; TODO: Read Word to ZL,ZH at given ZL/ZH Offset\r
+; Need for reading of single FAT16 Entrys without killing the\r
+; Entrys in hostbuffer...\r
+;
+;      in      zh,zl:          Pointer to Word within the Sector to read       
+;   in yh..xl: Start sector number (LBA)
+;      out     xh,xl   : word thats been read\r
+
+mmcReadWord:
+.if MMC_DEBUG > 1
+       printnewline
+       printstring     "mmcRdWord "
+.endif
+       lds             _tmp0,mmcStat
+       ldi             temp,RES_NOTRDY
+       sbrc    _tmp0,MMCST_NOINIT
+       ret
+       
+       spi_clkfast
+       lds             temp,mmcCardType
+       sbrs    temp,log2(CT_BLOCK)
+       rcall   mul_yx_512              ;Convert to byte address  (*512)
+\r
+       ldi             temp2,CMD17
+       rcall   mmcCmd
+       ldi             temp2,RES_ERROR
+       brne    mmc_rdexw
+       
+; Receive a data packet from MMC
+
+       ldiw    y,512                   ;Number of bytes to tranfer
+       ldi             temp,200                ;Wait for data packet in timeout of 200ms.
+       sts             delay_timer1,temp
+mmc_rcvw_wl:
+       rcall   spi_rcvr
+       cp              temp,_255
+       brne    mmc_rcvw_start
+       lds             temp2,delay_timer1
+       cpi             temp2,0
+       brne    mmc_rcvw_wl
+mmc_rcvw_start:
+       cpi             temp,0xFE               ;If not valid data token, 
+       ldi             temp2,RES_ERROR
+       brne    mmc_rdexw
+       
+       rcall   spi_rcvr                ;Shift in first byte.
+       out             SPDR,_255               ;Start shift in next byte.
+mmc_rcvw_rl:
+       sbiw    yl,1
+       breq    mmc_rcvw_rle
+       //st            z+,temp
+       spi_waitm
+       in              temp,SPDR
+       out             SPDR,_255
+       rjmp    mmc_rcvw_rl
+
+mmc_rcvw_rle:
+       //st            z+,temp                 ;Store last byte in buffer 
+       rcall   spi_wait                ;      while SPI module shifts in crc part1.
+       rcall   spi_rcvr                ;Read second crc.
+       
+       ldi             temp2,RES_OK            ;Return success
+mmc_rdexw:
+       rcall   mmcDeselect
+       spi_disable
+       mov     temp,temp2
+.if MMC_DEBUG > 1
+       printstring     "RdWordRes: "
+       rcall   printhex
+       printstring     " "
+.endif
+       ret\r
 
 ;--------------------------------------------------------------
 ; Write sector