📄 ide_diver.c
字号:
/*
Module Name : ide_drive.c
Functions : ide_drive
exe_mem_reg_init
software_ide_reset
check_status
ata_command
wait_drq
Purpose :
Notes :
*/
// Local header files
#include <user/ide_interface.h>
// Global variables
unsigned short drive_info_src[10];
// Forward declarations of functions included
void ide_drive(void);
void exe_mem_reg_init( void )
{
REG_MEM R_CS1CTRL2 = 0x1440; //good
REG_MEM R_CS1CTRL1A= 0x0c0d; //good
REG_MEM R_CS1CTRL1B= 0x0508; //good
REG_MEM R_CFCTRL2 = 0X0000; // disable IOIS16 pin function
REG_MEM R_CFCTRL1 = 0X0000;
REG_MEM 0x00030a4a = 0x09; //flash memory
REG_MEM 0x00030a4c = 0x49; //SDRAM
REG_MEM 0x00030a4e = 0x61; //CF
REG_MEM 0x00030a50 = 0x79; //Smart Media
REG_MEM 0x00030a52 = 0x91; //EM_CE0
REG_MEM 0x00030a54 = 0xA9; //EM_CE1
}
void software_ide_reset(void)
{
unsigned short *p,temp;
p = (unsigned short *)(control_register);
//*(unsigned short *)(control_register) = 4;
*p |= 0x04; /* reset ATC */
for(temp=0 ; temp < 1000 ; temp++);
//*(unsigned short *)(control_register) = 2;
*p = 0x02; /* Disable INTRQ */
}
unsigned char check_status(void)
{
unsigned int i,j;
unsigned int status_value;
for ( i = 0; i < 65536; i++ ) /* Wait loop for card ready (Adjust loop count for device ) */
{
for ( j = 0; j < 65536; j++ )
{
status_value = REG_MEM status_register;
status_value &= 0x0080;
;
;
;
if(status_value == 0)
break; /* READY ? */
}
if ( j < 65536 )
break;
}
for ( i = 0; i < 0x0C350; i ++ )
{
status_value = REG_MEM status_register;
;
;
;
status_value &= 0x0060;
;
;
;
if (status_value == 0x40) break;
}
if ( i == 0x0c350 ) return (0); /* fail */
return (1); /* ok */
}
void ata_command(unsigned char *cmdbuf)
{
REG_MEM data_register = cmdbuf[0];
REG_MEM error_register = cmdbuf[1];
REG_MEM sector_count = cmdbuf[2];
REG_MEM sector_number = cmdbuf[3];
REG_MEM cylinder_low = cmdbuf[4];
REG_MEM cylinder_high = cmdbuf[5];
REG_MEM drive_head = cmdbuf[6];
REG_MEM status_register = cmdbuf[7];
}
int wait_drq(void)
{
unsigned int value_s;
/* CMG we set to drive_head for alignment. It's just before status */
value_s = REG_MEM status_register;
;
;
;
//value_s >>= 24;
value_s &= 0x0008;
value_s >>= 3;
value_s &= 0x0001;
;
;
;
return (value_s);
}
void ide_drive(void)
{
unsigned short loop_count;
unsigned short identify_drive_information[256];
unsigned char atcmb[8];
unsigned short *p, *dptr;
exe_mem_reg_init();
for(loop_count = 0 ; loop_count<256 ; loop_count++)
{
identify_drive_information[loop_count] = 0;
}
software_ide_reset();
do{}while((check_status()==0));
do{}while((check_status()==0));
atcmb[6] = 0xa0;
atcmb[7] = 0xec; /* 0xEC = identify command */
ata_command(atcmb);
do{}while((check_status()==0));
do{}while((wait_drq()==0)); //do{}while((read_intrq() == 0));
p = (unsigned short *)(data_register); /* ATA_DATA_register address */
dptr = identify_drive_information;
for(loop_count = 0 ; loop_count<128 ; loop_count++)
{
/* obtain data of Identify Drive Information */
*dptr++ = *p;
*dptr++ = *p;
}
//27-46 M F Model number (40 ASCII characters)
for(loop_count = 0 ; loop_count<10 ; loop_count++) {
drive_info_src[loop_count] = identify_drive_information[loop_count+27];
}
/* check identify_drive_information[27] ~ identify_drive_information[46] */
/* identify_drive_information[27 - 46] = Hard-Disk manufacturer */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -