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

📄 sdcard.h

📁 ARM7 lpc2132+vs1003+sdcard 制作的 MP3 此程序在ADS1.2环境下编译
💻 H
字号:
/****************************************Copyright (c)***********************************************
**                              		qsw
**                                      
**                                
**--------------File Info----------------------------------------------------------------------------
** File name:			sdhal.c
** Last modified Date:	2007.11.20
** Last Version:		V1.0
** Descriptions:		sd 卡驱动软件包: 硬件抽象层 ---- SPI1操作函数
**						Soft Packet of SD Card Driver: hard abstrast layer ---- function of SPI1 operation
**
**------------------------------------------------------------------------------------------------
** Created by:			qsw
** Created date:		2007.11.20
** Version:				V1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------
** Modified by:			
** Modified date:		
** Version:				
** Descriptions:		
**
**************************************************************************************************/
#ifndef __SDCARD_H__
#define __SDCARD_H__

#define  SPI1_INIT()			PINSEL1 &= ~((0x03 << 2) + (0x03 << 4) + (0x03 << 6)); \
								PINSEL1 |=  (0x01 << 2) + (0x01 << 4) + (0x01 << 6);
//power  p0.09
#define  SD_POWER				0	
#define  SD_POWER_GPIO()		0
#define  SD_POWER_OUT()			0
#define  SD_POWER_OFF()			0
#define  SD_POWER_ON()			0

//cs	 p0.20	
#define  SPI1_CS      			(0x01 << 20)              	 	
#define  SPI1_CS_GPIO()			PINSEL1 &= ~(0x03 << 8)	 		
#define  SPI1_CS_OUT()			IO0DIR |= SPI1_CS			 
#define	 SPI1_CS_SET()			IO0SET |= SPI1_CS			
#define	 SPI1_CS_CLR()			IO0CLR |= SPI1_CS				

//sck	 p0.17
#define  SPI1_SCK				(0x01 << 17)						
#define  SPI1_SCK_GPIO()		PINSEL1 &= ~(0x03 << 2)		
#define  SPI1_SCK_OUT()			IO0DIR |= SPI1_SCK				
#define	 SPI1_SCK_SET()			IO0SET |= SPI1_SCK
#define	 SPI1_SCK_CLR()			IO0CLR |= SPI1_SCK			

//miso	 p0.18	
#define  SPI1_MISO				(0x01 << 18)						
#define  SPI1_MISO_GPIO()		PINSEL1 &= ~(0x03 << 4)			
#define  SPI1_MISO_OUT()		IO0DIR &=~(SPI1_MISO)
#define	 SPI1_MISO_SET()		IO0SET |= SPI1_MISO	
#define	 SPI1_MISO_CLR()		IO0CLR |= SPI1_MISO			

//mosi	 p0.19
#define  SPI1_MOSI				(0x01 << 19)
#define  SPI1_MOSI_GPIO()		PINSEL1 &= ~(0x03 << 6)			
#define  SPI1_MOSI_OUT()		IO0DIR |= SPI1_MOSI
#define	 SPI1_MOSI_SET()		IO0SET |= SPI1_MOSI	
#define	 SPI1_MOSI_CLR()		IO0CLR |= SPI1_MOSI			
												
//SD_IN  p0.16
#define  SD_INSERT				0	
#define  SD_INSERT_GPIO()		0
#define  SD_INSERT_IN()			0
#define  SD_INSERT_STATUS()  	0

//SD_WP	 
#define  SD_WP					0	
#define  SD_WP_GPIO()			0
#define  SD_WP_IN()				0
#define  SD_WP_STATUS()  		0



/******************************** 基本命令集 Basic command set **************************/
/* 复位SD 卡 Reset cards to idle state */
#define CMD0 0
#define CMD0_R R1

/* 读OCR寄存器 Read the OCR (MMC mode, do not use for SD cards) */
#define CMD1 1
#define CMD1_R R1

/* 读CSD寄存器 Card sends the CSD */
#define CMD9 9
#define CMD9_R R1

/* 读CID寄存器 Card sends CID */
#define CMD10 10
#define CMD10_R R1

/* 停止读多块时的数据传输 Stop a multiple block (stream) read/write operation */
#define CMD12 12
#define CMD12_R R1B

/* 读 Card_Status 寄存器 Get the addressed card's status register */
#define CMD13 13
#define CMD13_R R2

/***************************** 块读命令集 Block read commands **************************/

/* 设置块的长度 Set the block length */
#define CMD16 16
#define CMD16_R R1

/* 读单块 Read a single block */
#define CMD17 17
#define CMD17_R R1

/* 读多块,直至主机发送CMD12为止 Read multiple blocks until a CMD12 */
#define CMD18 18
#define CMD18_R R1

/***************************** 块写命令集 Block write commands *************************/
/* 写单块 Write a block of the size selected with CMD16 */
#define CMD24 24
#define CMD24_R R1

/* 写多块 Multiple block write until a CMD12 */
#define CMD25 25
#define CMD25_R R1

/* 写CSD寄存器 Program the programmable bits of the CSD */
#define CMD27 27
#define CMD27_R R1

/***************************** 写保护 Write protection *****************************/
/* Set the write protection bit of the addressed group */
#define CMD28 28
#define CMD28_R R1B

/* Clear the write protection bit of the addressed group */
#define CMD29 29
#define CMD29_R R1B

/* Ask the card for the status of the write protection bits */
#define CMD30 30
#define CMD30_R R1

/***************************** 擦除命令 Erase commands *******************************/
/* 设置擦除块的起始地址 Set the address of the first write block to be erased */
#define CMD32 32
#define CMD32_R R1

/* 设置擦除块的终止地址 Set the address of the last write block to be erased */
#define CMD33 33
#define CMD33_R R1

/* 擦除所选择的块 Erase the selected write blocks */
#define CMD38 38
#define CMD38_R R1B

/***************************** 锁卡命令 Lock Card commands ***************************/
/* 设置/复位密码或上锁/解锁卡 Set/reset the password or lock/unlock the card */
#define CMD42 42
#define CMD42_R	R1B
/* Commands from 42 to 54, not defined here */

/***************************** 应用命令 Application-specific commands ****************/
/* 禁止下一个命令为应用命令  Flag that the next command is application-specific */
#define CMD55 55
#define CMD55_R R1

/* 应用命令的通用I/O  General purpose I/O for application-specific commands */
#define CMD56 56
#define CMD56_R R1

/* 读OCR寄存器  Read the OCR (SPI mode only) */
#define CMD58 58
#define CMD58_R R3

/* 使能或禁止 CRC Turn CRC on or off */
#define CMD59 59
#define CMD59_R R1

/***************************** 应用命令 Application-specific commands ***************/
/* 获取 SD Status寄存器 Get the SD card's status */
#define ACMD13 13
#define ACMD13_R R2

/* 得到已写入卡中的块的个数 Get the number of written write blocks (Minus errors ) */
#define ACMD22 22
#define ACMD22_R R1

/* 在写之前,设置预先擦除的块的个数 Set the number of write blocks to be pre-erased before writing */
#define ACMD23 23
#define ACMD23_R R1

/* 读取OCR寄存器 Get the card's OCR (SD mode) */
#define ACMD41 41
#define ACMD41_R R1

/* 连接/断开CD/DATA[3]引脚上的上拉电阻 Connect or disconnect the 50kOhm internal pull-up on CD/DAT[3] */
#define ACMD42 42
#define ACMD42_R R1

/* 读取SCR寄存器 Get the SD configuration register */
#define ACMD51 51
#define ACMD51_R R1


//簇定义
#define MSDOSFSROOT     0               
#define CLUST_FREE      0               
#define MSDOSFSFREE     CLUST_FREE
#define CLUST_RSRVD     0xfffffff6      // 系统保留簇
#define CLUST_BAD       0xfffffff7      // 坏簇
#define CLUST_EOFS      0xfffffff8      // 第一个结束簇
#define CLUST_EOFE      0xffffffff      // 最后一个结束簇

#define FAT12_MASK      0x00000fff      // FAT12掩码
#define FAT16_MASK      0x0000ffff      // FAT16掩码
#define FAT32_MASK      0x0fffffff      // FAT32掩码

#define FAT12           0
#define FAT16           1
#define FAT32           2

// 分区类型
#define PART_TYPE_UNKNOWN		0x00
#define PART_TYPE_FAT12			0x01
#define PART_TYPE_XENIX			0x02
#define PART_TYPE_DOSFAT16	    0x04
#define PART_TYPE_EXTDOS		0x05
#define PART_TYPE_FAT16			0x06
#define PART_TYPE_NTFS			0x07
#define PART_TYPE_FAT32			0x0B
#define PART_TYPE_FAT32LBA	    0x0C
#define PART_TYPE_FAT16LBA	    0x0E
#define PART_TYPE_EXTDOSLBA	    0x0F
#define PART_TYPE_ONTRACK		0x33
#define PART_TYPE_NOVELL		0x40
#define PART_TYPE_PCIX			0x4B
#define PART_TYPE_PHOENIXSAVE	0xA0
#define PART_TYPE_CPM		    0xDB
#define PART_TYPE_DBFS			0xE0
#define PART_TYPE_BBT			0xFF









extern void SD_Delay_Nmicrosecond(uint32 n);
extern void SD_Power(void);
extern INT8U SPI1_SrByte(INT8U byte);
extern INT8U SD_ChkCard(void);
extern uint8 SD_WriteCom(INT8U cmd,INT32U arg);
extern INT8U SD_ReadBlock(INT32U address,INT8U *SD_BUFFER);
extern INT8U SD_Init(void);
extern INT8U Fat_Init(void);
extern INT8U Fat_ReadFileData(void);





#endif

⌨️ 快捷键说明

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