1 ; ----------------- MMC/SD routines ------------------
27 ;Wait till the mmc answers with the response in temp2, or till a timeout happens.
33 brne mmcWaitResploopEnd
45 printstring ": Error: MMC resp timeout!"
53 ;Init start: send 80 clocks with cs disabled
57 ldi temp2,10 ; exactly 80 clocks
95 ldi temp,0xff ;return byte
98 ldi temp2,0 ;Error Code 0
99 rcall mmcWaitResp ;Test on CMD0 is OK
101 sbi P_MMC_CS,mmc_cs ;disable /CS
105 ;Read OCR till card is ready
106 ldi temp2,100 ;repeat counter
110 cbi P_MMC_CS,mmc_cs ;enable /CS
129 rcall mmcWaitResp ;wait until mmc-card send a byte <> 0xFF
130 ;the first answer must be 0x01 (Idle-Mode)
132 breq mmcInitOcrLoopDone ;second answer is 0x00 (Idle-Mode leave) CMD1 is OK
134 sbi P_MMC_CS,mmc_cs ;disable /CS
143 brne mmcInitOcrLoop ;repeat
150 sbi P_MMC_CS,mmc_cs ;disable /CS
157 ;Call this with yh:yl:xh:xl = sector number
165 ldi temp,0x51 ;cmd (read sector)
167 lsl xl ;convert to byte address (*512)
180 ldi temp,0xff ;return byte
191 ;Read sector to AVR RAM
196 cpi zl,low(hostbuf+512)
198 cpi zh,high(hostbuf+512)
212 ;Call this with yh:yl:xh:xl = sector number
221 ldi temp,0x58 ;cmd (write sector)
223 lsl xl ;convert to byte address (*512)
236 ldi temp,0xff ;return byte
247 ;Write sector from AVR RAM
252 cpi zl,low(hostbuf+512)
254 cpi zh,high(hostbuf+512)
261 ;Status. Ignored for now.
264 ;Wait till the mmc has written everything
277 ;Set up wdt to time out after 1 sec.
279 lds temp,txcount ;Wait, till tx buffer is empty
286 ldi temp,(1<<WDCE) | (1<<WDE) | (110<<WDP0)