📄 sdmmc_mci.h
字号:
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
/// \page "sdcard sd mode initialization and identification"
///
/// !Purpose
///
/// sdcard sd mode initialization and identification sequence
///
/// !Description
/// - Host sends Cmd0 to do card reset, card is in "idle state".
/// - Host sends Cmd8 and checks the response of the card, only sdcard supports physical
/// layer version 2.00 will response correctly to Cmd8, and this command is mandatory to be
/// sent before ACmd41 for sdcard which support physical layer version 2.00, to enable new
/// functions or to validate a dual-voltage card.
/// - refer to "If Cmd8 response ok" branch for the initialize of sdcard 2.0.
/// - refer to "If Cmd8 response fail" branch for the initialize of sdcard 1.x, mmc card, sdcard2.0
/// with invalid voltage.
/// - If Cmd8 response ok
/// - Host sends ACmd41* with argument "HCS" equal to "1".
/// - If the response to ACmd41 failed, it means the card does not match the voltage
/// desired by the host, the card will be put into inactive state, initialize ends.
/// - If the response with "CCS" equal to "1", the card is a version 2.0 high capacity sdcard,
/// refer to "Card Initialize" for the succeeding initialize sequence.
/// - If the response with "CCS" equal to "0", the card is a version 2.0 standard capacity sdcard.
/// refer to "Card Initialize" for the succeeding initialize sequence.
/// - If Cmd8 response fail
/// - Host sends ACmd41* argument "HCS" equal to "0".
/// - If the response to ACmd41 ok, the card is a version 1.x sdcard, refer to "Card Initialize" for
/// the succeeding initialize sequence.
/// - If the response to ACmd41 fails
/// - Host sends Cmd0 to reset card.
/// - Host sends Cmd1 to card.
/// - If card has response to Cmd1, the card is a MMC card, refer to "Card Initialize" for the
/// succeeding initialize sequence.
/// - If card has no response to Cmd1, the card is either an unknown card or a card does
/// not match host's voltage, the initialize ends.
/// - Card Initialize
/// - Host sends Cmd2 to get the its unique card identification number (CID).
/// - Host sends Cmd3 to ask the card to publish a new relative card address (RCA), once the
/// RCA is received the card state changes to the "stand-by state".
/// - Host sends Cmd9 to get the Card Specific Data (CSD).
/// - At this stage, the initialization and identification process is over, the following steps are done
/// for the sdcard's succeeding operation.
/// - Host sends Cmd13 to obtain the card status, make sure the card is "ready-for-data".
/// - Host sends Cmd7 to transit card in "transfer state".
/// - If card is a sdcard*, hosts send ACmd6 to set bus to 4-wire mode.
/// - If card is a mmc card, the bus is set as 1-wire mode.
///
/// \note Send Cmd55 before send ACmd41. \endnote
/// \note sdcard include ver 1.x sdcard, ver2.0 standard capacity sdcard, ver2.0 high capacity sdcard \endnote
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// \page "sdcard sd mode write"
///
/// !Purpose
///
/// sdcard sd mode write process
///
/// !Description
/// - Make sure sdcard is under "transfer state", if the sdcard is under other state, host will send
/// Cmd12 to stop the current operation and to transit sdcard to "stand-by state".
/// - Host sends Cmd13 to check sdcard's status, to make sure sdcard is "ready-for-data".
/// - Host sends Cmd25 to do multiple blocks write, the address here is different between high capacity
/// sdcard and normal sdcard, the address of SDHC is equal to the block number, while normal sdcard's
/// address is equal to block number times 512.
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// \page "sdcard sd mode read"
///
/// !Purpose
///
/// sdcard sd mode read process
///
/// !Description
/// - Make sure sdcard is under "transfer state", if the sdcard is under other state, host will send
/// Cmd12 to stop the current operation and to transit sdcard to "stand-by state".
/// - Host sends Cmd13 to check sdcard's status, to make sure sdcard is "ready-for-data".
/// - Host sends Cmd18 to do multiple blocks read, the address here is different between high capacity
/// sdcard and normal sdcard, the address of SDHC is equal to the block number, while normal sdcard's
/// address is equal to block number times 512.
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// \page "sdhc"
///
/// !Purpose
///
/// highlight of sdhc
///
/// !Sdhc initialization and identification
///
/// - Refer to page "sdcard sd mode initialization and identification" for the initialization and identification
/// sequence of a sdhc.
///
/// !Functional difference between sdhc and standard capacity sdcard
///
/// - Command argument is different:
/// - Sdhc uses block address format in memory access commands*, block length is fixed to 512 bytes.
/// - Standard capacity sdcard uses byte address format in memory access commands, block length
/// is defined in Cmd16.
/// - Partial access and misalign access are disabled in sdhc as the block address is used.
/// - Sdhc does not support write-protected commands (Cmd28, Cmd29, Cmd30).
///
/// \note Memory access commands means block read commands (CMD17, CMD18), block write commands
/// (CMD24, CMD25), and block erase commands (CMD32, CMD33).
///
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// \page "sdmmc_mci"
///
/// !Purpose
///
/// Implementation for sdcard sd mode physical layer driver. Supply a set of sdcard sd mode's
/// interface.
///
/// !Usage
///
/// -# SD_Init: Run the SDcard initialization sequence
/// -# SD_MCI_Init : Run the SDcard SD Mode initialization sequence
/// -# SD_Stop: Stop the SDcard by sending Cmd12
/// -# SD_ReadBlock : Read blocks of data
/// -# SD_WriteBlock : Write blocks of data
//------------------------------------------------------------------------------
#ifndef SDCARD_H
#define SDCARD_H
//------------------------------------------------------------------------------
// Constants
//------------------------------------------------------------------------------
/// There was an error with the SD driver.
#define SD_ERROR_DRIVER 1
/// The SD card did not answer the command.
#define SD_ERROR_NORESPONSE 2
/// The SD card did not answer the command.
#define SD_ERROR_NOT_INITIALIZED 3
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -