⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdcard.h

📁 基于现场可编程门阵列的软核处理器的SD卡读写设计底层读写
💻 H
字号:
#ifndef _SDCARD_H_
#define _SDCARD_H_

#include <system.h>
#include <io.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

/*Setup macros for SD_CARD command*/
#define	CMD0	0x40    /*reset SD			*/
#define	CMD1	0x41    /*read OCR register		*/
#define	CMD2    0x42
#define	CMD3    0x43
#define	CMD4    0x44
#define	CMD5    0x45
#define	CMD6    0x46
#define	CMD7    0x47
#define	CMD8    0x48
#define	CMD9    0x49
#define	CMD10   0x4A
#define	CMD11	0x4B
#define	CMD12	0x4C
#define	CMD13	0x4D
#define	CMD14	0x4E
#define	CMD15	0x4F
#define	CMD16	0x50
#define	CMD17	0x51
#define	CMD18	0x52
#define	CMD19	0x53
#define	CMD20	0x54
#define	CMD21	0x55
#define	CMD22	0x56
#define	CMD23	0x57
#define	CMD24	0x58
#define	CMD25	0x59
#define	CMD26	0x5A
#define	CMD27	0x5B
/*abridge some macros as these  */
#define	CMD28	0x5C    /*set guard block address	*/
#define	CMD29	0x5D    /*stop guard block address	*/

/*Setup macros for data types*/
#define UINT8   unsigned char
#define UINT16  unsigned short
#define UINT32  unsigned long
/*define the number of clocks for NCR*/
#define NCR 8           /*NCR wait clocks' number*/
#define ADOSET 9        /*ADDRESS OFFSET*/

/*Setup macros for some high-frequency process*/
#define	SD_ENABLE	IOWR(SD_CS_BASE, 0, 0)		/*enable SD CS=0*/
#define	SD_DISABLE	IOWR(SD_CS_BASE, 0, 1)		/*disable SD cs=1*/
#define	SD_CLK_LOW	IOWR(SD_CLK_BASE, 0, 0)		/*SCLK=0*/
#define	SD_CLK_HIGH	IOWR(SD_CLK_BASE, 0, 1)		/*SCLK=1*/
#define	SD_DAT_LOW	IOWR(SD_DATOUT_BASE, 0, 0)	/*write 0 to SD*/
#define	SD_DAT_HIGH	IOWR(SD_DATOUT_BASE, 0, 1)	/*write 1 to SD*/
#define	SD_READ_DAT	IORD(SD_DATIN_BASE, 0)		/*read data from SD*/

/* simulate delay N clocks */
void delay_nclks(UINT8 n);

/* write a BYTE of data through spi */
UINT8 spi_write_out(UINT8 data);

/* read a BYTE of data through spi */
UINT8 spi_read_in(void);

/* write a command to SD and receive respone from SD */
UINT8 sd_command(UINT8 cmd, UINT32 sdarg);

/* reset SD card */
int  sd_reset(void);

/* init the SD device */
int  sd_init(void);

/* read 512 bytes of data from SD and store them to data */
int sd_read(UINT8 *data, UINT32 addr);

/* write 512 bytes of data to SD */
int sd_write(UINT8 *data, UINT32 addr);

#endif  /*_SDCARD_H_*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -