X-Git-Url: http://cloudbase.mooo.com/gitweb/avrcpm.git/blobdiff_plain/94175893adca548862102caa29fd8c998d7d0e67..8b13b36c6542ac4fac3a69ae45f7e296f7754bdb:/mmc.asm diff --git a/mmc.asm b/mmc.asm index 1a04542..49a1b9c 100644 --- a/mmc.asm +++ b/mmc.asm @@ -591,6 +591,81 @@ mmc_rdex: .endif ret + +;-------------------------------------------------------------- +; Read word +; TODO: Read Word to ZL,ZH at given ZL/ZH Offset +; Need for reading of single FAT16 Entrys without killing the +; Entrys in hostbuffer... +; +; 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 + +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) + + 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 ;-------------------------------------------------------------- ; Write sector