Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
248 Kevin 1
// *************************************************************************************
2
//
3
// Filename:  mmc.h: 
4
// Declarations for Communication with the MMC (see mmc.c) in unprotected SPI mode.
5
//
6
// Version 1.1
7
//    added ul declaration in macros mmcWriteSector and mmcReadSector
8
// *************************************************************************************
9
 
10
#ifndef _MMCLIB_H
11
#define _MMCLIB_H
12
 
13
 
14
// macro defines
15
#define HIGH(a) ((a>>8)&0xFF)               // high byte from word
16
#define LOW(a)  (a&0xFF)                    // low byte from word
17
 
18
#define MMC_SECTOR_SIZE 512ul
19
 
20
// Tokens (necessary  because at NPO/IDLE (and CS active) only 0xff is on the data/command line)
21
#define MMC_START_DATA_BLOCK_TOKEN          0xfe   // Data token start byte, Start Single Block Read
22
#define MMC_START_DATA_MULTIPLE_BLOCK_READ  0xfe   // Data token start byte, Start Multiple Block Read
23
#define MMC_START_DATA_BLOCK_WRITE          0xfe   // Data token start byte, Start Single Block Write
24
#define MMC_START_DATA_MULTIPLE_BLOCK_WRITE 0xfc   // Data token start byte, Start Multiple Block Write
25
#define MMC_STOP_DATA_MULTIPLE_BLOCK_WRITE  0xfd   // Data toke stop byte, Stop Multiple Block Write
26
 
27
 
28
// an affirmative R1 response (no errors)
29
#define MMC_R1_RESPONSE       0x00
30
 
31
 
32
// this variable will be used to track the current block length
33
// this allows the block length to be set only when needed
34
// unsigned long _BlockLength = 0;
35
 
36
// error/success codes
37
#define MMC_SUCCESS           0x00
38
#define MMC_BLOCK_SET_ERROR   0x01
39
#define MMC_RESPONSE_ERROR    0x02
40
#define MMC_DATA_TOKEN_ERROR  0x03
41
#define MMC_INIT_ERROR        0x04
42
#define MMC_CRC_ERROR         0x10
43
#define MMC_WRITE_ERROR       0x11
44
#define MMC_OTHER_ERROR       0x12
45
#define MMC_TIMEOUT_ERROR     0xFF
46
 
47
 
48
// commands: first bit 0 (start bit), second 1 (transmission bit); CMD-number + 0ffsett 0x40
49
#define MMC_GO_IDLE_STATE          0x40     //CMD0
50
#define MMC_SEND_OP_COND           0x41     //CMD1
51
#define MMC_READ_CSD               0x49     //CMD9
52
#define MMC_SEND_CID               0x4a     //CMD10
53
#define MMC_STOP_TRANSMISSION      0x4c     //CMD12
54
#define MMC_SEND_STATUS            0x4d     //CMD13
55
#define MMC_SET_BLOCKLEN           0x50     //CMD16 Set block length for next read/write
56
#define MMC_READ_SINGLE_BLOCK      0x51     //CMD17 Read block from memory
57
#define MMC_READ_MULTIPLE_BLOCK    0x52     //CMD18
58
#define MMC_CMD_WRITEBLOCK         0x54     //CMD20 Write block to memory
59
#define MMC_WRITE_BLOCK            0x58     //CMD24
60
#define MMC_WRITE_MULTIPLE_BLOCK   0x59     //CMD25
61
#define MMC_WRITE_CSD              0x5b     //CMD27 PROGRAM_CSD
62
#define MMC_SET_WRITE_PROT         0x5c     //CMD28
63
#define MMC_CLR_WRITE_PROT         0x5d     //CMD29
64
#define MMC_SEND_WRITE_PROT        0x5e     //CMD30
65
#define MMC_TAG_SECTOR_START       0x60     //CMD32
66
#define MMC_TAG_SECTOR_END         0x61     //CMD33
67
#define MMC_UNTAG_SECTOR           0x62     //CMD34
68
#define MMC_TAG_EREASE_GROUP_START 0x63     //CMD35
69
#define MMC_TAG_EREASE_GROUP_END   0x64     //CMD36
70
#define MMC_UNTAG_EREASE_GROUP     0x65     //CMD37
71
#define MMC_EREASE                 0x66     //CMD38
72
#define MMC_READ_OCR               0x67     //CMD39
73
#define MMC_CRC_ON_OFF             0x68     //CMD40
74
 
75
 
76
// mmc init
77
char mmcInit(void);
78
 
79
// check if MMC card is present
80
char mmcPing(void);
81
 
82
// send command to MMC
83
void mmcSendCmd (const char cmd, unsigned long data, const char crc);
84
 
85
// set MMC in Idle mode
86
char mmcGoIdle();
87
 
88
// set MMC block length of count=2^n Byte
89
char mmcSetBlockLength (const unsigned long);
90
 
91
// read a size Byte big block beginning at the address.
92
char mmcReadBlock(const unsigned long address, const unsigned long count, unsigned char *pBuffer);
93
#define mmcReadSector(sector, pBuffer) mmcReadBlock(sector*MMC_SECTOR_SIZE, MMC_SECTOR_SIZE, pBuffer)
94
 
95
// write a size Byte big block beginning at the (aligned) address
96
char mmcWriteBlock (const unsigned long address, const unsigned long count, unsigned char *pBuffer);
97
#define mmcWriteSector(sector, pBuffer) mmcWriteBlock(sector*MMC_SECTOR_SIZE, MMC_SECTOR_SIZE, pBuffer)
98
 
99
// Read Register arg1 with Length arg2 (into the buffer)
100
char mmcReadRegister(const char, const unsigned char, unsigned char *pBuffer);
101
 
102
// Read the Card Size from the CSD Register
103
unsigned long mmcReadCardSize(void);
104
 
105
 
106
#endif /* _MMCLIB_H */