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

📄 sdhost.h

📁 mp3播放器
💻 H
字号:
#ifndef _SDHOST_H
#define _SDHOST_H
//***********************************************
#include "absacc.h"
#include "config.h"
//***********************************************
#define TRUE                  1
#define FALSE                 0

#define OK                    1 
#define FAIL                  0
				   
#define ASSERT                0
#define NEGATE                1

#define ON                    1
#define OFF                   0

#ifndef NULL
#define NULL                  (( void *) 0 )
#endif


#ifndef ULONG //  DWORD -> Had define in <absacc.h>
  typedef volatile unsigned long    ULONG;
#endif

#ifndef WORD
  typedef volatile unsigned int     WORD;
#endif

#ifndef USHORT
  typedef volatile unsigned int     USHORT;
#endif

#ifndef UCHAR
  typedef volatile unsigned char    UCHAR;
#endif

#define SD_lba                      (*(ULONG *)(&SDVar.FlashAddr[0]))

typedef struct _SDDEVICE_VAR
{
   U8    FlashAddr[ 4 ];
   U8    OCR[ 4 ];                       
   U8    RCA[ 2 ];
   U8    CardStatus[ 2 ];
   U8    SResp[ 4 ];    // short response
   U8    LResp[ 15 ];   // Long response
   /*U8    BusBits; //0 -> 1 bit, 2 -> 4-bit bus 
   U8    SDCIF_IF;   //SDCIF interface, 0 -> SD Memory,1 -> SDIO,2 --> MMC 
   U8    CardVer2;*/
   SDDEVICE_INFO Info;
}SDDEVICE_VAR;  


typedef struct _SDDEVICE_INFO
{
   U8    BusBits     :  2; //0 -> 1 bit, 2 -> 4-bit bus 
   U8    SDCIF_IF    :  2;   //SDCIF interface, 0 -> SD Memory,1 -> SDIO,2 --> MMC 
   U8    CardVer2    :  1;
}SDDEVICE_INFO;  


#define SDCIF_REGBASE                  0x0500

// SD_CIF registers
#define SDIFCON0                       XBYTE[SDCIF_REGBASE+0x00]
#define SDIFCON1                       XBYTE[SDCIF_REGBASE+0x01]
#define BLKCNT11_08                 	XBYTE[SDCIF_REGBASE+0x02]
#define BLKCNT07_00                	   XBYTE[SDCIF_REGBASE+0x03]
#define BLKLEN11_08                    XBYTE[SDCIF_REGBASE+0x04]
#define BLKLEN07_00                    XBYTE[SDCIF_REGBASE+0x05]
#define DATACON                        XBYTE[SDCIF_REGBASE+0x06]
#define ARG31_24                 	   XBYTE[SDCIF_REGBASE+0x07]
#define ARG23_16                       XBYTE[SDCIF_REGBASE+0x08]	
#define ARG15_08                       XBYTE[SDCIF_REGBASE+0x09]	
#define ARG07_00                       XBYTE[SDCIF_REGBASE+0x0A]	
#define CMDCON                         XBYTE[SDCIF_REGBASE+0x0B]	
#define CMDINDEX                       XBYTE[SDCIF_REGBASE+0x0C]	
#define DTIMER15_08                    XBYTE[SDCIF_REGBASE+0x0D]	
#define DTIMER07_00                    XBYTE[SDCIF_REGBASE+0x0E]	
#define SDIFMASK15_08                  XBYTE[SDCIF_REGBASE+0x0F]	
#define SDIFMASK07_00                  XBYTE[SDCIF_REGBASE+0x10]	
#define STATUS15_08                    XBYTE[SDCIF_REGBASE+0x11]
#define STATUS07_00                    XBYTE[SDCIF_REGBASE+0x12]

