?? sd.h
字號:
#include "LPC2294.h"
typedef unsigned char uint8;
typedef signed char int8;
typedef unsigned short uint16;
typedef signed short int16;
typedef unsigned int uint32;
typedef signed int int32;
typedef float fp32;
typedef double fp64;
typedef unsigned char INT8U;
typedef signed char INT8;
typedef unsigned short INT16U;
typedef signed short INT16;
typedef unsigned int INT32U;
typedef signed int INT32;
typedef float FP32;
typedef double FP64;
#define CMD_SD_INIT 0x00 /* SD卡初始化卡命令 */
#define CMD_SD_READ 0x01 /* SD卡讀命令 */
#define CMD_SD_WRITE 0x02 /* SD卡寫命令 */
#define CMD_SD_ERASE 0x03 /* SD卡擦除命令 */
#define CMD_DATA_TRANS 0x04 /* 將sd_buf中的數據發送到PC機 */
#define CMD_DATA_RECV 0x05 /* 接收來自串口的數據,并放入sd_buf中 */
#define TRUE 1
#define FALSE 0
#define ON 1
#define OFF 0
#define MSK_IDLE 0x01
#define MSK_ERASE_RST 0x02
#define MSK_ILL_CMD 0x04
#define MSK_CRC_ERR 0x08
#define MSK_ERASE_SEQ_ERR 0x10
#define MSK_ADDR_ERR 0x20
#define MSK_PARAM_ERR 0x40
#define MSK_TOK_ERROR 0x01
#define MSK_TOK_CC_ERROR 0x02
#define MSK_TOK_ECC_FAILED 0x04
#define MSK_TOK_CC_OUTOFRANGE 0x08
#define MSK_TOK_CC_LOCKED 0x10
#define SD_TOK_READ_STARTBLOCK 0xFE
#define SD_TOK_WRITE_STARTBLOCK 0xFE
#define SD_TOK_READ_STARTBLOCK_M 0xFE
#define SD_TOK_WRITE_STARTBLOCK_M 0xFC
#define SD_TOK_STOP_MULTI 0xFD
#define SD_RESP_DATA_MSK 0x0F //數據響應掩碼
#define SD_RESP_DATA_ACCETPTED 0x05 //數據被接受
#define SD_RESP_DATA_REJECT_CRC 0x0B //由于CRC錯誤而被拒絕
#define SD_RESP_DATA_REJECT_WRITE 0x0D //由于寫錯誤而被拒絕
#define SD_WAIT_READ 0x00 //讀等待
#define SD_WAIT_WRITE 0x01 //寫等待
#define SD_WAIT_ERASE 0x02 //擦除等待
#define SD_READREG_TIMEOUT 8
/******************************** 基本命令集 Basic command set **************************/
/* 復位SD 卡 Reset cards to idle state */
#define CMD0 0
#define CMD0_R 1
/* 讀OCR寄存器 Read the OCR (MMC mode, do not use for SD cards) */
#define CMD1 1
#define CMD1_R 1
/* 讀CSD寄存器 Card sends the CSD */
#define CMD9 9
#define CMD9_R 1
/* 讀CID寄存器 Card sends CID */
#define CMD10 10
#define CMD10_R 1
/* 停止讀多塊時的數據傳輸 Stop a multiple block (stream) read/write operation */
#define CMD12 12
#define CMD12_R 2
/* 讀 Card_Status 寄存器 Get the addressed card's status register */
#define CMD13 13
#define CMD13_R 3
/***************************** 塊讀命令集 Block read commands **************************/
/* 設置塊的長度 Set the block length */
#define CMD16 16
#define CMD16_R 1
/* 讀單塊 Read a single block */
#define CMD17 17
#define CMD17_R 1
/* 讀多塊,直至主機發送CMD12為止 Read multiple blocks until a CMD12 */
#define CMD18 18
#define CMD18_R 1
/***************************** 塊寫命令集 Block write commands *************************/
/* 寫單塊 Write a block of the size selected with CMD16 */
#define CMD24 24
#define CMD24_R 1
/* 寫多塊 Multiple block write until a CMD12 */
#define CMD25 25
#define CMD25_R 1
/* 寫CSD寄存器 Program the programmable bits of the CSD */
#define CMD27 27
#define CMD27_R 1
/***************************** 寫保護 Write protection *****************************/
/* Set the write protection bit of the addressed group */
#define CMD28 28
#define CMD28_R 2
/* Clear the write protection bit of the addressed group */
#define CMD29 29
#define CMD29_R 2
/* Ask the card for the status of the write protection bits */
#define CMD30 30
#define CMD30_R 1
/***************************** 擦除命令 Erase commands *******************************/
/* 設置擦除塊的起始地址 Set the address of the first write block to be erased */
#define CMD32 32
#define CMD32_R 1
/* 設置擦除塊的終止地址 Set the address of the last write block to be erased */
#define CMD33 33
#define CMD33_R 1
/* 擦除所選擇的塊 Erase the selected write blocks */
#define CMD38 38
#define CMD38_R 2
/***************************** 鎖卡命令 Lock Card commands ***************************/
/* 設置/復位密碼或上鎖/解鎖卡 Set/reset the password or lock/unlock the card */
#define CMD42 42
#define CMD42_R 2
/* Commands from 42 to 54, not defined here */
/***************************** 應用命令 Application-specific commands ****************/
/* 禁止下一個命令為應用命令 Flag that the next command is application-specific */
#define CMD55 55
#define CMD55_R 1
/* 應用命令的通用I/O General purpose I/O for application-specific commands */
#define CMD56 56
#define CMD56_R 1
/* 讀OCR寄存器 Read the OCR (SPI mode only) */
#define CMD58 58
#define CMD58_R 4
/* 使能或禁止 CRC Turn CRC on or off */
#define CMD59 59
#define CMD59_R 1
/***************************** 應用命令 Application-specific commands ***************/
/* 獲取 SD Status寄存器 Get the SD card's status */
#define ACMD13 13
#define ACMD13_R 3
/* 得到已寫入卡中的塊的個數 Get the number of written write blocks (Minus errors ) */
#define ACMD22 22
#define ACMD22_R 1
/* 在寫之前,設置預先擦除的塊的個數 Set the number of write blocks to be pre-erased before writing */
#define ACMD23 23
#define ACMD23_R 1
/* 讀取OCR寄存器 Get the card's OCR (SD mode) */
#define ACMD41 41
#define ACMD41_R 1
/* 連接/斷開CD/DATA[3]引腳上的上拉電阻 Connect or disconnect the 50kOhm internal pull-up on CD/DAT[3] */
#define ACMD42 42
#define ACMD42_R 1
/* 讀取SCR寄存器 Get the SD configuration register */
#define ACMD51 51
#define ACMD51_R 1
#define SPI1_CS (0x01 << 21)
#define SPI1_CS_GPIO() PINSEL1 &= ~(0x03 << 10)
#define SPI1_CS_OUT() IO0DIR |= SPI1_CS
#define SPI1_CS_SET() IO0SET |= SPI1_CS
#define SPI1_CS_CLR() IO0CLR |= SPI1_CS
#define SPI1_SCK (0x01 << 17)
#define SPI1_SCK_GPIO() PINSEL1 &= ~(0x03 << 2)
#define SPI1_SCK_OUT() IO0DIR |= SPI1_SCK
#define SPI1_SCK_SET() IO0SET |= SPI1_SCK
#define SPI1_SCK_CLR() IO0CLR |= SPI1_SCK
#define SPI1_MISO (0x01 << 18)
#define SPI1_MISO_GPIO() PINSEL1 &= ~(0x03 << 4)
#define SPI1_MISO_OUT() IO0DIR &=~(SPI1_MISO)
#define SPI1_MISO_SET() IO0SET |= SPI1_MISO
#define SPI1_MISO_CLR() IO0CLR |= SPI1_MISO
#define SPI1_MOSI (0x01 << 19)
#define SPI1_MOSI_GPIO() PINSEL1 &= ~(0x03 << 6)
#define SPI1_MOSI_OUT() IO0DIR |= SPI1_MOSI
#define SPI1_MOSI_SET() IO0SET |= SPI1_MOSI
#define SPI1_MOSI_CLR() IO0CLR |= SPI1_MOSI
void SPI1_Init(INT8U speed);
INT8U SPI1_SrByte(INT8U byte);
INT8U SD_WriteCom(uint8 cmd,uint32 arg);
INT8U SD_ReadBlock(INT32U address,INT8U *SD_BUFFER);
INT8U SD_WriteBlock(INT32U len, INT8U *sendbuf);
INT8U SD_Init(void);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -