ButterflyMP3

mmc.h File Reference

MultiMedia Card low level Functions. More...

#include "types.h"
Include dependency graph for mmc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define MMC_PORT   PORTE
#define MMC_PIN   PINE
#define MMC_DDR   DDRE
#define MMC_CS   PE4
#define SPI_PORT   PORTB
#define SPI_DDR   DDRB
#define SPI_SS   PB0
#define SPI_SCK   PB1
#define SPI_MOSI   PB2
#define SPI_MISO   PB3
#define MMC_GO_IDLE_STATE   0
#define MMC_SEND_OP_COND   1
#define MMC_SEND_CSD   9
#define MMC_SEND_CID   10
#define MMC_SEND_STATUS   13
#define MMC_SET_BLOCKLEN   16
#define MMC_READ_SINGLE_BLOCK   17
#define MMC_WRITE_BLOCK   24
#define MMC_PROGRAM_CSD   27
#define MMC_SET_WRITE_PROT   28
#define MMC_CLR_WRITE_PROT   29
#define MMC_SEND_WRITE_PROT   30
#define MMC_TAG_SECTOR_START   32
#define MMC_TAG_SECTOR_END   33
#define MMC_UNTAG_SECTOR   34
#define MMC_TAG_ERASE_GROUP_START   35
#define MMC_TAG_ERARE_GROUP_END   36
#define MMC_UNTAG_ERASE_GROUP   37
#define MMC_ERASE   38
#define MMC_CRC_ON_OFF   59
#define MMC_R1_BUSY   0x80
#define MMC_R1_PARAMETER   0x40
#define MMC_R1_ADDRESS   0x20
#define MMC_R1_ERASE_SEQ   0x10
#define MMC_R1_COM_CRC   0x08
#define MMC_R1_ILLEGAL_COM   0x04
#define MMC_R1_ERASE_RESET   0x02
#define MMC_R1_IDLE_STATE   0x01
#define MMC_STARTBLOCK_READ   0xFE
#define MMC_STARTBLOCK_WRITE   0xFE
#define MMC_STARTBLOCK_MWRITE   0xFC
#define MMC_STOPTRAN_WRITE   0xFD
#define MMC_DE_MASK   0x1F
#define MMC_DE_ERROR   0x01
#define MMC_DE_CC_ERROR   0x02
#define MMC_DE_ECC_FAIL   0x04
#define MMC_DE_OUT_OF_RANGE   0x04
#define MMC_DE_CARD_LOCKED   0x04
#define MMC_DR_MASK   0x1F
#define MMC_DR_ACCEPT   0x05
#define MMC_DR_REJECT_CRC   0x0B
#define MMC_DR_REJECT_WRITE_ERROR   0x0D

Functions

void SpiInit (void)
 Setup Pin configuration of SPI bus for the AVR.
uint8 SpiByte (unsigned char byte)
 Main SPI routine

  • transmits a byte and receives a byte simultaneously
  • received byte is returned
  • if you only want to read a byte, put a dummy (say 0xff) in the transmit slot.

uint8 MMC_Reset (void)
 Perform a Hardware then software reset of the MMC.
uint16 MMC_Check (void)
 Send the get status command to the MMC and returns the result.
uint8 MMC_Read (uint32 lba)
 Grab the Serial number & info from the card.
char MMC_Detect (void)
 Checks if there is a memory card in the slot This requires a pull down resistor on the CS line of about 100K.

Variables

uint8 mmc_sbuf []
 512 byte sector buffer in internal RAM
uint8 mmc_scratch []
 32 byte Scratch buffer for CSD/CID/ ops

Detailed Description

MultiMedia Card low level Functions.

Author:
Nick Lott brokentoaster@users.sf.net
Date:
September 2004
Id:
mmc.h,v 1.7 2007/06/04 15:12:17 brokentoaster Exp

This file represents a convergence of a number of code snippets found on the web, some of the Yampp system by Jesper Hansen and the work done by Sylvain.Bissonnette@microsyl.com. The goal is to produce an adaptable library for doing low level MMC activities over the SPI bus. This code was written with the Atmega169V in mind (aka "Butterfly"). http://butterflymp3.sf.net

For details Concerning the MMC spec see www.sandisk.com. I refered to "SanDisk MultiMediaCard and Reduced-Size MultiMediaCard Product Manual" Doc No. 80-36-00320 v1.0 during the writing of this code.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

History:

24-26 Sep 2004: Initial write and port of functions collected over last few months