// Response
#define RESP127_120                    XBYTE[SDCIF_REGBASE+0x20]
#define RESP119_112                    XBYTE[SDCIF_REGBASE+0x21]
#define RREP111_104                    XBYTE[SDCIF_REGBASE+0x22]
#define RREP103_096                    XBYTE[SDCIF_REGBASE+0x23]
#define RREP095_088                    XBYTE[SDCIF_REGBASE+0x24]
#define RREP087_080                    XBYTE[SDCIF_REGBASE+0x25]
#define RREP079_072                    XBYTE[SDCIF_REGBASE+0x26]
#define RREP071_064                    XBYTE[SDCIF_REGBASE+0x27]
#define RREP063_056                    XBYTE[SDCIF_REGBASE+0x28]
#define RREP055_048                    XBYTE[SDCIF_REGBASE+0x29]
#define RREP047_040                    XBYTE[SDCIF_REGBASE+0x2A]
#define RREP039_032                    XBYTE[SDCIF_REGBASE+0x2B]
#define RREP031_024                    XBYTE[SDCIF_REGBASE+0x2C]
#define RREP023_016                    XBYTE[SDCIF_REGBASE+0x2D]
#define RREP015_008                    XBYTE[SDCIF_REGBASE+0x2E]
#define RREP007_000                    XBYTE[SDCIF_REGBASE+0x2F]

#define SDH_DMA_CS                     XBYTE[SDCIF_REGBASE+0x30]
#define SDH_DMA_ACK                    XBYTE[SDCIF_REGBASE+0x31]
#define SDH_CLOCK                      XBYTE[SDCIF_REGBASE+0x32]	


//	SD command definition
#define GO_IDLE_STATE               0
#define SEND_OP_COND                1
#define ALL_SEND_CID                2
#define SEND_RCA                    3
#define SDIO_CMD5                   5       // SDIO used
#define SWITCH_FUNCTION             6
#define SET_BUS_WIDTH               6	// ACMD6
#define SELECT_DESELECT             7
#define SEND_IF_COND                8
#define SEND_CSD                    9
#define SEND_CID                    10
#define STOP_TRANSMISSION           12
#define SEND_STATUS                 13
#define SD_STATUS                   13      // ACMD13
#define SET_BLOCKLEN                16
#define READ_SINGLE_BLOCK           17
#define READ_MULTI_BLOCK            18
#define SEND_NUMBER_WR_BLOCKS       22
#define WRITE_BLOCK                 24
#define WRITE_MULTIPLE_BLOCK        25
#define SECURE_WRITE_MULTI_BLOCK    25
#define SECURE_WRITE_MKB            26
#define PROGRAM_CSD                 27
#define SET_WRITE_PROT              28
#define CLR_WRITE_PROT              29
#define SEND_WRITE_PROT             30
#define ERASE_WR_BLK_START          32
#define ERASE_WR_BLK_END            33
#define ERASE                       38
#define SECURE_ERASE                38
#define SD_SEND_OP_COND             41    //ACMD41
#define LOCK_UNLOCK                 42
#define GET_MKB                     43
#define GET_MID                     44
#define SEND_SCR                    51
#define SDIO_RESET_CMD52            52    // SDIO used
#define SDIO_RESET_CMD53            53    // SDIO used
#define APP_CMD                     55
#define VWRITE_MULTIPLE_BLOCK       62
#define VREAD_MULTIPLE_BLOCK        63

//	SD Host Current state definition
#define CIF_IDLE                    0
#define CIF_READY                   1
#define CIF_IDENT                   2
#define CIF_STANDBY                 3
#define CIF_TRANS                   4
#define CIF_DATA                    5
#define CIF_RCV                     6
#define CIF_PRG                     7
#define CIF_DIS                     8

		
// end Bit Macro

#define BIT0                    	   0x01
#define BIT1                    		0x02
#define BIT2                    		0x04
#define BIT3                    		0x08
#define BIT4                    		0x10
#define BIT5                    		0x20
#define BIT6                    		0x40
#define BIT7                    		0x80


//***********************************************
//2006-10-27增加
//SDIFCON0
#define CLK_EN                0x01	//clock enable
#define HISPEED               0x02	//high speed
#define WIDEBUS               0x04	//wide bus mode

//CMDCON
#define LONGRSP               0x01  //long response is expected
#define WAITRSP               0x02	//response is expected
#define DATA_WITH             0x04	//data transfer with this command
#define STOP                  0x08	//current command is a stop command

