00001
00002
00003
00004
00005
00006
00007
00008
00016 #ifndef MICROSD_H
00017 #define MICROSD_H
00018
00019
00020
00021 #include "xspi_l.h"
00022 #include "microsd.h"
00023
00024
00025
00026 #define SD_STATUS_READY_MASK 0x01
00027 #define SD_STATUS_LEGACY_MASK 0x02
00028 #define SD_STATUS_HIGHCAP_MASK 0x04
00029 #define SD_STATUS_FAT_READY_MASK 0x10
00030 #define SD_STATUS_UNUSABLE_MASK 0x80
00031
00032 #define GO_IDLE_STATE 0
00033 #define SEND_IF_COND 8
00034 #define SET_BLOCKLEN 16
00035 #define READ_SINGLE_BLOCK 17
00036 #define WRITE_BLOCK 24
00037 #define SD_SEND_OP_COND 41
00038 #define APP_CMD 55
00039 #define READ_OCR 58
00040 #define CRC_ON_OFF 59
00041
00042 #define R1_IDLE_STATE 0x01
00043 #define R1_READY_STATE 0x00
00044 #define START_TOKEN 0xFE
00045
00046 #define R3_RESPONSE_SIZE 4
00047 #define R7_RESPONSE_SIZE 4
00048
00049 #define G_POLY7 0x89 // x^7 + x^3 + 1
00050 #define G_POLY16 0x1021 // (x^16) + x^12 + x^5 + 1
00051
00052
00053
00054
00055 typedef struct {
00056 Xuint32 SpiBaseAddr;
00057 Xuint8 Status;
00058 } Microsd;
00059
00060
00061
00070 #define Microsd_GetResponse(SDPtr) Microsd_GetRespToken(SDPtr, NULL, 0)
00071
00072
00081 #define Microsd_ReadSector(SDPtr, addrBySector, dataBuff) \
00082 Microsd_ReadBlock(SDPtr, (addrBySector)*SECTOR_SIZE, dataBuff, SECTOR_SIZE)
00083
00084
00085
00086
00087 Xuint8 Microsd_crc7(Xuint8 *MessBuff);
00088 Xuint16 Microsd_crc16(Xuint8 *MessBuff, unsigned int len);
00089 Xuint8 Microsd_GetRespToken(Microsd *SDPtr, Xuint8 *RecvBuff,
00090 unsigned int NumBytes);
00091 void Microsd_Initialize(Microsd *SDPtr, Xuint32 BaseAddr);
00092 void Microsd_FlushRxFifo(Microsd *SDPtr);
00093 Xuint8 Microsd_ReadBlock(Microsd *SDPtr, Xuint32 addr, Xuint8 data[], int len);
00094 Xuint8 Microsd_SendCmd(Microsd *SDPtr, Xuint8 cmd_idx, Xuint32 arg);
00095 Xuint8 Microsd_SetSpiMode(Microsd *SDPtr);
00096 void Microsd_SpiTransfer(Microsd *SDPtr, Xuint8 SendBuff[], Xuint8 RecvBuff[],
00097 unsigned int NumBytes);
00098
00099 #endif