From 9eaa6c49f9300e98674ec004c2aac81dc354a898 Mon Sep 17 00:00:00 2001 From: Byron Lathi Date: Sun, 10 Apr 2022 23:18:26 -0500 Subject: [PATCH] Add software support for sd response codes Polls the sd controller until the read flag is set, at which point it reads 32 bits of data from the controller. long response codes (such as CID) are not supported in hw or sw. --- sw/main.c | 59 +++++++++++++++++++++++++++++++++++++--------------- sw/sd_card.h | 2 ++ sw/sd_card.s | 25 +++++++++++++++++++++- 3 files changed, 68 insertions(+), 18 deletions(-) diff --git a/sw/main.c b/sw/main.c index 81e6cd6..c20b850 100644 --- a/sw/main.c +++ b/sw/main.c @@ -7,13 +7,14 @@ #include "sd_card.h" int main() { - int i; - uint8_t sw; - char s[16]; - s[15] = 0; + int i; + uint8_t sw; + uint32_t resp; + char s[16]; + s[15] = 0; - clrscr(); - cprintf("Hello, world!\n"); + clrscr(); + cprintf("Hello, world!\n"); for (i = 0; i < 16; i++){ cprintf("Mapping %1xxxx to %2xxxx\n", i, i); @@ -51,29 +52,53 @@ int main() { // The RCA is hard coded for the one that I have on hand as responses // are not implemented yet. sd_card_command(0, 0); + sd_card_command(0x000001aa, 8); + sd_card_resp(&resp); + cprintf("CMD8: %lx\n", resp); + sd_card_command(0, 55); sd_card_command(0x40180000, 41); + sd_card_resp(&resp); + cprintf("CMD41: %lx\n", resp); + sd_card_command(0, 55); sd_card_command(0x40180000, 41); + sd_card_resp(&resp); + cprintf("CMD41: %lx\n", resp); + sd_card_command(0, 2); + sd_card_resp(&resp); + cprintf("CMD2: %lx\n", resp); + sd_card_command(0, 3); + sd_card_resp(&resp); + cprintf("CMD3: %lx\n", resp); + sd_card_command(0x59b40000, 7); + sd_card_resp(&resp); + cprintf("CMD7: %lx\n", resp); + sd_card_command(0x59b41000, 13); + sd_card_resp(&resp); + cprintf("CMD13: %lx\n", resp); + sd_card_command(0, 17); + sd_card_resp(&resp); + cprintf("CMD17: %lx\n", resp); - while (1) { + while (1) { - sw = sw_read(); - led_set(sw); + sw = sw_read(); + led_set(sw); - cscanf("%15s", s); - cprintf("\n"); - for (i = 0; i < 16; i++) - cprintf("s[%d]=%c ", i, s[i]); - cprintf("\n"); - cprintf("Read string: %s\n", s); - } + cscanf("%15s", s); + cprintf("\n"); + for (i = 0; i < 16; i++) + cprintf("s[%d]=%c ", i, s[i]); + cprintf("\n"); + cprintf("Read string: %s\n", s); + } - return 0; + return 0; } diff --git a/sw/sd_card.h b/sw/sd_card.h index 1cd59af..df44704 100644 --- a/sw/sd_card.h +++ b/sw/sd_card.h @@ -5,4 +5,6 @@ void sd_card_command(uint32_t arg, uint8_t cmd); +void sd_card_resp(uint32_t* resp); + #endif \ No newline at end of file diff --git a/sw/sd_card.s b/sw/sd_card.s index f6c6ed6..13a5e0c 100644 --- a/sw/sd_card.s +++ b/sw/sd_card.s @@ -1,8 +1,9 @@ .include "io.inc65" -.importzp sp, sreg +.importzp sp, sreg, ptr1 .export _sd_card_command +.export _sd_card_resp .autoimport on @@ -25,3 +26,25 @@ _sd_card_command: pla sta SD_CMD rts + +; void sd_card_resp(uint32_t* resp); +_sd_card_resp: + phy + sta ptr1 ; store pointer + stx ptr1+1 +@1: lda SD_CMD ; wait for status flag + beq @1 + lda SD_ARG + ldy #$0 + sta (ptr1),y + lda SD_ARG+1 + iny + sta (ptr1),y + lda SD_ARG+2 + iny + sta (ptr1),y + lda SD_ARG+3 + iny + sta (ptr1),y + ply + rts