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

📄 mmc_io.h

📁 TELECHIPS MP3解决方案UMS实现源代码
💻 H
字号:
#ifndef __MMC_IO_H__
#define __MMC_IO_H__

#include "genlib.h"

// Reset all cards to idle state
#define MMC_GO_IDLE_STATE			0

// Asks all cards in idle state to send their operation conditions register
//      content in the respose on the CMD line
#define MMC_SEND_OP_COND			1

// Only MMC mode
// Asks all cards to send their CID numbers on the CMD line
#define MMC_ALL_SEND_CID			2

// Only MMC mode
// Assigns relative address to the card
#define MMC_SET_RELATIVE_ADDR		3

// Only MMC mode
// -- Not supported in "SanDisk" MMC card.
#define	MMC_SET_DSR					4

#define MMC_reserved_command_5		5
#define MMC_reserved_command_6		6

// Command toggles a card between the stand-by and transfer states or between
//         the programming and disconnect state.
// In both cases the card is selected by its own relative address and deselected by
//    any other address; address 0 deselects all.
#define MMC_SELECT_CARD				7

#define MMC_reserved_command_8		8

// Addressed card sends its card-specific data(CSD) on the CMD line.
#define MMC_SEND_CSD				9

// Addressed card sends its card identification(CID) on the CMD line.
#define MMC_SEND_CID				10

// Only MMC mode
// Reads data stream from the card, starting at the given address,
//       until a STOP_TRANSMISSION follows.
#define MMC_READ_DATA_UNTIL_STOP	11

// Only MMC mode
// Terminates a stream or a multiple block read/write operation.
// The card may become busy after this command
#define MMC_STOP_TRANSMISSION		12

// Addressed card sends its status register.
#define MMC_SEND_STATUS				13

#define MMC_reserved_command_14		14

// Only MMC mode
// Sets the card to inactive state.
#define MMC_GO_INACTIVE_STATE		15

// Selects a block length (in bytes) for all following block
//         commands (read and write)
// The default block length is as specified in the CSD (512 bytes).
//     A set block length of less than 512 bytes will cause a write error.
//     The only valid write set block length is 512 bytes.
//     This command is not mandatory if the default is accepted.
#define MMC_SET_BLOCKLEN			16

// Reads a block of the size selected by the SET_BLOCKLEN command.
// The data transferred must not cross a physical block boundary.
#define MMC_READ_SINGLE_BLOCK		17

// Only MMC mode
// Continuously send blocks of data
//              until interrupted by a stop or a new read command.
#define MMC_READ_MULTIPLE_BLOCK		18

#define MMC_reserved_command_19		19

// Only MMC mode
// Writes data stream from the host starting at the supplied address,
//        until a STOP_TRANSMISSION follows.
#define MMC_WRITE_DATA_UNTIL_STOP	20

#define MMC_reserved_command_21		21
#define MMC_reserved_command_22		22
#define MMC_reserved_command_23		23

// Writes a block of the size selected by the SET_BLOCKLEN command.
// All data blocks are responded to with a data response token followed by a busy signal.
// The data transferred must not cross a physical block boundary.
#define MMC_WRITE_SINGLE_BLOCK		24

// Only MMC mode
// Continuously writes blocks of data until a STOP_TRANSMISSION follows.
#define MMC_WRITE_MULTIPLE_BLOCK	25

#define MMC_reserved_command_26		26

// Programming of the programmable bits of the CSD.
#define MMC_PROGRAM_CSD				27

// This command sets the write protection bit of the addressed group.
// The properties of write protection are coded
//     in the card specific data (WP_GRP_SIZE).
#define MMC_SET_WRITE_PROT			28

// This command clears the write protection bit of the addressed group.
#define MMC_CLR_WRITE_PROT			29

// This command asks the card to send the status
//      of the write protection bits.
#define MMC_SEND_WRITE_PROT			30

#define MMC_reserved_command_31		31

// Sets the address of the first sector of the erase group.
#define MMC_TAG_SECTOR_START		32

// Sets the address of the last sector in a continuous range
//      within the selected erase group,
//             or the address of a single sector to be selected for erase.
#define MMC_TAG_SECTOR_END			33

// Removes one previously selected sector from the erase selection.
#define MMC_UNTAG_SECTOR			34

// Sets the address of the first erase group within a range
//      to be selected for erase.
#define MMC_TAG_ERASE_GROUP_START	35

// Sets the address of the last erase group within a continuous range
//      to be selected for erase.
#define MMC_TAG_ERASE_GROUP_END		36

// Removes one previously selected erase group from the erase selection.
#define MMC_UNTAG_ERASE_GROUP		37

// Erases all previously selected sectors or erase groups.
#define MMC_ERASE					38

#define MMC_APP_CMD					55		// SD card only

// Only SPI mode
// Read the OCR register.
//#define MMC_READ_OCR				58

