.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 zh,zl : 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
+ cp zl,_0\r
+ cpc zh,_0\r
+ breq mmc_rcvw_sto\r
+\r
+ sbiw zl,1\r
+ spi_waitm
+ in temp,SPDR
+ out SPDR,_255
+ rjmp mmc_rcvw_rl
+
+mmc_rcvw_sto:\r
+ mov zl,temp\r
+ spi_waitm
+ in temp,SPDR
+ out SPDR,_255
+ mov zh,temp\r
+\r
+mmc_rcvw_rl2:
+ sbiw yl,1
+ breq mmc_rcvw_rle
+ spi_waitm
+ in temp,SPDR
+ out SPDR,_255
+ rjmp mmc_rcvw_rl2\r
+mmc_rcvw_rle:
+ 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