📄 ch375_drv.c
字号:
#include "AT91SAM7S64.h"
#include "Board.h"
#include "type.h"
#include "dbgu.h"
#include "spi.h"
#include "port.h"
#include "ch375_drv.h"
#define CMD_REG 0x7f
#define DATA_REG 0x7e
/*
//----------------------------------------------------------------------
INT8U Usb_Interrupt()
{
INT8U u8Status;
while(1 == port_GetINT(CH375_INTRQ));
port_SendData(CMD_REG, 0x22);
delay(0x0fff);
u8Status = port_ReadData(DATA_REG);
return u8Status;
}
//----------------------------------------------------------------------
void CH375_Init()
{
INT8U temp;
CHRST: port_SendData(CMD_REG, 0x05); //reset
for(temp=0; temp<10; temp++)
{
delay(0xffff);
}
port_SendData(CMD_REG, 0x06); //check exist
port_SendData(DATA_REG, 0xaa); //send data
temp = port_ReadData(DATA_REG); //~data
if(temp == 0x55)
{
DBGU_Print("test chip successful\n");
}
else
{
DBGU_Print("test chip failed\n");
goto CHRST;
}
port_SendData(CMD_REG, 0x15); //set usb mode
port_SendData(DATA_REG, 0x06);
}
//----------------------------------------------------------------------
INT8U Udsik_Init()
{
INT8U u8Status;
port_SendData(CMD_REG,0x22);
u8Status = port_ReadData(DATA_REG);
if(u8Status == 0x16)
{
return u8Status;
}
port_SendData(CMD_REG,0x51);
for(u8Status=0; u8Status<10; u8Status++)
{
delay(0xffff);
}
u8Status = Usb_Interrupt();
if(u8Status != 0x14) //not success
{
return u8Status;
}
else
{
DBGU_Print("disk init successful\n");
}
port_SendData(CMD_REG, 0x53);
u8Status = Usb_Interrupt();
if(u8Status != 0x14)
{
port_SendData(CMD_REG, 0x53);
u8Status = Usb_Interrupt();
}
else
{
DBGU_Print("disk size successful\n");
}
if(u8Status != 0x14)
{
return u8Status;
}
return 0; //success
}
//----------------------------------------------------------------------
INT8U Udisk_ReadSector(INT32U u32Addr, INT8U *buffer)
{
INT8U count;
INT8U num;
RESECTOR: port_SendData(CMD_REG, 0x54);
port_SendData(DATA_REG, (INT8U)(u32Addr));
port_SendData(DATA_REG, (INT8U)(u32Addr >> 8));
port_SendData(DATA_REG, (INT8U)(u32Addr >> 16));
port_SendData(DATA_REG, (INT8U)(u32Addr >> 24));
port_SendData(DATA_REG, 1);
for(num=0; num<8; num++)
{
count = Usb_Interrupt();
if(count == 0x1d) //
{
port_SendData(CMD_REG, 0x28);
delay(0x0fff);
// port_SetAddress(DATA_REG);
count = port_ReadData(DATA_REG);//port_ReadDataNoAdd();
while(count --)
{
*buffer ++ = port_ReadData(DATA_REG);
}
delay(0x0fff);
port_SendData(CMD_REG, 0x55);
}
else
{
DBGU_Print("read sector failed\n");
goto RESECTOR;
}
}
count = Usb_Interrupt();
if(count == 0x14)
{
return 0;
}
return count;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -