Optimize SD card subsystem a bit

This commit is contained in:
Virgil Dupras 2020-10-29 21:03:11 -04:00
parent ce10320030
commit 480cf342fa
7 changed files with 24 additions and 33 deletions

11
blk/424
View File

@ -5,11 +5,6 @@
( spix 0xff until the response is something else than 0xff ( spix 0xff until the response is something else than 0xff
for a maximum of 20 times. Returns 0xff if no response. ) for a maximum of 20 times. Returns 0xff if no response. )
: _wait : _wait
0 ( cnt ) 0 ( dummy ) 20 0 DO
BEGIN DROP _idle DUP 0xff = NOT IF LEAVE THEN
_idle LOOP ;
DUP 0xff = IF DROP ELSE NIP EXIT THEN
1+
DUP 20 = UNTIL
DROP 0xff
;

View File

@ -10,7 +10,7 @@
_s+crc _s+crc ( a2 crc ) _s+crc _s+crc ( a2 crc )
SWAP 256 /MOD ROT ( h l crc ) SWAP 256 /MOD ROT ( h l crc )
_s+crc _s+crc ( crc ) _s+crc _s+crc ( crc )
0x01 OR ( ensure stop bit ) 1 OR ( ensure stop bit )
(spix) DROP ( send CRC ) (spix) DROP ( send CRC )
_wait ( wait for a valid response... ) _wait ( wait for a valid response... )
; ;

20
blk/431
View File

@ -1,16 +1,16 @@
: SDC$ : SDC$
10 0 DO _idle DROP LOOP 10 0 DO _idle DROP LOOP
0 ( dummy ) 10 0 DO ( r ) 10 0 DO ( r )
DROP 0x40 0 0 SDCMDR1 ( CMD0 ) 0x40 0 0 SDCMDR1 ( CMD0 )
DUP 0x01 = IF LEAVE THEN DUP 1 = IF LEAVE ELSE DROP THEN
LOOP 0x01 = NOT IF _err THEN LOOP 1 = NOT IF _err THEN
0x48 0 0x1aa ( CMD8 ) SDCMDR7 ( r arg1 arg2 ) 0x48 0 0x1aa ( CMD8 ) SDCMDR7 ( r arg1 arg2 )
0x1aa = NOT IF _err THEN ( arg2 check ) ( expected 1 0 0x1aa )
0 = NOT IF _err THEN ( arg1 check ) 0x1aa = ROT ( arg1 f r ) 1 = AND SWAP ( f&f arg1 )
0x01 = NOT IF _err THEN ( r check ) NOT ( 0 expected ) AND ( f&f&f ) NOT IF _err THEN
BEGIN BEGIN
0x77 0 0 SDCMDR1 ( CMD55 ) 0x77 0 0 SDCMDR1 ( CMD55 )
0x01 = NOT IF _err THEN 1 = NOT IF _err THEN
0x69 0x4000 0x0000 SDCMDR1 ( CMD41 ) 0x69 0x4000 0 SDCMDR1 ( CMD41 )
DUP 0x01 > IF _err THEN DUP 1 > IF _err THEN
NOT UNTIL ; ( out of idle mode, success! ) NOT UNTIL ; ( out of idle mode, success! )

10
blk/432
View File

@ -1,14 +1,14 @@
: _sdc@ ( dstaddr blkno -- ) : _ ( dstaddr blkno -- )
[ SDC_DEVID LITN ] (spie) [ SDC_DEVID LITN ] (spie)
0x51 ( CMD17 ) 0 ROT ( a cmd 0 blkno ) _cmd 0x51 ( CMD17 ) 0 ROT ( a cmd 0 blkno ) _cmd
IF _err THEN IF _err THEN
_wait 0xfe = NOT IF _err THEN _wait 0xfe = NOT IF _err THEN
0 SWAP ( crc a ) 0 SWAP ( crc a )
512 0 DO ( crc a ) 512 0 DO ( crc a )
DUP _idle ( crc a a n ) _idle ( crc a n )
DUP ROT C! ( crc a n ) DUP ROT C!+ ( crc n a+1 )
ROT SWAP _crc16 ( a crc ) ROT> _crc16 ( a+1 crc )
SWAP 1+ ( crc a+1 ) SWAP ( crc a+1 )
LOOP LOOP
DROP ( crc1 ) DROP ( crc1 )
_idle 8 LSHIFT _idle + ( crc2 ) _idle 8 LSHIFT _idle + ( crc2 )

View File

@ -1,6 +1,4 @@
: SDC@ : SDC@
2 * DUP BLK( SWAP ( b a b ) 2 * DUP BLK( SWAP ( b a b ) _
_sdc@ 1+ BLK( 512 + SWAP _
1+ BLK( 512 + SWAP
_sdc@
; ;

View File

@ -1,4 +1,4 @@
: _sdc! ( srcaddr blkno -- ) : _ ( srcaddr blkno -- )
[ SDC_DEVID LITN ] (spie) [ SDC_DEVID LITN ] (spie)
0x58 ( CMD24 ) 0 ROT ( a cmd 0 blkno ) _cmd 0x58 ( CMD24 ) 0 ROT ( a cmd 0 blkno ) _cmd
IF _err THEN IF _err THEN

View File

@ -1,6 +1,4 @@
: SDC! : SDC!
2 * DUP BLK( SWAP ( b a b ) 2 * DUP BLK( SWAP ( b a b ) _
_sdc! 1+ BLK( 512 + SWAP _
1+ BLK( 512 + SWAP
_sdc!
; ;