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

📄 mmc_sd.h

📁 mp3播放器
💻 H
字号:
//! @file mmc_sd.h,v
//!
//! Copyright (c) 2004 Atmel.
//!
//! Please read file license.txt for copyright notice.
//!
//! @brief This file contains the MMC SD driver routines
//!
//! @version 1.13 snd3-refd1-1_9_5 $Id: mmc_sd.h,v 1.13 2007/07/24 09:47:13 sguyon Exp $
//!
//! @todo
//! @bug

#ifndef _MMC_SD_H_
#define _MMC_SD_H_

//_____  I N C L U D E S ___________________________________________________

#include "config.h"
#include "lib_mcu\mmc\mmc_drv.h"
#include "conf\conf_access.h"
#include "conf\conf_mmc.h"
#include "modules\control_access\ctrl_status.h"
#include "lib_mcu\clock\clock_drv.h"         // Clock definition

//------- Check the configuration in conf_access.h
#ifndef  MEM_MMC
#  error MEM_MMC must be defined in conf_access.h
#endif


// _____ MMC/SD  N O R M S   S P E C I F I C A T I O N ________

// Commands
#define MMC_GO_IDLE_STATE         ((U8)0)
#define MMC_SEND_OP_COND          ((U8)1)  // MMC only
#define MMC_ALL_SEND_CID          ((U8)2)
#define MMC_SET_RELATIVE_ADDRESS  ((U8)3)
#define SD_SEND_RELATIVE_ADDRESS  ((U8)3)  // SD only
#define MMC_SET_DSR               ((U8)4)
#define MMC_SWITCH                ((U8)6)  // MMC only
#define SD_APP_SET_BUS_WIDTH      ((U8)6)
#define MMC_SELECT_CARD           ((U8)7)
#define MMC_SEND_EXT_CSD          ((U8)8)
#define SD_SEND_IF_COND           ((U8)8)
#define MMC_SEND_CSD              ((U8)9)
#define MMC_SEND_CID              ((U8)10)
#define MMC_READ_DATA_UNTIL_STOP  ((U8)11)
#define MMC_STOP_TRANSMISSION     ((U8)12)
#define MMC_SEND_STATUS           ((U8)13)
#define MMC_BUSTEST_R             ((U8)14)
#define MMC_GO_INACTIVE_STATE     ((U8)15)
#define MMC_SET_BLOCK_LEN         ((U8)16)
#define MMC_READ_SINGLE_BLOCK     ((U8)17)
#define MMC_READ_MULTIPLE_BLOCK   ((U8)18)
#define MMC_BUSTEST_W             ((U8)19)
#define MMC_WRITE_DATA_UNTIL_STOP ((U8)20)
#define MMC_WRITE_SINGLE_BLOCK    ((U8)24)
#define MMC_WRITE_MULTIPLE_BLOCK  ((U8)25)
#define MMC_PROGRAM_CSD           ((U8)27)
#define MMC_TAG_SECTOR_START      ((U8)32)
#define MMC_TAG_SECTOR_END        ((U8)33)
#define MMC_UNTAG_SECTOR          ((U8)34)
#define MMC_TAG_ERASE_GRP_START   ((U8)35)
#define MMC_TAG_ERASE_GRP_END     ((U8)36)
#define MMC_UNTAG_ERASE_GRP       ((U8)37)
#define MMC_ERASE                 ((U8)38)
#define SD_APP_OP_COND            ((U8)41) // SD only
#define MMC_LOCK_UNLOCK           ((U8)42)
#define MMC_APP_CMD               ((U8)55)

// Arguments of MMC_SWITCH command
#define MMC_SWITCH_WRITE          ((U8)03)
#define MMC_SWITCH_BUS_WIDTH      ((U8)183)
#define MMC_SWITCH_HIGH_SPEED     ((U8)185)
#define MMC_SWITCH_CMD_SET        ((U8)03)
#define MMC_SWITCH_VAL_LS         ((U8)00)
#define MMC_SWITCH_VAL_HS         ((U8)01)
#define MMC_SWITCH_VAL_1BIT       ((U8)00)
#define MMC_SWITCH_VAL_4BIT       ((U8)01)
#define MMC_SWITCH_VAL_8BIT       ((U8)02)

// Arguments of MMC_LOCK_UNLOCK command
#define CMD_FULL_ERASE           0x08
#define CMD_UNLOCK               0x00
#define CMD_CLEAR                0x02
#define CMD_LOCK                 0x01


// OCR register
#define OCR_MSK_BUSY              0x80000000 // Busy flag
#define OCR_MSK_HC                0x40000000 // High Capacity flag
#define OCR_MSK_VOLTAGE_3_2V_3_3V 0x00100000 // Voltage 3.2V to 3.3V flag
#define OCR_MSK_VOLTAGE_ALL       0x00FF8000 // All Voltage flag

// RCA register
#define RCA_RESERVE_ADR           0x00000000
#define RCA_MSK_ADR               0xFFFF0000
#define RCA_DEFAULT_ADR           0x0001FFFF // It can be changed

// CSD register
#define CSD_REG_SIZE              0x10
#define CSD_STRUCT_1_0            0x00
#define CSD_STRUCT_1_1            0x40
#define CSD_STRUCT_1_2            0x80
#define CSD_STRUCT_SUP            0xC0
#define CSD_MSK_STRUCT            0xC0
#define CSD_SPEC_VER_1_0          0x00
#define CSD_SPEC_VER_1_4          0x04
#define CSD_SPEC_VER_2_0          0x08
#define CSD_SPEC_VER_3_1          0x0C
#define CSD_SPEC_VER_4_0          0x10
#define CSD_MSK_SPEC_VER          0x3C
#define CSD_MSK_RBP               0x80
#define CSD_MSK_WBM               0x40
#define CSD_MSK_RBM               0x20
#define CSD_MSK_RBL               0x0F
#define CSD_MSK_CSH               0x03
#define CSD_MSK_CSL               0xC0
#define CSD_MSK_CSM               0x07
#define CSD_MSK_CSMH              0x03
#define CSD_MSK_CSML              0x80
#define CSD_MSK_WBL               0x03
#define CSD_MSK_WBH               0xC0
#define CSD_MSK_WBP               0x20
#define CSD_BLEN_2048             11
#define CSD_BLEN_512              9

#define MMC_STBY_STATE_MSK        ((U32)0x01D81E00)
#define MMC_STBY_STATE            ((U32)0x00000600)  // stby state
#define MMC_DATA_STATE_MSK        ((U32)0xE0040E00)
#define MMC_DATA_STATE            ((U32)0x00000A00)  // data state
#define MMC_RCV_STATE_MSK         ((U32)0xE0020E00)
#define MMC_RCV_STATE             ((U32)0x00000A00)  // rcv state
#define MMC_TRAN_STATE_MSK        ((U32)0xE0020E00)
#define MMC_TRAN_STATE            ((U32)0x00000800)  // tran state

// Flag error of "Card Status" in R1
#define CS_FLAGERROR_RD_WR  (CS_ADR_OUT_OF_RANGE|CS_ADR_MISALIGN|CS_BLOCK_LEN_ERROR|CS_ERASE_SEQ_ERROR|CS_ILLEGAL_COMMAND|CS_CARD_ERROR)
#define CS_ADR_OUT_OF_RANGE (1<<31)
#define CS_ADR_MISALIGN     (1<<30)
#define CS_BLOCK_LEN_ERROR  (1<<29)
#define CS_ERASE_SEQ_ERROR  (1<<28)
#define CS_ERASE_PARAM      (1<<27)
#define CS_WP_VIOLATION     (1<<26)
#define CS_CARD_IS_LOCKED   (1<<25)
#define CS_LOCK_UNLOCK_     (1<<24)
#define CS_COM_CRC_ERROR    (1<<23)
#define CS_ILLEGAL_COMMAND  (1<<22)
#define CS_CARD_ECC_FAILED  (1<<21)
#define CS_CARD_ERROR       (1<<20)
#define CS_EXEC_ERROR       (1<<19)
#define CS_UNDERRUN         (1<<18)
#define CS_OVERRUN          (1<<17)
#define CS_CIDCSD_OVERWRITE (1<<16)
#define CS_WP_ERASE_SKIP    (1<<15)
#define CS_ERASE_RESET      (1<<13)
#define CS_READY_FOR_DATA   (1<<8)
#define CS_SWITCH_ERROR     (1<<7)
#define CS_APP_CMD          (1<<5)

// SD bus width
#define SD_BUS_1_BIT      0x00000000
#define SD_BUS_4_BIT      0x00000002


//_____ D E F I N I T I O N S ______________________________________________

#define MMC_BLOCK_LENGTH_512B    512

#define CARD_MMC                 0x01
#define CARD_SD                  0x02
#define CARD_MMC_V4              0x04
#define CARD_SD_V2               0x08
#define CARD_SD_HC               0x10

// card state
#define CARD_UNINSTALLED         0
#define CARD_INSTALLED           1


//---- CONTROL FONCTIONS ----
Ctrl_status mmc_test_unit_ready     ( void );
Bool        mmc_state_change        ( void );
Ctrl_status mmc_read_capacity       ( U32 _MEM_TYPE_SLOW_ *u32_nb_sector );
Bool        mmc_wr_protect          ( void );
Bool        mmc_removal             ( void );


//---- LOCK/UNLOCK FONCTIONS ----
#if(MMC_CARD_SECU_FUNC == ENABLE)
Ctrl_status mmc_lock_unlock         ( Byte command_byte, U8 pwd_len, unsigned char * password );
Bool        mmc_is_locked           ( void );      
Bool        mmc_lock_unlock_failed  ( void );
#endif


//---- ACCESS DATA FONCTIONS ----
typedef enum
{
   MMC_READ=0
,  MMC_WRITE
} Mmc_sense;

// Standard fonctions for open in read/write mode the device
Ctrl_status mmc_10                  ( U32 addr , U16 nb_sector, Mmc_sense sense );


//** If your device transfer the datas by DFC (For Qundau product)
// !! This fonction is actualy mandatory only for NF and MMC/SD macro
#include "modules\control_access\dfc_mngt.h"
Ctrl_status mmc_dfc_read_resume     ( void );      // function that resume the dfc interface of the memory
Ctrl_status mmc_dfc_read_stop       ( void );      // function that stops  the dfc interface of the memory
Ctrl_status mmc_dfc_write_resume    ( void );      // function that resume the dfc interface of the memory
Ctrl_status mmc_dfc_write_stop      ( void );      // function that stops  the dfc interface of the memory

// A memory interface DFC must be able :
// - to stop a transfer in progress "mmc_dfc_x_standby()"
// - to start a new transfert       "mmc_10(x)"
// - at the end of the new transfer "mmc_dfc_x_stop()"
// - restart the previous transfer  "mmc_dfc_x_restart()"
void        mmc_dfc_read_standby    ( U16 u16_nb_sector_trans );
void        mmc_dfc_read_restart    ( void );
void        mmc_dfc_write_standby   ( U16 u16_nb_sector_trans );
void        mmc_dfc_write_restart   ( void );


#endif   // _MMC_SD_H_

⌨️ 快捷键说明

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