March 2005: Add new improvements based around Circuit cellar article. Updated Comments for Doxygen

Definition in file mmc.h.


Define Documentation

#define MMC_CLR_WRITE_PROT   29

Definition at line 69 of file mmc.h.

#define MMC_CRC_ON_OFF   59

Definition at line 78 of file mmc.h.

#define MMC_CS   PE4

Definition at line 50 of file mmc.h.

Referenced by MMC_Check(), MMC_Detect(), MMC_Read(), MMC_Reset(), MMCCommand(), and SpiInit().

#define MMC_DDR   DDRE

Definition at line 49 of file mmc.h.

Referenced by MMC_Detect(), and SpiInit().

#define MMC_DE_CARD_LOCKED   0x04

Definition at line 104 of file mmc.h.

#define MMC_DE_CC_ERROR   0x02

Definition at line 101 of file mmc.h.

#define MMC_DE_ECC_FAIL   0x04

Definition at line 102 of file mmc.h.

#define MMC_DE_ERROR   0x01

Definition at line 100 of file mmc.h.

#define MMC_DE_MASK   0x1F

Definition at line 99 of file mmc.h.

#define MMC_DE_OUT_OF_RANGE   0x04

Definition at line 103 of file mmc.h.

#define MMC_DR_ACCEPT   0x05

Definition at line 108 of file mmc.h.

#define MMC_DR_MASK   0x1F

Definition at line 107 of file mmc.h.

#define MMC_DR_REJECT_CRC   0x0B

Definition at line 109 of file mmc.h.

#define MMC_DR_REJECT_WRITE_ERROR   0x0D

Definition at line 110 of file mmc.h.

#define MMC_ERASE   38

Definition at line 77 of file mmc.h.

#define MMC_GO_IDLE_STATE   0

Definition at line 59 of file mmc.h.

#define MMC_PIN   PINE

Definition at line 48 of file mmc.h.

Referenced by MMC_Detect().

#define MMC_PORT   PORTE

Definition at line 47 of file mmc.h.

Referenced by MMC_Check(), MMC_Detect(), MMC_Read(), MMC_Reset(), MMCCommand(), and SpiInit().

#define MMC_PROGRAM_CSD   27

Definition at line 67 of file mmc.h.

#define MMC_R1_ADDRESS   0x20

Definition at line 83 of file mmc.h.

#define MMC_R1_BUSY   0x80

Definition at line 81 of file mmc.h.

#define MMC_R1_COM_CRC   0x08

Definition at line 85 of file mmc.h.

#define MMC_R1_ERASE_RESET   0x02

Definition at line 87 of file mmc.h.

#define MMC_R1_ERASE_SEQ   0x10

Definition at line 84 of file mmc.h.

#define MMC_R1_IDLE_STATE   0x01

Definition at line 88 of file mmc.h.

#define MMC_R1_ILLEGAL_COM   0x04

Definition at line 86 of file mmc.h.

#define MMC_R1_PARAMETER   0x40

Definition at line 82 of file mmc.h.

#define MMC_READ_SINGLE_BLOCK   17

Definition at line 65 of file mmc.h.

Referenced by MMC_Read().

#define MMC_SEND_CID   10

Definition at line 62 of file mmc.h.

#define MMC_SEND_CSD   9

Definition at line 61 of file mmc.h.

#define MMC_SEND_OP_COND   1

Definition at line 60 of file mmc.h.

#define MMC_SEND_STATUS   13

Definition at line 63 of file mmc.h.

Referenced by MMC_Check(), and MMC_Read().

#define MMC_SEND_WRITE_PROT   30

Definition at line 70 of file mmc.h.

#define MMC_SET_BLOCKLEN   16

Definition at line 64 of file mmc.h.

#define MMC_SET_WRITE_PROT   28

Definition at line 68 of file mmc.h.

#define MMC_STARTBLOCK_MWRITE   0xFC

Definition at line 93 of file mmc.h.

#define MMC_STARTBLOCK_READ   0xFE

Definition at line 91 of file mmc.h.

Referenced by MMC_Read().

#define MMC_STARTBLOCK_WRITE   0xFE

Definition at line 92 of file mmc.h.

#define MMC_STOPTRAN_WRITE   0xFD

Definition at line 96 of file mmc.h.

#define MMC_TAG_ERARE_GROUP_END   36

Definition at line 75 of file mmc.h.

#define MMC_TAG_ERASE_GROUP_START   35

