3 * Copyright 2008 Ettus Research LLC
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "memory_map.h"
25 #define SD_IDLE_WAIT_MAX 100
26 #define SD_CMD_TIMEOUT 100
27 #define SD_RD_TIMEOUT 1000
59 #define SD_CMD0_R SD_R1
60 #define SD_CMD16_R SD_R1
61 #define SD_CMD17_R SD_R1
62 #define SD_CMD55_R SD_R1
63 #define SD_ACMD41_R SD_R1
64 #define SD_CMD58_R SD_R3
66 #define SD_BLOCKLEN 512
67 #define SD_BLOCKLEN_NBITS 9
69 #define SD_MSK_IDLE 0x01
70 #define SD_MSK_OCR_33 0xC0
71 #define SD_MSK_TOK_DATAERROR 0xE0
79 // Wait for idle before doing anything
80 while(sdspi_regs->status != SD_READY)
82 sdspi_regs->status = 1;
88 // Wait for idle before doing anything
89 while(sdspi_regs->status != SD_READY)
91 sdspi_regs->status = 0;
97 // Wait for idle before doing anything
98 while(sdspi_regs->status != SD_READY)
100 sdspi_regs->send_dat = SD_IDLE;
101 while(sdspi_regs->status != SD_READY)
103 return sdspi_regs-> receive_dat;
107 sd_send_byte(char dat)
109 // Wait for idle before doing anything
110 while(sdspi_regs->status != SD_READY)
111 ; // Wait for status = 1 (ready)
112 sdspi_regs->send_dat = dat;
116 int sd_send_command(unsigned char cmd,unsigned char response_type,
117 unsigned char *response,unsigned char *argument);
119 int sd_read_block (unsigned int blockaddr, unsigned char *buf);
120 int sd_write_block(unsigned int blockaddr, const unsigned char *buf);
122 #endif /* INCLUDED_SD_H */