📄 mmc.h
字号:
// MMC Pin Assignments
#DEFINE MMC_CS PIN_C0 // Active Low Chip Select.
#DEFINE MMC_CD PIN_C1 // Active Low card detect pin.
#DEFINE MMC_SCLK PIN_C3 // Connected to SCK pin of PIC.
#DEFINE MMC_DO PIN_C4 // Connected to SDI pin of PIC.
#DEFINE MMC_DI PIN_C5 // Connected to SDO pin of PIC.
// SPI Mode MMC Command Indexes (With transmission bit ie 6th bit set)
#DEFINE MMC_CMD_GO_IDLE_STATE 0x40 // Resets the MultiMediaCard
#DEFINE MMC_CMD_SEND_OP_COND 0x41 // Activates the card's initialization process.
#DEFINE MMC_CMD_SEND_CSD 0x49 // Asks the selected card to send its card-specific data (CSD).
#DEFINE MMC_CMD_SEND_CID 0x4A // Asks the selected card to send its card identification (CID).
#DEFINE MMC_CMD_STOP_TRANSMISSION 0x4C // Stop transmission on multiple block read.
#DEFINE MMC_CMD_SEND_STATUS 0x4D // Asks the selected card to send its status register.
#DEFINE MMC_CMD_SET_BLOCKLEN 0x50 // Selects a block length (in bytes) for all following block commands (read and write).
#DEFINE MMC_CMD_READ_SINGLE_BLOCK 0x51 // Reads a block of the size selected by the SET_BLOCKLEN command.
#DEFINE MMC_CMD_READ_MULTIPLE_BLOCK 0x52 // Continuously transfers data blocks from card to host until interrupted by a Stop command or the requested number of data blocks transmitted.
#DEFINE MMC_CMD_WRITE_BLOCK 0x58 // Writes a block of the size selected by the SET_BLOCKLEN command.
#DEFINE MMC_CMD_WRITE_MULTIPLE_BLOCK 0x59 // Continuously writes blocks of data until a 'Stop Tran' Token or the requested number of blocks received.
#DEFINE MMC_CMD_PROGRAM_CSD 0x5B // Programming of the programmable bits of the CSD.
#DEFINE MMC_CMD_SET_WRITE_PROT 0x5C // If the card has write protection features, 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_CMD_CLR_WRITE_PROT 0x5D // If the card has write protection features, this command clears the write protection bit of the addressed group.
#DEFINE MMC_CMD_SEND_WRITE_PROT 0x5E // If the card has write protection features, this command asks the card to send the status of the write protection bits.
#DEFINE MMC_CMD_TAG_SECTOR_START 0x60 // Sets the address of the first sector of the erase group.
#DEFINE MMC_CMD_TAG_SECTOR_END 0x61 // 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_CMD_UNTAG_SECTOR 0x62 // Removes one previously selected erase group from the erase selection.
#DEFINE MMC_CMD_TAG_ERASE_GROUP_START 0x63 // Sets the address of the first erase group within a continuous range to be selected for erase.
#DEFINE MMC_CMD_TAG_ERASE_GROUP_END 0x64 // Sets the address of the last erase group within a continuous range to be selected for erase.
#DEFINE MMC_CMD_UNTAG_ERASE_GROUP 0x65 // Removes one previously selected erase group from the erase selection.
#DEFINE MMC_CMD_ERASE 0x66 // Erases all previously selected sectors.
#DEFINE MMC_CMD_LOCK_UNLOCK 0x6A // Used to set/reset the password or lock/unlock the card. The size of the Data Block is defined by the SET_BLOCK_LEN command.
#DEFINE MMC_CMD_READ_OCR 0x7A // Reads the OCR register of a card.
#DEFINE MMC_CMD_CRC_ON_OFF 0x7B // 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.
// MMC-SPI Command Format
// Command transmission always starts with the left bit of the bit string.
//typedef struct {
// BYTE cmd; // B7 - '0', B6 - '1', B5:0 - Command Index
// DWORD arg; // B39:8 - Argument
// BYTE crc; // B7:1 - CRC7, B0 - '1'
//} MMCCOMMAND;
//MMCCOMMAND command; // Global variable.
// MMC-SPI R1 Response Format
//typedef struct {
// BOOL reserved; // Reserved at value '0'.
// BOOL parameterError; // The command's argument (for example, address, block length) was out of the allowed range for this card.
// BOOL addressError; // A misaligned address, which did not match the block length, was used in the command.
// BOOL erase_Seq_Error; // An error occurred in the sequence of erase commands.
// BOOL comCRCError; // The CRC check of the last command field.
// BOOL illegalCommand; // An illegal command code was detected.
// BOOL eraseReset; // An erase sequence was cleared before executing because an out of erase sequence command was received.
// BOOL idleState; // The card is in idle state and running the initializing process.
//} MMCRESPONSE;
// MMC-SPI Status Response Format
// A SEND_STATUS command will give a response of R1 followed by the following Status Response byte.
//typedef struct {
// BOOL outOfRange_CSD_Overwrite; // This status bit has two functions. It is set if the command argument was out of its valid range, or if the host is trying to change the ROM section or reverse the copy bit (set as original) or permanent WP bit (un-protect) of the CSD register.
// BOOL eraseParam; // An invalid selection, sectors or groups, for erase.
// BOOL writeProtectViolation; // The command tried to write a write-protected block.
// BOOL cardECCFailed; // Card internal ECC was applied but failed to correct the data.
// BOOL cCError; // Internal card controller error.
// BOOL error; // A general or an unknown error occurred during the operation.
// BOOL writeProtect_PasswordErr; // An erase sequence was cleared before executing because an out of erase sequence command was received.
// BOOL cardIsLocked; // This bit is set when the card is locked by the user. It is reset when it is unlocked.
//} MMCSTATUS;
// MMC-SPI Data Response Format
// Every block will be ackowledged by a data response token.
//typedef struct {
// BYTE unused : 4; // B7:4 - Don't Care, B4 - '0'.
// BYTE status : 3; // B3:1 - Status (2=Data accepted,5=Data rejected due to a CRC error,6=Data rejected due to a Write error.)
// BYTE reserved : 1; // B0 - '1'
//} MMCDATARESPONSE;
#DEFINE MMCDATAOK 4
#DEFINE MMCCRCERROR 10
#DEFINE MMCWRITEERROR 12
// MMC-SPI Data Tokens
#DEFINE MMCSTARTSINGLEREAD 0xFE
#DEFINE MMCSTARTMULTIPLEREAD 0xFE
#DEFINE MMCSTARTSINGLEWRITE 0xFE
#DEFINE MMCSTARTMULTIPLEWRITE 0xFC
#DEFINE MMCSTOPTRANSACTION 0xFD
// MMC-SPI Data Error Token
//typedef struct {
// BYTE reserved : 3; // B7:5 - '0'.
// BOOL error; // A general or an unknown error occurred during the operation.
// BOOL cCError; // Internal card controller error.
// BOOL cardECCFailed; // Card internal ECC was applied but failed to correct the data.
// BOOL outOfRange; // Set if the read/write was out of its valid range.
// BOOL cardIsLocked; // This bit is set when the card is locked by the user. It is reset when it is unlocked.
//} MMCDATAERROR;
// Function Prototypes
BOOL mmcDetect();
#SEPARATE BOOL mmcInit();
#SEPARATE BYTE mmcSendCmd(BYTE cmd,DWORD arg,BYTE crc);
void mmcSetBlockLength(DWORD length);
BYTE mmcReadSingleByte(DWORD address);
void mmcDumpResponse(BYTE response);
BYTE mmcGetStatus();
#SEPARATE void mmcDumpCSD();
#SEPARATE void mmcDumpCID();
// Global Variables
BYTE mmcWriteBuffer[512]; // Buffer to be used for MMC write operations
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -