From 8d78ca9dacb7d711908eb53e0bf105fccaf7fab2 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Fri, 24 Apr 2020 18:23:29 -0400 Subject: [PATCH] tests: add test_sdc The SD card driver is a bit too slow to be bearable. I'll write _crc16 in z80 and see how it goes. --- blk/380 | 28 ++++++++++++++-------------- blk/381 | 26 ++++++++++++++++---------- blk/382 | 13 ------------- tests/forth/test_sdc.fs | 10 ++++++++++ 4 files changed, 40 insertions(+), 37 deletions(-) create mode 100644 tests/forth/test_sdc.fs diff --git a/blk/380 b/blk/380 index 0884215..12b7c44 100644 --- a/blk/380 +++ b/blk/380 @@ -1,16 +1,16 @@ : _err _sdcDesel ABORT" SDerr" ; -( Initialize a SD card. This should be called at least 1ms - after the powering up of the card. ) -: SDC$ -( Wake the SD card up. After power up, a SD card has to receive - at least 74 dummy clocks with CS and DI high. We send 80. ) - 10 0 DO _idle DROP LOOP - ( call cmd0 and expect a 0x01 response (card idle) - this should be called multiple times. we're actually - expected to. let's call this for a maximum of 10 times. ) - 0 ( dummy ) - 10 0 DO ( r ) - DROP 0x40 0 0 SDCMDR1 ( CMD0 ) - DUP 0x01 = IF LEAVE THEN - LOOP 0x01 = NOT IF _err THEN ( cont. ) +( Tight definition ahead, pre-comment. + + Initialize a SD card. This should be called at least 1ms + after the powering up of the card. We begin by waking up the + SD card. After power up, a SD card has to receive at least + 74 dummy clocks with CS and DI high. We send 80. + Then send cmd0 for a maximum of 10 times, success is when + we get 0x01. Then comes the CMD8. We send it with a 0x01aa + argument and expect a 0x01aa argument back, along with a + 0x01 R1 response. After that, we need to repeatedly run + CMD55+CMD41 (0x40000000) until the card goes out of idle + mode, that is, when it stops sending us 0x01 response and + send us 0x00 instead. Any other response means that + initialization failed. ) diff --git a/blk/381 b/blk/381 index 35528cf..748aa05 100644 --- a/blk/381 +++ b/blk/381 @@ -1,10 +1,16 @@ -( Then comes the CMD8. We send it with a 0x01aa argument and - expect a 0x01aa argument back, along with a 0x01 R1 - response. ) - 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 ) - - ( cont. ) +: 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 + 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 ) + BEGIN + 0x77 0 0 SDCMDR1 ( CMD55 ) + 0x01 = NOT IF _err THEN + 0x69 0x4000 0x0000 SDCMDR1 ( CMD41 ) + DUP 0x01 > IF _err THEN + NOT UNTIL ; ( out of idle mode, success! ) diff --git a/blk/382 b/blk/382 index ac24ea7..e69de29 100644 --- a/blk/382 +++ b/blk/382 @@ -1,13 +0,0 @@ -( Now we need to repeatedly run CMD55+CMD41 (0x40000000) - until the card goes out of idle mode, that is, when it stops - sending us 0x01 response and send us 0x00 instead. Any other - response means that initialization failed. ) - BEGIN - 0x77 0 0 SDCMDR1 ( CMD55 ) - 0x01 = NOT IF _err THEN - 0x69 0x4000 0x0000 SDCMDR1 ( CMD41 ) - DUP 0x01 > IF _err THEN - NOT UNTIL - ( Out of idle mode! Success! ) -; - diff --git a/tests/forth/test_sdc.fs b/tests/forth/test_sdc.fs new file mode 100644 index 0000000..a35d13d --- /dev/null +++ b/tests/forth/test_sdc.fs @@ -0,0 +1,10 @@ +212 LOAD ( z80a ) +: SDC_SPI 4 ; +: SDC_CSLOW 5 ; +: SDC_CSHIGH 6 ; +372 LOAD ( sdc.z80 ) +374 LOAD ( sdc.fs ) + +0x0000 0x0000 _crc16 0x0000 #eq +0x0000 0x0001 _crc16 0x1021 #eq +0x5678 0x1234 _crc16 0x43c4 #eq