mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-28 13:23:33 +08:00
Resync new repository with old repo r5166
git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5153 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see misc/tools/kconfig-language.txt.
|
||||
#
|
||||
config MMCSD_NSLOTS
|
||||
int "Number of MMC/SD slots"
|
||||
default 1
|
||||
---help---
|
||||
Number of MMC/SD slots supported by the
|
||||
driver. Default is one.
|
||||
|
||||
config MMCSD_READONLY
|
||||
bool "Disable MMC/SD write access"
|
||||
default n
|
||||
---help---
|
||||
Provide read-only access. Default is
|
||||
Read/Write
|
||||
|
||||
config MMCSD_MULTIBLOCK_DISABLE
|
||||
bool "Disable MMC/SD multiblock transfer"
|
||||
default n
|
||||
---help---
|
||||
Use only the single block transfer method.
|
||||
This setting is used to work around buggy SDIO drivers that cannot handle
|
||||
multiple block transfers.
|
||||
|
||||
config MMCSD_MMCSUPPORT
|
||||
bool "MMC cards support"
|
||||
default y
|
||||
---help---
|
||||
Enable support for MMC cards
|
||||
|
||||
config MMCSD_HAVECARDDETECT
|
||||
bool "MMC/SD card detection"
|
||||
default y
|
||||
---help---
|
||||
SDIO driver card detection is
|
||||
100% accurate
|
||||
|
||||
config MMCSD_SPI
|
||||
bool "MMC/SD spi transfer support"
|
||||
default y
|
||||
|
||||
config MMCSD_SPICLOCK
|
||||
int "MMC/SD maximum SPI clock"
|
||||
default 20000000
|
||||
depends on MMCSD_SPI
|
||||
---help---
|
||||
Maximum SPI clock to drive MMC/SD card.
|
||||
Default is 20MHz.
|
||||
|
||||
config MMCSD_SDIO
|
||||
bool "MMC/SD sdio transfer support"
|
||||
default y
|
||||
|
||||
if MMCSD_SDIO
|
||||
config SDIO_DMA
|
||||
bool "SDIO dma support"
|
||||
default n
|
||||
---help---
|
||||
SDIO driver supports DMA
|
||||
|
||||
config SDIO_MUXBUS
|
||||
bool "SDIO bus share support"
|
||||
default n
|
||||
---help---
|
||||
Set this SDIO interface if the SDIO interface
|
||||
or hardware resources are shared with other drivers.
|
||||
|
||||
config SDIO_WIDTH_D1_ONLY
|
||||
bool "SDIO 1-bit transfer"
|
||||
default n
|
||||
---help---
|
||||
Select 1-bit transfer mode. Default:
|
||||
4-bit transfer mode.
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
############################################################################
|
||||
# drivers/mmcsd/Make.defs
|
||||
#
|
||||
# Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Include MMC/SD drivers
|
||||
|
||||
CSRCS += mmcsd_sdio.c mmcsd_spi.c mmcsd_debug.c
|
||||
|
||||
# Include MMC/SD driver build support
|
||||
|
||||
DEPPATH += --dep-path mmcsd
|
||||
VPATH += :mmcsd
|
||||
CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/mmcsd}
|
||||
|
||||
|
||||
@@ -0,0 +1,424 @@
|
||||
/****************************************************************************
|
||||
* drivers/mmcsd/mmcsd_csd.h
|
||||
*
|
||||
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __DRIVERS_MMCSD_MMCSD_CSD_H
|
||||
#define __DRIVERS_MMCSD_MMCSD_CSD_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* CSD **********************************************************************/
|
||||
|
||||
/* The CSD is a 16 byte, / 128-bit packed structure. The following macros
|
||||
* can be used to extract each packed field from the CSD. Two types of
|
||||
* macros are supported, selected by CONFIG_MMCSD_BE16: (1) byte data (with
|
||||
* MS byte first), or (2) 16-bit big-endian data (with MS hword first).
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_MMCSD_BE16
|
||||
|
||||
/* CSD_STRUCTURE 126-127 */
|
||||
|
||||
#define MMCSD_CSD_CSDSTRUCT(csd) (csd[0] >> 14)
|
||||
|
||||
/* SPEC_VERS 122-125 = (word 0, bits 13:10) (MMC) Spec version */
|
||||
|
||||
#define MMC_CSD_SPECVERS(csd) ((csd[0] >> 10) & 0x0f)
|
||||
|
||||
/* Reserved 120-125 */
|
||||
|
||||
/* TAAC 112-119 = Data read access-time-1
|
||||
* TIME_VALUE 3-6 = Time mantissa
|
||||
* TIME_UNIT 0-2 = Time exponent
|
||||
*/
|
||||
|
||||
#define MMCSD_CSD_TAAC_TIMEVALUE(csd) ((csd[0] >> 3) & 0x0f)
|
||||
#define MMCSD_CSD_TAAC_TIMEUNIT(csd) (csd[0] & 7)
|
||||
|
||||
/* NSAC 111:104 = Data read access-time-2 in CLK cycle(NSAC*100) */
|
||||
|
||||
#define MMCSD_CSD_NSAC(csd) (csd[1] >> 8)
|
||||
|
||||
/* TRAN_SPEED 96-103 = Max. data transfer rate
|
||||
* TIME_VALUE 3-6 = Rate exponent
|
||||
* TRANSFER_RATE_UNIT 0-2 = Rate mantissa
|
||||
*/
|
||||
|
||||
#define MMCSD_CSD_TRANSPEED_TIMEVALUE(csd) ((csd[1] >> 3) & 0x0f)
|
||||
#define MMCSD_CSD_TRANSPEED_TRANSFERRATEUNIT(csd) (csd[1] & 7)
|
||||
|
||||
/* CCC 84-95 = Card command classes */
|
||||
|
||||
#define MMCSD_CSD_CCC(csd) ((csd[2] >> 4) & 0x0fff)
|
||||
|
||||
/* READ_BL_LEN 80-83 = Max. read data block length */
|
||||
|
||||
#define MMCSD_CSD_READBLLEN(csd) (csd[2] & 0x0f)
|
||||
|
||||
/* READ_BL_PARTIAL 79-79 = Partial blocks for read allowed */
|
||||
|
||||
#define MMCSD_CSD_READBLPARTIAL(csd) (csd[3] >> 15)
|
||||
|
||||
/* WRITE_BLK_MISALIGN 78-78 = Write block misalignment */
|
||||
|
||||
#define MMCSD_CSD_WRITEBLKMISALIN(csd) ((csd[3] >> 14) & 1)
|
||||
|
||||
/* READ_BLK_MISALIGN 77:77 = Read block misalignment */
|
||||
|
||||
#define MMCSD_CSD_READBLKMISALIN(csd) ((csd[3] >> 13) & 1)
|
||||
|
||||
/* DSR_IMP 76-76 = DSR implemented */
|
||||
|
||||
#define MMCSD_CSD_DSRIMP(csd) ((csd[3] >> 12) & 1)
|
||||
|
||||
/* C_SIZE 62-73 Device size */
|
||||
|
||||
#define MMCSD_CSD_CSIZE(csd) (((csd[3] & 0x03ff) << 2) | ((csd[4] >> 14) & 3))
|
||||
|
||||
/* VDD_R_CURR_MIN 59-61 = Max. read current at Vcc min */
|
||||
|
||||
#define MMCSD_CSD_VDDRCURRMIN(csd) ((csd[4] >> 11) & 7)
|
||||
|
||||
/* VDD_R_CURR_MAX 56-58 = Max. read current at Vcc max */
|
||||
|
||||
#define MMCSD_CSD_VDDRCURRMAX(csd) ((csd[4] >> 8) & 7)
|
||||
|
||||
/* VDD_W_CURR_MIN 53-55 = Max. write current at Vcc min */
|
||||
|
||||
#define MMCSD_CSD_VDDWCURRMIN(csd) ((csd[4] >> 5) & 7)
|
||||
|
||||
/* VDD_W_CURR_MAX 50-52 = Max. write current at Vcc max */
|
||||
|
||||
#define MMCSD_CSD_VDDWCURRMAX(csd) ((csd[4] >> 2) & 7)
|
||||
|
||||
/* C_SIZE_MULT 47-49 Device size multiplier */
|
||||
|
||||
#define MMCSD_CSD_CSIZEMULT(csd) (((csd[4] & 3) << 1) | (csd[5] >> 15))
|
||||
|
||||
/* ER_BLK_EN 46-46 =Erase single block enable (SD) */
|
||||
|
||||
#define SD_CSD_SDERBLKEN(csd) ((csd[5] >> 14) & 1)
|
||||
|
||||
/* SECTOR_SIZE 39-45 = Erase sector size (SD) */
|
||||
|
||||
#define SD_CSD_SECTORSIZE(csd) ((csd[5] >> 7) & 0x7f)
|
||||
|
||||
/* SECTOR_SIZE 42-46 = Erase sector size (MMC) */
|
||||
|
||||
#define MMC_CSD_SECTORSIZE(csd) ((csd[5] >> 10) & 0x1f)
|
||||
|
||||
/* ER_GRP_SIZE 37-41 = Erase group size (MMC)*/
|
||||
|
||||
#define MMC_CSD_ERGRPSIZE(csd) ((csd[5] >> 5) & 0x1f)
|
||||
|
||||
/* WP_GRP_SIZE 32-38 = Write protect group size (SD) */
|
||||
|
||||
#define SD_CSD_WPGRPSIZE(csd) (csd[5] & 0x7f)
|
||||
|
||||
/* WP_GRP_SIZE 32-36 = Write protect group size (MMC) */
|
||||
|
||||
#define MMC_CSD_WPGRPSIZE(csd) (csd[5] & 0x1f)
|
||||
|
||||
/* WP_GRP_EN 31-31 = Write protect group enable */
|
||||
|
||||
#define MMCSD_WPGRPEN(csd) (csd[6] >> 15)
|
||||
|
||||
/* DFLT_ECC 29-30 = Manufacturer default ECC (MMC) */
|
||||
|
||||
#define MMC_CSD_DFLTECC(csd) ((csd[6] >> 13) & 3)
|
||||
|
||||
/* R2W_FACTOR 26-28 = Write speed factor */
|
||||
|
||||
#define MMCSD_CSD_R2WFACTOR(csd) ((csd[6] >> 10) & 7)
|
||||
|
||||
/* WRITE_BL_LEN 22-25 = Max. write data block length */
|
||||
|
||||
#define MMCSD_CSD_WRITEBLLEN(csd) ((csd[6] >> 6) & 0x0f)
|
||||
|
||||
/* WRITE_BL_PARTIAL 21-21 = Partial blocks for write allowed */
|
||||
|
||||
#define MMCSD_CSD_WRITEBLPARTIAL(csd) ((csd[6] >> 5) & 1)
|
||||
|
||||
/* Reserved 16-20 */
|
||||
|
||||
/* FILE_FORMAT_GROUP 15-15 = File format group */
|
||||
|
||||
#define MMCSD_CSD_FILEFORMATGRP(csd) (csd[7] >> 15)
|
||||
|
||||
/* COPY 14-14 = Copy flag (OTP) */
|
||||
|
||||
#define MMCSD_CSD_COPY(csd) ((csd[7] >> 14) & 1)
|
||||
|
||||
/* PERM_WRITE_PROTECT 13-13 = Permanent write protection */
|
||||
|
||||
#define MMCSD_CSD_PERMWRITEPROTECT(csd) ((csd[7] >> 13) & 1)
|
||||
|
||||
/* TMP_WRITE_PROTECT 12-12 = Temporary write protection */
|
||||
|
||||
#define MMCSD_CSD_TMPWRITEPROTECT(csd) ((csd[7] >> 12) & 1)
|
||||
|
||||
/* FILE_FORMAT 10-11 = File format */
|
||||
|
||||
#define MMCSD_CSD_FILEFORMAT(csd) ((csd[7] >> 10) & 3)
|
||||
|
||||
/* ECC 8-9 = ECC (MMC) */
|
||||
|
||||
#define MMC_CSD_ECC(csd) ((csd[7] >> 8) & 3)
|
||||
|
||||
/* CRC 1-7 = CRC */
|
||||
|
||||
#define MMCSD_CSD_CRC(csd) ((csd[7] >> 1) & 0x7f)
|
||||
|
||||
/* Reserved 0-0 */
|
||||
|
||||
#else /* CONFIG_MMCSD_BE16 */
|
||||
|
||||
/* CSD_STRUCTURE 126-127 */
|
||||
|
||||
#define MMCSD_CSD_CSDSTRUCT(csd) (csd[0] >> 6)
|
||||
|
||||
/* SPEC_VERS 122-125 = (word 0, bits 13:10) (MMC) Spec version */
|
||||
|
||||
#define MMC_CSD_SPECVERS(csd) ((csd[0] >> 2) & 0x0f)
|
||||
|
||||
/* Reserved 120-155 */
|
||||
|
||||
/* TAAC 112-119 = Data read access-time-1
|
||||
* TIME_VALUE 3-6 = Time mantissa
|
||||
* TIME_UNIT 0-2 = Time exponent
|
||||
*/
|
||||
|
||||
#define MMCSD_CSD_TAAC_TIMEVALUE(csd) ((csd[1] >> 3) & 0x0f)
|
||||
#define MMCSD_CSD_TAAC_TIMEUNIT(csd) (csd[1] & 7)
|
||||
|
||||
#define SD20_CSD_TAC_TIMEVALUE(csd) (1)
|
||||
#define SD20_CSD_TAC_TIMEUNIT(csd) (6)
|
||||
|
||||
/* NSAC 111:104 = Data read access-time-2 in CLK cycle(NSAC*100) */
|
||||
|
||||
#define MMCSD_CSD_NSAC(csd) (csd[2])
|
||||
#define SD20_CSD_NSAC(csd) (0)
|
||||
|
||||
/* TRAN_SPEED 96-103 = Max. data transfer rate
|
||||
* TIME_VALUE 3-6 = Rate exponent
|
||||
* TRANSFER_RATE_UNIT 0-2 = Rate mantissa
|
||||
*/
|
||||
|
||||
#define MMCSD_CSD_TRANSPEED_TIMEVALUE(csd) ((csd[3] >> 3) & 0x0f)
|
||||
#define MMCSD_CSD_TRANSPEED_TRANSFERRATEUNIT(csd) (csd[3] & 7)
|
||||
|
||||
#define SD20_CSD_TRANSPEED_TIMEVALUE(csd) MMCSD_CSD_TRANSPEED_TIMEVALUE(csd)
|
||||
#define SD20_CSD_TRANSPEED_TRANSFERRATEUNIT(csd) MMCSD_CSD_TRANSPEED_TRANSFERRATEUNIT(csd)
|
||||
|
||||
/* CCC 84-95 = Card command classes */
|
||||
|
||||
#define MMCSD_CSD_CCC(csd) (((uint16_t)csd[4] << 4) | ((uint16_t)csd[5] >> 4))
|
||||
#define SD20_CSD_CCC(csd) MMCSD_CSD_CCC(csd)
|
||||
|
||||
/* READ_BL_LEN 80-83 = Max. read data block length */
|
||||
|
||||
#define MMCSD_CSD_READBLLEN(csd) (csd[5] & 0x0f)
|
||||
#define SD20_CSD_READBLLEN(csd) (9)
|
||||
|
||||
/* READ_BL_PARTIAL 79-79 = Partial blocks for read allowed */
|
||||
|
||||
#define MMCSD_CSD_READBLPARTIAL(csd) (csd[6] >> 7)
|
||||
#define SD20_CSD_READBLPARTIAL(csd) (0)
|
||||
|
||||
/* WRITE_BLK_MISALIGN 78-78 = Write block misalignment */
|
||||
|
||||
#define MMCSD_CSD_WRITEBLKMISALIGN(csd) ((csd[6] >> 6) & 1)
|
||||
#define SD20_CSD_WRITEBLKMISALIGN(csd) (0)
|
||||
|
||||
/* READ_BLK_MISALIGN 77:77 = Read block misalignment */
|
||||
|
||||
#define MMCSD_CSD_READBLKMISALIGN(csd) ((csd[6] >> 5) & 1)
|
||||
#define SD20_CSD_READBLKMISALIGN(csd) (0)
|
||||
|
||||
/* DSR_IMP 76-76 = DSR implemented */
|
||||
|
||||
#define MMCSD_CSD_DSRIMP(csd) ((csd[6] >> 4) & 1)
|
||||
#define SD20_CSD_DSRIMP(csd) MMCSD_CSD_DSRIMP(csd)
|
||||
|
||||
/* C_SIZE 62-73 Device size */
|
||||
|
||||
#define MMCSD_CSD_CSIZE(csd) (((csd[6] & 3) << 10) | (csd[7] << 2) | (csd[8] >> 6))
|
||||
#define SD20_CSD_CSIZE(csd) ((((uint32_t)csd[7] & 0x3f) << 16) | (csd[8] << 8) | csd[9])
|
||||
|
||||
/* VDD_R_CURR_MIN 59-61 = Max. read current at Vcc min */
|
||||
|
||||
#define MMCSD_CSD_VDDRCURRMIN(csd) ((csd[8] >> 3) & 7)
|
||||
#define SD20_CSD_VDDRCURRMIN(csd) (7)
|
||||
|
||||
/* VDD_R_CURR_MAX 56-58 = Max. read current at Vcc max */
|
||||
|
||||
#define MMCSD_CSD_VDDRCURRMAX(csd) (csd[8] & 7)
|
||||
#define SD20_CSD_VDDRCURRMAX(csd) (6)
|
||||
|
||||
/* VDD_W_CURR_MIN 53-55 = Max. write current at Vcc min */
|
||||
|
||||
#define MMCSD_CSD_VDDWCURRMIN(csd) ((csd[9] >> 5) & 7)
|
||||
#define SD20_CSD_VDDWCURRMIN(csd) (7)
|
||||
|
||||
/* VDD_W_CURR_MAX 50-52 = Max. write current at Vcc max */
|
||||
|
||||
#define MMCSD_CSD_VDDWCURRMAX(csd) ((csd[9] >> 2) & 7)
|
||||
#define SD20_CSD_VDDWCURRMAX(csd) (6)
|
||||
|
||||
/* C_SIZE_MULT 47-49 Device size multiplier */
|
||||
|
||||
#define MMCSD_CSD_CSIZEMULT(csd) (((csd[9] & 3) << 1) | (csd[10] >> 7))
|
||||
#define SD20_CSD_CSIZEMULT(csd) (10-2)
|
||||
|
||||
/* ER_BLK_EN 46-46 = Erase single block enable (SD) */
|
||||
|
||||
#define SD_CSD_SDERBLKEN(csd) ((csd[10] >> 6) & 1)
|
||||
#define SD20_CSD_SDERBLKEN(csd) (1)
|
||||
|
||||
/* SECTOR_SIZE 39-45 = Erase sector size (SD) */
|
||||
|
||||
#define SD_CSD_SECTORSIZE(csd) (((csd[10] & 0x3f) << 1) | (csd[11] >> 7))
|
||||
#define SD20_CSD_SECTORSIZE(csd) (0x7f)
|
||||
|
||||
/* SECTOR_SIZE 42-46 = Erase sector size (MMC) */
|
||||
|
||||
#define MMC_CSD_SECTORSIZE(csd) ((csd[10] >> 2) & 0x1f)
|
||||
|
||||
/* ER_GRP_SIZE 37-41 = Erase group size (MMC)*/
|
||||
|
||||
#define MMC_CSD_ERGRPSIZE(csd) (((csd[10] & 3) << 3) | (csd[11] > 5))
|
||||
|
||||
/* WP_GRP_SIZE 32-38 = Write protect group size (SD) */
|
||||
|
||||
#define SD_CSD_WPGRPSIZE(csd) (csd[11] & 0x7f)
|
||||
#define SD20_CSD_WPGRPSIZE(csd) (0)
|
||||
|
||||
/* WP_GRP_SIZE 32-36 = Write protect group size (MMC) */
|
||||
|
||||
#define MMC_CSD_WPGRPSIZE(csd) (csd[11] & 0x1f)
|
||||
|
||||
/* WP_GRP_EN 31-31 = Write protect group enable */
|
||||
|
||||
#define MMCSD_WPGRPEN(csd) (csd[12] >> 7)
|
||||
#define SD20_WPGRPEN(csd) (0)
|
||||
|
||||
/* DFLT_ECC 29-30 = Manufacturer default ECC (MMC) */
|
||||
|
||||
#define MMC_CSD_DFLTECC(csd) ((csd[12] >> 5) & 3)
|
||||
|
||||
/* R2W_FACTOR 26-28 = Write speed factor */
|
||||
|
||||
#define MMCSD_CSD_R2WFACTOR(csd) ((csd[12] >> 2) & 7)
|
||||
#define SD20_CSD_R2WFACTOR(csd) (2)
|
||||
|
||||
/* WRITE_BL_LEN 22-25 = Max. write data block length */
|
||||
|
||||
#define MMCSD_CSD_WRITEBLLEN(csd) (((csd[12] & 3) << 2) | (csd[13] >> 6))
|
||||
#define SD20_CSD_WRITEBLLEN(csd) (9)
|
||||
|
||||
/* WRITE_BL_PARTIAL 21-21 = Partial blocks for write allowed */
|
||||
|
||||
#define MMCSD_CSD_WRITEBLPARTIAL(csd) ((csd[13] >> 5) & 1)
|
||||
#define SD20_CSD_WRITEBLPARTIAL(csd) (0)
|
||||
|
||||
/* Reserved 16-20 */
|
||||
|
||||
/* FILE_FORMAT_GROUP 15-15 = File format group */
|
||||
|
||||
#define MMCSD_CSD_FILEFORMATGRP(csd) (csd[14] >> 7)
|
||||
#define SD20_CSD_FILEFORMATGRP(csd) (0)
|
||||
|
||||
/* COPY 14-14 = Copy flag (OTP) */
|
||||
|
||||
#define MMCSD_CSD_COPY(csd) ((csd[14] >> 6) & 1)
|
||||
#define SD20_CSD_COPY(csd) MMCSD_CSD_COPY(csd)
|
||||
|
||||
/* PERM_WRITE_PROTECT 13-13 = Permanent write protection */
|
||||
|
||||
#define MMCSD_CSD_PERMWRITEPROTECT(csd) ((csd[14] >> 5) & 1)
|
||||
#define SD20_CSD_PERMWRITEPROTECT(csd) MMCSD_CSD_PERMWRITEPROTECT(csd)
|
||||
|
||||
/* TMP_WRITE_PROTECT 12-12 = Temporary write protection */
|
||||
|
||||
#define MMCSD_CSD_TMPWRITEPROTECT(csd) ((csd[14] >> 4) & 1)
|
||||
#define SD20_CSD_TMPWRITEPROTECT(csd) MMCSD_CSD_TMPWRITEPROTECT(csd)
|
||||
|
||||
/* FILE_FORMAT 10-11 = File format */
|
||||
|
||||
#define MMCSD_CSD_FILEFORMAT(csd) ((csd[14] >> 2) & 3)
|
||||
#define SD20_CSD_FILEFORMAT(csd) (0)
|
||||
|
||||
/* ECC 8-9 = ECC (MMC) */
|
||||
|
||||
#define MMC_CSD_ECC(csd) (csd[14] & 3)
|
||||
|
||||
/* CRC 1-7 = CRC */
|
||||
|
||||
#define MMCSD_CSD_CRC(csd) (csd[15] >> 1)
|
||||
#define SD20_CSD_CRC(csd) MMCSD_CSD_CRC(csd)
|
||||
|
||||
/* Reserved 0-0 */
|
||||
|
||||
#endif /* CONFIG_MMCSD_BE16 */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
#endif /* __DRIVERS_MMCSD_MMCSD_CSD_H */
|
||||
@@ -0,0 +1,183 @@
|
||||
/****************************************************************************
|
||||
* drivers/mmcsd/mmcsd_debug.c
|
||||
*
|
||||
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include "mmcsd_csd.h"
|
||||
#include "mmcsd_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* This needs to match the logic in include/debug.h */
|
||||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# define message(format, arg...) lib_rawprintf(format, ##arg)
|
||||
#else
|
||||
# define message lib_rawprintf
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mmcsd_dmpcsd
|
||||
*
|
||||
* Description:
|
||||
* Dump the contents of the CSD
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_FS)
|
||||
void mmcsd_dmpcsd(FAR const uint8_t *csd, uint8_t cardtype)
|
||||
{
|
||||
bool mmc = (cardtype == MMCSD_CARDTYPE_MMC);
|
||||
bool sd2 = (MMCSD_CSD_CSDSTRUCT(csd) == 1);
|
||||
|
||||
fvdbg("CSD\n");
|
||||
fvdbg(" CSD_STRUCTURE: 1.%d\n", MMCSD_CSD_CSDSTRUCT(csd));
|
||||
if (mmc)
|
||||
{
|
||||
fvdbg(" MMC SPEC_VERS: %d\n", MMC_CSD_SPECVERS(csd));
|
||||
}
|
||||
fvdbg(" TAAC:\n",
|
||||
sd2 ? SD20_CSD_TAC_TIMEVALUE(csd) : MMCSD_CSD_TAAC_TIMEVALUE(csd));
|
||||
fvdbg(" TIME_VALUE: 0x%02x\n",
|
||||
sd2 ? SD20_CSD_TAC_TIMEVALUE(csd) : MMCSD_CSD_TAAC_TIMEVALUE(csd));
|
||||
fvdbg(" TIME_UNIT: 0x%02x\n",
|
||||
sd2 ? SD20_CSD_TAC_TIMEUNIT(csd) : MMCSD_CSD_TAAC_TIMEUNIT(csd));
|
||||
fvdbg(" NSAC: 0x%02x\n",
|
||||
sd2 ? SD20_CSD_NSAC(csd) : MMCSD_CSD_NSAC(csd));
|
||||
fvdbg(" TRAN_SPEED:\n");
|
||||
fvdbg(" TIME_VALUE: 0x%02x\n",
|
||||
sd2 ? SD20_CSD_TRANSPEED_TIMEVALUE(csd) : MMCSD_CSD_TRANSPEED_TIMEVALUE(csd));
|
||||
fvdbg(" RATE_UNIT: 0x%02x\n",
|
||||
sd2 ? SD20_CSD_TRANSPEED_TRANSFERRATEUNIT(csd) : MMCSD_CSD_TRANSPEED_TRANSFERRATEUNIT(csd));
|
||||
fvdbg(" CCC: 0x%03x\n",
|
||||
sd2 ? SD20_CSD_CCC(csd) : MMCSD_CSD_CCC(csd));
|
||||
fvdbg(" READ_BL_LEN: %d\n",
|
||||
sd2 ? SD20_CSD_READBLLEN(csd) : MMCSD_CSD_READBLLEN(csd));
|
||||
fvdbg(" READ_BL_PARTIAL: %d\n",
|
||||
sd2 ? SD20_CSD_READBLPARTIAL(csd) : MMCSD_CSD_READBLPARTIAL(csd));
|
||||
fvdbg(" WRITE_BLK_MISALIGN: %d\n",
|
||||
sd2 ? SD20_CSD_WRITEBLKMISALIGN(csd) : MMCSD_CSD_WRITEBLKMISALIGN(csd));
|
||||
fvdbg(" READ_BLK_MISALIGN: %d\n",
|
||||
sd2 ? SD20_CSD_READBLKMISALIGN(csd) : MMCSD_CSD_READBLKMISALIGN(csd));
|
||||
fvdbg(" DSR_IMP: %d\n",
|
||||
sd2 ? SD20_CSD_DSRIMP(csd) : MMCSD_CSD_DSRIMP(csd));
|
||||
fvdbg(" C_SIZE: %d\n",
|
||||
sd2 ? SD20_CSD_CSIZE(csd) : MMCSD_CSD_CSIZE(csd));
|
||||
fvdbg(" VDD_R_CURR_MIN: %d\n",
|
||||
sd2 ? SD20_CSD_VDDRCURRMIN(csd) : MMCSD_CSD_VDDRCURRMIN(csd));
|
||||
fvdbg(" VDD_R_CURR_MAX: %d\n",
|
||||
sd2 ? SD20_CSD_VDDRCURRMAX(csd) : MMCSD_CSD_VDDRCURRMAX(csd));
|
||||
fvdbg(" VDD_W_CURR_MIN: %d\n",
|
||||
sd2 ? SD20_CSD_VDDWCURRMIN(csd) : MMCSD_CSD_VDDWCURRMIN(csd));
|
||||
fvdbg(" VDD_W_CURR_MAX: %d\n",
|
||||
sd2 ? SD20_CSD_VDDWCURRMAX(csd) : MMCSD_CSD_VDDWCURRMAX(csd));
|
||||
fvdbg(" C_SIZE_MULT: %d\n",
|
||||
sd2 ? SD20_CSD_CSIZEMULT(csd) : MMCSD_CSD_CSIZEMULT(csd));
|
||||
if (mmc)
|
||||
{
|
||||
fvdbg(" MMC SECTOR_SIZE: %d\n", MMC_CSD_SECTORSIZE(csd));
|
||||
fvdbg(" MMC ER_GRP_SIZE: %d\n", MMC_CSD_ERGRPSIZE(csd));
|
||||
fvdbg(" MMC WP_GRP_SIZE: %d\n", MMC_CSD_WPGRPSIZE(csd));
|
||||
fvdbg(" MMC DFLT_ECC: %d\n", MMC_CSD_DFLTECC(csd));
|
||||
}
|
||||
else
|
||||
{
|
||||
fvdbg(" SD ER_BLK_EN: %d\n",
|
||||
sd2 ? SD20_CSD_SDERBLKEN(csd) : SD_CSD_SDERBLKEN(csd));
|
||||
fvdbg(" SD SECTOR_SIZE: %d\n",
|
||||
sd2 ? SD20_CSD_SECTORSIZE(csd) : SD_CSD_SECTORSIZE(csd));
|
||||
fvdbg(" SD WP_GRP_SIZE: %d\n",
|
||||
sd2 ? SD_CSD_WPGRPSIZE(csd) : SD_CSD_WPGRPSIZE(csd));
|
||||
}
|
||||
fvdbg(" WP_GRP_EN: %d\n",
|
||||
sd2 ? SD20_WPGRPEN(csd) : MMCSD_WPGRPEN(csd));
|
||||
fvdbg(" R2W_FACTOR: %d\n",
|
||||
sd2 ? SD20_CSD_R2WFACTOR(csd) : MMCSD_CSD_R2WFACTOR(csd));
|
||||
fvdbg(" WRITE_BL_LEN: %d\n",
|
||||
sd2 ? SD20_CSD_WRITEBLLEN(csd) : MMCSD_CSD_WRITEBLLEN(csd));
|
||||
fvdbg(" WRITE_BL_PARTIAL: %d\n",
|
||||
sd2 ? SD20_CSD_WRITEBLPARTIAL(csd) : MMCSD_CSD_WRITEBLPARTIAL(csd));
|
||||
fvdbg(" FILE_FORMAT_GROUP: %d\n",
|
||||
sd2 ? SD20_CSD_FILEFORMATGRP(csd) : MMCSD_CSD_FILEFORMATGRP(csd));
|
||||
fvdbg(" COPY: %d\n",
|
||||
sd2 ? SD20_CSD_COPY(csd) : MMCSD_CSD_COPY(csd));
|
||||
fvdbg(" PERM_WRITE_PROTECT: %d\n",
|
||||
sd2 ? SD20_CSD_PERMWRITEPROTECT(csd) : MMCSD_CSD_PERMWRITEPROTECT(csd));
|
||||
fvdbg(" TMP_WRITE_PROTECT: %d\n",
|
||||
sd2 ?SD20_CSD_TMPWRITEPROTECT(csd) : MMCSD_CSD_TMPWRITEPROTECT(csd));
|
||||
fvdbg(" FILE_FORMAT: %d\n",
|
||||
sd2 ? SD20_CSD_FILEFORMAT(csd) : MMCSD_CSD_FILEFORMAT(csd));
|
||||
if (mmc)
|
||||
{
|
||||
fvdbg(" MMC ECC: %d\n",
|
||||
sd2 ? MMC_CSD_ECC(csd) : MMC_CSD_ECC(csd));
|
||||
}
|
||||
fvdbg(" CRC: %02x\n",
|
||||
sd2 ? SD20_CSD_CRC(csd) : MMCSD_CSD_CRC(csd));
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,105 @@
|
||||
/****************************************************************************
|
||||
* drivers/mmcsd/mmcsd_internal.h
|
||||
*
|
||||
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __DRIVERS_MMCSD_MMCSD_INTERNAL_H
|
||||
#define __DRIVERS_MMCSD_MMCSD_INTERNAL_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdint.h>
|
||||
#include <debug.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Enable excessive debug options */
|
||||
|
||||
#undef CONFIG_MMCSD_DUMPALL /* MUST BE DEFINED MANUALLY */
|
||||
|
||||
#if !defined(CONFIG_DEBUG_VERBOSE) || !defined(CONFIG_DEBUG_FS)
|
||||
# undef CONFIG_MMCSD_DUMPALL
|
||||
#endif
|
||||
|
||||
/* Card type */
|
||||
|
||||
#define MMCSD_CARDTYPE_UNKNOWN 0 /* Unknown card type */
|
||||
#define MMCSD_CARDTYPE_MMC 1 /* Bit 0: MMC card */
|
||||
#define MMCSD_CARDTYPE_SDV1 2 /* Bit 1: SD version 1.x */
|
||||
#define MMCSD_CARDTYPE_SDV2 4 /* Bit 2: SD version 2.x with byte addressing */
|
||||
#define MMCSD_CARDTYPE_BLOCK 8 /* Bit 3: SD version 2.x with block addressing */
|
||||
|
||||
#define IS_MMC(t) (((t) & MMCSD_CARDTYPE_MMC) != 0)
|
||||
#define IS_SD(t) (((t) & (MMCSD_CARDTYPE_SDV1|MMCSD_CARDTYPE_SDV2)) != 0)
|
||||
#define IS_SDV1(t) (((t) & MMCSD_CARDTYPE_SDV1) != 0)
|
||||
#define IS_SDV2(t) (((t) & MMCSD_CARDTYPE_SDV2) != 0)
|
||||
#define IS_BLOCK(t) (((t) & MMCSD_CARDTYPE_BLOCK) != 0)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MMCSD_DUMPALL
|
||||
# define mmcsd_dumpbuffer(m,b,l) fvdbgdumpbuffer(m,b,l)
|
||||
#else
|
||||
# define mmcsd_dumpbuffer(m,b,l)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_FS)
|
||||
EXTERN void mmcsd_dmpcsd(FAR const uint8_t *csd, uint8_t cardtype);
|
||||
#else
|
||||
# define mmcsd_dmpcsd(csd,cadtype)
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
#endif /* __DRIVERS_MMCSD_MMCSD_INTERNAL_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,339 @@
|
||||
/********************************************************************************************
|
||||
* drivers/mmcsd/mmcsd_sdio.h
|
||||
*
|
||||
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#ifndef __DRIVERS_MMCSD_MMCSD_SDIO_H
|
||||
#define __DRIVERS_MMCSD_MMCSD_SDIO_H
|
||||
|
||||
/********************************************************************************************
|
||||
* Included Files
|
||||
********************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/********************************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
********************************************************************************************/
|
||||
|
||||
/* CMD8 Argument:
|
||||
* [31:12]: Reserved (shall be set to '0')
|
||||
* [11:8]: Supply Voltage (VHS) 0x1 (Range: 2.7-3.6 V)
|
||||
* [7:0]: Check Pattern (recommended 0xaa)
|
||||
* CMD8 Response: R7
|
||||
*/
|
||||
|
||||
#define MMCSD_CMD8VOLTAGE_SHIFT (8) /* Bits 8-11: Supply voltage */
|
||||
#define MMCSD_CMD8VOLTAGE_MASK ((uint32_t)0x0f << MMCSD_CMD8VOLTAGE_SHIFT)
|
||||
# define MMCSD_CMD8VOLTAGE_27 ((uint32_t)0x01 << MMCSD_CMD8VOLTAGE_SHIFT) /* 2.7-3.6V */
|
||||
#define MMCSD_CMD8ECHO_SHIFT (0) /* Bits 0-7: Check pattern */
|
||||
#define MMCSD_CMD8ECHO_MASK ((uint32_t)0xff << MMCSD_CMD8ECHO_SHIFT)
|
||||
# define MMCSD_CMD8CHECKPATTERN ((uint32_t)0xaa << MMCSD_CMD8ECHO_SHIFT)
|
||||
|
||||
/* ACMD6 argument */
|
||||
|
||||
#define MMCSD_ACMD6_BUSWIDTH_1 ((uint32_t)0) /* Bus width = 1-bit */
|
||||
#define MMCSD_ACMD6_BUSWIDTH_4 ((uint32_t)2) /* Bus width = 4-bit */
|
||||
|
||||
/* ACMD41 argument */
|
||||
|
||||
#define MMCSD_ACMD41_VOLTAGEWINDOW ((uint32_t)0x80100000)
|
||||
#define MMCSD_ACMD41_HIGHCAPACITY ((uint32_t)1 << 30)
|
||||
#define MMCSD_ACMD41_STDCAPACITY ((uint32_t)0)
|
||||
|
||||
/* ACMD42 argument */
|
||||
|
||||
#define MMCSD_ACMD42_CD_DISCONNECT ((uint32_t)0) /* Disconnect card detection logic */
|
||||
#define MMCSD_ACMD42_CD_CONNECT ((uint32_t)1) /* Connect card detection logic */
|
||||
|
||||
/* R1 Card Status bit definitions */
|
||||
|
||||
#define MMCSD_R1_OUTOFRANGE ((uint32_t)1 << 31) /* Bad argument */
|
||||
#define MMCSD_R1_ADDRESSERROR ((uint32_t)1 << 30) /* Bad address */
|
||||
#define MMCSD_R1_BLOCKLENERROR ((uint32_t)1 << 29) /* Bad block length */
|
||||
#define MMCSD_R1_ERASESEQERROR ((uint32_t)1 << 28) /* Erase cmd error */
|
||||
#define MMCSD_R1_ERASEPARAM ((uint32_t)1 << 27) /* Bad write blocks */
|
||||
#define MMCSD_R1_WPVIOLATION ((uint32_t)1 << 26) /* Erase access failure */
|
||||
#define MMCSD_R1_CARDISLOCKED ((uint32_t)1 << 25) /* Card is locked */
|
||||
#define MMCSD_R1_LOCKUNLOCKFAILED ((uint32_t)1 << 24) /* Password error */
|
||||
#define MMCSD_R1_COMCRCERROR ((uint32_t)1 << 23) /* CRC error */
|
||||
#define MMCSD_R1_ILLEGALCOMMAND ((uint32_t)1 << 22) /* Bad command */
|
||||
#define MMCSD_R1_CARDECCFAILED ((uint32_t)1 << 21) /* Failed to correct data */
|
||||
#define MMCSD_R1_CCERROR ((uint32_t)1 << 20) /* Card controller error */
|
||||
#define MMCSD_R1_ERROR ((uint32_t)1 << 19) /* General error */
|
||||
#define MMCSD_R1_UNDERRUN ((uint32_t)1 << 18) /* Underrun (MMC only) */
|
||||
#define MMCSD_R1_OVERRRUN ((uint32_t)1 << 17) /* Overrun (MMC only) */
|
||||
#define MMCSD_R1_CIDCSDOVERWRITE ((uint32_t)1 << 16) /* CID/CSD error */
|
||||
#define MMCSD_R1_WPERASESKIP ((uint32_t)1 << 15) /* Not all erased */
|
||||
#define MMCSD_R1_CARDECCDISABLED ((uint32_t)1 << 14) /* Internal ECC not used */
|
||||
#define MMCSD_R1_ERASERESET ((uint32_t)1 << 13) /* Reset sequence cleared */
|
||||
#define MMCSD_R1_STATE_SHIFT (9) /* Current card state */
|
||||
#define MMCSD_R1_STATE_MASK ((uint32_t)15 << MMCSD_R1_STATE_SHIFT)
|
||||
/* Card identification mode states */
|
||||
# define MMCSD_R1_STATE_IDLE ((uint32_t)0 << MMCSD_R1_STATE_SHIFT) /* 0=Idle state */
|
||||
# define MMCSD_R1_STATE_READY ((uint32_t)1 << MMCSD_R1_STATE_SHIFT) /* 1=Ready state */
|
||||
# define MMCSD_R1_STATE_IDENT ((uint32_t)2 << MMCSD_R1_STATE_SHIFT) /* 2=Identification state */
|
||||
/* Data transfer states */
|
||||
# define MMCSD_R1_STATE_STBY ((uint32_t)3 << MMCSD_R1_STATE_SHIFT) /* 3=Standby state */
|
||||
# define MMCSD_R1_STATE_TRAN ((uint32_t)4 << MMCSD_R1_STATE_SHIFT) /* 4=Transfer state */
|
||||
# define MMCSD_R1_STATE_DATA ((uint32_t)5 << MMCSD_R1_STATE_SHIFT) /* 5=Sending data state */
|
||||
# define MMCSD_R1_STATE_RCV ((uint32_t)6 << MMCSD_R1_STATE_SHIFT) /* 6=Receiving data state */
|
||||
# define MMCSD_R1_STATE_PRG ((uint32_t)7 << MMCSD_R1_STATE_SHIFT) /* 7=Programming state */
|
||||
# define MMCSD_R1_STATE_DIS ((uint32_t)8 << MMCSD_R1_STATE_SHIFT) /* 8=Disconnect state */
|
||||
#define MMCSD_R1_READYFORDATA ((uint32_t)1 << 8) /* Buffer empty */
|
||||
#define MMCSD_R1_APPCMD ((uint32_t)1 << 5) /* Next CMD is ACMD */
|
||||
#define MMCSD_R1_AKESEQERROR ((uint32_t)1 << 3) /* Authentication error */
|
||||
#define MMCSD_R1_ERRORMASK ((uint32_t)0xfdffe008) /* Error mask */
|
||||
|
||||
#define IS_STATE(v,s) ((((uint32_t)v)&MMCSD_R1_STATE_MASK)==(s))
|
||||
|
||||
/* R3 (OCR) */
|
||||
|
||||
#define MMC_VDD_20_36 ((uint32_t)0x00ffff00) /* VDD voltage 2.0-3.6 */
|
||||
|
||||
#define MMCSD_VDD_145_150 ((uint32_t)1 << 0) /* VDD voltage 1.45 - 1.50 */
|
||||
#define MMCSD_VDD_150_155 ((uint32_t)1 << 1) /* VDD voltage 1.50 - 1.55 */
|
||||
#define MMCSD_VDD_155_160 ((uint32_t)1 << 2) /* VDD voltage 1.55 - 1.60 */
|
||||
#define MMCSD_VDD_160_165 ((uint32_t)1 << 3) /* VDD voltage 1.60 - 1.65 */
|
||||
#define MMCSD_VDD_165_170 ((uint32_t)1 << 4) /* VDD voltage 1.65 - 1.70 */
|
||||
#define MMCSD_VDD_17_18 ((uint32_t)1 << 5) /* VDD voltage 1.7 - 1.8 */
|
||||
#define MMCSD_VDD_18_19 ((uint32_t)1 << 6) /* VDD voltage 1.8 - 1.9 */
|
||||
#define MMCSD_VDD_19_20 ((uint32_t)1 << 7) /* VDD voltage 1.9 - 2.0 */
|
||||
#define MMCSD_VDD_20_21 ((uint32_t)1 << 8) /* VDD voltage 2.0-2.1 */
|
||||
#define MMCSD_VDD_21_22 ((uint32_t)1 << 9) /* VDD voltage 2.1-2.2 */
|
||||
#define MMCSD_VDD_22_23 ((uint32_t)1 << 10) /* VDD voltage 2.2-2.3 */
|
||||
#define MMCSD_VDD_23_24 ((uint32_t)1 << 11) /* VDD voltage 2.3-2.4 */
|
||||
#define MMCSD_VDD_24_25 ((uint32_t)1 << 12) /* VDD voltage 2.4-2.5 */
|
||||
#define MMCSD_VDD_25_26 ((uint32_t)1 << 13) /* VDD voltage 2.5-2.6 */
|
||||
#define MMCSD_VDD_26_27 ((uint32_t)1 << 14) /* VDD voltage 2.6-2.7 */
|
||||
#define MMCSD_VDD_27_28 ((uint32_t)1 << 15) /* VDD voltage 2.7-2.8 */
|
||||
#define MMCSD_VDD_28_29 ((uint32_t)1 << 16) /* VDD voltage 2.8-2.9 */
|
||||
#define MMCSD_VDD_29_30 ((uint32_t)1 << 17) /* VDD voltage 2.9-3.0 */
|
||||
#define MMCSD_VDD_30_31 ((uint32_t)1 << 18) /* VDD voltage 3.0-3.1 */
|
||||
#define MMCSD_VDD_31_32 ((uint32_t)1 << 19) /* VDD voltage 3.1-3.2 */
|
||||
#define MMCSD_VDD_32_33 ((uint32_t)1 << 20) /* VDD voltage 3.2-3.3 */
|
||||
#define MMCSD_VDD_33_34 ((uint32_t)1 << 21) /* VDD voltage 3.3-3.4 */
|
||||
#define MMCSD_VDD_34_35 ((uint32_t)1 << 22) /* VDD voltage 3.4-3.5 */
|
||||
#define MMCSD_VDD_35_36 ((uint32_t)1 << 23) /* VDD voltage 3.5-3.6 */
|
||||
#define MMCSD_R3_HIGHCAPACITY ((uint32_t)1 << 30) /* true: Card supports block addressing */
|
||||
#define MMCSD_CARD_BUSY ((uint32_t)1 << 31) /* Card power-up busy bit */
|
||||
|
||||
/* R6 Card Status bit definitions */
|
||||
|
||||
#define MMCSD_R6_RCA_SHIFT (16) /* New published RCA */
|
||||
#define MMCSD_R6_RCA_MASK ((uint32_t)0xffff << MMCSD_R6_RCA_SHIFT)
|
||||
#define MMCSD_R6_COMCRCERROR ((uint32_t)1 << 15) /* CRC error */
|
||||
#define MMCSD_R6_ILLEGALCOMMAND ((uint32_t)1 << 14) /* Bad command */
|
||||
#define MMCSD_R6_ERROR ((uint32_t)1 << 13) /* General error */
|
||||
#define MMCSD_R6_STATE_SHIFT (9) /* Current card state */
|
||||
#define MMCSD_R6_STATE_MASK ((uint32_t)15 << MMCSD_R6_STATE_SHIFT)
|
||||
/* Card identification mode states */
|
||||
# define MMCSD_R6_STATE_IDLE ((uint32_t)0 << MMCSD_R6_STATE_SHIFT) /* 0=Idle state */
|
||||
# define MMCSD_R6_STATE_READY ((uint32_t)1 << MMCSD_R6_STATE_SHIFT) /* 1=Ready state */
|
||||
# define MMCSD_R6_STATE_IDENT ((uint32_t)2 << MMCSD_R6_STATE_SHIFT) /* 2=Identification state */
|
||||
/* Data transfer states */
|
||||
# define MMCSD_R6_STATE_STBY ((uint32_t)3 << MMCSD_R6_STATE_SHIFT) /* 3=Standby state */
|
||||
# define MMCSD_R6_STATE_TRAN ((uint32_t)4 << MMCSD_R6_STATE_SHIFT) /* 4=Transfer state */
|
||||
# define MMCSD_R6_STATE_DATA (5(uint32_t) << MMCSD_R6_STATE_SHIFT) /* 5=Sending data state */
|
||||
# define MMCSD_R6_STATE_RCV ((uint32_t)6 << MMCSD_R6_STATE_SHIFT) /* 6=Receiving data state */
|
||||
# define MMCSD_R6_STATE_PRG ((uint32_t)7 << MMCSD_R6_STATE_SHIFT) /* 7=Programming state */
|
||||
# define MMCSD_R6_STATE_DIS ((uint32_t) << MMCSD_R6_STATE_SHIFT) /* 8=Disconnect state */
|
||||
#define MMCSD_R6_ERRORMASK ((uint32_t)0x0000e000) /* Error mask */
|
||||
|
||||
/* SD Configuration Register (SCR) encoding */
|
||||
|
||||
#define MMCSD_SCR_BUSWIDTH_1BIT (1)
|
||||
#define MMCSD_SCR_BUSWIDTH_2BIT (2)
|
||||
#define MMCSD_SCR_BUSWIDTH_4BIT (4)
|
||||
#define MMCSD_SCR_BUSWIDTH_8BIT (8)
|
||||
|
||||
/* Last 4 bytes of the 48-bit R7 response */
|
||||
|
||||
#define MMCSD_R7VERSION_SHIFT (28) /* Bits 28-31: Command version number */
|
||||
#define MMCSD_R7VERSION_MASK ((uint32_t)0x0f << MMCSD_R7VERSION_SHIFT)
|
||||
#define MMCSD_R7VOLTAGE_SHIFT (8) /* Bits 8-11: Voltage accepted */
|
||||
#define MMCSD_R7VOLTAGE_MASK ((uint32_t)0x0f << MMCSD_R7VOLTAGE_SHIFT)
|
||||
# define MMCSD_R7VOLTAGE_27 ((uint32_t)0x01 << MMCSD_R7VOLTAGE_SHIFT) /* 2.7-3.6V */
|
||||
#define MMCSD_R7ECHO_SHIFT (0) /* Bits 0-7: Echoed check pattern */
|
||||
#define MMCSD_R7ECHO_MASK ((uint32_t)0xff << MMCSD_R7ECHO_SHIFT)
|
||||
# define MMCSD_R7CHECKPATTERN ((uint32_t)0xaa << MMCSD_R7ECHO_SHIFT)
|
||||
|
||||
/********************************************************************************************
|
||||
* Public Types
|
||||
********************************************************************************************/
|
||||
|
||||
/* Decoded Card Identification (CID) register */
|
||||
|
||||
struct mmcsd_cid_s
|
||||
{
|
||||
uint8_t mid; /* 127:120 8-bit Manufacturer ID */
|
||||
uint16_t oid; /* 119:104 16-bit OEM/Application ID (ascii) */
|
||||
uint8_t pnm[6]; /* 103:64 40-bit Product Name (ascii) + null terminator */
|
||||
uint8_t prv; /* 63:56 8-bit Product revision */
|
||||
uint32_t psn; /* 55:24 32-bit Product serial number */
|
||||
/* 23:20 4-bit (reserved) */
|
||||
uint16_t mdt; /* 19:8 12-bit Manufacturing date */
|
||||
uint8_t crc; /* 7:1 7-bit CRC7 */
|
||||
/* 0:0 1-bit (not used) */
|
||||
};
|
||||
|
||||
/* Decoded Card Specific Data (CSD) register */
|
||||
|
||||
struct mmcsd_csd_s
|
||||
{
|
||||
uint8_t csdstructure; /* 127:126 CSD structure */
|
||||
uint8_t mmcspecvers; /* 125:122 MMC Spec version (MMC only) */
|
||||
|
||||
struct
|
||||
{
|
||||
uint8_t timeunit; /* 2:0 Time exponent */
|
||||
uint8_t timevalue; /* 6:3 Time mantissa */
|
||||
} taac; /* 119:112 Data read access-time-1 */
|
||||
|
||||
uint8_t nsac; /* 111:104 Data read access-time-2 in CLK cycle(NSAC*100) */
|
||||
|
||||
struct
|
||||
{
|
||||
uint8_t transferrateunit; /* 2:0 Rate exponent */
|
||||
uint8_t timevalue; /* 6:3 Rate mantissa */
|
||||
} transpeed; /* 103:96 Max. data transfer rate */
|
||||
|
||||
uint16_t ccc; /* 95:84 Card command classes */
|
||||
uint8_t readbllen; /* 83:80 Max. read data block length */
|
||||
uint8_t readblpartial; /* 79:79 Partial blocks for read allowed */
|
||||
uint8_t writeblkmisalign; /* 78:78 Write block misalignment */
|
||||
uint8_t readblkmisalign; /* 77:77 Read block misalignment */
|
||||
uint8_t dsrimp; /* 76:76 DSR implemented */
|
||||
|
||||
union
|
||||
{
|
||||
#ifdef CONFIG_MMCSD_MMCSUPPORT
|
||||
struct
|
||||
{
|
||||
uint16_t csize; /* 73:62 Device size */
|
||||
uint8_t vddrcurrmin; /* 61:59 Max. read current at Vdd min */
|
||||
uint8_t vddrcurrmax; /* 58:56 Max. read current at Vdd max */
|
||||
uint8_t vddwcurrmin; /* 55:53 Max. write current at Vdd min */
|
||||
uint8_t vddwcurrmax; /* 52:50 Max. write current at Vdd max */
|
||||
uint8_t csizemult; /* 49:47 Device size multiplier */
|
||||
|
||||
union
|
||||
{
|
||||
struct /* MMC system specification version 3.1 */
|
||||
{
|
||||
uint8_t ergrpsize; /* 46:42 Erase group size (MMC 3.1) */
|
||||
uint8_t ergrpmult; /* 41:37 Erase group multiplier (MMC 3.1) */
|
||||
} mmc31;
|
||||
struct /* MMC system specification version 2.2 */
|
||||
{
|
||||
uint8_t sectorsize; /* 46:42 Erase sector size (MMC 2.2) */
|
||||
uint8_t ergrpsize; /* 41:37 Erase group size (MMC 2.2) */
|
||||
} mmc22;
|
||||
} er;
|
||||
|
||||
uint8_t mmcwpgrpsize; /* 36:32 Write protect group size (MMC) */
|
||||
} mmc;
|
||||
#endif
|
||||
struct
|
||||
{
|
||||
uint16_t csize; /* 73:62 Device size */
|
||||
uint8_t vddrcurrmin; /* 61:59 Max. read current at Vdd min */
|
||||
uint8_t vddrcurrmax; /* 58:56 Max. read current at Vdd max */
|
||||
uint8_t vddwcurrmin; /* 55:53 Max. write current at Vdd min */
|
||||
uint8_t vddwcurrmax; /* 52:50 Max. write current at Vdd max */
|
||||
uint8_t csizemult; /* 49:47 Device size multiplier */
|
||||
uint8_t sderblen; /* 46:46 Erase single block enable (SD) */
|
||||
uint8_t sdsectorsize; /* 45:39 Erase sector size (SD) */
|
||||
uint8_t sdwpgrpsize; /* 38:32 Write protect group size (SD) */
|
||||
} sdbyte;
|
||||
|
||||
struct
|
||||
{
|
||||
/* 73:70 (reserved) */
|
||||
uint32_t csize; /* 69:48 Device size */
|
||||
/* 47:47 (reserved) */
|
||||
uint8_t sderblen; /* 46:46 Erase single block enable (SD) */
|
||||
uint8_t sdsectorsize; /* 45:39 Erase sector size (SD) */
|
||||
uint8_t sdwpgrpsize; /* 38:32 Write protect group size (SD) */
|
||||
} sdblock;
|
||||
} u;
|
||||
|
||||
uint8_t wpgrpen; /* 31:31 Write protect group enable */
|
||||
uint8_t mmcdfltecc; /* 30:29 Manufacturer default ECC (MMC) */
|
||||
uint8_t r2wfactor; /* 28:26 Write speed factor */
|
||||
uint8_t writebllen; /* 25:22 Max. write data block length */
|
||||
uint8_t writeblpartial; /* 21:21 Partial blocks for write allowed */
|
||||
uint8_t fileformatgrp; /* 15:15 File format group */
|
||||
uint8_t copy; /* 14:14 Copy flag (OTP) */
|
||||
uint8_t permwriteprotect; /* 13:13 Permanent write protection */
|
||||
uint8_t tmpwriteprotect; /* 12:12 Temporary write protection */
|
||||
uint8_t fileformat; /* 10:11 File format */
|
||||
uint8_t mmcecc; /* 9:8 ECC (MMC) */
|
||||
uint8_t crc; /* 7:1 CRC */
|
||||
/* 0:0 Not used */
|
||||
};
|
||||
|
||||
struct mmcsd_scr_s
|
||||
{
|
||||
uint8_t scrversion; /* 63:60 Version of SCR structure */
|
||||
uint8_t sdversion; /* 59:56 SD memory card physical layer version */
|
||||
uint8_t erasestate; /* 55:55 Data state after erase (1 or 0) */
|
||||
uint8_t security; /* 54:52 SD security support */
|
||||
uint8_t buswidth; /* 51:48 DAT bus widthes supported */
|
||||
/* 47:32 SD reserved space */
|
||||
uint32_t mfgdata; /* 31:0 Reserved for manufacturing data */
|
||||
};
|
||||
|
||||
/********************************************************************************************
|
||||
* Public Data
|
||||
********************************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/********************************************************************************************
|
||||
* Public Functions
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
#endif /* __DRIVERS_MMCSD_MMCSD_SDIO_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,187 @@
|
||||
/****************************************************************************
|
||||
* drivers/mmcsd/mmcsd_spi.h
|
||||
*
|
||||
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __DRIVERS_MMCSD_MMCSD_SPI_H
|
||||
#define __DRIVERS_MMCSD_MMCSD_SPI_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* SPI *******************************************************************/
|
||||
|
||||
/* SPI Command Set */
|
||||
|
||||
#define CMD0 0x40 /* GO_IDLE_STATE: Resets all cards to idle state */
|
||||
#define CMD1 0x41 /* SEND_OP_COND: Sends capacity support information */
|
||||
#define CMD6 0x46 /* SWITCH_FUNC: Checks switchable function */
|
||||
#define CMD8 0x48 /* SEND_IF_COND: Sends SD Memory Card interface condition */
|
||||
#define CMD9 0x49 /* SEND_CSD: Asks card to send its card specific data (CSD) */
|
||||
#define CMD10 0x4a /* SEND_CID: Asks card to send its card identification (CID) */
|
||||
#define CMD12 0x4c /* STOP_TRANSMISSION: Forces the card to stop transmission */
|
||||
#define CMD13 0x4d /* SEND_STATUS: Asks card to send its status register */
|
||||
#define CMD16 0x50 /* SET_BLOCKLEN: Sets a block length (in bytes) */
|
||||
#define CMD17 0x51 /* READ_SINGLE_BLOCK: Reads a block of the selected size */
|
||||
#define CMD18 0x52 /* READ_MULTIPLE_BLOCK: Continuously transfers blocks from card to host */
|
||||
#define CMD20 0x54 /* CMD_WRITEBLOCK: Write block to memory (MMC) */
|
||||
#define CMD24 0x58 /* WRITE_BLOCK: Writes a block of the selected size */
|
||||
#define CMD25 0x59 /* WRITE_MULTIPLE_BLOCK: Continuously writes blocks of data */
|
||||
#define CMD27 0x5b /* PROGRAM_CSD: Set programmable bits of the CSD */
|
||||
#define CMD28 0x5c /* SET_WRITE_PROT: Sets the write protection bit of group */
|
||||
#define CMD29 0x5d /* CLR_WRITE_PROT: Clears the write protection bit of group */
|
||||
#define CMD30 0x5e /* SEND_WRITE_PROT: Asks card to send state of write protection bits */
|
||||
#define CMD32 0x60 /* ERASE_WR_BLK_START_ADDR: Sets address of first block to erase */
|
||||
#define CMD33 0x61 /* ERASE_WR_BLK_END_ADDR: Sets address of last block to erase */
|
||||
#define CMD34 0x62 /* UNTAG_SECTOR: (MMC) */
|
||||
#define CMD35 0x63 /* TAG_ERASE_GROUP_START: (MMC) */
|
||||
#define CMD36 0x64 /* TAG_ERASE_GOUPR_END: (MMC) */
|
||||
#define CMD37 0x65 /* UNTAG_ERASE_GROUP: (MMC) */
|
||||
#define CMD38 0x66 /* ERASE: Erases all previously selected write blocks */
|
||||
#define CMD40 0x68 /* CRC_ON_OFF: (MMC) */
|
||||
#define CMD42 0x6a /* LOCK_UNLOCK: Used to Set/Reset the Password or lock/unlock card */
|
||||
#define CMD55 0x77 /* APP_CMD: Tells card that the next command is an application specific command */
|
||||
#define CMD56 0x78 /* GEN_CMD: Used transfer a block to or get block from card */
|
||||
#define CMD58 0x7a /* READ_OCR :Reads the OCR register of a card */
|
||||
#define CMD59 0x7b /* CRC_ON_OFF: Turns the CRC option on or off */
|
||||
#define ACMD13 0x4d /* SD_STATUS: Send the SD Status */
|
||||
#define ACMD22 0x56 /* SEND_NUM_WR_BLOCKS: Send number of the errorfree blocks */
|
||||
#define ACMD23 0x57 /* SET_WR_BLK_ERASE_COUNT: Set number blocks to erase before writing */
|
||||
#define ACMD41 0x69 /* SD_SEND_OP_COND: Sends host capacity support information */
|
||||
#define ACMD42 0x6a /* SET_CLR_CARD_DETECT: Connect/disconnect pull-up resistor on CS */
|
||||
#define ACMD51 0x73 /* SEND_SCR: Reads the SD Configuration Register (SCR) */
|
||||
|
||||
/* SPI 8-bit R1 response */
|
||||
|
||||
#define MMCSD_SPIR1_OK 0x00 /* No error bits set */
|
||||
#define MMCSD_SPIR1_IDLESTATE 0x01 /* Idle state */
|
||||
#define MMCSD_SPIR1_ERASERESET 0x02 /* Erase reset */
|
||||
#define MMCSD_SPIR1_ILLEGALCMD 0x04 /* Illegal command */
|
||||
#define MMCSD_SPIR1_CRCERROR 0x08 /* Com CRC error */
|
||||
#define MMCSD_SPIR1_ERASEERROR 0x10 /* Erase sequence error */
|
||||
#define MMCSD_SPIR1_ADDRERROR 0x20 /* Address error */
|
||||
#define MMCSD_SPIR1_PARAMERROR 0x40 /* Parameter error */
|
||||
|
||||
/* SPI 8-bit R2 response */
|
||||
|
||||
#define MMCSD_SPIR2_CARDLOCKED 0x0001 /* Card is locked */
|
||||
#define MMCSD_SPIR2_WPERASESKIP 0x0002 /* WP erase skip */
|
||||
#define MMCSD_SPIR2_LOCKFAIL 0x0002 /* Lock/unlock cmd failed */
|
||||
#define MMCSD_SPIR2_ERROR 0x0004 /* Error */
|
||||
#define MMCSD_SPIR2_CCERROR 0x0008 /* CC error */
|
||||
#define MMCSD_SPIR2_CARDECCFAIL 0x0010 /* Card ECC failed */
|
||||
#define MMCSD_SPIR2_WPVIOLATION 0x0020 /* WP violoation */
|
||||
#define MMCSD_SPIR2_ERASEPARAM 0x0040 /* Erase parameter */
|
||||
#define MMCSD_SPIR2_OUTOFRANGE 0x0080 /* Out of range */
|
||||
#define MMCSD_SPIR2_CSDOVERWRITE 0x0080 /* CSD overwrite */
|
||||
#define MMCSD_SPIR2_IDLESTATE 0x0100 /* In idle state */
|
||||
#define MMCSD_SPIR2_ERASERESET 0x0200 /* Erase reset */
|
||||
#define MMCSD_SPIR2_ILLEGALCMD 0x0400 /* Illegal command */
|
||||
#define MMCSD_SPIR2_CRCERROR 0x0800 /* Com CRC error */
|
||||
#define MMCSD_SPIR2_ERASEERROR 0x1000 /* Erase sequence error */
|
||||
#define MMCSD_SPIR2_ADDRERROR 0x2000 /* Address error */
|
||||
#define MMCSD_SPIR2_PARAMERROR 0x4000 /* Parameter error */
|
||||
|
||||
/* Last 4 bytes of the 5 byte R7 response */
|
||||
|
||||
#define MMCSD_SPIR7_VERSION_SHIFT (28) /* Bits 28-31: Command version number */
|
||||
#define MMCSD_SPIR7_VERSION_MASK ((uint32_t)0x0f << MMCSD_SPIR7_VERSION_SHIFT)
|
||||
#define MMCSD_SPIR7_VOLTAGE_SHIFT (8) /* Bits 8-11: Voltage accepted */
|
||||
#define MMCSD_SPIR7_VOLTAGE_MASK ((uint32_t)0x0f << MMCSD_SPIR7_VOLTAGE_SHIFT)
|
||||
#define MMCSD_SPIR7_VOLTAGE_27 ((uint32_t)0x01 << MMCSD_SPIR7_VOLTAGE_SHIFT) /* 2.7-3.6V */
|
||||
#define MMCSD_SPIR7_ECHO_SHIFT (0) /* Bits 0-7: Echoed check pattern */
|
||||
#define MMCSD_SPIR7_ECHO_MASK ((uint32_t)0xff << MMCSD_SPIR7_ECHO_SHIFT)
|
||||
|
||||
/* Data Response */
|
||||
|
||||
#define MMCSD_SPIDR_MASK 0x1f /* Mask for valid data response bits */
|
||||
#define MMCSD_SPIDR_ACCEPTED 0x05 /* Data accepted */
|
||||
#define MMCSD_SPIDR_CRCERROR 0x0b /* Data rejected due to CRC error */
|
||||
#define MMCSD_SPIDR_WRERROR 0x0d /* Data rejected due to write error */
|
||||
|
||||
/* Data Tokens */
|
||||
|
||||
#define MMCSD_SPIDT_STARTBLKSNGL 0xfe /* First byte of block, single block */
|
||||
#define MMCSD_SPIDT_STARTBLKMULTI 0xfc /* First byte of block, multi-block */
|
||||
#define MMCSD_SPIDT_STOPTRANS 0xfd /* Stop transmission */
|
||||
|
||||
/* Data error token */
|
||||
|
||||
#define MMCSD_SPIDET_UPPER 0xf0 /* The upper four bits are zero */
|
||||
#define MMCSD_SPIDET_ERROR 0x01 /* Error */
|
||||
#define MMCSD_SPIDET_CCERROR 0x02 /* CC error */
|
||||
#define MMCSD_SPIDET_CARDECCFAIL 0x04 /* Card ECC failed */
|
||||
#define MMCSD_SPIDET_OUTOFRANGE 0x08 /* Out of range */
|
||||
|
||||
/* Operating Conditions register */
|
||||
|
||||
#define MMCSD_OCR_V27 ((uint32_t)1 << 15) /* Bit 15: 2.7-2.8V */
|
||||
#define MMCSD_OCR_V28 ((uint32_t)1 << 16) /* Bit 16: 2.8-2.9V */
|
||||
#define MMCSD_OCR_V29 ((uint32_t)1 << 17) /* Bit 17: 2.9-3.0V */
|
||||
#define MMCSD_OCR_V30 ((uint32_t)1 << 18) /* Bit 18: 3.0-3.1V */
|
||||
#define MMCSD_OCR_V31 ((uint32_t)1 << 19) /* Bit 19: 3.1-3.2V */
|
||||
#define MMCSD_OCR_V32 ((uint32_t)1 << 20) /* Bit 20: 3.2-3.3V */
|
||||
#define MMCSD_OCR_V33 ((uint32_t)1 << 21) /* Bit 21: 3.3-3.4V */
|
||||
#define MMCSD_OCR_V34 ((uint32_t)1 << 22) /* Bit 22: 3.4-3.5V */
|
||||
#define MMCSD_OCR_V35 ((uint32_t)1 << 23) /* Bit 23: 3.5-3.6V */
|
||||
#define MMCSD_OCR_CCS ((uint32_t)1 << 30) /* Bit 30: Card capacity status */
|
||||
#define MMCSD_OCR_BUSY ((uint32_t)1 << 31) /* Bit 31: Card powered up status bit */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
#endif /* __DRIVERS_MMCSD_MMCSD_SPI_H */
|
||||
Reference in New Issue
Block a user