ButterflyMP3

mmc.c File Reference

MultiMedia Card low level Functions. More...

#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include "types.h"
#include "mmc.h"
#include "delay.h"
#include "main.h"
#include "uart.h"
#include "vs1001.h"
Include dependency graph for mmc.c:

Go to the source code of this file.

Defines

#define MMC_C

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 MMCGet (void)
 Retrieve data from then MMC.
void MMCCommand (unsigned char command, uint8 px, uint8 py, uint8 pz)
 Send a control command to the MMC.
uint8 MMC_Reset (void)
 Perform a Hardware then software reset of the MMC.
uint8 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.
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.

Variables

uint8 mmc_sbuf [512]
 512 byte sector buffer in internal RAM
uint8 mmc_scratch [32]
 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.c,v 1.18 2009/01/10 22:40:12 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.c.


Define Documentation

#define MMC_C

Definition at line 50 of file mmc.c.


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:

uint8 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:

void MMCCommand ( unsigned char  command,
uint8  px,
uint8  py,
uint8  pz 
)

Send a control command to the MMC.

send one byte of 0xff, then issue command + params + (fake) crc eat up the one command of nothing after the CRC Clears the MMC_CS and BSYNC_PIN lines. MMC must be de-selected outside of this code !!

Parameters:
commandMMC Command to be sent
pxfirst byte of command parameters
pysecond byte of command parameters
pzthird byte of command parameters

Definition at line 155 of file mmc.c.

References CBI, MMC_CS, MMC_PORT, and SpiByte().

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

Here is the call graph for this function:

uint8 MMCGet ( void  )

Retrieve data from then MMC.

Pings the card until it gets a non-0xff value

Returns:
first byte of data usualy a data token.

Definition at line 130 of file mmc.c.

References SpiByte().

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

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.

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

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