📄 ide_x_hw.c
字号:
Description:
FS driver hardware layer function. Set the CYLINDER HIGH register.
Parameters:
Unit - Unit number.
Data - Value to write to the CYLINDER HIGH register.
Return value:
None.
*/
void FS_IDE_HW_X_SetCylHigh(FS_u32 Unit, unsigned char Data) {
// __MEMCFG2 = 0x1f13; /* CS5 8 bit */
Cylinder_High = Data;
}
/*********************************************************************
*
* FS_IDE_HW_X_GetCylHigh
*
Description:
FS driver hardware layer function. Read the CYLINDER HIGH register.
Parameters:
Unit - Unit number.
Return value:
Value of the CYLINDER HIGH register.
*/
unsigned char FS_IDE_HW_X_GetCylHigh(FS_u32 Unit) {
unsigned char data;
// __MEMCFG2 = 0x1f13; /* CS5 8 bit */
data =Cylinder_High;
return data;
}
/*********************************************************************
*
* FS_IDE_HW_X_SetDevice
*
Description:
FS driver hardware layer function. Set the DEVICE/HEAD register.
Parameters:
Unit - Unit number.
Data - Value to write to the DEVICE/HEAD register.
Return value:
None.
*/
void FS_IDE_HW_X_SetDevice(FS_u32 Unit, unsigned char Data) {
// __MEMCFG2 = 0x1f13; /* CS5 8 bit */
SDH = Data;
}
/*********************************************************************
*
* FS_IDE_HW_X_GetDevice
*
Description:
FS driver hardware layer function. Read the DEVICE/HEAD register.
Parameters:
Unit - Unit number.
Return value:
Value of the DEVICE/HEAD register.
*/
unsigned char FS_IDE_HW_X_GetDevice(FS_u32 Unit) {
unsigned char data;
// __MEMCFG2 = 0x1f13; /* CS5 8 bit */
data = SDH;
return data;
}
/*********************************************************************
*
* FS_IDE_HW_X_SetCommand
*
Description:
FS driver hardware layer function. Set the COMMAND register.
Parameters:
Unit - Unit number.
Data - Value to write to the COMMAND register.
Return value:
None.
*/
void FS_IDE_HW_X_SetCommand(FS_u32 Unit, unsigned char Data) {
// __MEMCFG2 = 0x1f13; /* CS5 8 bit */
Command_Reg = Data;
}
/*********************************************************************
*
* FS_IDE_HW_X_GetStatus
*
Description:
FS driver hardware layer function. Read the STATUS register.
Parameters:
Unit - Unit number.
Return value:
Value of the STATUS register.
*/
unsigned char FS_IDE_HW_X_GetStatus(FS_u32 Unit) {
unsigned char data;
// __MEMCFG2 = 0x1f13; /* CS5 8 bit */
data = Status_Reg;
return data;
}
/*********************************************************************
*
* FS_IDE_HW_X_SetDevControl
*
Description:
FS driver hardware layer function. Set the DEVICE CONTROL register.
Parameters:
Unit - Unit number.
Data - Value to write to the DEVICE CONTROL register.
Return value:
None.
*/
void FS_IDE_HW_X_SetDevControl(FS_u32 Unit, unsigned char Data) {
// __MEMCFG2 = 0x1f13; /* CS5 8 bit */
Dev_control_Reg = Data;
}
/*********************************************************************
*
* FS_IDE_HW_X_GetAltStatus
*
Description:
FS driver hardware layer function. Read the ALTERNATE STATUS register.
Parameters:
Unit - Unit number.
Return value:
Value of the ALTERNATE STATUS register.
*/
unsigned char FS_IDE_HW_X_GetAltStatus(FS_u32 Unit) {
unsigned char data;
// __MEMCFG2 = 0x1f13; /* CS5 8 bit */
data = Alt_Status_Reg;
return data;
}
/*********************************************************************
*
* FS_IDE_HW_X_DetectStatus
*
Description:
FS driver hardware layer function. Check if the device is present.
Parameters:
Unit - Unit number.
Return value:
==0 - Device is connected.
!=0 - Device has not been found.
*/
char FS_IDE_HW_X_DetectStatus(FS_u32 Unit) {
static char init;
int lexp;
unsigned char a;
unsigned char b;
if (!init) {
init = 1;
// __MEMCFG2 = 0x1f13; /* CS5 8 bit */
// __SYSCON1 |= 0x40000ul; /* enable expansion clock */
}
if (Unit == 0) {
FS_IDE_HW_X_SetDevice(Unit, 0xa0);
}
else {
FS_IDE_HW_X_SetDevice(Unit, 0xe0);
}
HW__DELAY400NS;
FS_IDE_HW_X_SetSectorCount(Unit, 0x55);
FS_IDE_HW_X_SetSectorNo(Unit, 0xaa);
FS_IDE_HW_X_SetSectorCount(Unit, 0xaa);
FS_IDE_HW_X_SetSectorNo(Unit, 0x55);
FS_IDE_HW_X_SetSectorCount(Unit, 0x55);
FS_IDE_HW_X_SetSectorNo(Unit, 0xaa);
a = FS_IDE_HW_X_GetSectorCount(Unit);
b = FS_IDE_HW_X_GetSectorNo(Unit);
lexp = (a == 0x55);
lexp = lexp && (b == 0xaa);
if (lexp) {
_HW_DevicePresent[Unit] = 1;
}
else {
_HW_DevicePresent[Unit] = 0;
}
return (!_HW_DevicePresent[Unit]);
}
/*********************************************************************
*
* FS_IDE_HW_X_HWReset
*
Description:
FS driver hardware layer function. This function is called, when
the driver detects a new media is present. For ATA HD drives, there
is no action required and this function can be empty.
When using a CF card, please be aware, that the card needs to be
power cycled while ~OE is grounded. If the card is inserted, VCC &
GND will provide the card before ~OE is connected and the card will
be in PC Card ATA mode.
Parameters:
Unit - Unit number.
Return value:
None.
*/
void FS_IDE_HW_X_HWReset(FS_u32 Unit) {
//volatile unsigned long int to;
// if (Unit!=0) {
// return;
// }
// P8 |= 0x10; /* power off */
// PD7 = 0x00;
// to = 10000;
// while (to) {
// to--;
// }
// PD7 = 0xff;
// P8 &= 0xef; /* power on */
// P7 |= 0x80; /* RESET high */
// P7 &= 0x7f; /* RESET low */
// FS__IDE_DELAY_RESET;
// P7 |= 0x80; /* RESET high */
if (Unit != 0) {
return;
}
}
//-------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------
int FS__IDE_Init(FS_u32 Unit)
{
printf("The present LBA is:0x%x 0x%x 0x%x 0x%x test01\n",LBA3,LBA2,LBA1,LBA0);
while ((Status_Reg & 0xC0)!=0x40);// Wait for RDY and Not BUSY //
Dev_control_Reg=0x0c;//Command_Reg=0x91;// Reset with SRCT=1 for device control register //
LBA3=0xe0;
LBA2=0x00;
LBA1=0x00;
LBA0=0x01;
printf("The present LBA is:0x%x 0x%x 0x%x 0x%x test02\n",LBA3,LBA2,LBA1,LBA0);
return 0;
}
int FS__IDE_ReadSector(FS_u32 Unit,unsigned long Sector,unsigned char *pBuffer)
{
U16 DATA_TEMP;
U32 i,LBA,Drv;
unsigned char *pBuf;
pBuf=pBuffer;
LBA=Sector;
Drv=0xe0;
Sector_Count=0x01;
LBA3=0xe0|(LBA/256/256/256);
LBA2=(LBA/256/256);
LBA1=(LBA/256);
LBA0=(LBA);
//printf("(R)0x%x-->",LBA);
while ((Status_Reg & 0xC0)!=0x40);// Wait for RDY and Not BUSY //
Command_Reg=0x20;//Read_Sectors_Retry;// Issue the Read Sectors with Retry ATA command //
while ((Status_Reg & 0x88)!=0x08);// Wait for DRQ and NOT BUSY //
//while (Status_Reg !=0x58);//printf("You mei you qintu!\n");
for(i=0;i<(HDD_Sector_Size/2);i++)
{// Driver is Ready for read out data //
DATA_TEMP=Data_Reg_re;
*pBuf=DATA_TEMP%256;
pBuf++;
*pBuf=DATA_TEMP/256;
pBuf++;
}
if(Status_Reg==0x20) printf("Write ERRor001!!");
if((Status_Reg & 0x08)==0x08)// Judge the DRQ //
{
printf("READ ERRor001!!");
return(ATA_FAIL);
} // If the DRQ is still High,There is some error //
else
return(ATA_OK); // ATA OK //
}
int FS__IDE_WriteSector(FS_u32 Unit,unsigned long Sector,unsigned char *pBuffer)
{
U16 DATA_TEMP;
U32 i,k;
unsigned long LBA;
unsigned char *buf;
LBA=Sector;
buf=pBuffer;
printf("The start of write LBA is: 0x%x\n",Sector);
Sector_Count=0x01;
LBA3=0xe0|(LBA>>24);
LBA2=(LBA>>16);
LBA1=(LBA>>8);
LBA0=(LBA);
while ((Status_Reg & 0xC0)!=0x40);// Wait for RDY
Command_Reg=Write_Sectors_Retry;// Issue the Read Sectors with Retry ATA command //
while ((Status_Reg & 0x88)!=0x08);// Wait for DRQ and NOT BUSY
// Write Out Sec_Num*HDD_Sector_Size Bytes Data to HDD //
for(i=0;i<(HDD_Sector_Size/2);i++)
{
DATA_TEMP=*buf;
buf++;
Data_Reg_wr=(*buf*256)+DATA_TEMP;
buf++;
}
// Judge the DRQ //
if((Status_Reg & 0x08)==0x08)
return(ATA_FAIL); // If the DRQ is still High,There is some error //
else
return(ATA_OK); // ATA OK //
}
#endif /* FS_USE_IDE_DRIVER */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -