|
GNU Radio 3.3.0 C++ API
|
00001 /* -*- c -*- */ 00002 /* 00003 * Copyright 2008 Ettus Research LLC 00004 * 00005 * This program is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation, either version 3 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #ifndef INCLUDED_SD_H 00020 #define INCLUDED_SD_H 00021 00022 #include "memory_map.h" 00023 00024 #define SD_READY 1 00025 #define SD_IDLE_WAIT_MAX 100 00026 #define SD_CMD_TIMEOUT 100 00027 #define SD_RD_TIMEOUT 1000 00028 00029 #define SD_CMD0 0 00030 #define SD_CMD1 1 00031 #define SD_CMD9 9 00032 #define SD_CMD10 10 00033 #define SD_CMD12 12 00034 #define SD_CMD13 13 00035 #define SD_CMD16 16 00036 #define SD_CMD17 17 00037 #define SD_CMD18 18 00038 #define SD_CMD24 24 00039 #define SD_CMD25 25 00040 #define SD_CMD27 27 00041 #define SD_CMD28 28 00042 #define SD_CMD29 29 00043 #define SD_CMD30 30 00044 #define SD_CMD32 32 00045 #define SD_CMD33 33 00046 #define SD_CMD38 38 00047 #define SD_CMD55 55 00048 #define SD_CMD58 58 00049 #define SD_CMD59 59 00050 #define SD_ACMD41 41 00051 #define SD_IDLE 0xFF 00052 #define SD_CRC 0x95 00053 00054 #define SD_R1 1 00055 #define SD_R1B 2 00056 #define SD_R2 3 00057 #define SD_R3 4 00058 00059 #define SD_CMD0_R SD_R1 00060 #define SD_CMD16_R SD_R1 00061 #define SD_CMD17_R SD_R1 00062 #define SD_CMD55_R SD_R1 00063 #define SD_ACMD41_R SD_R1 00064 #define SD_CMD58_R SD_R3 00065 00066 #define SD_BLOCKLEN 512 00067 #define SD_BLOCKLEN_NBITS 9 00068 00069 #define SD_MSK_IDLE 0x01 00070 #define SD_MSK_OCR_33 0xC0 00071 #define SD_MSK_TOK_DATAERROR 0xE0 00072 00073 00074 int sd_init(void); 00075 00076 static inline void 00077 sd_assert_cs(void) 00078 { 00079 // Wait for idle before doing anything 00080 while(sdspi_regs->status != SD_READY) 00081 ; 00082 sdspi_regs->status = 1; 00083 } 00084 00085 static inline void 00086 sd_deassert_cs(void) 00087 { 00088 // Wait for idle before doing anything 00089 while(sdspi_regs->status != SD_READY) 00090 ; 00091 sdspi_regs->status = 0; 00092 } 00093 00094 static inline char 00095 sd_rcv_byte(void) 00096 { 00097 // Wait for idle before doing anything 00098 while(sdspi_regs->status != SD_READY) 00099 ; 00100 sdspi_regs->send_dat = SD_IDLE; 00101 while(sdspi_regs->status != SD_READY) 00102 ; 00103 return sdspi_regs-> receive_dat; 00104 } 00105 00106 static inline void 00107 sd_send_byte(char dat) 00108 { 00109 // Wait for idle before doing anything 00110 while(sdspi_regs->status != SD_READY) 00111 ; // Wait for status = 1 (ready) 00112 sdspi_regs->send_dat = dat; 00113 } 00114 00115 00116 int sd_send_command(unsigned char cmd,unsigned char response_type, 00117 unsigned char *response,unsigned char *argument); 00118 00119 int sd_read_block (unsigned int blockaddr, unsigned char *buf); 00120 int sd_write_block(unsigned int blockaddr, const unsigned char *buf); 00121 00122 #endif /* INCLUDED_SD_H */