//STATUS07_00
#define CMDSEND               0x01	//command transmitted
#define RSPRXVP               0x02	//response received
#define RSPTIMEOUT            0x04	//timeout
#define CRC7ERROR             0x08	//response CRC error
#define CRC16ERROR            0x10	//receive crc fail
#define CRCSTA_ERROR          0x20	//crc status fail
#define DTIMEOUT              0x40	//timeout
#define XFEREND               0x80	//data transfer end

//STATUS15_08
#define BUSYEND               0x01	//busy end
#define SDIO_INT              0x02	//SDIO device interrupt event

//SDH_CLOCK
#define CLK_SEL               0x80	//system clock

//DATCON
#define CHK_BC                0x01	//
#define MULTI                 0x02	//
#define XFER_MODE0            0x04	//data transfer mode
#define XFER_MODE1            0x80	//

#define XFER_MODE_0           0x00	//block read mode
#define XFER_MODE_1           XFER_MODE0  //block write mode
#define XFER_MODE_2           XFER_MODE1	//check busy end

//SDH_DMA_ACK
#define DMA_ACK_F             0x01	//DMA acknowledge flag, low active
#define DMA_ACK               0x02	//DMA acknowledge
#define DMA_REQ               0x04	//DMA request, low active
#define DMA_AUTO              0x80  //auto clear DMA request in multiple block mode
//
//***********************************************
//***********************************************
#define IDLE_STATUS           0
#define READY_STATUS          1
#define IDENT_STATUS          2
#define STBY_STATUS           3
#define TRAN_STATUS           4
#define DATA_STATUS           5
#define RCV_STATUS            6
#define PRG_STATUS            7
#define DIS_STATUS            8
//***********************************************

/* FAT Format Structure */
typedef struct  
{
  Uint16 nb_cylinder;
  Byte   nb_head;
  Byte   nb_sector;
  Byte   nb_hidden_sector;
  Byte   nb_sector_per_cluster;
} s_format;


#define sd_flag						SDVar.SDCIF_IF

/* Memory flag */
#define SD                 ((U8)0)         /* connected card is sd */
#define MMC                ((U8)2)         /* connected card is mmc */

s_format * sd_format (void);

/* Card Size based on 512 bytes block size */
#define MMC_SIZE_4MB        ((Uint32)8192 - 1)
#define MMC_SIZE_8MB        ((Uint32)16384 - 1)
#define MMC_SIZE_16MB       ((Uint32)32768 - 1)
#define MMC_SIZE_28MB       ((Uint32)57344 - 1)
#define MMC_SIZE_32MB       ((Uint32)65536 - 1)
#define MMC_SIZE_64MB       ((Uint32)131072 - 1)
#define MMC_SIZE_128MB      ((Uint32)262144 - 1)
#define MMC_SIZE_256MB      ((Uint32)524288 - 1)

#define MMC_4MB             ((Byte)0)
#define MMC_8MB             ((Byte)1)
#define MMC_16MB            ((Byte)2)
#define MMC_28MB            ((Byte)3)
#define MMC_32MB            ((Byte)4)
#define MMC_64MB            ((Byte)5)
#define MMC_128MB           ((Byte)6)
#define MMC_256MB           ((Byte)7)

#define SD_SIZE_4MB        ((Uint32)8032 - 1)
#define SD_SIZE_8MB        ((Uint32)16224 - 1)
#define SD_SIZE_16MB       ((Uint32)32448 - 1)
#define SD_SIZE_32MB       ((Uint32)64896 - 1)
#define SD_SIZE_64MB       ((Uint32)126792 - 1)
#define SD_SIZE_128MB      ((Uint32)259584 - 1)
#define SD_SIZE_256MB      ((Uint32)519168 - 1)

#define SD_4MB        ((Byte)0)
#define SD_8MB        ((Byte)1)
#define SD_16MB       ((Byte)2)
#define SD_32MB       ((Byte)3)
#define SD_64MB       ((Byte)4)
#define SD_128MB      ((Byte)5)
#define SD_256MB      ((Byte)6)

#define CSD_MSK_CSH               ((Byte)0x03)
#define CSD_MSK_CSL               ((Byte)0xC0)
#define CSD_MSK_CSM               ((Byte)0x07)
//***********************************************

#endif

⌨️ 快捷键说明

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