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
for a maximum of 20 times. Returns 0xff if no response. )
: _wait
0 ( cnt )
BEGIN
_idle
DUP 0xff = IF DROP ELSE NIP EXIT THEN
1+
DUP 20 = UNTIL
DROP 0xff
;
0 ( dummy ) 20 0 DO
DROP _idle DUP 0xff = NOT IF LEAVE THEN
LOOP ;

View File

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

20
blk/431
View File

@ -1,16 +1,16 @@
: SDC$
10 0 DO _idle DROP LOOP
0 ( dummy ) 10 0 DO ( r )
DROP 0x40 0 0 SDCMDR1 ( CMD0 )
DUP 0x01 = IF LEAVE THEN
LOOP 0x01 = NOT IF _err THEN
10 0 DO ( r )
0x40 0 0 SDCMDR1 ( CMD0 )
DUP 1 = IF LEAVE ELSE DROP THEN
LOOP 1 = NOT IF _err THEN
0x48 0 0x1aa ( CMD8 ) SDCMDR7 ( r arg1 arg2 )
0x1aa = NOT IF _err THEN ( arg2 check )
0 = NOT IF _err THEN ( arg1 check )
0x01 = NOT IF _err THEN ( r check )
( expected 1 0 0x1aa )
0x1aa = ROT ( arg1 f r ) 1 = AND SWAP ( f&f arg1 )
NOT ( 0 expected ) AND ( f&f&f ) NOT IF _err THEN
BEGIN
0x77 0 0 SDCMDR1 ( CMD55 )
0x01 = NOT IF _err THEN
0x69 0x4000 0x0000 SDCMDR1 ( CMD41 )
DUP 0x01 > IF _err THEN
1 = NOT IF _err THEN
0x69 0x4000 0 SDCMDR1 ( CMD41 )
DUP 1 > IF _err THEN
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)
0x51 ( CMD17 ) 0 ROT ( a cmd 0 blkno ) _cmd
IF _err THEN
_wait 0xfe = NOT IF _err THEN
0 SWAP ( crc a )
512 0 DO ( crc a )
DUP _idle ( crc a a n )
DUP ROT C! ( crc a n )
ROT SWAP _crc16 ( a crc )
SWAP 1+ ( crc a+1 )
_idle ( crc a n )
DUP ROT C!+ ( crc n a+1 )
ROT> _crc16 ( a+1 crc )
SWAP ( crc a+1 )
LOOP
DROP ( crc1 )
_idle 8 LSHIFT _idle + ( crc2 )

View File

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

View File

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

View File

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