// Only SPI mode
// Turns the CRC option on or off.
//       A '1' in the CRC option bit will turn the option on, 
//       A '0' will turn it off
//#define MMC_CRC_ON_OFF				59

/////////////////////////////////////////////////////////////////////////////
// APP CMD
#define SD_APP_SET_BUS_WIDTH		6
#define SD_APP_OP_COND				41
#define	SD_APP_SET_CLR_CARD_DETECT	42
#define SD_APP_SEND_SCR				51

/////////////////////////////////////////////////////////////////////////////

#define MMC_CMD0					MMC_GO_IDLE_STATE
#define MMC_CMD1					MMC_SEND_OP_COND
#define MMC_CMD2					MMC_ALL_SEND_CID
#define MMC_CMD3					MMC_SET_RELARIVE_ADDR
#define MMC_CMD4					MMC_SET_DSR
//#define MMC_CMD5					MMC_reserved_command_5
//#define MMC_CMD6					MMC_reserved_command_6
#define MMC_CMD7					MMC_SELECT_CARD
//#define MMC_CMD8					MMC_reserved_command_7
#define MMC_CMD9					MMC_SEND_CSD
#define MMC_CMD10					MMC_SEND_CID
#define MMC_CMD11					MMC_READ_DATA_UNTIL_STOP
#define MMC_CMD12					MMC_STOP_TRANSMISSION
#define MMC_CMD13					MMC_SEND_STATUS
//#define MMC_CMD14					MMC_reserved_command_14
#define MMC_CMD15					MMC_GO_INACTIVE_STATE
#define MMC_CMD16					MMC_SET_BLOCKLEN
#define MMC_CMD17					MMC_READ_SINGLE_BLOCK
#define MMC_CMD18					MMC_READ_MULTIPLE_BLOCK
//#define MMC_CMD19					MMC_reserved_command_19
#define MMC_CMD20					MMC_WRITE_DATA_UNTIL_STOP
//#define MMC_CMD21					MMC_reserved_command_21
//#define MMC_CMD22					MMC_reserved_command_22
//#define MMC_CMD23					MMC_reserved_command_23
#define MMC_CMD24					MMC_WRITE_SINGLE_BLOCK
#define MMC_CMD25					MMC_WRITE_MULTIPL_BLOCK
//#define MMC_CMD26					MMC_reserved_command_26
#define MMC_CMD27					MMC_PROGRAM_CSD
#define MMC_CMD28					MMC_SET_WRITE_PROT
#define MMC_CMD29					MMC_CLR_WRITE_PROT
#define MMC_CMD30					MMC_SEND_WRITE_PROT
//#define MMC_CMD31					MMC_reserved_command_31
#define MMC_CMD32					MMC_TAG_SECTOR_START
#define MMC_CMD33					MMC_TAG_SECTOR_END
#define MMC_CMD34					MMC_UNTAG_SECTOR
#define MMC_CMD35					MMC_TAG_ERASE_GROUP_START
#define MMC_CMD36					MMC_TAG_ERASE_GROUP_END
#define MMC_CMD37					MMC_UNTAG_ERASE_GROUP
#define MMC_CMD38					MMC_ERASE

#define MMC_CMD55					MMC_APP_CMD			// SD card only

#define MMC_CMD58					MMC_READ_OCR
#define MMC_CMD59					MMC_CRC_ON_OFF

/////////////////////////////////////////////////////////////////////////////

#define SD_ACMD6					SD_APP_SET_BUS_WIDTH
#define SD_ACMD41					SD_APP_OP_COND
#define SD_ACMD42					SD_APP_SET_CLR_CARD_DETECT
#define SD_ACMD51					SD_APP_SEND_SCR

/////////////////////////////////////////////////////////////////////////////
enum __MMC_CardType {
		MMC_CARD_UNKNOWN = 0,
		MMC_CARD_MMC,
		MMC_CARD_SD,
		MMC_CARD_COUNT
	};

#define TCC730_MMC_BLOCK_SIZE		512

/////////////////////////////////////////////////////////////////////////////
#ifndef MMC_BOOL_DEFINED
#define MMC_BOOL_DEFINED
typedef int MMC_BOOL;
#endif

#pragma packed on
typedef struct _tag_mmc_Command
{
	unsigned char	bCommand;
	unsigned char	bParameters[4];
	unsigned char	bCRC;
} MMC_COMMAND;
#pragma packed off

/////////////////////////////////////////////////////////////////////////////

