1.5wuling_zhuanjietou/SYSTEM/sd.h

129 lines
3.2 KiB
C
Raw Normal View History

2024-10-17 01:06:51 +00:00
/*-------------------------------------------------*/
/* SD<53><44>ͷ<EFBFBD>ļ<EFBFBD> */
/*-------------------------------------------------*/
#ifndef _SD_H_
#define _SD_H_
#include "stm32f10x.h"
#include "stdio.h"
#include "string.h"
// SD<53><44><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>
#define SD_TYPE_ERR 0X00
#define SD_TYPE_MMC 0X01
#define SD_TYPE_V1 0X02
#define SD_TYPE_V2 0X04
#define SD_TYPE_V2HC 0X06
// SD<53><44>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>
#define CMD0 0 //<2F><><EFBFBD><EFBFBD>λ
#define CMD1 1
#define CMD8 8 //<2F><><EFBFBD><EFBFBD>8 <20><>SEND_IF_COND
#define CMD9 9 //<2F><><EFBFBD><EFBFBD>9 <20><><EFBFBD><EFBFBD>CSD<53><44><EFBFBD><EFBFBD>
#define CMD10 10 //<2F><><EFBFBD><EFBFBD>10<31><30><EFBFBD><EFBFBD>CID<49><44><EFBFBD><EFBFBD>
#define CMD12 12 //<2F><><EFBFBD><EFBFBD>12<31><32>ֹͣ<CDA3><D6B9><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
#define CMD16 16 //<2F><><EFBFBD><EFBFBD>16<31><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SectorSize Ӧ<><D3A6><EFBFBD><EFBFBD>0x00
#define CMD17 17 //<2F><><EFBFBD><EFBFBD>17<31><37><EFBFBD><EFBFBD>sector
#define CMD18 18 //<2F><><EFBFBD><EFBFBD>18<31><38><EFBFBD><EFBFBD>Multi sector
#define CMD23 23 //<2F><><EFBFBD><EFBFBD>23<32><33><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD>sectorд<72><D0B4>ǰԤ<C7B0>Ȳ<EFBFBD><C8B2><EFBFBD>N<EFBFBD><4E>block
#define CMD24 24 //<2F><><EFBFBD><EFBFBD>24<32><34>дsector
#define CMD25 25 //<2F><><EFBFBD><EFBFBD>25<32><35>дMulti sector
#define CMD41 41 //<2F><><EFBFBD><EFBFBD>41<34><31>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>0x00
#define CMD55 55 //<2F><><EFBFBD><EFBFBD>55<35><35>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>0x01
#define CMD58 58 //<2F><><EFBFBD><EFBFBD>58<35><38><EFBFBD><EFBFBD>OCR<43><52>Ϣ
#define CMD59 59 //<2F><><EFBFBD><EFBFBD>59<35><39>ʹ<EFBFBD><CAB9>/<2F><>ֹCRC<52><43>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>0x00
//<2F><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define MSD_DATA_OK 0x05
#define MSD_DATA_CRC_ERROR 0x0B
#define MSD_DATA_WRITE_ERROR 0x0D
#define MSD_DATA_OTHER_ERROR 0xFF
//SD<53><44><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define MSD_RESPONSE_NO_ERROR 0x00
#define MSD_IN_IDLE_STATE 0x01
#define MSD_ERASE_RESET 0x02
#define MSD_ILLEGAL_COMMAND 0x04
#define MSD_COM_CRC_ERROR 0x08
#define MSD_ERASE_SEQUENCE_ERROR 0x10
#define MSD_ADDRESS_ERROR 0x20
#define MSD_PARAMETER_ERROR 0x40
#define MSD_RESPONSE_FAILURE 0xFF
#define SD_CS_PIN (GPIO_Pin_4)
#define SD_CS_PORT GPIOA
#define SD_CS_CTL(x) (x?(GPIO_WriteBit(SD_CS_PORT, SD_CS_PIN, Bit_SET)) : \
(GPIO_WriteBit(SD_CS_PORT, SD_CS_PIN, Bit_RESET)) )
#define SD_INSERT_PIN (GPIO_Pin_4)
#define SD_INSERT_PORT GPIOC
#define SD_CD_INSERT() GPIO_ReadInputDataBit(SD_INSERT_PORT, SD_INSERT_PIN)
extern u8 SD_Type;//SD<53><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 SD_SPI_ReadWriteByte(u8 data);
void SD_SPI_SpeedLow(void);
void SD_SPI_SpeedHigh(void);
u8 SD_WaitReady(void); //<2F>ȴ<EFBFBD>SD<53><44>׼<EFBFBD><D7BC>
u8 SD_GetResponse(u8 Response); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
u8 SD_Init(void); //<2F><>ʼ<EFBFBD><CABC>
u8 SD_ReadDisk(u8*buf,u32 sector,u8 cnt); //<2F><><EFBFBD><EFBFBD>
u8 SD_WriteDisk(u8*buf,u32 sector,u8 cnt); //д<><D0B4>
u32 SD_GetSectorCount(void); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 SD_GetCID(u8 *cid_data); //<2F><>SD<53><44>CID
u8 SD_GetCSD(u8 *csd_data); //<2F><>SD<53><44>CSD
void SD_SPI_Init(void);
void SD_ReadUserData(void);
void OpenSDFile(void);
int CheckUpload(void);
int programdata(void);
void removeupload(void);
void LED_GPIO_Config(void);
//-------------------------------
void log_printf(char* fmt,...);
#define LOG_DEBUG_TX_SIZE 512
typedef struct
{
unsigned char log_accepted:1;
char server_addr[64];
int server_port;
char server_path[256];
char file_name[64];
int file_length;
int read_length;
char *buff;
int buff_size;
} log_handle_t;
extern log_handle_t log_handle;
extern int check_log_file(void);
extern int log_file_handler(void);
extern void User_Write_Debug(char *loginfo, int loglen);
#endif