ButterflyMP3
|
MultiMedia Card low level Functions. More...
#include "types.h"
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
| |
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 |
MultiMedia Card low level Functions.
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 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_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_READ_SINGLE_BLOCK 17 |
Definition at line 65 of file mmc.h.
Referenced by MMC_Read().
#define MMC_SEND_STATUS 13 |
Definition at line 63 of file mmc.h.
Referenced by MMC_Check(), and MMC_Read().
#define MMC_STARTBLOCK_READ 0xFE |
Definition at line 91 of file mmc.h.
Referenced by MMC_Read().
uint16 MMC_Check | ( | void | ) |
Send the get status command to the MMC and returns the result.
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().
char MMC_Detect | ( | void | ) |
Grab the Serial number & info from the card.
Returns status response from card. if successful CID is in mmc_scratch[1..16]
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().
uint8 MMC_Reset | ( | void | ) |
Perform a Hardware then software reset of the MMC.
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().
uint8 SpiByte | ( | unsigned char | byte | ) |
Main SPI routine
byte | Byte to transmit |
Definition at line 105 of file mmc.c.
Referenced by MMC_Check(), MMC_Read(), MMC_Reset(), MMCCommand(), and MMCGet().
void SpiInit | ( | void | ) |
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().