/* SD-Karten Interface */ #ifndef SDIOINCLUDED #define SDIOINCLUDED struct TSD_CSD /* Card Specific Data */ { volatile byte CSDStruct; /* CSD structure */ volatile byte SysSpecVersion; /* System specification version */ volatile byte Reserved1; /* Reserved */ volatile byte TAAC; /* Data read access-time 1 */ volatile byte NSAC; /* Data read access-time 2 in CLK cycles */ volatile byte MaxBusClkFrec; /* Max. bus clock frequency */ volatile word CardComdClasses; /* Card command classes */ volatile byte RdBlockLen; /* Max. read data block length */ volatile byte PartBlockRead; /* Partial blocks for read allowed */ volatile byte WrBlockMisalign; /* Write block misalignment */ volatile byte RdBlockMisalign; /* Read block misalignment */ volatile byte DSRImpl; /* DSR implemented */ volatile byte Reserved2; /* Reserved */ volatile dword DeviceSize; /* Device Size */ volatile byte MaxRdCurrentVDDMin; /* Max. read current @ VDD min */ volatile byte MaxRdCurrentVDDMax; /* Max. read current @ VDD max */ volatile byte MaxWrCurrentVDDMin; /* Max. write current @ VDD min */ volatile byte MaxWrCurrentVDDMax; /* Max. write current @ VDD max */ volatile byte DeviceSizeMul; /* Device size multiplier */ volatile byte EraseGrSize; /* Erase group size */ volatile byte EraseGrMul; /* Erase group size multiplier */ volatile byte WrProtectGrSize; /* Write protect group size */ volatile byte WrProtectGrEnable; /* Write protect group enable */ volatile byte ManDeflECC; /* Manufacturer default ECC */ volatile byte WrSpeedFact; /* Write speed factor */ volatile byte MaxWrBlockLen; /* Max. write data block length */ volatile byte WriteBlockPaPartial; /* Partial blocks for write allowed */ volatile byte Reserved3; /* Reserded */ volatile byte ContentProtectAppli; /* Content protection application */ volatile byte FileFormatGrouop; /* File format group */ volatile byte CopyFlag; /* Copy flag (OTP) */ volatile byte PermWrProtect; /* Permanent write protection */ volatile byte TempWrProtect; /* Temporary write protection */ volatile byte FileFormat; /* File Format */ volatile byte ECC; /* ECC code */ volatile byte CSD_CRC; /* CSD CRC */ volatile byte Reserved4; /* always 1*/ }; struct TSD_CID /*Card Identification Data*/ { byte ManufacturerID; /* ManufacturerID */ word OEM_AppliID; /* OEM/Application ID */ char ProdName[6]; /* Product Name 5 chars */ char ProdRev[4]; /* Product Revision 3 chars */ dword ProdSN; /* Product Serial Number */ byte Reserved1; /* Reserved1 */ word ManufactDate; /* Manufacturing Date */ byte CID_CRC; /* CID CRC */ byte Reserved2; /* always 1 */ }; #define TSDCARDINFO struct TSDCardInfo struct TSDCardInfo { struct TSD_CSD SD_csd; struct TSD_CID SD_cid; dword CardCapacity; /* Card Capacity */ dword CardBlockSize; /* Card Block Size */ word RCA; byte CardType; bool is_readonly; }; /*** Definition der allgemeinen SDIO Fehlernummern *****/ #define SD_OK 0 /* alles in Ordnung */ #define SD_CMD_CRC_FAIL 1 /* Command response received (but CRC check failed) */ #define SD_DATA_CRC_FAIL 2 /* Data bock sent/received (CRC check Failed) */ #define SD_CMD_RSP_TIMEOUT 3 /* Command response timeout */ #define SD_DATA_TIMEOUT 4 /* Data time out */ #define SD_TX_UNDERRUN 5 /* Transmit FIFO under-run */ #define SD_RX_OVERRUN 6 /* Receive FIFO over-run */ #define SD_START_BIT_ERR 7 /* Start bit not detected on all data signals in widE bus mode */ #define SD_CMD_OUT_OF_RANGE 8 /* CMD's argument was out of range.*/ #define SD_ADDR_MISALIGNED 9 /* Misaligned address */ #define SD_BLOCK_LEN_ERR 10 /* Transferred block length is not allowed for the card or the number of transferred bytes does not match the block length */ #define SD_ERASE_SEQ_ERR 11 /* An error in the sequence of erase command occurs.*/ #define SD_BAD_ERASE_PARAM 12 /* An Invalid selection for erase groups */ #define SD_WRITE_PROT_VIOLATION 13 /* Attempt to program a write protect block */ #define SD_LOCK_UNLOCK_FAILED 14 /* Sequence or password error has been detected in unlock command or if there was an attempt to access a locked card */ #define SD_COM_CRC_FAILED 15 /* CRC check of the previous command failed */ #define SD_ILLEGAL_CMD 16 /* Command is not legal for the card state */ #define SD_CARD_ECC_FAILED 17 /* Card internal ECC was applied but failed to correct the data */ #define SD_CC_ERROR 18 /* Internal card controller error */ #define SD_GENERAL_UNKNOWN_ERROR 19 /* General or Unknown error */ #define SD_STREAM_READ_UNDERRUN 20 /* The card could not sustain data transfer in stream read operation. */ #define SD_STREAM_WRITE_OVERRUN 21 /* The card could not sustain data programming in stream mode */ #define SD_CID_CSD_OVERWRITE 22 /* CID/CSD overwrite error */ #define SD_WP_ERASE_SKIP 23 /* only partial address space was erased */ #define SD_CARD_ECC_DISABLED 24 /* Command has been executed without using internal ECC */ #define SD_ERASE_RESET 25 /* Erase sequence was cleared before executing because an out of erase sequence command was received */ #define SD_AKE_SEQ_ERROR 26 /* Error in sequence of authentication. */ #define SD_INVALID_VOLTRANGE 27 #define SD_ADDR_OUT_OF_RANGE 28 #define SD_SWITCH_ERROR 29 #define SD_SDIO_DISABLED 30 #define SD_SDIO_FUNCTION_BUSY 31 #define SD_SDIO_FUNCTION_FAILED 32 #define SD_SDIO_UNKNOWN_FUNCTION 33 /* Standard error defines */ #define SD_INTERNAL_ERROR 100 #define SD_NOT_CONFIGURED 101 #define SD_REQUEST_PENDING 102 #define SD_REQUEST_NOT_APPLICABLE 103 #define SD_INVALID_PARAMETER 104 #define SD_UNSUPPORTED_FEATURE 105 #define SD_UNSUPPORTED_HW 106 #define SD_ERROR 107 /******* Konstanten **********************/ #define SD_DMA_MODE 0 #define SD_INTERRUPT_MODE 1 #define SD_POLLING_MODE 2 /* Supported Memory Cards */ #define no_SD 0 /* keine Karte detektiert */ #define SD_err -1 /* war Fehler beim SD Erkennen */ #define SD1_1 1 /* SDIO_STD_CAPACITY_SD_CARD_V1_1 */ #define SD2_0 2 /* SDIO_STD_CAPACITY_SD_CARD_V2_0 */ #define SDHC 3 /* SDIO_HIGH_CAPACITY_SD_CARD */ #define MMC 4 /* SDIO_MULTIMEDIA_CARD */ #define SD_IO 5 /* SDIO_SECURE_DIGITAL_IO_CARD z.Z. nicht detektiert */ #define SDHSMM 6 /* SDIO_HIGH_SPEED_MULTIMEDIA_CARD z.Z. nicht detektiert */ #define SDCOMBO 7 /* SDIO_SECURE_DIGITAL_IO_COMBO_CARD z.Z. nicht detektiert */ #define SDHC_MMC 8 /* SDIO_HIGH_CAPACITY_MMC_CARD z.Z. nicht detektiert */ /* Variablen */ extern dword CSD_Tab[4]; /* Card Specific Data */ extern dword CID_Tab[4]; /* Card Identification Data */ extern dword RCA; /* momentane Card Adresse */ extern dword SCR; /* SDCard Conf Register */ extern dword SCR2; /* OEM SDCard Conf Register */ extern dword OCR; /* mit ACMD41 gelesen */ extern dword TRSTATUS; /* letzter Status bei Rd+Wr */ /* zu TRSTATUS: wird von den I/O-Routinen nie gelöscht, sondern nur immer Bits dazugesetzt. Wer Fehler eingrenzen will, muß also vor allen Transfers TRSTATUS ablöschen. zusätzliche Bits in TRSTATUS sind: */ #define BadCardError (1<<12) #define WriteOnROnly (1<<13) #define BadCardState (1<<14) #define Bls512Error (1<<15) #define ErrWrCommand (1<<16) #define ErrRdCommand (1<<17) #define TranTimeout (1<<18) extern dword BlockErrors; extern byte IntMerk; extern TSDCARDINFO SDCardInfo; /* exportierte Funktionen */ extern bool SD_DriveInit (void); extern bool SD_ReadBlock (dword SecNum, dword *readbuff); extern bool SD_WriteBlock (dword SecNum, dword *writebuff); #endif