00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00055
00056 #ifndef MMC_H
00057 #define MMC_H
00058
00059 #include "global.h"
00060 #include "task.h"
00061 #include "MessageQueue.h"
00062
00063
00064
00065 #define MMC_GO_IDLE_STATE 0 //< initialize card to SPI-type access
00066 #define MMC_SEND_OP_COND 1 //< set card operational mode
00067 #define MMC_SEND_CSD 9 //< get card's CSD
00068 #define MMC_SEND_CID 10 //< get card's CID
00069 #define MMC_SEND_STATUS 13
00070 #define MMC_SET_BLOCKLEN 16
00071 #define MMC_READ_SINGLE_BLOCK 17
00072 #define MMC_WRITE_BLOCK 24
00073 #define MMC_PROGRAM_CSD 27
00074 #define MMC_SET_WRITE_PROT 28
00075 #define MMC_CLR_WRITE_PROT 29
00076 #define MMC_SEND_WRITE_PROT 30
00077 #define MMC_TAG_SECTOR_START 32
00078 #define MMC_TAG_SECTOR_END 33
00079 #define MMC_UNTAG_SECTOR 34
00080 #define MMC_TAG_ERASE_GROUP_START 35
00081 #define MMC_TAG_ERARE_GROUP_END 36
00082 #define MMC_UNTAG_ERASE_GROUP 37
00083 #define MMC_ERASE 38
00084 #define MMC_SEND_OP_COND_A 41 //alternate OP_COND command
00085 #define MMC_APP_CMD 55 //application specific command
00086 #define MMC_CRC_ON_OFF 59
00087 // R1 Response bit-defines
00088 #define MMC_R1_BUSY 0x80
00089 #define MMC_R1_PARAMETER 0x40
00090 #define MMC_R1_ADDRESS 0x20
00091 #define MMC_R1_ERASE_SEQ 0x10
00092 #define MMC_R1_COM_CRC 0x08
00093 #define MMC_R1_ILLEGAL_COM 0x04
00094 #define MMC_R1_ERASE_RESET 0x02
00095 #define MMC_R1_IDLE_STATE 0x01
00096
00097 #define MMC_R2_CSD_OVERWRITE 0x8000
00098 #define MMC_R2_ERASE_PARAM 0x4000
00099 #define MMC_R2_WP 0x2000
00100 #define MMC_R2_ECC_FAILED 0x1000
00101 #define MMC_R2_CC_FAILED 0x0800
00102 #define MMC_R2_ERROR 0x0400
00103 #define MMC_R2_WP_ERASESKIPPED 0x0200
00104 #define MMC_R2_CARD_LOCKED 0x0100
00105
00106
00107 #define MMC_STARTBLOCK_READ 0xFE
00108 #define MMC_STARTBLOCK_WRITE 0xFE
00109 #define MMC_STARTBLOCK_MWRITE 0xFC
00110
00111 #define MMC_STOPTRAN_WRITE 0xFD
00112
00113 #define MMC_DE_MASK 0x1F
00114 #define MMC_DE_ERROR 0x01
00115 #define MMC_DE_CC_ERROR 0x02
00116 #define MMC_DE_ECC_FAIL 0x04
00117 #define MMC_DE_OUT_OF_RANGE 0x04
00118 #define MMC_DE_CARD_LOCKED 0x04
00119
00120 #define MMC_DR_MASK 0x1F
00121 #define MMC_DR_ACCEPT 0x05
00122 #define MMC_DR_REJECT_CRC 0x0B
00123 #define MMC_DR_REJECT_WRITE_ERROR 0x0D
00124
00125
00126
00127
00128
00129 #define MMC_CMD_RESET 0
00130 #define MMC_CMD_RDSECTOR 1
00131 #define MMC_CMD_WDSECTOR 2
00132 #define MMC_CMD_STATUS 3
00133 #define MMC_CMD_WRITE_FILE 4
00134
00135 extern MESSAGE_QUEUE *SDcardMSG;
00136 extern TCB Tmmc;
00137
00138
00141 extern void mmcInit(void);
00142
00145 extern u08 mmcReset(void);
00146
00149 extern u08 mmcSendCommand(u08 cmd, u32 arg);
00150
00153 extern u08 mmcRead(u32 sector, u08* buffer);
00154
00157 extern u08 mmcWrite(u32 sector, u08* buffer);
00158
00161 extern u08 mmcCommand(u08 cmd, u32 arg, char *b);
00162 extern unsigned short mmcSendStatus(void);
00163 extern u08 mmcSendSEND_OP_COND(u32 *ocr);
00164 extern u08 mmcSendSetBlockLen(unsigned short len);
00165
00166
00167
00168
00169
00170 extern void MsgMMCReset(void);
00171 extern void MsgMMCReadSector(unsigned long sector);
00172 extern void MsgMMCWriteSector(unsigned long sector,char *b,int n);
00173 extern void MsgMMCSendStatus(void);
00174 extern void MsgMMCWriteTestFile(void);
00175
00176 #endif
00177