#ifdef CSR_SDCORE_BASE
-unsigned int sdcard_response[SD_RESPONSE_SIZE/4];
+unsigned int sdcard_response[SD_CMD_RESPONSE_SIZE/4];
/*-----------------------------------------------------------------------*/
/* SDCard command helpers */
int sdcard_wait_cmd_done(void) {
unsigned int cmdevt;
while (1) {
- cmdevt = sdcore_cmdevt_read();
+ cmdevt = sdcore_cmd_event_read();
busy_wait_us(1);
#ifdef SDCARD_DEBUG
printf("cmdevt: %08x\n", cmdevt);
int sdcard_wait_data_done(void) {
unsigned int dataevt;
while (1) {
- dataevt = sdcore_dataevt_read();
+ dataevt = sdcore_data_event_read();
busy_wait_us(1);
#ifdef SDCARD_DEBUG
printf("dataevt: %08x\n", dataevt);
status = sdcard_wait_cmd_done();
- csr_rd_buf_uint32(CSR_SDCORE_RESPONSE_ADDR, sdcard_response, SD_RESPONSE_SIZE/4);
+ csr_rd_buf_uint32(CSR_SDCORE_CMD_RESPONSE_ADDR, sdcard_response, SD_CMD_RESPONSE_SIZE/4);
#ifdef SDCARD_DEBUG
- for(i = 0; i < SD_RESPONSE_SIZE/4; i++) {
+ for(i = 0; i < SD_CMD_RESPONSE_SIZE/4; i++) {
printf("%08x ", sdcard_response[i]);
}
printf("\n");
#ifdef SDCARD_DEBUG
printf("CMD0: GO_IDLE\n");
#endif
- sdcore_argument_write(0x00000000);
- sdcore_command_write((0 << 8) | SDCARD_CTRL_RESPONSE_NONE);
- sdcore_send_write(1);
+ sdcore_cmd_argument_write(0x00000000);
+ sdcore_cmd_command_write((0 << 8) | SDCARD_CTRL_RESPONSE_NONE);
+ sdcore_cmd_send_write(1);
}
int sdcard_send_ext_csd(void) {
#ifdef SDCARD_DEBUG
printf("CMD8: SEND_EXT_CSD, arg: 0x%08x\n", arg);
#endif
- sdcore_argument_write(arg);
- sdcore_command_write((8 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
- sdcore_send_write(1);
+ sdcore_cmd_argument_write(arg);
+ sdcore_cmd_command_write((8 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
+ sdcore_cmd_send_write(1);
return sdcard_wait_response();
}
#ifdef SDCARD_DEBUG
printf("CMD55: APP_CMD\n");
#endif
- sdcore_argument_write(rca << 16);
- sdcore_command_write((55 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
- sdcore_send_write(1);
+ sdcore_cmd_argument_write(rca << 16);
+ sdcore_cmd_command_write((55 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
+ sdcore_cmd_send_write(1);
return sdcard_wait_response();
}
#ifdef SDCARD_DEBUG
printf("ACMD41: APP_SEND_OP_COND, arg: %08x\n", arg);
#endif
- sdcore_argument_write(arg);
- sdcore_command_write((41 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
- sdcore_send_write(1);
+ sdcore_cmd_argument_write(arg);
+ sdcore_cmd_command_write((41 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
+ sdcore_cmd_send_write(1);
return sdcard_wait_response();
}
#ifdef SDCARD_DEBUG
printf("CMD2: ALL_SEND_CID\n");
#endif
- sdcore_argument_write(0x00000000);
- sdcore_command_write((2 << 8) | SDCARD_CTRL_RESPONSE_LONG);
- sdcore_send_write(1);
+ sdcore_cmd_argument_write(0x00000000);
+ sdcore_cmd_command_write((2 << 8) | SDCARD_CTRL_RESPONSE_LONG);
+ sdcore_cmd_send_write(1);
return sdcard_wait_response();
}
#ifdef SDCARD_DEBUG
printf("CMD3: SET_RELATIVE_ADDRESS\n");
#endif
- sdcore_argument_write(0x00000000);
- sdcore_command_write((3 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
- sdcore_send_write(1);
+ sdcore_cmd_argument_write(0x00000000);
+ sdcore_cmd_command_write((3 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
+ sdcore_cmd_send_write(1);
return sdcard_wait_response();
}
#ifdef SDCARD_DEBUG
printf("CMD10: SEND_CID\n");
#endif
- sdcore_argument_write(rca << 16);
- sdcore_command_write((10 << 8) | SDCARD_CTRL_RESPONSE_LONG);
- sdcore_send_write(1);
+ sdcore_cmd_argument_write(rca << 16);
+ sdcore_cmd_command_write((10 << 8) | SDCARD_CTRL_RESPONSE_LONG);
+ sdcore_cmd_send_write(1);
return sdcard_wait_response();
}
#ifdef SDCARD_DEBUG
printf("CMD9: SEND_CSD\n");
#endif
- sdcore_argument_write(rca << 16);
- sdcore_command_write((9 << 8) | SDCARD_CTRL_RESPONSE_LONG);
- sdcore_send_write(1);
+ sdcore_cmd_argument_write(rca << 16);
+ sdcore_cmd_command_write((9 << 8) | SDCARD_CTRL_RESPONSE_LONG);
+ sdcore_cmd_send_write(1);
return sdcard_wait_response();
}
#ifdef SDCARD_DEBUG
printf("CMD7: SELECT_CARD\n");
#endif
- sdcore_argument_write(rca << 16);
- sdcore_command_write((7 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
- sdcore_send_write(1);
+ sdcore_cmd_argument_write(rca << 16);
+ sdcore_cmd_command_write((7 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
+ sdcore_cmd_send_write(1);
return sdcard_wait_response();
}
#ifdef SDCARD_DEBUG
printf("ACMD6: SET_BUS_WIDTH\n");
#endif
- sdcore_argument_write(0x00000002);
- sdcore_command_write((6 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
- sdcore_send_write(1);
+ sdcore_cmd_argument_write(0x00000002);
+ sdcore_cmd_command_write((6 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
+ sdcore_cmd_send_write(1);
return sdcard_wait_response();
}
arg &= ~(0xf << (group * 4));
arg |= value << (group * 4);
- sdcore_argument_write(arg);
- sdcore_blocksize_write(64);
- sdcore_blockcount_write(1);
- sdcore_command_write((6 << 8) | SDCARD_CTRL_RESPONSE_SHORT |
+ sdcore_cmd_argument_write(arg);
+ sdcore_block_length_write(64);
+ sdcore_block_count_write(1);
+ sdcore_cmd_command_write((6 << 8) | SDCARD_CTRL_RESPONSE_SHORT |
(SDCARD_CTRL_DATA_TRANSFER_READ << 5));
- sdcore_send_write(1);
+ sdcore_cmd_send_write(1);
sdcard_wait_response();
return sdcard_wait_data_done();
}
#ifdef SDCARD_DEBUG
printf("CMD51: APP_SEND_SCR\n");
#endif
- sdcore_argument_write(0x00000000);
- sdcore_blocksize_write(8);
- sdcore_blockcount_write(1);
- sdcore_command_write((51 << 8) | SDCARD_CTRL_RESPONSE_SHORT |
+ sdcore_cmd_argument_write(0x00000000);
+ sdcore_block_length_write(8);
+ sdcore_block_count_write(1);
+ sdcore_cmd_command_write((51 << 8) | SDCARD_CTRL_RESPONSE_SHORT |
(SDCARD_CTRL_DATA_TRANSFER_READ << 5));
- sdcore_send_write(1);
+ sdcore_cmd_send_write(1);
sdcard_wait_response();
return sdcard_wait_data_done();
}
#ifdef SDCARD_DEBUG
printf("CMD16: SET_BLOCKLEN\n");
#endif
- sdcore_argument_write(blocklen);
- sdcore_command_write((16 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
- sdcore_send_write(1);
+ sdcore_cmd_argument_write(blocklen);
+ sdcore_cmd_command_write((16 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
+ sdcore_cmd_send_write(1);
return sdcard_wait_response();
}
#endif
int cmd_response = -1;
while (cmd_response != SD_OK) {
- sdcore_argument_write(blockaddr);
- sdcore_blocksize_write(512);
- sdcore_blockcount_write(1);
- sdcore_command_write((24 << 8) | SDCARD_CTRL_RESPONSE_SHORT |
+ sdcore_cmd_argument_write(blockaddr);
+ sdcore_block_length_write(512);
+ sdcore_block_count_write(1);
+ sdcore_cmd_command_write((24 << 8) | SDCARD_CTRL_RESPONSE_SHORT |
(SDCARD_CTRL_DATA_TRANSFER_WRITE << 5));
- sdcore_send_write(1);
+ sdcore_cmd_send_write(1);
cmd_response = sdcard_wait_response();
}
return cmd_response;
#endif
int cmd_response = -1;
while (cmd_response != SD_OK) {
- sdcore_argument_write(blockaddr);
- sdcore_blocksize_write(512);
- sdcore_blockcount_write(blockcnt);
- sdcore_command_write((25 << 8) | SDCARD_CTRL_RESPONSE_SHORT |
+ sdcore_cmd_argument_write(blockaddr);
+ sdcore_block_length_write(512);
+ sdcore_block_count_write(blockcnt);
+ sdcore_cmd_command_write((25 << 8) | SDCARD_CTRL_RESPONSE_SHORT |
(SDCARD_CTRL_DATA_TRANSFER_WRITE << 5));
- sdcore_send_write(1);
+ sdcore_cmd_send_write(1);
cmd_response = sdcard_wait_response();
}
return cmd_response;
#endif
int cmd_response = -1;
while (cmd_response != SD_OK) {
- sdcore_argument_write(blockaddr);
- sdcore_blocksize_write(512);
- sdcore_blockcount_write(1);
- sdcore_command_write((17 << 8) | SDCARD_CTRL_RESPONSE_SHORT |
+ sdcore_cmd_argument_write(blockaddr);
+ sdcore_block_length_write(512);
+ sdcore_block_count_write(1);
+ sdcore_cmd_command_write((17 << 8) | SDCARD_CTRL_RESPONSE_SHORT |
(SDCARD_CTRL_DATA_TRANSFER_READ << 5));
- sdcore_send_write(1);
+ sdcore_cmd_send_write(1);
cmd_response = sdcard_wait_response();
}
return sdcard_wait_data_done();
#endif
int cmd_response = -1;
while (cmd_response != SD_OK) {
- sdcore_argument_write(blockaddr);
- sdcore_blocksize_write(512);
- sdcore_blockcount_write(blockcnt);
- sdcore_command_write((18 << 8) | SDCARD_CTRL_RESPONSE_SHORT |
+ sdcore_cmd_argument_write(blockaddr);
+ sdcore_block_length_write(512);
+ sdcore_block_count_write(blockcnt);
+ sdcore_cmd_command_write((18 << 8) | SDCARD_CTRL_RESPONSE_SHORT |
(SDCARD_CTRL_DATA_TRANSFER_READ << 5));
- sdcore_send_write(1);
+ sdcore_cmd_send_write(1);
cmd_response = sdcard_wait_response();
}
return cmd_response;
#ifdef SDCARD_DEBUG
printf("CMD12: STOP_TRANSMISSION\n");
#endif
- sdcore_argument_write(0x0000000);
- sdcore_command_write((12 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
- sdcore_send_write(1);
+ sdcore_cmd_argument_write(0x0000000);
+ sdcore_cmd_command_write((12 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
+ sdcore_cmd_send_write(1);
return sdcard_wait_response();
}
#ifdef SDCARD_DEBUG
printf("CMD13: SEND_STATUS\n");
#endif
- sdcore_argument_write(rca << 16);
- sdcore_command_write((13 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
- sdcore_send_write(1);
+ sdcore_cmd_argument_write(rca << 16);
+ sdcore_cmd_command_write((13 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
+ sdcore_cmd_send_write(1);
return sdcard_wait_response();
}
#ifdef SDCARD_DEBUG
printf("CMD23: SET_BLOCK_COUNT\n");
#endif
- sdcore_argument_write(blockcnt);
- sdcore_command_write((23 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
- sdcore_send_write(1);
+ sdcore_cmd_argument_write(blockcnt);
+ sdcore_cmd_command_write((23 << 8) | SDCARD_CTRL_RESPONSE_SHORT);
+ sdcore_cmd_send_write(1);
return sdcard_wait_response();
}
int sdcard_init(void) {
unsigned short rca;
+ /* initialize card */
+ sdphy_init_initialize_write(1);
+ busy_wait(1);
+
/* reset card */
sdcard_go_idle();
busy_wait(1);