Add software interface for reading SD card data

Adds functions to wait for data to be read, and to read data form the sd
card controller.
This commit is contained in:
Byron Lathi
2022-04-11 14:03:42 -05:00
parent 87d1457d94
commit f4e16c0c12
4 changed files with 29 additions and 0 deletions

View File

@@ -13,5 +13,6 @@ MM_DATA = $7fe0
SD_ARG = $7ff8
SD_CMD = $7ffc
SD_DATA = $7ffd
IRQ_STATUS = $7fff

View File

@@ -87,6 +87,16 @@ int main() {
sd_card_resp(&resp);
cprintf("CMD17: %lx\n", resp);
while(sw_read());
sd_card_wait_for_data();
cprintf("Read data: \n");
for (i = 0; i < 512; i++){
cprintf("%c", sd_card_read_byte());
}
while (1) {
sw = sw_read();

View File

@@ -6,5 +6,7 @@
void sd_card_command(uint32_t arg, uint8_t cmd);
void sd_card_resp(uint32_t* resp);
uint8_t sd_card_read_byte();
void sd_card_wait_for_data();
#endif

View File

@@ -4,6 +4,8 @@
.export _sd_card_command
.export _sd_card_resp
.export _sd_card_read_byte
.export _sd_card_wait_for_data
.autoimport on
@@ -33,6 +35,7 @@ _sd_card_resp:
sta ptr1 ; store pointer
stx ptr1+1
@1: lda SD_CMD ; wait for status flag
and #$01
beq @1
lda SD_ARG
ldy #$0
@@ -48,3 +51,16 @@ _sd_card_resp:
sta (ptr1),y
ply
rts
_sd_card_read_byte:
lda SD_DATA
ldx #$00
rts
_sd_card_wait_for_data:
pha
@1: lda SD_CMD ; wait for status flag
and #$02
beq @1
pla
rts