Definition at line 74 of file mmc.h.

#define MMC_TAG_SECTOR_END   33

Definition at line 72 of file mmc.h.

#define MMC_TAG_SECTOR_START   32

Definition at line 71 of file mmc.h.

#define MMC_UNTAG_ERASE_GROUP   37

Definition at line 76 of file mmc.h.

#define MMC_UNTAG_SECTOR   34

Definition at line 73 of file mmc.h.

#define MMC_WRITE_BLOCK   24

Definition at line 66 of file mmc.h.

#define SPI_DDR   DDRB

Definition at line 52 of file mmc.h.

Referenced by SpiInit().

#define SPI_MISO   PB3

Definition at line 56 of file mmc.h.

Referenced by SpiInit().

#define SPI_MOSI   PB2

Definition at line 55 of file mmc.h.

Referenced by SpiInit().

#define SPI_PORT   PORTB

Definition at line 51 of file mmc.h.

#define SPI_SCK   PB1

Definition at line 54 of file mmc.h.

Referenced by SpiInit().

#define SPI_SS   PB0

Definition at line 53 of file mmc.h.

Referenced by SpiInit().


Function Documentation

uint16 MMC_Check ( void  )

Send the get status command to the MMC and returns the result.

Returns:
2 byte value from MMC status register

Definition at line 281 of file mmc.c.

References MMC_CS, MMC_PORT, MMC_SEND_STATUS, MMCCommand(), MMCGet(), SBI, and SpiByte().

Referenced by handle_mmc(), and MMC_tester().

Here is the call graph for this function:

char MMC_Detect ( void  )

Checks if there is a memory card in the slot This requires a pull down resistor on the CS line of about 100K.

Returns:
FALSE card not detected
TRUE card detected

Definition at line 251 of file mmc.c.

References FALSE, MMC_CS, MMC_DDR, MMC_PIN, MMC_PORT, and TRUE.

Referenced by handle_mmc().

uint8 MMC_Read ( uint32  lba)

Grab the Serial number & info from the card.

Returns status response from card. if successful CID is in mmc_scratch[1..16]

Returns:
byte response from the CID command Retrieves the CSD Register from the mmc and stores it in mmc_scratch[1..17]
Status response from cmd Calculates the capacity of the MMC in blocks
uint32 capacity of MMC in blocks or -1 in error; Read the OEM/Manufcatures MMC Name into the scratchpad.
status of MMC from SEND_CID cmd.

Definition at line 422 of file mmc.c.

References CBI, MMC_CS, MMC_PORT, MMC_READ_SINGLE_BLOCK, mmc_sbuf, MMC_SEND_STATUS, MMC_STARTBLOCK_READ, MMCCommand(), MMCGet(), SBI, and SpiByte().

Referenced by FAT_tester(), init_HW(), and MMC_tester().

Here is the call graph for this function:

uint8 MMC_Reset ( void  )

Perform a Hardware then software reset of the MMC.

Returns:
00 if reset successful
FF if reset unsuccessful

Definition at line 200 of file mmc.c.

References MMC_CS, MMC_PORT, MMCCommand(), MMCGet(), SBI, and SpiByte().

Referenced by FAT_tester(), handle_mmc(), init_mmc_fat(), MMC_tester(), and streaming().

Here is the call graph for this function:

uint8 SpiByte ( unsigned char  byte)

Main SPI routine

  • transmits a byte and receives a byte simultaneously
  • received byte is returned
  • if you only want to read a byte, put a dummy (say 0xff) in the transmit slot.

Parameters:
byteByte to transmit
Returns:
byte clocked in during transmit

Definition at line 105 of file mmc.c.

Referenced by MMC_Check(), MMC_Read(), MMC_Reset(), MMCCommand(), and MMCGet().

void SpiInit ( void  )

Setup Pin configuration of SPI bus for the AVR.

Definition at line 65 of file mmc.c.

References CBI, MMC_CS, MMC_DDR, MMC_PORT, SBI, SPI_DDR, SPI_MISO, SPI_MOSI, SPI_SCK, and SPI_SS.

Referenced by init_HW().


Variable Documentation

512 byte sector buffer in internal RAM

Definition at line 58 of file mmc.c.

32 byte Scratch buffer for CSD/CID/ ops

Definition at line 59 of file mmc.c.

Referenced by FAT_tester(), init_HW(), and MMC_tester().

 All Files Functions Variables Typedefs Enumerations Enumerator Defines