#if defined(__cplusplus)
extern "C" {
#endif

/////////////////////////////////////////////////////////////////////////////
// for MMC MODE
// mmcmmca.s	for MMC mode

void			TCC730_MMC_InitPort_MMC		(void);
void			TCC730_MMC_OutportCmd		(unsigned char bCmd);
unsigned char	TCC730_MMC_InportCmd		(void);
void			TCC730_MMC_OutportDat		(unsigned char bDat);
unsigned char	TCC730_MMC_InportDat		(void);

MMC_BOOL		TCC730_MMC_WaitForCmdResponse(unsigned nTimeout, unsigned char* lpbHeader);
MMC_BOOL		TCC730_MMC_WaitForDatResponse(unsigned nTimeout, unsigned char* lpbStatus);
MMC_BOOL		TCC730_MMC_WaitForStartDat	(unsigned nTimeout);
MMC_BOOL		TCC730_MMC_WaitForCompleteDat(unsigned nTimeout, unsigned nBitCount);

void			TCC730_MMC_StreamOutCmd		(CONST_FAKE void* lpBuffer, unsigned nLen);
void 			TCC730_MMC_StreamInCmd		(void* lpBuffer, unsigned nLen);
void			TCC730_MMC_StreamOutDat		(CONST_FAKE void* lpBuffer, unsigned nLen);
void			TCC730_MMC_StreamInDat		(void* lpBuffer, unsigned nLen);

//unsigned char	TCC730_MMC_GetCRC7			(CONST_FAKE void* lpBuffer, unsigned nLen);
//unsigned		TCC730_MMC_GetCRC16			(CONST_FAKE void* lpBuffer, unsigned nLen);
void			TCC730_MMC_GetCRC7ByTable	(CONST_FAKE void* lpBuffer, unsigned nLen, unsigned char* lpbCrc);
void			TCC730_MMC_GetCRC16ByTable	(CONST_FAKE void* lpBuffer, unsigned nLen, unsigned char bCrc[2]);

void			TCC730_SD_OutportDat		(unsigned char bDat);
unsigned char	TCC730_SD_InportDat			(void);
MMC_BOOL		TCC730_SD_WaitForStartDat	(unsigned nTimeout);
void			TCC730_SD_StreamOutDat		(CONST_FAKE void* lpBuffer, unsigned nLen);
void			TCC730_SD_StreamInDat		(void* lpBuffer, unsigned nLen);
void			TCC730_SD_GetCRC16ByTable	(CONST_FAKE void* lpBuffer, unsigned nLen, unsigned char bCrc[8]);

/////////////////////////////////////////////////////////////////////////////

/* mmc730.c */
void			TCC730_MMC_InitPort			(void);
MMC_BOOL		TCC730_MMC_InitCard			(void);

MMC_BOOL		TCC730_MMC_SendCommand		(CONST_FAKE MMC_COMMAND* lpCommand);
MMC_BOOL		TCC730_MMC_ReceiveResponse	(int nCmd, int nAppCmd, void* lpBuffer);
MMC_BOOL		TCC730_MMC_ProcessCommand	(int nCmd, unsigned long dwParam, void* lpBuffer);
MMC_BOOL		TCC730_SD_ProcessAppCommand	(int nAppCmd, unsigned long dwParam, void* lpBuffer);

MMC_BOOL		TCC730_MMC_TransmitOneBlock	(CONST_FAKE void* lpBuffer, unsigned nLen, MMC_BOOL bMultiple);
MMC_BOOL		TCC730_MMC_CheckTransmissionOneBlockResult(MMC_BOOL bMultiple);

MMC_BOOL		TCC730_MMC_ReceiveBlock		(void* lpBuffer, unsigned nSize);
MMC_BOOL		TCC730_MMC_TransmitBlock	(CONST_FAKE void* lpBuffer, unsigned nSize, int bMultiple);

MMC_BOOL		TCC730_MMC_IsExistent		(void);
MMC_BOOL		TCC730_MMC_IsInited			(void);
MMC_BOOL		TCC730_MMC_IsWriteProtected	(void);
MMC_BOOL		TCC730_MMC_SetWriteProtect	(MMC_BOOL bProtect);
MMC_BOOL		TCC730_MMC_IsWriteProtectedBlock(unsigned long int dwBlockAddr);
MMC_BOOL		TCC730_MMC_SetWriteProtectAllBlock(MMC_BOOL bProtect);

unsigned long	TCC730_MMC_CalcCapacity		(unsigned long int* lpdwBlockCount, unsigned int* lpwBlockSize);
MMC_BOOL		TCC730_MMC_CalcCHS			(unsigned int* lpnCylinder, unsigned int* lpnHead, unsigned int* lpnSectorNum, unsigned int* lpnSectorSize);
MMC_BOOL		TCC730_MMC_ReadSingleBlock	(unsigned long int dwBlockAddr, void* lpBuffer);
MMC_BOOL		TCC730_MMC_WriteSingleBlock	(unsigned long int dwBlockAddr, CONST_FAKE void* lpBuffer);
MMC_BOOL		TCC730_MMC_StopTransmission	(MMC_BOOL bReadStop);
MMC_BOOL		TCC730_MMC_ReadMultipleBlock(unsigned long int dwBlockAddr);
MMC_BOOL		TCC730_MMC_WriteMultipleBlock(unsigned long int dwBlockAddr);

#if defined(__cplusplus)
}
#endif

#endif

⌨️ 快捷键说明

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