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

📄 sd.h

📁 MP3设计源代码 使用atmel的单片机
💻 H
字号:
/*H**************************************************************************
* NAME:         sd.h         
*----------------------------------------------------------------------------
* Copyright (c) 2002 Atmel.
*----------------------------------------------------------------------------
* RELEASE:      snd1c-demo-df-sd-3_0_0      
* REVISION:     1.2     
*----------------------------------------------------------------------------
* PURPOSE:
* This file contains the high level SD or MMC definitions
*****************************************************************************/

#ifndef _SD_H_
#define _SD_H_

/*_____ I N C L U D E S ____________________________________________________*/

#include "lib_mcu\mmc\mmc_drv.h"              /* SD / MMC driver definition */


/*_____ M A C R O S ________________________________________________________*/


/* Clock */
#define SD_CLK_INIT        ((FOSC / 400) - 1)      /* 400 KHz */
#define SD_CLK_TRANS       ((FOSC / 8000) - 1)     /* 8 MHz */


/* Card RCA */
#define SD_NO_CARD         ((Uint32)0x0000FFFF)
#define SD_RCA_DEFAULT     ((Uint32)0x0000FFFF)
#define MMC_RCA            ((Uint32)0x0002FFFF)

#define MMC_PAGE_MASK       ((Byte)0x01)
/* 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)

/* Functions parameters & returns */
#define SD_BUSY         0
#define SD_END          1
#define SD_ERROR        2


/* Functions states */
#define MMC_MSK_STATE         ((Byte)0xF0)
#define SD_INIT               ((Byte)0x00)    /* sd install */

#define SD_ACQ                ((Byte)0x10)
#define SD_SINGLE_OP_COND     (SD_ACQ)          /* sd_single_ack */
#define SD_SINGLE_OP_COND_2   (SD_ACQ + 5)
#define SD_SINGLE_CID         (SD_ACQ + 1)
#define SD_SINGLE_SRA         (SD_ACQ + 2)
#define SD_SINGLE_CSD         (SD_ACQ + 3)
#define SD_SINGLE_END         (SD_ACQ + 4)

#define SD_SETUP              ((Byte)0x20)
#define SD_SETUP_SELECT       (SD_SETUP)   /* sd_setup_card */
#define SD_SETUP_STATUS       (SD_SETUP + 1)


#define SD_MASS_BLOCK_SIZE ((Uint16)2048)   /* mass storage block size */

#define SD_FUNCT_TIME      ((Byte)0x00)    /* execution delay */
#define SD_RESPONSE_TIME   ((Byte)15)       /* 64 + 48 bits time_out */
#define SD_RESP_TIME       ((Byte)0xFE)     /* 2 ticks time_out */
#define SD_DATA_TIME       ((Byte)0xFC)     /* 4 ticks time_out */
#define SD_TIME_OUT        ((Byte)0x00)
#define SD_WRITE_TIME      ((Byte)0xF0)
#define SD_DELAY_TIME     ((Byte)0x02)    /* 1 tick min time_out */

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



/*_____ D E F I N I T I O N ________________________________________________*/

extern  idata   Uint32  sd_mem_size;


/*_____ D E C L A R A T I O N ______________________________________________*/

/* System */
bit     sd_init (void);
bit     sd_init_csd (void);
bit     sd_read_open (Uint32);
bit     sd_read_close (void);
Byte    sd_read_byte (void);
bit     sd_read_sector (Uint16);
bit     sd_write_open (Uint32);
bit     sd_write_close (void);
bit     sd_write_byte (Byte);
bit     sd_write_sector (Uint16);

s_format * sd_format (void);

#define Sd_disk_size()         ((Uint32)(sd_mem_size))
#define Sd_disk_size_0()       (((Byte *)&sd_mem_size)[0])
#define Sd_disk_size_1()       (((Byte *)&sd_mem_size)[1])
#define Sd_disk_size_2()       (((Byte *)&sd_mem_size)[2])
#define Sd_disk_size_3()       (((Byte *)&sd_mem_size)[3])
#define Sd_block_size()        ((Uint32)512)
#define Sd_block_size_0()      ((Byte)(Sd_block_size() >> 24))
#define Sd_block_size_1()      ((Byte)(Sd_block_size() >> 16))
#define Sd_block_size_2()      ((Byte)(Sd_block_size() >> 8))
#define Sd_block_size_3()      ((Byte)Sd_block_size())

/* Control */
Byte    sd_install (void);
void    sd_init_card (void);
Byte    sd_acq_card (void);
Byte    sd_setup_card (void);
bit     sd_check_presence (void);

#endif /* _SD_H_ */

⌨️ 快捷键说明

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