Hi bewing,
I have done the changes as told by you.But i am getting zero output.What i did, in my header file i changed that data type Volatile short to volatile char or unsigned char.But when i change it to volatile short,i am getting FFFFFF50 value in status register.And according to bit patten of status register,i am getting DRDY and DSC bit high.Because i am considering only the last two nibbles for my case.As i am using 16 bit registers,that why i am using volatile short as my data type.Hope it is clear to you.
I have referred one document from sourceforge:
http://minirighi.sourceforge.net/html/IdeAta_8c.html
they have the same thing, as told by you.
I am having a different code,which i m using for DVD drive.when i am testing that code for DVD drive,the last two nibbles i am getting them as 58h,that means i am getting DRDY,DSC and DRQ bits high.But when i m testing the same code for Hard disk drives,by changing the contents of Device head and Command register,i am still getting 50h for hard disks.
As far as i know hard disk is an ATA device and DVD is an ATAPI device.
What can be difference between the two drives.
For your reference i have posted the code of DVD drive:
#include "xparameters.h"
#include "stdio.h"
#include "xutil.h"
#include "atapi.h"
//========================================================
int check_val=0;
short data_write[5];
short *memory_read_data;
//====================================================
//====================================================
int main (void) {
int i=0,j=0,k=0;
/*
* Enable and initialize cache
*/
#if XPAR_MICROBLAZE_0_USE_ICACHE
microblaze_init_icache_range(0, XPAR_MICROBLAZE_0_CACHE_BYTE_SIZE);
microblaze_enable_icache();
#endif
#if XPAR_MICROBLAZE_0_USE_DCACHE
microblaze_init_dcache_range(0, XPAR_MICROBLAZE_0_DCACHE_BYTE_SIZE);
microblaze_enable_dcache();
#endif
print("-- Entering main() --\r\n");
/*
* MemoryTest routine will not be run for the memory at
* 0x00000000 (dlmb_cntlr)
* because it is being used to hold a part of this application program
*/
/* Testing SDRAM Memory (Micron_SDRAM_MT48V2M32LFFC)*/
{
XStatus status;
// print("Starting MemoryTest for Micron_SDRAM_MT48V2M32LFFC:\r\n");
// print(" Running 32-bit test...");
status = XUtil_MemoryTest32((Xuint32*)XPAR_MICRON_SDRAM_MT48V2M32LFFC_BASEADDR, 1024, 0xAAAA5555, XUT_ALLMEMTESTS);
if (status == XST_SUCCESS) {
print("PASSED!\r\n");
}
else {
print("FAILED!\r\n");
}
// print(" Running 16-bit test...");
status = XUtil_MemoryTest16((Xuint16*)XPAR_MICRON_SDRAM_MT48V2M32LFFC_BASEADDR, 2048, 0xAA55, XUT_ALLMEMTESTS);
if (status == XST_SUCCESS) {
print("PASSED!\r\n");
}
else {
print("FAILED!\r\n");
}
// print(" Running 8-bit test...");
status = XUtil_MemoryTest8((Xuint8*)XPAR_MICRON_SDRAM_MT48V2M32LFFC_BASEADDR, 4096, 0xA5, XUT_ALLMEMTESTS);
if (status == XST_SUCCESS) {
print("PASSED!\r\n");
}
else {
print("FAILED!\r\n");
}
}
/*
* Disable cache and reinitialize it so that other
* applications can be run with no problems
*/
#if XPAR_MICROBLAZE_0_USE_DCACHE
microblaze_disable_dcache();
microblaze_init_dcache_range(0, XPAR_MICROBLAZE_0_DCACHE_BYTE_SIZE);
#endif
#if XPAR_MICROBLAZE_0_USE_ICACHE
microblaze_disable_icache();
microblaze_init_icache_range(0, XPAR_MICROBLAZE_0_CACHE_BYTE_SIZE);
#endif
/***********/
Master_IDENTIFY_DEVICE(0xEC00,1);
print("-- Exiting main() --\r\n");
return;
}
void Master_IDENTIFY_DEVICE(unsigned int cmd,short pr)
{
unsigned int identify[256];
int i,d,j;
xil_printf("\r\n==========================================\r\n");
Device_selection_protocol();
/* xil_printf("Writing required command \r\n");
// Command_Register(write,0xA000,0xF400);
Command_Register(write,cmd,0xF400);
for(i=0;i<5;i++)
{
if (BUSY == 0 && DRQ == 1 || DRDY==1)
{
i =10;
xil_printf("BUSY =0 DRQ =1 OR DRDY =1\r\n");
}
else
{
Master_Status_Register();
i=2;
}
}
for(j=0;j<=256;j++)
{
*memory_location_FPGA = 0x1600;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done == 1)
{
*memory_location_FPGA = 0x0C00;
done =0;
i=10;
}
else
{
check_for_done_pin();
i=2;
}
}
// xil_printf("j =%d \r\n",j);
identify[j] = *memory_location_DR;
}
for(j=1;j<=9;j++)
readall_memory(j);
xil_printf("\r\n");
if(pr == 1)
{
for(j=0;j<=256;j++)
{
xil_printf("data[%d] %c = %x \r\n",j,identify[j],identify[j]);
}
}
*/
return ;
}
void Device_selection_protocol()
{ int i=0;
// xil_printf("\r\n Device Selection protocol Function\r\n");
Master_Status_Register();
Master_Busy_Drq();
*memory_location_DHR = 0xA000;//0x0000 ;
*memory_location_FPGA =0x7400; //0x7800 ;
check_for_done_pin();
for(i=0;i<5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0x0C00; //0x6C00 ;
done =0;
i=10;
}
else
{
check_for_done_pin();
i=2;
}
}
//DELAY(1);
Master_Status_Register();
Master_Busy_Drq();
return;
}
void Master_Status_Register()
{
int i=0;
unsigned short memory_status_register;
short error_code;
int remainder;
*memory_location_FPGA = 0xF600;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0x0C00;
done =0;
i=10;
}
else
{
i =2;
check_for_done_pin();
}
}
// reading from the memory address and comparing to expacted
memory_status_register = *memory_location_SR;
error_code = memory_status_register ;
xil_printf("Address %x Status Register %x \r\n",memory_location_SR,*memory_location_SR);
// memory_status_register = memory_status_register << 8;
// xil_printf("Address %x Status Register %x\r\n",memory_location_SR,memory_status_register);
if(memory_status_register <= 1)
{
//xil_printf("Asif");
return memory_status_register;
}
remainder = memory_status_register % 2;
if(remainder == 1) {
xil_printf("%s\r\n",Master_Status_Register_Read[0]);
Err = 1;
}
else {
Err = 0;
}
// xil_printf("Error = %x \r\n",Err);
memory_status_register = memory_status_register >> 1 ;
remainder = memory_status_register %2;
if(remainder == 1)
xil_printf("%s\r\n",Master_Status_Register_Read[1]);
memory_status_register = memory_status_register >> 1 ;
remainder = memory_status_register %2;
if(remainder == 1)
xil_printf("%s\r\n",Master_Status_Register_Read[2]);
memory_status_register = memory_status_register >> 1 ;
remainder = memory_status_register %2;
if(remainder == 1) {
xil_printf("%s\r\n",Master_Status_Register_Read[3]);
DRQ =1;
}
else {
DRQ =0;
}
// xil_printf("DRQ = %x \r\n",DRQ);
memory_status_register = memory_status_register >> 1 ;
remainder = memory_status_register %2;
if(remainder == 1)
{
xil_printf("%s\r\n",Master_Status_Register_Read[4]);
SERV =1;
}
else
{
SERV =0;
}
memory_status_register = memory_status_register >> 1 ;
remainder = memory_status_register %2;
if(remainder == 1)
xil_printf("%s\r\n",Master_Status_Register_Read[5]);
memory_status_register = memory_status_register >> 1 ;
remainder = memory_status_register %2;
if(remainder == 1)
{
xil_printf("%s\r\n",Master_Status_Register_Read[6]);
DRDY =1;
}
else
{
DRDY =0;
}
memory_status_register = memory_status_register >> 1 ;
remainder = memory_status_register %2;
if(remainder == 1) {
xil_printf("%s\r\n",Master_Status_Register_Read[7]);
BUSY = 1;
}
else {
BUSY = 0;
}
// xil_printf("BUSY = %x \r\n",BUSY);
return ;//error_code;
}
void Master_Busy_Drq()
{
int i;
for(i=0;i<5;i++) {
if(BUSY == 1 || DRQ == 1)
{
Master_Status_Register();
i=2;
}
else
i=10;
}
}
void check_for_done_pin()
{
// check slv_reg18 (0x77200024)
// pin no 3 if it is one come out from this loop else wait till it becomes zero.
unsigned short memory_status_register;
int remainder;
memory_status_register = *memory_location_DPSR;
// xil_printf("Address %x Status Register %x\r\n",memory_location_DPSR,memory_status_register);
memory_status_register = memory_status_register >> 8;
if(memory_status_register <= 1)
{
return memory_status_register;
}
remainder = memory_status_register % 2;
if(remainder == 1);
// xil_printf("a");
memory_status_register = memory_status_register >> 1 ;
remainder = memory_status_register %2;
if(remainder == 1);
// xil_printf("b");
memory_status_register = memory_status_register >> 1 ;
remainder = memory_status_register %2;
if(remainder == 1);
// xil_printf("c");
memory_status_register = memory_status_register >> 1 ;
remainder = memory_status_register %2;
if(remainder == 1);
// xil_printf("d");
memory_status_register = memory_status_register >> 1 ;
remainder = memory_status_register %2;
if(remainder == 1)
{
// xil_printf("DONE IS high\r\n");
done=1;
}
else
{
// xil_printf("DONE IS low\r\n");
done =0;
}
memory_status_register = memory_status_register >> 1 ;
remainder = memory_status_register %2;
if(remainder == 1)
INTRQ = 1;
else
INTRQ = 0;
// xil_printf("INTRQ");
memory_status_register = memory_status_register >> 1 ;
remainder = memory_status_register %2;
if(remainder == 1) ;
// xil_printf("IORDY\r\n");
memory_status_register = memory_status_register >> 1 ;
remainder = memory_status_register %2;
if(remainder == 1);
// xil_printf("dmreq\r\n");
// xil_printf("\r\n");
return;
}
void DELAY(unsigned int a)
{
int i=0,j=0;
for(i=0;i<=a;i++)
for(j=0;j<=255;j++)
;
// xil_printf("%x\t",j);
return ;
}
void Writing_required_command(short as, unsigned int value)
{
short i = 0;
// xil_printf(" Write Required Command == %x \r\n ",as);
// xil_printf(" Write Required Value == %x \r\n ",value);
switch(as)
{
case Feature:
*memory_location_FR = value;//0x0000;
*memory_location_FPGA = 0x9400;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0x8C00;
done =0;
i=10;
}
else
{
check_for_done_pin();
i=2;
}
}
break;
case Sector_count:
*memory_location_SCR = value;
*memory_location_FPGA = 0x5400;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0x4C00;
done =0;
i = 10;
}
else
{
check_for_done_pin();
i=2;
}
}
break;
case Sector_Number:
*memory_location_SNR = value;//0x0000 ;
*memory_location_FPGA = 0xD400 ;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0xCC00;
done =0;
i = 10;
}
else
{
check_for_done_pin();
i=2;
}
}
break;
case Cylinder_Low:
*memory_location_CLB = value;
*memory_location_FPGA = 0x3400 ;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0x2400;
done =0;
i = 10;
}
else
{
check_for_done_pin();
i=2;
}
}
break;
case Cylinder_High:
*memory_location_CHB = value;//0x0000;
*memory_location_FPGA = 0xB400 ;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0xA400;
done =0;
i = 10;
}
else
{
check_for_done_pin();
i=2;
}
}
break;
case Device_Head:
// Drive Head Register write
*memory_location_DHR = value;
*memory_location_FPGA = 0x7400;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0x6C00;
done =0;
i=10;
}
else
{
check_for_done_pin();
}
}
break;
default:
break;
}
//DELAY(1);
return ;
}
/*
*/
void Master_Error()
{
unsigned short memory_data_read;
short error_test;
int remainder;
xil_printf("Master Error Function\r\n");
*memory_location_FPGA = 0x9600;
check_for_done_pin();
if(done==1)
{
*memory_location_FPGA = 0x0C00;
done =0;
}
else
{
check_for_done_pin();
}
// reading from the memory address and comparing to expacted
memory_data_read = *memory_location_ER;
// memory_data_read = memory_data_read << 8;
xil_printf("Address %x Error Register Data %x\r\n",memory_location_ER,memory_data_read);
/*
if(memory_data_read <= 1)
{
// xil_printf("ASIF %x\r\n",memory_data_read);
return memory_data_read;
}
remainder = memory_data_read % 2;
if(remainder == 1)
{
xil_printf("%s\r\n",Master_error_read_BIT_0[1]);
}
else
{
xil_printf("%s\r\n",Master_error_read_BIT_0[0]);
}
memory_data_read = memory_data_read >> 1 ;
remainder = memory_data_read %2;
if(remainder == 1)
{
xil_printf("%s\r\n",Master_error_read_BIT_1[1]);
}
else
{
xil_printf("%s\r\n",Master_error_read_BIT_1[0]);
}
memory_data_read = memory_data_read >> 1 ;
remainder = memory_data_read %2;
if(remainder == 1)
{
xil_printf("%s\r\n",Master_error_read_BIT_2[1]);
}
else
{
xil_printf("%s\r\n",Master_error_read_BIT_2[0]);
}
memory_data_read = memory_data_read >> 1 ;
remainder = memory_data_read %2;
if(remainder == 1)
{
xil_printf("%s\r\n",Master_error_read_BIT_3[1]);
}
else
{
xil_printf("%s\r\n",Master_error_read_BIT_3[0]);
}
memory_data_read = memory_data_read >> 1 ;
remainder = memory_data_read %2;
if(remainder == 1)
{
xil_printf("%s\r\n",Master_error_read_BIT_4[1]);
}
else
{
xil_printf("%s\r\n",Master_error_read_BIT_4[0]);
}
memory_data_read = memory_data_read >> 1 ;
remainder = memory_data_read %2;
if(remainder == 1)
{
xil_printf("%s\r\n",Master_error_read_BIT_5[1]);
}
else
{
xil_printf("%s\r\n",Master_error_read_BIT_5[0]);
}
memory_data_read = memory_data_read >> 1 ;
remainder = memory_data_read %2;
if(remainder == 1)
{
xil_printf("%s\r\n",Master_error_read_BIT_6[1]);
}
else
{
xil_printf("%s\r\n",Master_error_read_BIT_6[0]);
}
memory_data_read = memory_data_read >> 1 ;
remainder = memory_data_read %2;
if(remainder == 1)
{
xil_printf("%s\r\n",Master_error_read_BIT_7[1]);
}
else
{
xil_printf("%s\r\n",Master_error_read_BIT_7[0]);
}*/
}
/*
*/
void readall_memory(short any)
{
//volatile int *memory_location = 0x73e00000;
volatile short *memory_location = 0x77200000;// 0x73e00000;
//int mem_size = 0x26;
short i=0;
short any1 = 0;
//xil_printf("Read all Register\r\n");
switch(any)
{
case 1:
// DATA Register
*memory_location_FPGA = 0x1600;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0x0C00;
done =0;
i=10;
}
else
{
check_for_done_pin();
}
}
xil_printf("Data Register Address = %x data == %x \r\n",memory_location_DR,*memory_location_DR);
break;
case 2:
// Read Cylinder High Register
*memory_location_FPGA = 0xB600;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0xA600;
done =0;
i=10;
}
else
{
check_for_done_pin();
}
}
xil_printf("Cylinder High Register Address = %x data == %x \r\n",memory_location_CHB_r,*memory_location_CHB_r);
break;
case 3:
// Read Cylinder Low Register
*memory_location_FPGA = 0x3600;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0x2600;
done =0;
i=10;
}
else
{
check_for_done_pin();
}
}
xil_printf("Cylinder Low Register Address = %x data == %x \r\n",memory_location_CLB_r,*memory_location_CLB_r);
break;
case 4:
// Device HEAD Register
*memory_location_FPGA = 0x7600;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0x6C00;
done =0;
i=10;
}
else
{
check_for_done_pin();
}
}
xil_printf("Device HEAD REGISTER Address = %x data == %x \r\n",memory_location_DHR_r,*memory_location_DHR_r);
break;
case 5:
// Error Register
*memory_location_FPGA = 0x9600;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0x8C00;
done =0;
i=10;
}
else
{
check_for_done_pin();
}
}
xil_printf("Error REGISTER Address = %x data == %x \r\n",memory_location_ER,*memory_location_ER);
break;
case 6:
// Sector count Register
*memory_location_FPGA = 0x5600;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0x4C00;
done =0;
i=10;
}
else
{
check_for_done_pin();
}
}
xil_printf("Sector count REGISTER Address = %x data == %x \r\n",memory_location_SCR_r,*memory_location_SCR_r);
break;
case 7:
// Sector Number Register
*memory_location_FPGA = 0xD600;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0xCC00;
done =0;
i=10;
}
else
{
check_for_done_pin();
}
}
xil_printf("Sector Number REGISTER Address = %x data == %x \r\n",memory_location_SNR_r,*memory_location_SNR_r);
break;
case 8:
// Status Register
*memory_location_FPGA = 0xF600;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0xEC00;
done =0;
i=10;
}
else
{
check_for_done_pin();
}
}
xil_printf("Status REGISTER Address = %x data == %x \r\n",memory_location_SR,*memory_location_SR);
break;
case 9:
// read Alternate Status Register
*memory_location_FPGA = 0x7A00;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0x6A00;
done =0;
i=10;
}
else
{
check_for_done_pin();
}
}
xil_printf("Read Alternate Status Register Address = %x Memory Read data == %x \r\n",memory_location_ASR,*memory_location_ASR);
break;
}
return;
}
/*
*/
/*
This function is working fine
*/
void Master_Alt_Status_Register()
{ int i=0;
*memory_location_FPGA = 0x7A00;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done==1)
{
*memory_location_FPGA = 0x6C00;
done =0;
i=10;
}
else
{
check_for_done_pin();
}
}
xil_printf("Read Alternate Status Register Address = %x Memory Read data == %x \r\n",memory_location_ASR,*memory_location_ASR);
return;
}
/*
read =1
write =0
*/
void Command_Register(short rw,int cmd,int Add_cs)
{
short m=0;
xil_printf("RW =%x,CMD =%x,add_cs= %x\r\n ",rw,cmd,Add_cs);
if(rw == read)
{
*memory_location_FPGA = Add_cs;
}
if(rw == write)
{
*memory_location_CR = cmd;
*memory_location_FPGA = Add_cs;
}
check_for_done_pin();
for(m=0;m<=5;m++)
{
if(done == 1)
{
*memory_location_FPGA = 0x0C00;
done =0;
m=10;
}
else
{
// xil_printf("a1");
check_for_done_pin();
m=2;
}
}
return ;
}
/*
drw = 1 read
drw = 0 write
*/
void Data_Register_read_Write(short drw,short data)
{
short i=0;
if(drw == write)
{
*memory_location_DW = data;//0x0000;
*memory_location_FPGA = 0x1400;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done == 1)
{
*memory_location_FPGA = 0x0C00;
done =0;
i=10;
}
else
{
check_for_done_pin();
i=2;
}
}
xil_printf("Data = %x \r\n",*memory_location_DW);
}
if(drw == read)
{
*memory_location_FPGA = 0x1600;
check_for_done_pin();
for(i=0;i<=5;i++)
{
if(done == 1)
{
*memory_location_FPGA = 0x0C00;
done =0;
i=10;
}
else
{
check_for_done_pin();
i=2;
}
}
xil_printf("Data %x \r\n",*memory_location_DR);
}
return ;
}