( SPI interface to MMC disk ) : BITS-ON ( mask -) IOSET ! ; : BITS-OFF ( mask -) IOCLR ! ; : PIN13 ( - mask) $00002000 ; : DISABLE-MMC ( -) PIN13 BITS-ON ; : ENABLE-MMC ( -) PIN13 BITS-OFF ; : SPI!@ ( c - c) ( send a byte then collect the returned byte) SPDR ! BEGIN SPSR @ $80 AND UNTIL SPDR @ ; : SPI! ( c -) ( sned a byte but throw away returned byte) SPI!@ DROP ; : SPI@ ( - c) ( send a dumm byte and collect returned byte) $FF SPI!@ ; : DUMMY-SPI-BYTES ( # -) FOR $FF SPI! NEXT ;
: GET-MMC-RESPONSE ( - f) ( Try up to 256 times to get a response. A zero response ) ( means no error. A valid response is a byte whose MSBit is zero.) ( Return -1 in case of a time-out. ) 256 ( remaining tries) ( fall through to next word) : (GET-MMC-RESPONSE ( remaining# - f) ( PAUSE ) SPI@ DUP $80 AND NOT IF NIP ( cardResponse) ; THEN DROP ( remaining#) 1- DUP 0= IF DROP -1 ; THEN (GET-MMC-RESPONSE ;
FIXME:…